Commit bbeea2dc authored by xuxin's avatar xuxin

alex让做的统计数据接口

parent 38acd057
......@@ -26,9 +26,9 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
List<UserPrePaidBilling> findByUsernameAndPayMethodIn(String username, List<Integer> payMethod);
List<UserPrePaidBilling> findByUsernameAndPayMethod(String username, int payMethod);
List<UserPrePaidBilling> findByUsernameLike(String username, List<Integer> payMethod);
List<UserPrePaidBilling> findByUsernameAndChargeType(String username, int chargeType);
List<UserPrePaidBilling> findByUsernameAndPayMethod(String username, int payMethod);
List<UserPrePaidBilling> findByYearAndMonth(int year, int month);
......@@ -51,4 +51,6 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanAndChargeTypeIsNotAndPayMethodOrderByTimestampDesc(String username, long time, int chargeType, int payMethod, Pageable pageable);
Page<UserPrePaidBilling> findByAdministratorAndTimestampGreaterThanAndChargeTypeIsNotAndPayMethodOrderByTimestampDesc(String administrator, long time, int chargeType, int payMethod, Pageable pageable);
List<UserPrePaidBilling> findByUsernameLikeAndPayMethodIn(String name, List<Integer> asList);
}
......@@ -35,6 +35,4 @@ public interface UserPrePaidBillingRepositoryCustom {
List<UserPrePaidBilling> findBillStatisticsByUsernameAndService(String username, Services service);
List<UserPrePaidBilling> findOverviewByYearAndMonth(String username, int year, int month, String zoneId, Services service);
}
......@@ -38,7 +38,7 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
@Override
public long countPrepaidOrderNum(int year, int month) {
MatchOperation matchOperation = Aggregation.match(where("year").is(year).and("month").is(month).and("chargeType").in(Arrays.asList(1,2)));
MatchOperation matchOperation = Aggregation.match(where("year").is(year).and("month").is(month).and("chargeType").in(Arrays.asList(1, 2)));
CountOperation countOperation = Aggregation.count().as("count");
AggregationResults<HashMap> result = mongoTemplate.aggregate(Aggregation.newAggregation(matchOperation, countOperation),
UserPrePaidBilling.class, HashMap.class);
......@@ -92,7 +92,7 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
@Override
public float companyIncomeAmount(int year, int month) {
MatchOperation matchOperation = Aggregation.match(where("year").is(year).and("month").is(month).and("payMethod").in(Arrays.asList(1,2)));
MatchOperation matchOperation = Aggregation.match(where("year").is(year).and("month").is(month).and("payMethod").in(Arrays.asList(1, 2)));
GroupOperation groupOperation = Aggregation.group("month").sum("total").as("prepaidAmount");
AggregationResults<Map> totalSum = mongoTemplate.aggregate(Aggregation.newAggregation(matchOperation, groupOperation),
......@@ -191,22 +191,22 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
if (chargeTypes == null || chargeTypes.length == 0) {
criteriaDefinition = where("username").is(username)
.and("timestamp").gte(dayBeginTime).lt(dayEndTime);
.and("timestamp").gte(dayBeginTime).lt(dayEndTime);
} else {
criteriaDefinition = where("chargeType").in(chargeType)
.and("username").is(username).and("timestamp")
.gte(dayBeginTime).lt(dayEndTime);
.and("username").is(username).and("timestamp")
.gte(dayBeginTime).lt(dayEndTime);
}
match = new MatchOperation(criteriaDefinition);
} else {
if (chargeTypes == null || chargeTypes.length == 0) {
criteriaDefinition = where("username").is(username)
.and("year").is(year).and("month").is(month);
.and("year").is(year).and("month").is(month);
} else {
criteriaDefinition = where("chargeType").in(chargeType)
.and("username").is(username)
.and("year").is(year).and("month").is(month);
.and("username").is(username)
.and("year").is(year).and("month").is(month);
}
match = new MatchOperation(criteriaDefinition);
}
......@@ -286,8 +286,8 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
}
}
GroupOperation group = Aggregation.group("year", "month", "services", "isPrepaid", "chargeType")
.sum("amount").as("amount")
.sum("total").as("total");
.sum("amount").as("amount")
.sum("total").as("total");
SortOperation sort = Aggregation.sort(Sort.Direction.DESC, "year").and(Sort.Direction.DESC, "month").and(Sort.Direction.ASC, "total");
AggregationResults<UserPrePaidBilling> results = mongoTemplate.aggregate(Aggregation.newAggregation(match, group, sort), UserPrePaidBilling.class, UserPrePaidBilling.class);
if (results.getMappedResults().size() != 0) {
......@@ -306,15 +306,15 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
Update update = new Update();
update.set("timestamp", timestamp)
.set("ownPotentialCost", potential)
.set("ownActualCost", actual)
.set("ownBillingCost", ownCost)
.set("total", total)
.set("status", status)
.set("isPrepaid", isPrepaid)
.set("chargeType", chargeType)
.set("period", 1)
.set("target", target);
.set("ownPotentialCost", potential)
.set("ownActualCost", actual)
.set("ownBillingCost", ownCost)
.set("total", total)
.set("status", status)
.set("isPrepaid", isPrepaid)
.set("chargeType", chargeType)
.set("period", 1)
.set("target", target);
mongoTemplate.upsert(basicQuery, update, UserPrePaidBilling.class);
}
......@@ -341,8 +341,8 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
match = Aggregation.match(where("username").is(username).and("services").is(service));
}
GroupOperation group = Aggregation.group("year", "month", "services", "isPrepaid", "chargeType", "status")
.sum("amount").as("amount")
.sum("total").as("total");
.sum("amount").as("amount")
.sum("total").as("total");
SortOperation sort = Aggregation.sort(Sort.Direction.DESC, "year").and(Sort.Direction.DESC, "month").and(Sort.Direction.ASC, "total");
AggregationResults<UserPrePaidBilling> results = mongoTemplate.aggregate(Aggregation.newAggregation(match, group, sort), UserPrePaidBilling.class, UserPrePaidBilling.class);
if (results.getMappedResults().size() != 0) {
......@@ -353,8 +353,6 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
return Arrays.asList();
}
@Override
public List<UserPrePaidBilling> findOverviewByYearAndMonth(String username, int year, int month, String zoneId, Services service) {
......@@ -378,7 +376,7 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
}
match = Aggregation.match(criteria);
GroupOperation group = Aggregation.group("services", "isPrepaid", "chargeType", "status")
.sum("amount").as("amount").sum("total").as("total");
.sum("amount").as("amount").sum("total").as("total");
// SortOperation sort = Aggregation.sort(Sort.Direction.ASC, "services").and(Sort.Direction.ASC, "status");
AggregationResults<UserPrePaidBilling> results = mongoTemplate
.aggregate(Aggregation.newAggregation(match, group), UserPrePaidBilling.class, UserPrePaidBilling.class);
......@@ -389,5 +387,4 @@ public class UserPrePaidBillingRepositoryCustomImpl implements UserPrePaidBillin
return Arrays.asList();
}
}
......@@ -4,6 +4,7 @@ import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
import com.edgec.browserbackend.browser.dto.FavoriteUrlDto;
import com.edgec.browserbackend.browser.dto.TempReportDto;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.browser.service.TempService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -63,7 +64,7 @@ public class TempController {
public ResultDto deleteFavoritesByShopId(@RequestBody FavoriteUrlDto favoriteUrlDto) {
ResultDto resultDto = new ResultDto();
try {
FavoriteUrl favoriteUrl = new FavoriteUrl("",favoriteUrlDto.getUrl());
FavoriteUrl favoriteUrl = new FavoriteUrl("", favoriteUrlDto.getUrl());
resultDto.setData(shopService.deleteFavoritesByShopId(favoriteUrlDto.getShopId(), favoriteUrl));
resultDto.setStatus(0);
} catch (ClientRequestException e) {
......@@ -79,7 +80,7 @@ public class TempController {
public ResultDto saveFavoritesByShopId(@RequestBody FavoriteUrlDto favoriteUrlDto) {
ResultDto resultDto = new ResultDto();
try {
FavoriteUrl favoriteUrl = new FavoriteUrl(favoriteUrlDto.getTitle(),favoriteUrlDto.getUrl());
FavoriteUrl favoriteUrl = new FavoriteUrl(favoriteUrlDto.getTitle(), favoriteUrlDto.getUrl());
shopService.saveFavoritesByShopId(favoriteUrlDto.getShopId(), favoriteUrl);
resultDto.setData(true);
resultDto.setStatus(0);
......@@ -89,6 +90,11 @@ public class TempController {
return resultDto;
}
@GetMapping("/report")
public TempReportDto getReport() {
return tempService.getReport();
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.account.domain.Account;
import java.util.Date;
/**
* @author xuxin
* @date 2020/10/12 14:56
* @description
*/
public class TempAccountDto {
/*用户名-注册时间-注册码-累计消费*/
private String name;
private Date signupDate;
private String promotionCode;
private Double consume;
public TempAccountDto(Account account) {
this.name = account.getName();
this.signupDate = account.getSignupDate();
this.promotionCode = account.getPromotionCode();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getSignupDate() {
return signupDate;
}
public void setSignupDate(Date signupDate) {
this.signupDate = signupDate;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
public Double getConsume() {
return consume;
}
public void setConsume(Double consume) {
this.consume = consume;
}
}
package com.edgec.browserbackend.browser.dto;
import java.util.List;
/**
* @author xuxin
* @date 2020/10/12 14:47
* @description
*/
public class TempReportDto {
/*注册用户总数*/
private int totalUsers;
/*注册用户总消费*/
private double totalConsume;
/*推荐码为 123456 的用户数*/
private int promotionCode123456UsersNum;
/*推荐码为 123456 的用户总消费*/
private double promotionCode123456UsersTotalConsume;
/*推荐码为 空 的用户数*/
private int noPromotionCodeUsersNum;
/*推荐码为 空 的用户总消费*/
private double noPromotionCodeUsersTotalConsume;
/* 用户名-注册时间-注册码-累计消费*/
private List<TempAccountDto> list;
public double getTotalConsume() {
return totalConsume;
}
public void setTotalConsume(double totalConsume) {
this.totalConsume = totalConsume;
}
public int getTotalUsers() {
return totalUsers;
}
public void setTotalUsers(int totalUsers) {
this.totalUsers = totalUsers;
}
public int getPromotionCode123456UsersNum() {
return promotionCode123456UsersNum;
}
public void setPromotionCode123456UsersNum(int promotionCode123456UsersNum) {
this.promotionCode123456UsersNum = promotionCode123456UsersNum;
}
public double getPromotionCode123456UsersTotalConsume() {
return promotionCode123456UsersTotalConsume;
}
public void setPromotionCode123456UsersTotalConsume(double promotionCode123456UsersTotalConsume) {
this.promotionCode123456UsersTotalConsume = promotionCode123456UsersTotalConsume;
}
public int getNoPromotionCodeUsersNum() {
return noPromotionCodeUsersNum;
}
public void setNoPromotionCodeUsersNum(int noPromotionCodeUsersNum) {
this.noPromotionCodeUsersNum = noPromotionCodeUsersNum;
}
public double getNoPromotionCodeUsersTotalConsume() {
return noPromotionCodeUsersTotalConsume;
}
public void setNoPromotionCodeUsersTotalConsume(double noPromotionCodeUsersTotalConsume) {
this.noPromotionCodeUsersTotalConsume = noPromotionCodeUsersTotalConsume;
}
public List<TempAccountDto> getList() {
return list;
}
public void setList(List<TempAccountDto> list) {
this.list = list;
}
}
package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.repository.UserPrePaidBillingRepository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.dto.TempAccountDto;
import com.edgec.browserbackend.browser.dto.TempReportDto;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.UserCodeRepository;
import com.edgec.browserbackend.browser.service.TempService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
*
......@@ -21,6 +32,12 @@ public class TempServiceImpl implements TempService {
@Autowired
private IpResourceRepository ipResourceRepository;
@Autowired
private AccountRepository accountRepository;
@Autowired
private UserPrePaidBillingRepository userPrePaidBillingRepository;
@Override
public void save(UserCode userCode) {
userCodeRepository.save(userCode);
......@@ -53,4 +70,30 @@ public class TempServiceImpl implements TempService {
}
return password;
}
@Override
public TempReportDto getReport() {
TempReportDto tempReportDto = new TempReportDto();
List<Account> accounts = accountRepository.findAll();
List<TempAccountDto> list = accounts.stream().filter(x -> StringUtils.isEmpty(x.getParent())).map(TempAccountDto::new).collect(Collectors.toList());
for (TempAccountDto tempAccountDto : list) {
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByUsernameLikeAndPayMethodIn(tempAccountDto.getName(), Arrays.asList(1, 2, 3));
if (userPrePaidBillings != null && userPrePaidBillings.size() > 0) {
tempAccountDto.setConsume(userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum());
} else {
tempAccountDto.setConsume(0.0);
}
}
tempReportDto.setTotalUsers(list.size());
tempReportDto.setTotalConsume(list.stream().mapToDouble(TempAccountDto::getConsume).sum());
tempReportDto.setList(list);
tempReportDto.setNoPromotionCodeUsersNum((int) (list.stream().filter(x -> StringUtils.isEmpty(x.getPromotionCode())).count()));
tempReportDto.setNoPromotionCodeUsersTotalConsume(list.stream().filter(x -> StringUtils.isEmpty(x.getPromotionCode())).mapToDouble(TempAccountDto::getConsume).sum());
tempReportDto.setPromotionCode123456UsersNum((int) (list.stream().filter(x -> "123456".equals(x.getPromotionCode())).count()));
tempReportDto.setPromotionCode123456UsersTotalConsume(list.stream().filter(x -> "123456".equals(x.getPromotionCode())).mapToDouble(TempAccountDto::getConsume).sum());
return tempReportDto;
}
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.dto.TempReportDto;
/**
*
......@@ -11,4 +12,6 @@ public interface TempService {
void saveIpResource(String addr, String flag);
String getPassword(String ip);
TempReportDto getReport();
}
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