Commit d76aab9d authored by renjie's avatar renjie

IpSummary

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