Commit 581d8b5f authored by renjie's avatar renjie

修改admin bug

修改ip和shop对应关系存储
parent 706b227b
package com.edgec.browserbackend;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
......@@ -51,4 +54,18 @@ public class BrowserBackendApplication {
};
}
}
// @Bean
// public ServletWebServerFactory servletContainer() {
// TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
// tomcat.addAdditionalTomcatConnectors(createStandardConnector());
// return tomcat;
// }
//
// private Connector createStandardConnector() {
// Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
// connector.setPort(8080);
// return connector;
// }
}
package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.browser.dto.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
......@@ -18,6 +19,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Account findByPhoneNumber(String phone);
Account findByPhoneNumberAndParentIsNull(String phone);
List<Account> findByParent(String parent);
List<Account> findByParentIsNull();
......@@ -26,6 +29,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAll(Pageable pageable);
List<Account> findByNameIn(List<String> names);
......
......@@ -87,7 +87,7 @@ public class AdministratorServiceImpl implements AdministratorService {
@Override
public Account getAccountByPhoneNumber(String phoneNumber) {
Account account = accountRepository.findByPhoneNumber(phoneNumber);
Account account = accountRepository.findByPhoneNumberAndParentIsNull(phoneNumber);
if (account == null)
throw new ClientRequestException(AccountErrorCode.PHONENOTEXIST, "Can not find account with phone number" + phoneNumber);
return account;
......@@ -161,7 +161,7 @@ public class AdministratorServiceImpl implements AdministratorService {
try {
Date dateTime1 = formatter.parse(strDate1);
Date dateTime2 = formatter.parse(strDate2);
accounts = accountRepository.findAllBySignupDateBetween(pageable, dateTime1, dateTime2);
accounts = accountRepository.findAllBySignupDateBetweenAndParentIsNull(pageable, dateTime1, dateTime2);
}catch (ParseException e){
e.printStackTrace();
......
package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue;
......
......@@ -26,7 +26,7 @@ public class IpControlloer {
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){
ResultDto resultDto = new ResultDto();
try {
IpTransactionDto ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
List<String> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
......@@ -102,23 +102,6 @@ public class IpControlloer {
}
@RequestMapping(value = "/queryTransaction", method = RequestMethod.POST)
public ResultDto queryTransaction(Principal principal, @RequestBody IpTransactionDto ipTransactionDto) {
ResultDto resultDto = new ResultDto();
try {
IpTransactionDto ipTransactionDto1 = ipResourceService.queryTransaction(principal.getName(), ipTransactionDto.getTid());
resultDto.setData(ipTransactionDto1);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResultDto updateIp(Principal principal, @RequestBody IpResourceUpdateDto ipResourceUpdateDto) {
ResultDto resultDto = new ResultDto();
......
......@@ -31,12 +31,13 @@ public class IpResource implements Serializable {
private String username;
private String owner;
private String userParent;
private String shopId;
private String shopName;
private List<String> protocol;
private String password;
private double price;
private String shopId;
private String shopName;
private boolean isLocked;
private long lockTimestamp;
......@@ -165,22 +166,6 @@ public class IpResource implements Serializable {
this.userParent = userParent;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public List<String> getProtocol() {
return protocol;
}
......@@ -252,4 +237,20 @@ public class IpResource implements Serializable {
public void setPrice(double price) {
this.price = price;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 9:42 上午
**/
@Document("iptransaction")
public class IpTransaction {
@Id
private String tid;
private String username;
private long createTime;
private int status;
private List<String> ipIds;
private boolean isLocked;
private long lockTimestamp;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getTid() {
return tid;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getCreateTime() {
return createTime;
}
public void setTid(String tid) {
this.tid = tid;
}
public List<String> getIpIds() {
return ipIds;
}
public void setIpIds(List<String> ipIds) {
this.ipIds = ipIds;
}
public void setLocked(boolean locked) {
isLocked = locked;
}
public boolean isLocked() {
return isLocked;
}
public long getLockTimestamp() {
return lockTimestamp;
}
public void setLockTimestamp(long lockTimestamp) {
this.lockTimestamp = lockTimestamp;
}
}
......@@ -23,14 +23,6 @@ public class Shop {
private String shopPlatform;
private String ipRegion;
private String ipRegionCn;
private String ip;
private String ipId;
private String shopAccount;
private String shopPassword;
......@@ -71,12 +63,6 @@ public class Shop {
}
public Shop of(Shop shop) {
if (shop.getIp() != null)
this.setIp(shop.getIp());
if (shop.getIpId() != null)
this.setIpId(shop.getIpId());
if (shop.getIpRegion() != null)
this.setIpRegion(shop.getIpRegion());
if (shop.getShopUrl() != null)
this.setShopUrl(shop.getShopUrl());
if (shop.getOwner() != null)
......@@ -97,27 +83,13 @@ public class Shop {
this.setShopCookie(shop.getShopCookie());
if (shop.getCreateTime() != 0)
this.setCreateTime(shop.getCreateTime());
if (shop.getIpRegionCn() != null)
this.setIpRegionCn(shop.getIpRegionCn());
return this;
}
public String getIp() {
return ip;
}
public String getShopId() {
return shopId;
}
public String getIpId() {
return ipId;
}
public String getIpRegion() {
return ipRegion;
}
public String getShopUrl() {
return shopUrl;
}
......@@ -138,22 +110,10 @@ public class Shop {
return transferStatus;
}
public void setIp(String ip) {
this.ip = ip;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public void setIpId(String ipId) {
this.ipId = ipId;
}
public void setIpRegion(String ipRegion) {
this.ipRegion = ipRegion;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
......@@ -214,11 +174,4 @@ public class Shop {
this.createTime = createTime;
}
public String getIpRegionCn() {
return ipRegionCn;
}
public void setIpRegionCn(String ipRegionCn) {
this.ipRegionCn = ipRegionCn;
}
}
......@@ -17,8 +17,6 @@ public class UserShop {
private String groupId;
private String ipId;
public UserShop(){
}
......@@ -37,7 +35,6 @@ public class UserShop {
this.username = username;
this.shopId = shopId;
this.groupId = groupId;
this.ipId = ipId;
}
public String getId() {
......@@ -72,11 +69,4 @@ public class UserShop {
this.groupId = groupId;
}
public String getIpId() {
return ipId;
}
public void setIpId(String ipId) {
this.ipId = ipId;
}
}
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 9:57 上午
**/
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpTransactionDto {
private String tid;
private int status;
private List<IpResourceDto> ipResourceDtos;
public IpTransactionDto(){
}
public IpTransactionDto(IpTransaction ipTransaction) {
this.tid = ipTransaction.getTid();
this.status = ipTransaction.getStatus();
ipResourceDtos = new ArrayList<>();
}
public String getTid() {
return tid;
}
public void setTid(String tid) {
this.tid = tid;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public List<IpResourceDto> getIpResourceDtos() {
return ipResourceDtos;
}
public void setIpResourceDtos(List<IpResourceDto> ipResourceDtos) {
this.ipResourceDtos = ipResourceDtos;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -14,19 +15,22 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
IpResource findByIdAndIsDeletedAndIsLocked(String id, boolean isDeleted, boolean isLocked);
IpResource findByIdAndIsDeleted(String id, boolean isDeleted);
List<IpResource> findByIdInAndIsDeleted(List<String> ipIds, boolean isDeleted);
List<IpResource> findByShopIdInAndIsDeleted(List<String> ipIds, boolean isDeleted);
Page<IpResource> findByIdInAndIsDeletedOrderByPurchasedTimeDesc(List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted);
List<IpResource> findByOwnerAndStatusIsNotInAndIsDeletedAndShopIdIsNull(String owner, List<Integer> status, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int status, boolean isDeleted);
List<IpResource> findByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
List<IpResource> findByStatusAndShopIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
Page<IpResource> findByAddrLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String addr, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String vendor, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByRegionCnLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String region, List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByRegionCnLikeAndShopIdInAndIsDeleted(String regionCn, List<String> shopIds, boolean isDeleted);
List<IpResource> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp);
List<IpResource> findByValidTimeBetween(long beginTime, long endTime);
IpResource findByShopIdAndIsDeleted(String shopId, boolean isDeleted);
int countByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 5:21 下午
**/
public interface IpTransactionRepository extends MongoRepository<IpTransaction, String>, IpTransactionRepositoryCustom {
List<IpTransaction> findByStatus(int status);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import java.util.List;
public interface IpTransactionRepositoryCustom {
boolean lockTask(IpTransaction ipTransaction);
boolean unLockTask(String id);
List<IpTransaction> sampleTasks(int status, long timestamp);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.mongodb.client.result.UpdateResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.SampleOperation;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Update;
import java.time.Instant;
import java.util.List;
import static org.springframework.data.mongodb.core.query.Criteria.where;
public class IpTransactionRepositoryCustomImpl implements IpTransactionRepositoryCustom {
@Autowired
MongoTemplate mongoTemplate;
@Override
public boolean lockTask(IpTransaction ipTransaction) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
Criteria criteria = new Criteria();
criteria.orOperator(where("tid").is(ipTransaction.getTid()).and("isLocked").is(false).and("status").is(ipTransaction.getStatus()),
where("lockTimestamp").lte(Instant.now().minusSeconds(300).toEpochMilli()).and("status").is(ipTransaction.getStatus()));
basicQuery.addCriteria(criteria);
Update update = new Update();
update.set("isLocked", true).set("lockTimestamp", Instant.now().toEpochMilli());
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
}
@Override
public boolean unLockTask(String id) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("id").is(id));
Update update = new Update();
update.set("isLocked", false).set("lockTimestamp", Instant.now().toEpochMilli());
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
}
@Override
public List<IpTransaction> sampleTasks(int status, long timestamp) {
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").is(status).and("isLocked").is(false),
where("isLocked").is(true).and("lockTimestamp").lte(timestamp));
MatchOperation match = Aggregation.match(matchCriteria);
SampleOperation sample = Aggregation.sample(20);
AggregationResults<IpTransaction> results = mongoTemplate.aggregate(Aggregation.newAggregation(match, sample), IpTransaction.class, IpTransaction.class);
List<IpTransaction> mappedResults = results.getMappedResults();
return mappedResults;
}
}
......@@ -8,9 +8,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> {
Page<Shop> findByShopIdInAndIpRegionCnLikeOrderByCreateTimeDesc(List<String> shopIds, String ipRegion, Pageable pageable);
Page<Shop> findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLikeOrderByCreateTimeDesc(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByShopIdInOrderByCreateTimeDesc(List<String> shopIds, Pageable pageable);
List<Shop> findByOwnerAndIpIsNotNull(String username);
}
......@@ -7,14 +7,9 @@ import java.util.List;
public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom {
List<UserShop> findByUsername(String username);
List<UserShop> findByUsernameAndIpIdIsNull(String username);
UserShop findByUsernameAndShopId(String username, String shopId);
List<UserShop> findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId);
List<UserShop> findByUsernameAndGroupIdAndIpIdIsNull(String username, String groupId);
List<UserShop> findByUsernameAndGroupIdAndIpIdIsNotNull(String username, String groupId);
List<UserShop> findByUsernameAndShopIdIn(String username, List<String> shopIds);
List<UserShop> findByUsernameAndIpIdIsNotNull(String username);
int countByUsernameAndIpIdIsNull(String username);
int countByUsername(String username);
}
......@@ -62,27 +62,19 @@ public class IpAndShopServiceImpl implements IpAndShopService {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
}
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopRequestDto);
}
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
IpResource bind = ipResourceRepository.findByShopIdAndIsDeleted(shopId, false);
if (bind != null) {
shopRequestDto.setShopId(shopId);
shopRequestDto.setIpId(ipResource.getId());
unBindShop(username, shopRequestDto);
}
try {
shop.setIp(ipResource.getAddr());
shop.setIpId(ipResource.getId());
shop.setIpRegion(ipResource.getRegion());
shop.setIpRegionCn(ipResource.getRegionCn());
shopRepository.save(shop);
ipResource.setShopId(shopId);
if (shop.getShopName()!=null)
ipResource.setShopName(shop.getShopName());
ipResource.setShopId(shop.getShopId());
ipResource.setShopName(shop.getShopName());
ipResourceRepository.save(ipResource);
List<UserShop> userShopList = userShopRepository.findByShopId(shopId);
for (UserShop userShop1 : userShopList) {
userShop1.setIpId(ipResource.getId());
userShopRepository.save(userShop1);
}
} catch (Exception e) {
logger.error("fail to bind shop and ip", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......@@ -113,7 +105,7 @@ public class IpAndShopServiceImpl implements IpAndShopService {
}
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
if (!ipResource.getId().equals(shop.getIpId()))
if (ipResource.getShopId() == null && !ipResource.getShopId().equals(shop.getShopId()))
throw new ClientRequestException(BrowserErrorCode.IPNOTBINDTOSHOP);
try {
List<BindHistory> history = ipResource.getBindHistory();
......@@ -123,19 +115,9 @@ public class IpAndShopServiceImpl implements IpAndShopService {
bindHistory.setShopName(shop.getShopName());
bindHistory.setUnbindTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
history.add(bindHistory);
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
shop.setIpRegionCn(null);
ipResource.setShopId(null);
ipResource.setShopName(null);
ipResourceRepository.save(ipResource);
shopRepository.save(shop);
List<UserShop> userShopList = userShopRepository.findByShopId(shopId);
for (UserShop userShop1 : userShopList) {
userShop1.setIpId(null);
userShopRepository.save(userShop1);
}
} catch (Exception e) {
logger.error("fail to unbind", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......
......@@ -80,9 +80,6 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private PlatformOptionsRepository platformOptionsRepository;
@Autowired
private IpTransactionRepository ipTransactionRepository;
@Autowired
private IpAndShopService ipAndShopService;
......@@ -165,7 +162,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
@Override
public IpTransactionDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
public List<String> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -193,11 +190,6 @@ public class IpResourceServiceImpl implements IpResourceService {
else
password = genRandom(3, 12);
IpTransaction ipTransaction = new IpTransaction();
ipTransaction.setCreateTime(Instant.now().toEpochMilli());
ipTransaction.setUsername(username);
ipTransaction.setStatus(0);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> ipIds = new ArrayList<>();
......@@ -239,17 +231,6 @@ public class IpResourceServiceImpl implements IpResourceService {
ipIds.add(ipResource1.getId());
}
if (ipResourceRequestDto.getVendor().equals("local")) {
ipTransaction.setStatus(1);
ipTransactionRepository.save(ipTransaction);
}
ipTransaction.setIpIds(ipIds);
ipTransactionRepository.save(ipTransaction);
IpTransactionDto ipTransactionDto = new IpTransactionDto(ipTransaction);
ipTransactionDto.setIpResourceDtos(ipResourceDtos);
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1, ipResourceRequestDto.getPayMethod());
accountService.chargeByMoney(username, newprice * ipChargeRequestDto.getAmount(), ipChargeRequestDto);
......@@ -259,7 +240,8 @@ public class IpResourceServiceImpl implements IpResourceService {
shopRequestDto.setShopId(ipResourceRequestDto.getShopId());
ipAndShopService.bindShop(username, shopRequestDto);
}
return ipTransactionDto;
return ipIds;
}
@Override
......@@ -379,8 +361,10 @@ public class IpResourceServiceImpl implements IpResourceService {
return;
}
UserShop userShop = null;
if (ipResource.getShopId() != null) {
userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId());
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null) {
userShop = userShopRepository.findByUsernameAndShopId(username, shop.getShopId());
if (userShop == null) {
ipOperationResultDto.getFailList().add(ipAddr);
return;
......@@ -395,20 +379,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if (ipResource.getStatus() == 6)
ipResourceRepository.delete(ipResource);
else {
ipResource.setShopId(null);
ipResource.setShopName(null);
ipResource.setDeleted(true);
ipResourceRepository.save(ipResource);
}
if (userShop != null){
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null) {
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
shopRepository.save(shop);
}
userShop.setIpId(null);
userShopRepository.save(userShop);
}
ipOperationResultDto.getSuccessList().add(ipAddr);
} catch (Exception e) {
logger.error("fail to renew ip", e.getMessage());
......@@ -432,8 +407,9 @@ public class IpResourceServiceImpl implements IpResourceService {
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
}
UserShop userShop = null;
if (ipResource.getShopId() != null) {
userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId());
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null) {
userShop = userShopRepository.findByUsernameAndShopId(username, shop.getShopId());
if (userShop == null) {
ipOperationResultDto.getFailList().add(ipId);
return;
......@@ -443,18 +419,9 @@ public class IpResourceServiceImpl implements IpResourceService {
return;
}
ipResource.setDeleted(true);
ipResource.setShopId(null);
ipResource.setShopName(null);
ipResourceRepository.save(ipResource);
if (userShop != null){
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null) {
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
shopRepository.save(shop);
}
userShop.setIpId(null);
userShopRepository.save(userShop);
}
ipOperationResultDto.getSuccessList().add(ipId);
});
}
......@@ -471,22 +438,21 @@ public class IpResourceServiceImpl implements IpResourceService {
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
List<String> ipIds = userShopRepository.findByUsername(username).stream().filter(x -> (x.getShopId() != null && x.getIpId() != null))
.map(x -> x.getIpId()).collect(Collectors.toList());
List<String> shopIds = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).collect(Collectors.toList());
List<IpResource> ipResources = new ArrayList<>();
List<IpResource> notUsed = null;
switch (groupType) {
case 1:
ipResources = ipResourceRepository.findByIdInAndIsDeleted(ipIds, false);;
ipResources = ipResourceRepository.findByShopIdInAndIsDeleted(shopIds, false);
notUsed = ipResourceRepository.findByOwnerAndIsDeletedAndShopIdIsNull(username, false);
break;
case 2:
ipResources = ipResourceRepository.findByStatusAndIdInAndIsDeleted(2, ipIds, false);
ipResources = ipResourceRepository.findByStatusAndShopIdInAndIsDeleted(2, shopIds, false);
notUsed = ipResourceRepository.findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(username, 2, false);
break;
case 3:
ipResources = ipResourceRepository.findByStatusAndIdInAndIsDeleted(1, ipIds, false);
ipResources = ipResourceRepository.findByStatusAndShopIdInAndIsDeleted(1, shopIds, false);
notUsed = ipResourceRepository.findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(username, 1, false);
break;
case 4:
......@@ -512,14 +478,13 @@ public class IpResourceServiceImpl implements IpResourceService {
if (ipResources1 != null) {
ipResources1.getContent().forEach(x -> {
ShopDto shopDto;
if (x.getShopId() == null) {
Shop shop = null;
if (x.getShopId() != null)
shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop == null) {
shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
shopDto = new ShopDto(shop);
}
if (StringUtils.isNotBlank(x.getAddr())) {
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli()) {
......@@ -603,35 +568,14 @@ public class IpResourceServiceImpl implements IpResourceService {
}
}
@Override
public IpTransactionDto queryTransaction(String username, String tid) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
IpTransaction ipTransaction = ipTransactionRepository.findById(tid).orElse(null);
if (ipTransaction == null)
throw new ClientRequestException(BrowserErrorCode.IPTRANSACTIONNOTEXIST);
IpTransactionDto ipTransactionDto = new IpTransactionDto(ipTransaction);
for (String id : ipTransaction.getIpIds()) {
IpResource ipResource = ipResourceRepository.findById(id).orElse(null);
if (ipResource != null) {
IpResourceDto ipResourceDto = new IpResourceDto(ipResource, null, false);
ipTransactionDto.getIpResourceDtos().add(ipResourceDto);
}
}
return ipTransactionDto;
}
@Override
public IpSummary getIpSummary(String username) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
IpSummary ipSummary = new IpSummary();
List<String> used = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().map(x -> x.getIpId()).collect(Collectors.toList());
List<String> shopIds = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).collect(Collectors.toList());
List<String> used = ipResourceRepository.findByShopIdInAndIsDeleted(shopIds,false).stream().map(x -> x.getId()).collect(Collectors.toList());
List<String> unbind = ipResourceRepository.findByOwnerAndIsDeletedAndShopIdIsNull(username, false).stream().map(x -> x.getId()).collect(Collectors.toList());
ipSummary.setUnbind(unbind.size());
unbind.addAll(used);
......@@ -690,14 +634,11 @@ public class IpResourceServiceImpl implements IpResourceService {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
ShopDto shopDto;
if (ipResource.getShopId() == null) {
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop == null) {
shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
shopDto = new ShopDto(shop);
}
if (StringUtils.isNotBlank(ipResource.getAddr())) {
if (ipResource.getValidTime() <= Instant.now().plusSeconds(60 * 60 * 24 * 7).toEpochMilli() && ipResource.getValidTime() > Instant.now().toEpochMilli()) {
......
......@@ -207,11 +207,11 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
ShopRequestDto shopRequestDto = new ShopRequestDto();
shopRequestDto.setShopId(shopId);
shopRequestDto.setIpId(shop.getIpId());
ipAndShopService.unBindShop(username, shopRequestDto);
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(shop.getShopId(), false);
if (ipResource != null) {
ipResource.setShopName(null);
ipResource.setShopId(null);
ipResourceRepository.save(ipResource);
}
boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId);
if (result) {
......@@ -269,10 +269,6 @@ public class ShopServiceImpl implements ShopService {
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId());
if (userShop1 != null)
return;
userShop1 = new UserShop(account1.getName(), shop.getShopId(), "-1");
if (shop.getIpId() != null)
userShop1.setIpId(shop.getIpId());
userShopRepository.save(userShop1);
}
} catch (Exception e) {
logger.error("fail to assign", e.getMessage());
......@@ -303,26 +299,47 @@ public class ShopServiceImpl implements ShopService {
if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsername(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1)
shopIds = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else
shopIds = userShopRepository.findByUsernameAndIpIdIsNull(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1) {
List<String> allIds = userShopRepository.findByUsername(username).stream()
.map(x -> x.getShopId()).collect(Collectors.toList());
shopIds = ipResourceRepository.findByShopIdInAndIsDeleted(allIds, false)
.stream().map(x -> x.getShopId()).collect(Collectors.toList());
}
else {
List<String> allIds = userShopRepository.findByUsername(username).stream()
.map(x -> x.getShopId()).collect(Collectors.toList());
for (String id:allIds) {
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(id, false);
if (ipResource == null)
shopIds.add(id);
}
}
} else {
if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1)
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNotNull(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNull(username, groupId).stream().
else if (shopFilterDto.getBindIp() == 1) {
List<String> allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
shopIds = ipResourceRepository.findByShopIdInAndIsDeleted(allIds, false)
.stream().map(x -> x.getShopId()).collect(Collectors.toList());
}
else {
List<String> allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream()
.map(x -> x.getShopId()).collect(Collectors.toList());
for (String id:allIds) {
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(id, false);
if (ipResource == null)
shopIds.add(id);
}
}
}
Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion()))
shops = shopRepository.findByShopIdInAndIpRegionCnLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getIpRegion(), pageable);
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion())) {
List<String> filter = ipResourceRepository.findByRegionCnLikeAndShopIdInAndIsDeleted(shopFilterDto.getIpRegion(), shopIds, false)
.stream().map(x -> x.getShopId()).collect(Collectors.toList());
shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(filter, pageable);
}
else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopAccount()))
shops = shopRepository.findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getShopAccount(), pageable);
else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopName()))
......@@ -333,7 +350,7 @@ public class ShopServiceImpl implements ShopService {
return new ShopPageResultDto();
List<ShopResultDto> shopResultDtos = new ArrayList<>();
shops.getContent().stream().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByIdAndIsDeleted(x.getIpId(), false);
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(x.getShopId(), false);
if (ipResource == null)
ipResource = new IpResource();
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
......@@ -356,9 +373,15 @@ public class ShopServiceImpl implements ShopService {
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
ShopSummary shopSummary = new ShopSummary();
int unbind = userShopRepository.countByUsernameAndIpIdIsNull(username);
shopSummary.setUnbind(unbind);
List<String> bind = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().map(x -> x.getIpId()).collect(Collectors.toList());
List<String> unbind = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).collect(Collectors.toList());
for (String id:unbind) {
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(id, false);
if (ipResource != null)
unbind.remove(id);
}
shopSummary.setUnbind(unbind.size());
List<String> shopIds = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).collect(Collectors.toList());
List<String> bind = ipResourceRepository.findByShopIdInAndIsDeleted(shopIds, false).stream().map(x -> x.getId()).collect(Collectors.toList());
int expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, bind, false);
int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false);
shopSummary.setExpired(expired);
......
......@@ -7,7 +7,7 @@ import java.util.List;
public interface IpResourceService {
IpTransactionDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
List<String> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
......@@ -21,8 +21,6 @@ public interface IpResourceService {
List<PlatformOptions> getPlatformOptions();
IpTransactionDto queryTransaction(String username, String transactionId);
IpSummary getIpSummary(String username);
void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto);
......
package com.edgec.browserbackend.browser.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.IpChargeRequestDto;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.IpTransactionRepository;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.utils.PollerUtils;
import com.edgec.browserbackend.common.utils.ThreadPoolUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -30,7 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@Component
......@@ -209,33 +201,6 @@ public class BrowserTask {
}
}
// @Scheduled(cron = "0 0/1 * * * ?")
// public void queryIpTransaction() {
// String URL = (profiles.equals("dev") || profiles.equals("staging")) ? TESTURL : CLOUDAMURL;
// long time = Instant.now().minusSeconds(300).toEpochMilli();
// List<IpTransaction> ipTransactions = ipTransactionRepository.findByStatus(0);
// for (IpTransaction ipTransaction : ipTransactions) {
// long start = System.currentTimeMillis();
// CompletableFuture.runAsync(() -> {
// List<String> ipIds = ipTransaction.getIpIds();
// boolean result = true;
// for (String ipId : ipIds) {
// IpResource ipResource = ipResourceRepository.findById(ipId).orElse(null);
// if (ipResource == null)
// continue;
// if (ipResource.getStatus() == 3 || ipResource.getStatus() == 6) {
// result = false;
// break;
// }
// }
// if (result == true) {
// ipTransaction.setStatus(1);
// ipTransactionRepository.save(ipTransaction);
// }
// }, ThreadPoolUtils.queryIpTransactionPool);
// }
// }
}
......@@ -40,7 +40,11 @@ security:
server:
port: 1729
# ssl:
# protocol: TLS
# key-store: classpath:javastack.keystore
# key-store-password: javastack
# key-store-type: JKS
---
spring:
profiles: dev
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment