Commit 581d8b5f authored by renjie's avatar renjie

修改admin bug

修改ip和shop对应关系存储
parent 706b227b
package com.edgec.browserbackend; package com.edgec.browserbackend;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
...@@ -51,4 +54,18 @@ public class BrowserBackendApplication { ...@@ -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; package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.Account; 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.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
...@@ -18,6 +19,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc ...@@ -18,6 +19,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Account findByPhoneNumber(String phone); Account findByPhoneNumber(String phone);
Account findByPhoneNumberAndParentIsNull(String phone);
List<Account> findByParent(String parent); List<Account> findByParent(String parent);
List<Account> findByParentIsNull(); List<Account> findByParentIsNull();
...@@ -26,6 +29,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc ...@@ -26,6 +29,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate); Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAll(Pageable pageable); Page<Account> findAll(Pageable pageable);
List<Account> findByNameIn(List<String> names); List<Account> findByNameIn(List<String> names);
......
...@@ -87,7 +87,7 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -87,7 +87,7 @@ public class AdministratorServiceImpl implements AdministratorService {
@Override @Override
public Account getAccountByPhoneNumber(String phoneNumber) { public Account getAccountByPhoneNumber(String phoneNumber) {
Account account = accountRepository.findByPhoneNumber(phoneNumber); Account account = accountRepository.findByPhoneNumberAndParentIsNull(phoneNumber);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.PHONENOTEXIST, "Can not find account with phone number" + phoneNumber); throw new ClientRequestException(AccountErrorCode.PHONENOTEXIST, "Can not find account with phone number" + phoneNumber);
return account; return account;
...@@ -161,7 +161,7 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -161,7 +161,7 @@ public class AdministratorServiceImpl implements AdministratorService {
try { try {
Date dateTime1 = formatter.parse(strDate1); Date dateTime1 = formatter.parse(strDate1);
Date dateTime2 = formatter.parse(strDate2); Date dateTime2 = formatter.parse(strDate2);
accounts = accountRepository.findAllBySignupDateBetween(pageable, dateTime1, dateTime2); accounts = accountRepository.findAllBySignupDateBetweenAndParentIsNull(pageable, dateTime1, dateTime2);
}catch (ParseException e){ }catch (ParseException e){
e.printStackTrace(); e.printStackTrace();
......
package com.edgec.browserbackend.browser.ErrorCode; package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.edgec.browserbackend.common.commons.error.ErrorCode; import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
......
...@@ -26,7 +26,7 @@ public class IpControlloer { ...@@ -26,7 +26,7 @@ public class IpControlloer {
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){ public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
IpTransactionDto ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto); List<String> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto); resultDto.setData(ipResourceDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
...@@ -102,23 +102,6 @@ public class IpControlloer { ...@@ -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) @RequestMapping(value = "/update", method = RequestMethod.POST)
public ResultDto updateIp(Principal principal, @RequestBody IpResourceUpdateDto ipResourceUpdateDto) { public ResultDto updateIp(Principal principal, @RequestBody IpResourceUpdateDto ipResourceUpdateDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
......
...@@ -31,12 +31,13 @@ public class IpResource implements Serializable { ...@@ -31,12 +31,13 @@ public class IpResource implements Serializable {
private String username; private String username;
private String owner; private String owner;
private String userParent; private String userParent;
private String shopId;
private String shopName;
private List<String> protocol; private List<String> protocol;
private String password; private String password;
private double price; private double price;
private String shopId;
private String shopName;
private boolean isLocked; private boolean isLocked;
private long lockTimestamp; private long lockTimestamp;
...@@ -165,22 +166,6 @@ public class IpResource implements Serializable { ...@@ -165,22 +166,6 @@ public class IpResource implements Serializable {
this.userParent = userParent; 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() { public List<String> getProtocol() {
return protocol; return protocol;
} }
...@@ -252,4 +237,20 @@ public class IpResource implements Serializable { ...@@ -252,4 +237,20 @@ public class IpResource implements Serializable {
public void setPrice(double price) { public void setPrice(double price) {
this.price = 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 { ...@@ -23,14 +23,6 @@ public class Shop {
private String shopPlatform; private String shopPlatform;
private String ipRegion;
private String ipRegionCn;
private String ip;
private String ipId;
private String shopAccount; private String shopAccount;
private String shopPassword; private String shopPassword;
...@@ -71,12 +63,6 @@ public class Shop { ...@@ -71,12 +63,6 @@ public class Shop {
} }
public Shop of(Shop 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) if (shop.getShopUrl() != null)
this.setShopUrl(shop.getShopUrl()); this.setShopUrl(shop.getShopUrl());
if (shop.getOwner() != null) if (shop.getOwner() != null)
...@@ -97,27 +83,13 @@ public class Shop { ...@@ -97,27 +83,13 @@ public class Shop {
this.setShopCookie(shop.getShopCookie()); this.setShopCookie(shop.getShopCookie());
if (shop.getCreateTime() != 0) if (shop.getCreateTime() != 0)
this.setCreateTime(shop.getCreateTime()); this.setCreateTime(shop.getCreateTime());
if (shop.getIpRegionCn() != null)
this.setIpRegionCn(shop.getIpRegionCn());
return this; return this;
} }
public String getIp() {
return ip;
}
public String getShopId() { public String getShopId() {
return shopId; return shopId;
} }
public String getIpId() {
return ipId;
}
public String getIpRegion() {
return ipRegion;
}
public String getShopUrl() { public String getShopUrl() {
return shopUrl; return shopUrl;
} }
...@@ -138,22 +110,10 @@ public class Shop { ...@@ -138,22 +110,10 @@ public class Shop {
return transferStatus; return transferStatus;
} }
public void setIp(String ip) {
this.ip = ip;
}
public void setShopId(String shopId) { public void setShopId(String shopId) {
this.shopId = 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) { public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl; this.shopUrl = shopUrl;
} }
...@@ -214,11 +174,4 @@ public class Shop { ...@@ -214,11 +174,4 @@ public class Shop {
this.createTime = createTime; this.createTime = createTime;
} }
public String getIpRegionCn() {
return ipRegionCn;
}
public void setIpRegionCn(String ipRegionCn) {
this.ipRegionCn = ipRegionCn;
}
} }
...@@ -17,8 +17,6 @@ public class UserShop { ...@@ -17,8 +17,6 @@ public class UserShop {
private String groupId; private String groupId;
private String ipId;
public UserShop(){ public UserShop(){
} }
...@@ -37,7 +35,6 @@ public class UserShop { ...@@ -37,7 +35,6 @@ public class UserShop {
this.username = username; this.username = username;
this.shopId = shopId; this.shopId = shopId;
this.groupId = groupId; this.groupId = groupId;
this.ipId = ipId;
} }
public String getId() { public String getId() {
...@@ -72,11 +69,4 @@ public class UserShop { ...@@ -72,11 +69,4 @@ public class UserShop {
this.groupId = groupId; 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; package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource; import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.google.gson.internal.$Gson$Preconditions; import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -14,19 +15,22 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String ...@@ -14,19 +15,22 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted); IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
IpResource findByIdAndIsDeletedAndIsLocked(String id, boolean isDeleted, boolean isLocked); IpResource findByIdAndIsDeletedAndIsLocked(String id, boolean isDeleted, boolean isLocked);
IpResource findByIdAndIsDeleted(String id, boolean isDeleted); 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); Page<IpResource> findByIdInAndIsDeletedOrderByPurchasedTimeDesc(List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted); List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted);
List<IpResource> findByOwnerAndStatusIsNotInAndIsDeletedAndShopIdIsNull(String owner, List<Integer> status, boolean isDeleted); List<IpResource> findByOwnerAndStatusIsNotInAndIsDeletedAndShopIdIsNull(String owner, List<Integer> status, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int 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> findByAddrLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String addr, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String vendor, 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); 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> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp);
List<IpResource> findByValidTimeBetween(long beginTime, long endTime); List<IpResource> findByValidTimeBetween(long beginTime, long endTime);
IpResource findByShopIdAndIsDeleted(String shopId, boolean isDeleted);
int countByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, 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; ...@@ -8,9 +8,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> { 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> findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLikeOrderByCreateTimeDesc(List<String> shopIds, String shopName, Pageable pageable); Page<Shop> findByShopIdInAndShopNameLikeOrderByCreateTimeDesc(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByShopIdInOrderByCreateTimeDesc(List<String> shopIds, Pageable pageable); Page<Shop> findByShopIdInOrderByCreateTimeDesc(List<String> shopIds, Pageable pageable);
List<Shop> findByOwnerAndIpIsNotNull(String username);
} }
...@@ -7,14 +7,9 @@ import java.util.List; ...@@ -7,14 +7,9 @@ import java.util.List;
public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom { public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom {
List<UserShop> findByUsername(String username); List<UserShop> findByUsername(String username);
List<UserShop> findByUsernameAndIpIdIsNull(String username);
UserShop findByUsernameAndShopId(String username, String shopId); UserShop findByUsernameAndShopId(String username, String shopId);
List<UserShop> findByShopId(String shopId); List<UserShop> findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId); 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> findByUsernameAndShopIdIn(String username, List<String> shopIds);
List<UserShop> findByUsernameAndIpIdIsNotNull(String username);
int countByUsernameAndIpIdIsNull(String username);
int countByUsername(String username); int countByUsername(String username);
} }
...@@ -62,27 +62,19 @@ public class IpAndShopServiceImpl implements IpAndShopService { ...@@ -62,27 +62,19 @@ public class IpAndShopServiceImpl implements IpAndShopService {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false); ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
} }
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopRequestDto);
}
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); 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 { try {
shop.setIp(ipResource.getAddr()); ipResource.setShopId(shop.getShopId());
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.setShopName(shop.getShopName());
ipResourceRepository.save(ipResource); ipResourceRepository.save(ipResource);
List<UserShop> userShopList = userShopRepository.findByShopId(shopId);
for (UserShop userShop1 : userShopList) {
userShop1.setIpId(ipResource.getId());
userShopRepository.save(userShop1);
}
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to bind shop and ip", e.getMessage()); logger.error("fail to bind shop and ip", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN); throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
...@@ -113,7 +105,7 @@ public class IpAndShopServiceImpl implements IpAndShopService { ...@@ -113,7 +105,7 @@ public class IpAndShopServiceImpl implements IpAndShopService {
} }
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); 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); throw new ClientRequestException(BrowserErrorCode.IPNOTBINDTOSHOP);
try { try {
List<BindHistory> history = ipResource.getBindHistory(); List<BindHistory> history = ipResource.getBindHistory();
...@@ -123,19 +115,9 @@ public class IpAndShopServiceImpl implements IpAndShopService { ...@@ -123,19 +115,9 @@ public class IpAndShopServiceImpl implements IpAndShopService {
bindHistory.setShopName(shop.getShopName()); bindHistory.setShopName(shop.getShopName());
bindHistory.setUnbindTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); bindHistory.setUnbindTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
history.add(bindHistory); history.add(bindHistory);
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
shop.setIpRegionCn(null);
ipResource.setShopId(null); ipResource.setShopId(null);
ipResource.setShopName(null); ipResource.setShopName(null);
ipResourceRepository.save(ipResource); 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) { } catch (Exception e) {
logger.error("fail to unbind", e.getMessage()); logger.error("fail to unbind", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN); throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......
...@@ -207,11 +207,11 @@ public class ShopServiceImpl implements ShopService { ...@@ -207,11 +207,11 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null); Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null) if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) { IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(shop.getShopId(), false);
ShopRequestDto shopRequestDto = new ShopRequestDto(); if (ipResource != null) {
shopRequestDto.setShopId(shopId); ipResource.setShopName(null);
shopRequestDto.setIpId(shop.getIpId()); ipResource.setShopId(null);
ipAndShopService.unBindShop(username, shopRequestDto); ipResourceRepository.save(ipResource);
} }
boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId); boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId);
if (result) { if (result) {
...@@ -269,10 +269,6 @@ public class ShopServiceImpl implements ShopService { ...@@ -269,10 +269,6 @@ public class ShopServiceImpl implements ShopService {
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId()); UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId());
if (userShop1 != null) if (userShop1 != null)
return; return;
userShop1 = new UserShop(account1.getName(), shop.getShopId(), "-1");
if (shop.getIpId() != null)
userShop1.setIpId(shop.getIpId());
userShopRepository.save(userShop1);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to assign", e.getMessage()); logger.error("fail to assign", e.getMessage());
...@@ -303,26 +299,47 @@ public class ShopServiceImpl implements ShopService { ...@@ -303,26 +299,47 @@ public class ShopServiceImpl implements ShopService {
if (shopFilterDto.getBindIp() == 0) if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsername(username).stream(). shopIds = userShopRepository.findByUsername(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList()); map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1) else if (shopFilterDto.getBindIp() == 1) {
shopIds = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream(). List<String> allIds = userShopRepository.findByUsername(username).stream()
map(x -> x.getShopId()).collect(Collectors.toList()); .map(x -> x.getShopId()).collect(Collectors.toList());
else shopIds = ipResourceRepository.findByShopIdInAndIsDeleted(allIds, false)
shopIds = userShopRepository.findByUsernameAndIpIdIsNull(username).stream(). .stream().map(x -> x.getShopId()).collect(Collectors.toList());
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 { } else {
if (shopFilterDto.getBindIp() == 0) if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream(). shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList()); map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1) else if (shopFilterDto.getBindIp() == 1) {
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNotNull(username, groupId).stream(). List<String> allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNull(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList()); 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; Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion())) if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion())) {
shops = shopRepository.findByShopIdInAndIpRegionCnLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getIpRegion(), pageable); 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())) else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopAccount()))
shops = shopRepository.findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getShopAccount(), pageable); shops = shopRepository.findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getShopAccount(), pageable);
else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopName())) else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopName()))
...@@ -333,7 +350,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -333,7 +350,7 @@ public class ShopServiceImpl implements ShopService {
return new ShopPageResultDto(); return new ShopPageResultDto();
List<ShopResultDto> shopResultDtos = new ArrayList<>(); List<ShopResultDto> shopResultDtos = new ArrayList<>();
shops.getContent().stream().forEach(x -> { shops.getContent().stream().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByIdAndIsDeleted(x.getIpId(), false); IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(x.getShopId(), false);
if (ipResource == null) if (ipResource == null)
ipResource = new IpResource(); ipResource = new IpResource();
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId(); String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
...@@ -356,9 +373,15 @@ public class ShopServiceImpl implements ShopService { ...@@ -356,9 +373,15 @@ public class ShopServiceImpl implements ShopService {
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
ShopSummary shopSummary = new ShopSummary(); ShopSummary shopSummary = new ShopSummary();
int unbind = userShopRepository.countByUsernameAndIpIdIsNull(username); List<String> unbind = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).collect(Collectors.toList());
shopSummary.setUnbind(unbind); for (String id:unbind) {
List<String> bind = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().map(x -> x.getIpId()).collect(Collectors.toList()); 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 expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, bind, false);
int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false); int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false);
shopSummary.setExpired(expired); shopSummary.setExpired(expired);
......
...@@ -7,7 +7,7 @@ import java.util.List; ...@@ -7,7 +7,7 @@ import java.util.List;
public interface IpResourceService { 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; IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
...@@ -21,8 +21,6 @@ public interface IpResourceService { ...@@ -21,8 +21,6 @@ public interface IpResourceService {
List<PlatformOptions> getPlatformOptions(); List<PlatformOptions> getPlatformOptions();
IpTransactionDto queryTransaction(String username, String transactionId);
IpSummary getIpSummary(String username); IpSummary getIpSummary(String username);
void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto); void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto);
......
package com.edgec.browserbackend.browser.task; 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.domain.IpChargeRequestDto;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.service.AccountService; 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.domain.*;
import com.edgec.browserbackend.browser.dto.*; import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; 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.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.utils.PollerUtils;
import com.edgec.browserbackend.common.utils.ThreadPoolUtils; import com.edgec.browserbackend.common.utils.ThreadPoolUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -30,7 +23,6 @@ import java.util.HashMap; ...@@ -30,7 +23,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@Component @Component
...@@ -209,33 +201,6 @@ public class BrowserTask { ...@@ -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: ...@@ -40,7 +40,11 @@ security:
server: server:
port: 1729 port: 1729
# ssl:
# protocol: TLS
# key-store: classpath:javastack.keystore
# key-store-password: javastack
# key-store-type: JKS
--- ---
spring: spring:
profiles: dev 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