Commit 59c9cae9 authored by xuxin's avatar xuxin

管理员界面-推广码下线查询 性能优化

parent 7d3e1115
...@@ -50,6 +50,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc ...@@ -50,6 +50,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByPromotionCodeAndParentIsNull(String code); List<Account> findByPromotionCodeAndParentIsNull(String code);
List<Account> findByPromotionCodeInAndParentIsNull(List<String> code);
int countByPromotionCodeAndParentIsNull(String promotionCode); int countByPromotionCodeAndParentIsNull(String promotionCode);
} }
...@@ -521,10 +521,10 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -521,10 +521,10 @@ public class AdministratorServiceImpl implements AdministratorService {
// promotion 用来存储所有用户的消费信息 // promotion 用来存储所有用户的消费信息
PromotionInfoDto promotionInfoDto = new PromotionInfoDto(); PromotionInfoDto promotionInfoDto = new PromotionInfoDto();
promotionInfoDto.setFirstLevelCommission(0); /*promotionInfoDto.setFirstLevelCommission(0);
promotionInfoDto.setFirstLevelIps(0); promotionInfoDto.setFirstLevelIps(0);
promotionInfoDto.setSecondLevelCommission(0); promotionInfoDto.setSecondLevelCommission(0);
promotionInfoDto.setSecondLevelIps(0); promotionInfoDto.setSecondLevelIps(0);*/
Account finalAccount = account; Account finalAccount = account;
try { try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
...@@ -535,8 +535,8 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -535,8 +535,8 @@ public class AdministratorServiceImpl implements AdministratorService {
if (accounts != null && accounts.size() > 0) { if (accounts != null && accounts.size() > 0) {
// 邀请的一级用户数 // 邀请的一级用户数
promotionInfoDto.setFirstLevelInvitedUsers(accounts.size()); promotionInfoDto.setFirstLevelInvitedUsers(accounts.size());
int i = 3, j = 0;
accounts.forEach(x -> { /*accounts.forEach(x -> {
long start2 = System.currentTimeMillis(); long start2 = System.currentTimeMillis();
int[] arr1 = getCommissionAndIps(beginTime, endTime, x); int[] arr1 = getCommissionAndIps(beginTime, endTime, x);
log.info("===>countPromotionInfos step-3-{} consume time {}", accounts.indexOf(x) + 1, (System.currentTimeMillis() - start2)); log.info("===>countPromotionInfos step-3-{} consume time {}", accounts.indexOf(x) + 1, (System.currentTimeMillis() - start2));
...@@ -548,14 +548,14 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -548,14 +548,14 @@ public class AdministratorServiceImpl implements AdministratorService {
// 获取当前账户的下级账户 // 获取当前账户的下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode()); List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) { if (secondPromotes != null && secondPromotes.size() > 0) {
/*for (Account secondPromote : secondPromotes) { *//*for (Account secondPromote : secondPromotes) {
// 将下级账户及下级账户的子账户中未过期的ip统计到 ipCount中 // 将下级账户及下级账户的子账户中未过期的ip统计到 ipCount中
long start3 = System.currentTimeMillis(); long start3 = System.currentTimeMillis();
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromote); int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromote);
log.info("===>countPromotionInfos step-3-{}-{} consume time {}", accounts.indexOf(x) + 1, secondPromotes.indexOf(secondPromote) + 1, (System.currentTimeMillis() - start3)); log.info("===>countPromotionInfos step-3-{}-{} consume time {}", accounts.indexOf(x) + 1, secondPromotes.indexOf(secondPromote) + 1, (System.currentTimeMillis() - start3));
promotionInfoDto.setSecondLevelCommission(promotionInfoDto.getSecondLevelCommission() + arr2[0]); promotionInfoDto.setSecondLevelCommission(promotionInfoDto.getSecondLevelCommission() + arr2[0]);
promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]); promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]);
}*/ }*//*
long start3 = System.currentTimeMillis(); long start3 = System.currentTimeMillis();
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromotes.stream().map(Account::getName).collect(Collectors.toList())); int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromotes.stream().map(Account::getName).collect(Collectors.toList()));
log.info("===>countPromotionInfos step-3-{}-{} consume time {}", accounts.indexOf(x) + 1, "1", (System.currentTimeMillis() - start3)); log.info("===>countPromotionInfos step-3-{}-{} consume time {}", accounts.indexOf(x) + 1, "1", (System.currentTimeMillis() - start3));
...@@ -563,7 +563,25 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -563,7 +563,25 @@ public class AdministratorServiceImpl implements AdministratorService {
promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]); promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]);
} }
} }
}); });*/
long start2 = System.currentTimeMillis();
int[] arr1 = getCommissionAndIps(beginTime, endTime, accounts.stream().map(Account::getName).collect(Collectors.toList()));
log.info("===>countPromotionInfos step-3-1 consume time {}", (System.currentTimeMillis() - start2));
promotionInfoDto.setFirstLevelCommission(arr1[0]);
promotionInfoDto.setFirstLevelIps(arr1[1]);
List<String> codeList = accounts.stream().filter(x -> x.getParent() == null).map(x -> x.getPromotion().getCode()).collect(Collectors.toList());
if (finalAccount.getPromotion().isSale()) {
List<Account> secondPromotes = accountRepository.findByPromotionCodeInAndParentIsNull(codeList);
if (secondPromotes != null && secondPromotes.size() > 0) {
long start3 = System.currentTimeMillis();
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromotes.stream().map(Account::getName).collect(Collectors.toList()));
log.info("===>countPromotionInfos step-3-2 consume time {}", (System.currentTimeMillis() - start3));
promotionInfoDto.setSecondLevelCommission(arr2[0]);
promotionInfoDto.setSecondLevelIps(arr2[1]);
}
}
} }
log.info("===>countPromotionInfos step-4 consume time {}", System.currentTimeMillis() - start); log.info("===>countPromotionInfos step-4 consume time {}", System.currentTimeMillis() - start);
// 设置总ip // 设置总ip
...@@ -665,7 +683,7 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -665,7 +683,7 @@ public class AdministratorServiceImpl implements AdministratorService {
return arr; return arr;
} }
// 计算当前用户的所有下级用户的消费 countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan // 计算当前用户的购买的 所有ip 与 消费
private int[] getCommissionAndIps(Date beginTime, Date endTime, List<String> nameList) { private int[] getCommissionAndIps(Date beginTime, Date endTime, List<String> nameList) {
Integer ownIps = (int) ipResourceRepository.countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(nameList, false, Instant.now().toEpochMilli()); Integer ownIps = (int) ipResourceRepository.countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(nameList, false, Instant.now().toEpochMilli());
List<Account> children = accountRepository.findByParentIn(nameList); List<Account> children = accountRepository.findByParentIn(nameList);
......
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