Commit aa8e8c32 authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

提供前端查询ip

See merge request !174
parents 752513f1 7d3e1115
...@@ -23,6 +23,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc ...@@ -23,6 +23,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByParent(String parent); List<Account> findByParent(String parent);
List<Account> findByParentIn(List<String> list);
List<Account> findByParentIsNull(); List<Account> findByParentIsNull();
Page<Account> findByParent(String parent, Pageable pageable); Page<Account> findByParent(String parent, Pageable pageable);
......
...@@ -2,13 +2,11 @@ package com.edgec.browserbackend.account.repository; ...@@ -2,13 +2,11 @@ package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.BillStatus; import com.edgec.browserbackend.account.domain.BillStatus;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling; import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
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;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Repository @Repository
...@@ -38,6 +36,8 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai ...@@ -38,6 +36,8 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
List<UserPrePaidBilling> findByAdministratorAndPayMethodInAndTimestampBetween(String username, List<Integer> payMehtods, long time1, long time2); List<UserPrePaidBilling> findByAdministratorAndPayMethodInAndTimestampBetween(String username, List<Integer> payMehtods, long time1, long time2);
List<UserPrePaidBilling> findByAdministratorInAndPayMethodInAndTimestampBetween(List<String> usernames, List<Integer> payMehtods, long time1, long time2);
List<UserPrePaidBilling> findByAdministratorAndChargeTypeAndTimestampBetween(String username, int chargeType, long time1, long time2); List<UserPrePaidBilling> findByAdministratorAndChargeTypeAndTimestampBetween(String username, int chargeType, long time1, long time2);
Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable); Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable);
......
...@@ -548,14 +548,19 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -548,14 +548,19 @@ 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();
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));
promotionInfoDto.setSecondLevelCommission(promotionInfoDto.getSecondLevelCommission() + arr2[0]);
promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]);
} }
} }
}); });
...@@ -587,7 +592,6 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -587,7 +592,6 @@ public class AdministratorServiceImpl implements AdministratorService {
Date beginTime = formatter.parse(beginDate); Date beginTime = formatter.parse(beginDate);
Date endTime = formatter.parse(endDate); Date endTime = formatter.parse(endDate);
Page<Account> accountPage = accountRepository.findAllByPromotionCodeAndParentIsNull(pageable, account.getPromotion().getCode()); Page<Account> accountPage = accountRepository.findAllByPromotionCodeAndParentIsNull(pageable, account.getPromotion().getCode());
List<AccountPromotionDto> list = new ArrayList<>(); List<AccountPromotionDto> list = new ArrayList<>();
if (accountPage.getNumberOfElements() > 0) { if (accountPage.getNumberOfElements() > 0) {
...@@ -661,6 +665,25 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -661,6 +665,25 @@ public class AdministratorServiceImpl implements AdministratorService {
return arr; return arr;
} }
// 计算当前用户的所有下级用户的消费 countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan
private int[] getCommissionAndIps(Date beginTime, Date endTime, List<String> nameList) {
Integer ownIps = (int) ipResourceRepository.countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(nameList, false, Instant.now().toEpochMilli());
List<Account> children = accountRepository.findByParentIn(nameList);
if (children != null && children.size() > 0) {
ownIps += (int) ipResourceRepository.countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(children.stream().map(Account::getName).collect(Collectors.toList()), false, Instant.now().toEpochMilli());
}
// 计算出账户的所有消费
double commission = 0;
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByAdministratorInAndPayMethodInAndTimestampBetween(nameList, Arrays.asList(1, 2, 3), beginTime.getTime(), endTime.getTime());
if (userPrePaidBillings1 != null && userPrePaidBillings1.size() > 0) {
commission = userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
int[] arr = {(int) commission, ownIps};
return arr;
}
@Override @Override
public void addWhiteList(String website) { public void addWhiteList(String website) {
WhiteSite whiteSite = new WhiteSite(); WhiteSite whiteSite = new WhiteSite();
......
...@@ -24,8 +24,8 @@ public class TempController { ...@@ -24,8 +24,8 @@ public class TempController {
} }
@GetMapping("/{ip}") @GetMapping("/{ip}")
public String getPaasword(@PathVariable("ip") String ip) { public String getPassword(@PathVariable("ip") String ip) {
return tempService.getPaasword(ip); return tempService.getPassword(ip);
} }
} }
...@@ -68,5 +68,6 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String ...@@ -68,5 +68,6 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
long countAllByOwner(String username); long countAllByOwner(String username);
IpResource findFirstByAddrOrderByPurchasedTimeDesc(String addr); IpResource findFirstByAddrOrderByPurchasedTimeDesc(String addr);
} }
...@@ -43,13 +43,13 @@ public class TempServiceImpl implements TempService { ...@@ -43,13 +43,13 @@ public class TempServiceImpl implements TempService {
} }
@Override @Override
public String getPaasword(String ip) { public String getPassword(String ip) {
IpResource ipResource = ipResourceRepository.findFirstByAddrOrderByPurchasedTimeDesc(ip); IpResource ipResource = ipResourceRepository.findFirstByAddrOrderByPurchasedTimeDesc(ip);
String password; String password;
if ("mainland".equals(ipResource.getRegion())) { if (ipResource.getProxyPassword() == null) {
password = ipResource.getPassword(); password = ipResource.getUsername() + "\n" + ipResource.getPassword();
} else { } else {
password = ipResource.getProxyPassword(); password = ipResource.getProxyUsername() + "\n" + ipResource.getPassword();
} }
return password; return password;
} }
......
...@@ -10,5 +10,5 @@ public interface TempService { ...@@ -10,5 +10,5 @@ public interface TempService {
void saveIpResource(String addr, String flag); void saveIpResource(String addr, String flag);
String getPaasword(String ip); String getPassword(String ip);
} }
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