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
List<Account> findByParent(String parent);
List<Account> findByParentIn(List<String> list);
List<Account> findByParentIsNull();
Page<Account> findByParent(String parent, Pageable pageable);
......
......@@ -2,13 +2,11 @@ package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.BillStatus;
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.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Arrays;
import java.util.List;
@Repository
......@@ -38,6 +36,8 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
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);
Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable);
......
......@@ -548,14 +548,19 @@ public class AdministratorServiceImpl implements AdministratorService {
// 获取当前账户的下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) {
/*for (Account secondPromote : secondPromotes) {
// 将下级账户及下级账户的子账户中未过期的ip统计到 ipCount中
long start3 = System.currentTimeMillis();
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromote);
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.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 {
Date beginTime = formatter.parse(beginDate);
Date endTime = formatter.parse(endDate);
Page<Account> accountPage = accountRepository.findAllByPromotionCodeAndParentIsNull(pageable, account.getPromotion().getCode());
List<AccountPromotionDto> list = new ArrayList<>();
if (accountPage.getNumberOfElements() > 0) {
......@@ -661,6 +665,25 @@ public class AdministratorServiceImpl implements AdministratorService {
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
public void addWhiteList(String website) {
WhiteSite whiteSite = new WhiteSite();
......
......@@ -24,8 +24,8 @@ public class TempController {
}
@GetMapping("/{ip}")
public String getPaasword(@PathVariable("ip") String ip) {
return tempService.getPaasword(ip);
public String getPassword(@PathVariable("ip") String ip) {
return tempService.getPassword(ip);
}
}
......@@ -68,5 +68,6 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
long countAllByOwner(String username);
IpResource findFirstByAddrOrderByPurchasedTimeDesc(String addr);
}
......@@ -43,13 +43,13 @@ public class TempServiceImpl implements TempService {
}
@Override
public String getPaasword(String ip) {
public String getPassword(String ip) {
IpResource ipResource = ipResourceRepository.findFirstByAddrOrderByPurchasedTimeDesc(ip);
String password;
if ("mainland".equals(ipResource.getRegion())) {
password = ipResource.getPassword();
if (ipResource.getProxyPassword() == null) {
password = ipResource.getUsername() + "\n" + ipResource.getPassword();
} else {
password = ipResource.getProxyPassword();
password = ipResource.getProxyUsername() + "\n" + ipResource.getPassword();
}
return password;
}
......
......@@ -10,5 +10,5 @@ public interface TempService {
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