Commit f73bddee authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !171
parents fae5790e c9d2de37
......@@ -458,9 +458,58 @@ public class AdministratorController {
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
Pageable pageable = PageRequest.of(page, size);
resultDto.setData(administratorService.queryPromotion(pageable, username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryPromotion executed time: {} ms", (end - begin));
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
//统计推广码下消费
@PreAuthorize(Securitys.ADMIN_EL)
@GetMapping("/0xadministrator/promotioncode/queryinfo")
public ResultDto queryCountPromotionInfo(@RequestParam(value = "strDate1") String strDate1, @RequestParam(value = "strDate2") String strDate2,
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
resultDto.setData(administratorService.countPromotionInfos(username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryCountPromotionInfo executed time: {} ms", (end - begin));
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
//统计推广码下消费
@PreAuthorize(Securitys.ADMIN_EL)
@GetMapping("/0xadministrator/promotioncode/querypage")
public ResultDto queryPagePromotionInfos(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size,
@RequestParam(value = "strDate1") String strDate1, @RequestParam(value = "strDate2") String strDate2,
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
Pageable pageable = PageRequest.of(page, size);
resultDto.setData(administratorService.pagePromotionInfos(pageable, username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryPagePromotionInfos executed time: {} ms", (end - begin));
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.Promotion;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Date;
......@@ -10,7 +9,12 @@ import java.util.Date;
public class AccountPromotionDto {
private String username;
private Date signupDate;
private Promotion promotion;
//private Promotion promotion;
private Integer firstLevelIps;
private Integer secondLevelIps;
private Integer firstLevelCommission;
private Integer secondLevelCommission;
public AccountPromotionDto() {
......@@ -19,7 +23,6 @@ public class AccountPromotionDto {
public AccountPromotionDto(Account account) {
this.username = account.getName();
this.signupDate = account.getSignupDate();
this.promotion = account.getPromotion();
}
public String getUsername() {
......@@ -37,4 +40,36 @@ public class AccountPromotionDto {
public void setSignupDate(Date signupDate) {
this.signupDate = signupDate;
}
public Integer getFirstLevelIps() {
return firstLevelIps;
}
public void setFirstLevelIps(Integer firstLevelIps) {
this.firstLevelIps = firstLevelIps;
}
public Integer getSecondLevelIps() {
return secondLevelIps;
}
public void setSecondLevelIps(Integer secondLevelIps) {
this.secondLevelIps = secondLevelIps;
}
public Integer getFirstLevelCommission() {
return firstLevelCommission;
}
public void setFirstLevelCommission(Integer firstLevelCommission) {
this.firstLevelCommission = firstLevelCommission;
}
public Integer getSecondLevelCommission() {
return secondLevelCommission;
}
public void setSecondLevelCommission(Integer secondLevelCommission) {
this.secondLevelCommission = secondLevelCommission;
}
}
package com.edgec.browserbackend.account.dto;
/**
* @author xuxin
* @date 2020/9/15 17:22
* @description
*/
public class PromotionInfoDto {
private Integer firstLevelInvitedUsers;
private Integer firstLevelIps;
private Integer secondLevelIps;
private Integer allLevelIps;
/**
* 当前推荐码用户应当获取的礼金
*/
private Double gift;
private Integer firstLevelCommission;
private Integer secondLevelCommission;
public Integer getFirstLevelInvitedUsers() {
return firstLevelInvitedUsers;
}
public void setFirstLevelInvitedUsers(Integer firstLevelInvitedUsers) {
this.firstLevelInvitedUsers = firstLevelInvitedUsers;
}
public Integer getFirstLevelIps() {
return firstLevelIps;
}
public void setFirstLevelIps(Integer firstLevelIps) {
this.firstLevelIps = firstLevelIps;
}
public Integer getSecondLevelIps() {
return secondLevelIps;
}
public void setSecondLevelIps(Integer secondLevelIps) {
this.secondLevelIps = secondLevelIps;
}
public Integer getAllLevelIps() {
return allLevelIps;
}
public void setAllLevelIps(Integer allLevelIps) {
this.allLevelIps = allLevelIps;
}
public Double getGift() {
return gift;
}
public void setGift(Double gift) {
this.gift = gift;
}
public Integer getFirstLevelCommission() {
return firstLevelCommission;
}
public void setFirstLevelCommission(Integer firstLevelCommission) {
this.firstLevelCommission = firstLevelCommission;
}
public Integer getSecondLevelCommission() {
return secondLevelCommission;
}
public void setSecondLevelCommission(Integer secondLevelCommission) {
this.secondLevelCommission = secondLevelCommission;
}
}
......@@ -33,6 +33,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findAllByPromotionCodeAndParentIsNull(String code);
Page<Account> findAllByPromotionCodeAndParentIsNull(Pageable pageable, String code);
Page<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Pageable pageable, Date startDate, Date endDate, String promotionCode);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
......
package com.edgec.browserbackend.account.service;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.BillQueryResultDto;
import com.edgec.browserbackend.account.dto.IpCountQueryResultDto;
import com.edgec.browserbackend.account.dto.PromotionQueryResultDto;
import com.edgec.browserbackend.account.dto.UserUsedDto;
import com.edgec.browserbackend.account.dto.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -58,6 +55,10 @@ public interface AdministratorService {
PromotionQueryResultDto queryPromotion(Pageable pageable, String username, String promotionCode, String strDate1, String strDate2);
PromotionInfoDto countPromotionInfos(String username, String promotionCode, String beginDate, String endDate);
Page<AccountPromotionDto> pagePromotionInfos(Pageable pageable, String username, String promotionCode, String beginDate, String endDate);
void addWhiteList(String website);
void addUserWhiteList(String username, String website);
......
......@@ -14,6 +14,7 @@ import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ProxyConfigRepository;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -410,7 +411,6 @@ public class AdministratorServiceImpl implements AdministratorService {
if (StringUtils.isBlank(username) && StringUtils.isBlank(promotionCode)) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
Account account = null;
if (!StringUtils.isBlank(username)) {
account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
......@@ -420,17 +420,19 @@ public class AdministratorServiceImpl implements AdministratorService {
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getParent() != null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
PromotionQueryResultDto promotionQueryResultDto = new PromotionQueryResultDto(account);
promotionQueryResultDto.setUsername(username);
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date dateTime1 = formatter.parse(strDate1);
Date dateTime2 = formatter.parse(strDate2);
Page<Account> accountPage = accountRepository.findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(pageable, dateTime1, dateTime2, account.getPromotion().getCode());
List<AccountPromotionDto> accountPromotionDtos = new ArrayList<>();
if (accountPage.getNumberOfElements() > 0) {
......@@ -438,7 +440,6 @@ public class AdministratorServiceImpl implements AdministratorService {
accountPromotionDtos.add(new AccountPromotionDto(account1));
});
}
Page<AccountPromotionDto> accountPromotionDtoPage = new PageImpl<AccountPromotionDto>(accountPromotionDtos);
promotionQueryResultDto.setUsers(accountPromotionDtoPage);
......@@ -506,6 +507,151 @@ public class AdministratorServiceImpl implements AdministratorService {
}
}
@Override
public PromotionInfoDto countPromotionInfos(String username, String promotionCode, String beginDate, String endDate) {
// 1. 根据传入的 username 或者 推荐码 获取用户信息
Account account = getAccount(username, promotionCode);
// 2. 获取 该推荐码下所有的用户
List<Account> accounts = accountRepository.findAllByPromotionCodeAndParentIsNull(account.getPromotion().getCode());
// promotion 用来存储所有用户的消费信息
PromotionInfoDto promotionInfoDto = new PromotionInfoDto();
promotionInfoDto.setFirstLevelCommission(0);
promotionInfoDto.setFirstLevelIps(0);
promotionInfoDto.setSecondLevelCommission(0);
promotionInfoDto.setSecondLevelIps(0);
Account finalAccount = account;
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date beginTime = formatter.parse(beginDate);
Date endTime = formatter.parse(endDate);
if (accounts != null && accounts.size() > 0) {
// 邀请的一级用户数
promotionInfoDto.setFirstLevelInvitedUsers(accounts.size());
accounts.forEach(x -> {
int[] arr1 = getCommissionAndIps(beginTime, endTime, x);
promotionInfoDto.setFirstLevelCommission(promotionInfoDto.getFirstLevelCommission() + arr1[0]);
promotionInfoDto.setFirstLevelIps(promotionInfoDto.getFirstLevelIps() + arr1[1]);
// 如果当前账户的推荐码是公司销售的推荐码,且当前账户是父账户
if (finalAccount.getPromotion().isSale() && x.getParent() == null) {
// 获取当前账户的下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) {
// 将下级账户及下级账户的子账户中未过期的ip统计到 ipCount中
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromote);
promotionInfoDto.setSecondLevelCommission(promotionInfoDto.getSecondLevelCommission() + arr2[0]);
promotionInfoDto.setSecondLevelIps(promotionInfoDto.getSecondLevelIps() + arr2[1]);
}
}
}
});
}
// 设置总ip
promotionInfoDto.setAllLevelIps(promotionInfoDto.getFirstLevelIps() + promotionInfoDto.getSecondLevelIps());
// 设置应当提现的礼物金额
if (finalAccount.getPromotion().isSale()) {
promotionInfoDto.setGift(promotionInfoDto.getFirstLevelCommission() * 0.1 + promotionInfoDto.getSecondLevelCommission() * 0.02);
} else {
promotionInfoDto.setGift(promotionInfoDto.getFirstLevelCommission() * 0.08);
}
return promotionInfoDto;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
@Override
public Page<AccountPromotionDto> pagePromotionInfos(Pageable pageable, String username, String promotionCode, String beginDate, String endDate) {
// 1. 根据传入的 username 或者 推荐码 获取用户信息
Account account = getAccount(username, promotionCode);
//PromotionQueryResultDto promotionQueryResultDto = new PromotionQueryResultDto(account);
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
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) {
accountPage.get().forEach(x -> {
AccountPromotionDto accountPromotionDto = new AccountPromotionDto(x);
accountPromotionDto.setFirstLevelCommission(0);
accountPromotionDto.setFirstLevelIps(0);
accountPromotionDto.setSecondLevelCommission(0);
accountPromotionDto.setSecondLevelIps(0);
int[] arr1 = getCommissionAndIps(beginTime, endTime, x);
accountPromotionDto.setFirstLevelCommission(arr1[0]);
accountPromotionDto.setFirstLevelIps(arr1[1]);
if (account.getPromotion().isSale() && x.getParent() == null) {
// 获取当前账户的下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) {
// 将下级账户及下级账户的子账户中未过期的ip统计到 ipCount中
int[] arr2 = getCommissionAndIps(beginTime, endTime, secondPromote);
accountPromotionDto.setSecondLevelCommission(accountPromotionDto.getSecondLevelCommission() + arr2[0]);
accountPromotionDto.setSecondLevelIps(accountPromotionDto.getSecondLevelIps() + arr2[1]);
}
}
}
list.add(accountPromotionDto);
});
}
Page<AccountPromotionDto> page = new PageImpl<AccountPromotionDto>(list);
return page;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
@NotNull
private Account getAccount(String username, String promotionCode) {
if (StringUtils.isBlank(username) && StringUtils.isBlank(promotionCode)) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
Account account = null;
if (!StringUtils.isBlank(username)) {
account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
} else {
account = accountRepository.findByPromotion(promotionCode);
}
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getParent() != null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
return account;
}
private int[] getCommissionAndIps(Date beginTime, Date endTime, Account currentAccount) {
Integer ownIps = (int) ipResourceRepository.countAllByOwnerAndIsDeletedAndValidTimeGreaterThan(currentAccount.getName(), false, Instant.now().toEpochMilli());
List<Account> children = accountRepository.findByParent(currentAccount.getName());
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.findByAdministratorAndPayMethodInAndTimestampBetween(currentAccount.getName(), 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();
......
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