|
|
@@ -1,16 +1,13 @@
|
|
|
package com.izouma.jiashanxia.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.izouma.jiashanxia.domain.OrderInfo;
|
|
|
import com.izouma.jiashanxia.domain.Withdraw;
|
|
|
import com.izouma.jiashanxia.domain.WxFee;
|
|
|
-import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
import com.izouma.jiashanxia.dto.StatisticDTO;
|
|
|
import com.izouma.jiashanxia.enums.OrderInfoStatus;
|
|
|
import com.izouma.jiashanxia.enums.WithdrawStatus;
|
|
|
import com.izouma.jiashanxia.repo.*;
|
|
|
-import com.izouma.jiashanxia.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -33,7 +30,6 @@ public class StatisticService {
|
|
|
private final WxFeeRepo wxFeeRepo;
|
|
|
private final WithdrawRepo withdrawRepo;
|
|
|
private final UserService userService;
|
|
|
- private final OrderInfoService orderInfoService;
|
|
|
|
|
|
/*
|
|
|
数据总揽
|
|
|
@@ -107,22 +103,6 @@ public class StatisticService {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
LocalDateTime start = LocalDateTime.of(now.toLocalDate().minusDays(day - 1), LocalTime.MIN);
|
|
|
List<OrderInfo> orderInfos = orderInfoRepo.findAllByPaidAtBetweenAndStatus(start, now, OrderInfoStatus.PAID);
|
|
|
-
|
|
|
-// List<StatisticDTO> dtos = new ArrayList<>();
|
|
|
-// while (day > 0) {
|
|
|
-// LocalDateTime end = start.plusDays(1);
|
|
|
-// LocalDateTime finalStart = start;
|
|
|
-// long order = orderInfos.stream()
|
|
|
-// .filter(orderInfo -> !finalStart.isAfter(orderInfo.getPaidAt()) && end.isAfter(orderInfo.getPaidAt()))
|
|
|
-// .count();
|
|
|
-// dtos.add(StatisticDTO.builder()
|
|
|
-// .date(finalStart.toLocalDate())
|
|
|
-// .dayOrder(order)
|
|
|
-// .build());
|
|
|
-// day--;
|
|
|
-// start = end;
|
|
|
-// }
|
|
|
-// return dtos;
|
|
|
return this.getDTOS(orderInfos, start, day);
|
|
|
}
|
|
|
|
|
|
@@ -146,6 +126,15 @@ public class StatisticService {
|
|
|
LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
|
|
|
LocalDateTime end = start.plusMonths(1);
|
|
|
long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay() - 1;
|
|
|
+ List<Long> childrenId = userService.childrenId(userId);
|
|
|
+ List<WxFee> wxFeeList = wxFeeRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ and.add(root.get("userId").in(childrenId));
|
|
|
+ and.add(criteriaBuilder.greaterThanOrEqualTo(root.get("paidAt"), start));
|
|
|
+ and.add(criteriaBuilder.lessThan(root.get("paidAt"), end));
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }));
|
|
|
+
|
|
|
Map<Integer, List<WxFee>> collect = wxFeeRepo.findAllByCreatedAtBetweenAndUserId(start, end, userId)
|
|
|
.stream()
|
|
|
.collect(Collectors.groupingBy(WxFee::getAction));
|
|
|
@@ -155,8 +144,8 @@ public class StatisticService {
|
|
|
if (CollUtil.isNotEmpty(wxFees1)) {
|
|
|
refunds = wxFees1;
|
|
|
}
|
|
|
- List<Withdraw> withdraws = withdrawRepo.findAllByStatusAndUserId(WithdrawStatus.SUCCESS, userId);
|
|
|
- return getDTOS2(wxFees, refunds, withdraws, start, (int) day);
|
|
|
+
|
|
|
+ return getDTOS2(wxFees, refunds, start, (int) day);
|
|
|
}
|
|
|
|
|
|
public List<StatisticDTO> getDTOS(List<OrderInfo> orderInfos, LocalDateTime start, int day) {
|
|
|
@@ -177,15 +166,13 @@ public class StatisticService {
|
|
|
return dtos;
|
|
|
}
|
|
|
|
|
|
- public List<StatisticDTO> getDTOS2(List<WxFee> wxFees, List<WxFee> refunds, List<Withdraw> withdraws,
|
|
|
+ public List<StatisticDTO> getDTOS2(List<WxFee> wxFees, List<WxFee> refunds,
|
|
|
LocalDateTime start, int day) {
|
|
|
List<StatisticDTO> dtos = new ArrayList<>();
|
|
|
while (day > 0) {
|
|
|
LocalDateTime end = start.plusDays(1);
|
|
|
LocalDateTime finalStart = start;
|
|
|
-// long order = orderInfos.stream()
|
|
|
-// .filter(orderInfo -> !finalStart.isAfter(orderInfo.getPaidAt()) && end.isAfter(orderInfo.getPaidAt()))
|
|
|
-// .count();
|
|
|
+
|
|
|
// BigDecimal fee = wxFees.stream()
|
|
|
// .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
// .map(WxFee::getAmount)
|
|
|
@@ -194,16 +181,11 @@ public class StatisticService {
|
|
|
// .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
// .map(WxFee::getAmount)
|
|
|
// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal withdraw = withdraws.stream()
|
|
|
- .filter(wxFee -> !finalStart.isAfter(wxFee.getAuditTime()) && end.isAfter(wxFee.getAuditTime()))
|
|
|
- .map(Withdraw::getAmount)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
|
|
|
dtos.add(StatisticDTO.builder()
|
|
|
.date(finalStart.toLocalDate())
|
|
|
-// .dayOrder(order)
|
|
|
// .dayFee(fee)
|
|
|
- .dayWithdraw(withdraw)
|
|
|
// .dayRefund(refund)
|
|
|
.build());
|
|
|
day--;
|