Commit d76aab9d authored by renjie's avatar renjie

IpSummary

排序
parent 5036f086
package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.browser.domain.IpSummary;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import java.util.ArrayList;
......@@ -42,6 +43,8 @@ public class AccountDto {
private ShopSummary shopSummary;
private IpSummary ipSummary;
private List<String> queryIpUrlList;
public AccountDto(){
......@@ -199,6 +202,14 @@ public class AccountDto {
this.shopSummary = shopSummary;
}
public IpSummary getIpSummary() {
return ipSummary;
}
public void setIpSummary(IpSummary ipSummary) {
this.ipSummary = ipSummary;
}
public List<String> getQueryIpUrlList() {
return queryIpUrlList;
}
......
......@@ -12,6 +12,7 @@ import com.edgec.browserbackend.account.utils.AccountServicePool;
import com.edgec.browserbackend.auth.exception.AuthErrorCode;
import com.edgec.browserbackend.auth.repository.UserRepository;
import com.edgec.browserbackend.auth.service.UserAuthService;
import com.edgec.browserbackend.browser.domain.IpSummary;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.PageInfo;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
......@@ -91,6 +92,9 @@ public class AccountServiceImpl implements AccountService {
@Autowired
private ShopService shopService;
@Autowired
private IpResourceService ipResourceService;
@Override
public List<UserBillList> getUserBills0(String name) {
......@@ -337,6 +341,10 @@ public class AccountServiceImpl implements AccountService {
if (shopSummary != null)
current.setShopSummary(shopSummary);
IpSummary ipSummary = ipResourceService.getIpSummary(name);
if (ipSummary != null)
current.setIpSummary(ipSummary);
resultDto.setStatus(0);
resultDto.setData(current);
} catch (Exception e) {
......
package com.edgec.browserbackend.browser.domain;
public class IpSummary {
private int total;
private int unbind;
private int willExpire;
private int expired;
public int getExpired() {
return expired;
}
public void setExpired(int expired) {
this.expired = expired;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getUnbind() {
return unbind;
}
public void setUnbind(int unbind) {
this.unbind = unbind;
}
public int getWillExpire() {
return willExpire;
}
public void setWillExpire(int willExpire) {
this.willExpire = willExpire;
}
}
......@@ -36,6 +36,8 @@ public class Shop {
private String shopCookie;
private long createTime;
public Shop(){
}
......@@ -60,6 +62,7 @@ public class Shop {
this.setShopUA(shop.getShopUA());
if (shop.getShopCookie() != null)
this.setShopCookie(shop.getShopCookie());
this.setCreateTime(shop.getCreateTime());
return this;
}
......@@ -88,6 +91,7 @@ public class Shop {
this.setShopUA(shop.getShopUA());
if (shop.getShopCookie() != null)
this.setShopCookie(shop.getShopCookie());
this.setCreateTime(shop.getCreateTime());
return this;
}
......@@ -194,4 +198,12 @@ public class Shop {
public void setShopUA(String shopUA) {
this.shopUA = shopUA;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
}
......@@ -32,6 +32,8 @@ public class ShopResultDto {
private IpResource bindIp;
private long createTime;
public static ShopResultDto of(Shop shop, String group, IpResource ipResources) {
ShopResultDto shopResultDto = new ShopResultDto();
shopResultDto.setShopId(shop.getShopId());
......@@ -55,6 +57,7 @@ public class ShopResultDto {
shopResultDto.setShopAccount(shop.getShopAccount());
shopResultDto.setGroup(group);
shopResultDto.setBindIp(ipResources);
shopResultDto.setCreateTime(shop.getCreateTime());
return shopResultDto;
}
......@@ -153,4 +156,12 @@ public class ShopResultDto {
public void setShopCookie(String shopCookie) {
this.shopCookie = shopCookie;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
}
......@@ -14,9 +14,9 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int status, boolean isDeleted);
List<IpResource> findByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
Page<IpResource> findByAddrLikeAndIdInAndIsDeleted(String addr, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdInAndIsDeleted(String vendor, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByRegionLikeAndIdInAndIsDeleted(String region, 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> findByRegionLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String region, List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByValidTimeBetween(long beginTime, long endTime);
......
......@@ -8,9 +8,9 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> {
Page<Shop> findByShopIdInAndIpRegionLike(List<String> shopIds, String ipRegion, Pageable pageable);
Page<Shop> findByShopIdInAndShopAccountLike(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLike(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByShopIdIn(List<String> shopIds, Pageable pageable);
Page<Shop> findByShopIdInAndIpRegionLikeOrderByCreateTimeDesc(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);
}
......@@ -432,13 +432,13 @@ public class IpResourceServiceImpl implements IpResourceService {
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList());
Page<IpResource> ipResources1 = null;
if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) {
ipResources1 = ipResourceRepository.findByRegionLikeAndIdInAndIsDeleted(ipFilterDto.getRegion(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByRegionLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getRegion(), allIpIds, false, pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getAddr())) {
ipResources1 = ipResourceRepository.findByAddrLikeAndIdInAndIsDeleted(ipFilterDto.getAddr(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByAddrLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getAddr(), allIpIds, false, pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) {
ipResources1 = ipResourceRepository.findByVendorLikeAndIdInAndIsDeleted(ipFilterDto.getVendor(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByVendorLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getVendor(), allIpIds, false, pageable);
} else {
ipResources.forEach(x -> {
ShopDto shopDto;
......@@ -574,4 +574,22 @@ public class IpResourceServiceImpl implements IpResourceService {
// }
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> unbind = ipResourceRepository.findByOwnerAndIsDeletedAndShopIdIsNull(username, false).stream().map(x -> x.getId()).collect(Collectors.toList());
ipSummary.setUnbind(unbind.size());
unbind.addAll(used);
int expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, unbind, false);
ipSummary.setExpired(expired);
int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, unbind, false);
ipSummary.setWillExpire(willexpired);
ipSummary.setTotal(unbind.size());
return ipSummary;
}
}
......@@ -315,7 +315,7 @@ public class ShopServiceImpl implements ShopService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Pageable pageable = PageRequest.of(0, 100);
List<Shop> shops = shopRepository.findByShopIdIn(shopIds, pageable).getContent();
List<Shop> shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(shopIds, pageable).getContent();
if (shops == null || shops.size() < 1)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
List<Account> accounts = accountRepository.findByNameIn(users);
......@@ -381,13 +381,13 @@ public class ShopServiceImpl implements ShopService {
}
Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion()))
shops = shopRepository.findByShopIdInAndIpRegionLike(shopIds, shopFilterDto.getIpRegion(), pageable);
shops = shopRepository.findByShopIdInAndIpRegionLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getIpRegion(), pageable);
else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopAccount()))
shops = shopRepository.findByShopIdInAndShopAccountLike(shopIds, shopFilterDto.getShopAccount(), pageable);
shops = shopRepository.findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getShopAccount(), pageable);
else if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getShopName()))
shops = shopRepository.findByShopIdInAndShopNameLike(shopIds, shopFilterDto.getShopName(), pageable);
shops = shopRepository.findByShopIdInAndShopNameLikeOrderByCreateTimeDesc(shopIds, shopFilterDto.getShopName(), pageable);
else
shops = shopRepository.findByShopIdIn(shopIds, pageable);
shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(shopIds, pageable);
if (shops == null || shops.getNumberOfElements() < 1)
return new ShopPageResultDto();
List<ShopResultDto> shopResultDtos = new ArrayList<>();
......@@ -411,6 +411,9 @@ public class ShopServiceImpl implements ShopService {
@Override
public ShopSummary getShopSummary(String username) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
ShopSummary shopSummary = new ShopSummary();
int unbind = userShopRepository.countByUsernameAndIpIdIsNull(username);
shopSummary.setUnbind(unbind);
......
......@@ -22,4 +22,6 @@ public interface IpResourceService {
List<PlatformOptions> getPlatformOptions();
IpTransactionDto queryTransaction(String username, String transactionId);
IpSummary getIpSummary(String username);
}
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