|
|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.jiashanxia.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.izouma.jiashanxia.domain.CommissionRecord;
|
|
|
import com.izouma.jiashanxia.domain.OrderInfo;
|
|
|
import com.izouma.jiashanxia.domain.Withdraw;
|
|
|
import com.izouma.jiashanxia.domain.WxFee;
|
|
|
@@ -24,12 +25,13 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class StatisticService {
|
|
|
- private final UserRepo userRepo;
|
|
|
- private final CompanyRepo companyRepo;
|
|
|
- private final OrderInfoRepo orderInfoRepo;
|
|
|
- private final WxFeeRepo wxFeeRepo;
|
|
|
- private final WithdrawRepo withdrawRepo;
|
|
|
- private final UserService userService;
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final CompanyRepo companyRepo;
|
|
|
+ private final OrderInfoRepo orderInfoRepo;
|
|
|
+ private final WxFeeRepo wxFeeRepo;
|
|
|
+ private final WithdrawRepo withdrawRepo;
|
|
|
+ private final UserService userService;
|
|
|
+ private final CommissionRecordRepo commissionRecordRepo;
|
|
|
|
|
|
/*
|
|
|
数据总揽
|
|
|
@@ -106,7 +108,7 @@ public class StatisticService {
|
|
|
return this.getDTOS(orderInfos, start, day);
|
|
|
}
|
|
|
|
|
|
- public List<StatisticDTO> employee(int year, int month, Long userId) {
|
|
|
+ public List<StatisticDTO> employeeOrder(int year, int month, Long userId) {
|
|
|
LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
|
|
|
LocalDateTime end = start.plusMonths(1);
|
|
|
List<Long> childrenId = userService.childrenId(userId);
|
|
|
@@ -122,7 +124,7 @@ public class StatisticService {
|
|
|
return this.getDTOS(orderInfos, start, (int) day);
|
|
|
}
|
|
|
|
|
|
- public List<StatisticDTO> employee2(int year, int month, Long userId) {
|
|
|
+ public List<StatisticDTO> employeeOrderFee(int year, int month, Long userId) {
|
|
|
LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
|
|
|
LocalDateTime end = start.plusMonths(1);
|
|
|
long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay() - 1;
|
|
|
@@ -130,14 +132,12 @@ public class StatisticService {
|
|
|
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));
|
|
|
+ and.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), start));
|
|
|
+ and.add(criteriaBuilder.lessThan(root.get("createdAt"), 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));
|
|
|
+ Map<Integer, List<WxFee>> collect = wxFeeList.stream().collect(Collectors.groupingBy(WxFee::getAction));
|
|
|
List<WxFee> wxFees = collect.get(0);
|
|
|
List<WxFee> refunds = new ArrayList<>();
|
|
|
List<WxFee> wxFees1 = collect.get(1);
|
|
|
@@ -173,20 +173,52 @@ public class StatisticService {
|
|
|
LocalDateTime end = start.plusDays(1);
|
|
|
LocalDateTime finalStart = start;
|
|
|
|
|
|
-// BigDecimal fee = wxFees.stream()
|
|
|
-// .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
-// .map(WxFee::getAmount)
|
|
|
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// BigDecimal refund = refunds.stream()
|
|
|
-// .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
-// .map(WxFee::getAmount)
|
|
|
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal fee = wxFees.stream()
|
|
|
+ .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
+ .map(WxFee::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal refund = refunds.stream()
|
|
|
+ .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
|
|
|
+ .map(WxFee::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
|
|
dtos.add(StatisticDTO.builder()
|
|
|
.date(finalStart.toLocalDate())
|
|
|
-// .dayFee(fee)
|
|
|
-// .dayRefund(refund)
|
|
|
+ .dayFee(fee)
|
|
|
+ .dayRefund(refund)
|
|
|
+ .build());
|
|
|
+ day--;
|
|
|
+ start = end;
|
|
|
+ }
|
|
|
+ return dtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<StatisticDTO> employeeCommission(int year, int month, Long userId) {
|
|
|
+ LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
|
|
|
+ LocalDateTime end = start.plusMonths(1);
|
|
|
+ long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay() - 1;
|
|
|
+ List<CommissionRecord> recordList = commissionRecordRepo.findAllByUserIdAndCreatedAtBetween(userId, start, end);
|
|
|
+ List<Withdraw> withdraws = withdrawRepo.findAllByStatusAndUserIdAndAuditTimeBetween(WithdrawStatus.SUCCESS, userId, start, end);
|
|
|
+
|
|
|
+ List<StatisticDTO> dtos = new ArrayList<>();
|
|
|
+ while (day > 0) {
|
|
|
+ LocalDateTime finalEnd = start.plusDays(1);
|
|
|
+ LocalDateTime finalStart = start;
|
|
|
+
|
|
|
+ BigDecimal fee = recordList.stream()
|
|
|
+ .filter(commission -> !finalStart.isAfter(commission.getCreatedAt()) && finalEnd.isAfter(commission.getCreatedAt()))
|
|
|
+ .map(CommissionRecord::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())
|
|
|
+ .dayFee(fee)
|
|
|
+ .dayWithdraw(withdraw)
|
|
|
.build());
|
|
|
day--;
|
|
|
start = end;
|