Commit 25401d34 authored by renjie's avatar renjie

admin接口

parent 1939c414
...@@ -405,6 +405,27 @@ public class AdministratorController { ...@@ -405,6 +405,27 @@ public class AdministratorController {
return resultDto; return resultDto;
} }
//统计推广码下消费
@PreAuthorize(Securitys.ADMIN_EL)
@RequestMapping(path = "/0xadministrator/promotioncode/query", method = RequestMethod.GET)
public ResultDto queryPromotion(Principal principal, @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 {
Pageable pageable = PageRequest.of(page, size);
resultDto.setData(administratorService.queryPromotion(pageable, username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
}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;
}
} }
......
...@@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; ...@@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
public class Promotion { public class Promotion {
private String code; private String code;
private int invitedUsers; private int invitedUsers;
//好友总消费 //好友本月以前总消费
private int totalCommission; private int totalCommission;
//好友当月消费 //好友当月消费
private int commission; private int commission;
......
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.Promotion;
import java.util.Date;
public class AccountPromotionDto {
private String username;
private Date signupDate;
private Promotion promotion;
public AccountPromotionDto() {
}
public AccountPromotionDto(Account account) {
this.username = account.getName();
this.signupDate = account.getSignupDate();
this.promotion = account.getPromotion();
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getSignupDate() {
return signupDate;
}
public void setSignupDate(Date signupDate) {
this.signupDate = signupDate;
}
}
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.Promotion;
import org.springframework.data.domain.Page;
public class PromotionQueryResultDto {
private String username;
private String code;
Page<AccountPromotionDto> users;
Promotion promotion;
public PromotionQueryResultDto(){
}
public PromotionQueryResultDto(Account account){
this.username = account.getName();
this.code = account.getPromotion().getCode();
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Promotion getPromotion() {
return promotion;
}
public void setPromotion(Promotion promotion) {
this.promotion = promotion;
}
public Page<AccountPromotionDto> getUsers() {
return users;
}
public void setUsers(Page<AccountPromotionDto> users) {
this.users = users;
}
}
...@@ -29,6 +29,10 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc ...@@ -29,6 +29,10 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate); Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate);
List<Account> findAllBySignupDateBetweenAndPromotionCode(Date startDate, Date endDate, String promotionCode);
Page<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Pageable pageable, Date startDate, Date endDate, String promotionCode);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate); Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAllBySignupDateBetweenAndParentIsNullAndAuthorizedNot(Pageable pageable, Date startDate, Date endDate, int authorized); Page<Account> findAllBySignupDateBetweenAndParentIsNullAndAuthorizedNot(Pageable pageable, Date startDate, Date endDate, int authorized);
......
...@@ -3,6 +3,7 @@ package com.edgec.browserbackend.account.service; ...@@ -3,6 +3,7 @@ package com.edgec.browserbackend.account.service;
import com.edgec.browserbackend.account.domain.*; import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.BillQueryResultDto; import com.edgec.browserbackend.account.dto.BillQueryResultDto;
import com.edgec.browserbackend.account.dto.IpCountQueryResultDto; import com.edgec.browserbackend.account.dto.IpCountQueryResultDto;
import com.edgec.browserbackend.account.dto.PromotionQueryResultDto;
import com.edgec.browserbackend.browser.domain.IpResource; import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.IpResourceDto; import com.edgec.browserbackend.browser.dto.IpResourceDto;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -56,7 +57,7 @@ public interface AdministratorService { ...@@ -56,7 +57,7 @@ public interface AdministratorService {
IpCountQueryResultDto queyrIpCount(String username); IpCountQueryResultDto queyrIpCount(String username);
HashMap queryGift(String username); PromotionQueryResultDto queryPromotion(Pageable pageable, String username, String promotionCode, String strDate1, String strDate2);
void addWhiteList(String website); void addWhiteList(String website);
} }
package com.edgec.browserbackend.account.service.impl; package com.edgec.browserbackend.account.service.impl;
import com.edgec.browserbackend.account.domain.*; import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.AccountPromotionDto;
import com.edgec.browserbackend.account.dto.BillQueryResultDto; import com.edgec.browserbackend.account.dto.BillQueryResultDto;
import com.edgec.browserbackend.account.dto.IpCountQueryResultDto; import com.edgec.browserbackend.account.dto.IpCountQueryResultDto;
import com.edgec.browserbackend.account.dto.PromotionQueryResultDto;
import com.edgec.browserbackend.account.exception.AccountErrorCode; import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.*; import com.edgec.browserbackend.account.repository.*;
import com.edgec.browserbackend.account.service.AdministratorService; import com.edgec.browserbackend.account.service.AdministratorService;
import com.edgec.browserbackend.auth.service.UserAuthService; import com.edgec.browserbackend.auth.service.UserAuthService;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -15,17 +18,16 @@ import org.slf4j.LoggerFactory; ...@@ -15,17 +18,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.*; import java.util.*;
import java.util.stream.DoubleStream;
@Service @Service
...@@ -363,8 +365,49 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -363,8 +365,49 @@ public class AdministratorServiceImpl implements AdministratorService {
} }
@Override @Override
public HashMap queryGift(String username) { public PromotionQueryResultDto queryPromotion(Pageable pageable, String username, String promotionCode, String strDate1, String strDate2) {
return null; if (StringUtils.isBlank(username) && StringUtils.isBlank(promotionCode))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Account account = null;
if (!StringUtils.isBlank(username))
account = accountRepository.findByName(username);
else account = accountRepository.findByPromotion(promotionCode);
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 {
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<>();
accountPage.get().forEach(account1 -> {
accountPromotionDtos.add(new AccountPromotionDto(account1));
});
Page<AccountPromotionDto> accountPromotionDtoPage = new PageImpl<AccountPromotionDto>(accountPromotionDtos);
promotionQueryResultDto.setUsers(accountPromotionDtoPage);
List<Account> accounts = accountRepository.findAllBySignupDateBetweenAndPromotionCode(dateTime1, dateTime2, account.getPromotion().getCode());
Promotion promotion = new Promotion();
accounts.forEach(x -> {
promotion.setInvitedUsers(promotion.getInvitedUsers() + 1);
promotion.setTotalCommission(promotion.getTotalCommission() + x.getPromotion().getTotalCommission());
promotion.setCommission(promotion.getCommission() + x.getPromotion().getCommission());
promotion.setWithdrawn(promotion.getWithdrawn() + x.getPromotion().getWithdrawn());
promotion.setAllGift(promotion.getAllGift() + x.getPromotion().getAllGift());
promotion.setGift(promotion.getGift() + x.getPromotion().getGift());
promotion.setCommissionLastMonth(promotion.getCommissionLastMonth() + x.getPromotion().getCommissionLastMonth());
});
promotionQueryResultDto.setPromotion(promotion);
return promotionQueryResultDto;
} catch (Exception e) {
log.error(e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
} }
@Override @Override
......
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