Pārlūkot izejas kodu

应收款报表,逾期报表

wangqifan 5 gadi atpakaļ
vecāks
revīzija
e70f0f8bda

+ 2 - 0
src/main/java/com/izouma/zhumj/repo/sale/ContractRepo.java

@@ -147,6 +147,8 @@ public interface ContractRepo extends JpaRepository<Contract, Long>, JpaSpecific
 
     List<Contract> findByStatus(ContractStatus status);
 
+    List<Contract> findByStatusNot(ContractStatus status);
+
     List<Contract> findByContractEndTimeBetween(LocalDateTime start, LocalDateTime end);
 
     List<Contract> findByContractEndTimeBetweenAndStatusNot(LocalDateTime start, LocalDateTime end, ContractStatus contractStatus);

+ 335 - 287
src/main/java/com/izouma/zhumj/service/report/ReportService.java

@@ -346,7 +346,8 @@ public class ReportService {
         //获取房费列表
         List<RoomFee> roomFeeList = roomFeeRepo.findByStoreIdAndSettleTimeBetweenAndEnabled(storeId, start, end, true);
         //获取个人费用列表
-        List<PersonalFee> personalFeeList = personalFeeRepo.findByStoreIdAndSettleTimeBetweenAndEnabled(storeId, start, end, true);
+        List<PersonalFee> personalFeeList = personalFeeRepo
+                .findByStoreIdAndSettleTimeBetweenAndEnabled(storeId, start, end, true);
         //获取入住信息列表
         List<CheckinInfo> checkinInfoList = new ArrayList<>();
         if (selectedCustomerId != null) {
@@ -516,7 +517,8 @@ public class ReportService {
             long bedCount = bedInfoRepo.countByStoreIdAndVirtualFalseAndEnabledTrue(storeInfo.getId());
             long roomCount = roomInfoRepo.countAllByStoreId(storeInfo.getId());
             List<CheckinInfoDTO> checkinInfoList;
-            checkinInfoList = checkinInfoRepo.monthRateReport(storeInfo.getId(), date.atStartOfDay(), date.atTime(Constants.TIME_MAX));
+            checkinInfoList = checkinInfoRepo
+                    .monthRateReport(storeInfo.getId(), date.atStartOfDay(), date.atTime(Constants.TIME_MAX));
             long lastYear = checkinInfoRepo.monthRateReport(storeInfo.getId(), date.atStartOfDay()
                     .minusYears(1), date.atTime(Constants.TIME_MAX).minusYears(1)).size();
 
@@ -570,7 +572,8 @@ public class ReportService {
                             .getTypeCode())).findFirst().orElse(null);
             if (roomTypeInfo != null) {
                 long checkinBeds = checkinInfoRepo
-                        .monthRateReportByRoomTypeId(storeInfo.getId(), date.atStartOfDay(), date.atTime(LocalTime.MAX), roomTypeInfo
+                        .monthRateReportByRoomTypeId(storeInfo.getId(), date.atStartOfDay(), date
+                                .atTime(LocalTime.MAX), roomTypeInfo
                                 .getId()).size();
                 long lastMonthBaiLing = checkinInfoRepo
                         .monthRateReportByRoomTypeId(storeInfo.getId(), date.atStartOfDay()
@@ -580,8 +583,9 @@ public class ReportService {
                         .monthRateReportByRoomTypeId(storeInfo.getId(), date.atStartOfDay()
                                 .minusYears(1), date.atTime(LocalTime.MAX).minusYears(1), roomTypeInfo
                                 .getId()).size();
-                long bailingCount = bedInfoRepo.countAllByStoreIdAndRoomTypeIdAndEnabledTrue(storeInfo.getId(), roomTypeInfo
-                        .getId());
+                long bailingCount = bedInfoRepo
+                        .countAllByStoreIdAndRoomTypeIdAndEnabledTrue(storeInfo.getId(), roomTypeInfo
+                                .getId());
                 long freeBeds = bailingCount - checkinBeds;
                 if (bailingCount > 0 && freeBeds > 0) {
                     BigDecimal bailingRate = BigDecimal.valueOf(checkinBeds)
@@ -596,7 +600,8 @@ public class ReportService {
                             .map(CheckinInfoDTO::getMonthRate)
                             .reduce(BigDecimal::add)
                             .orElse(BigDecimal.ZERO);
-                    BigDecimal bailingAverage = oneTotal.divide(BigDecimal.valueOf(freeBeds), 2, RoundingMode.HALF_EVEN);
+                    BigDecimal bailingAverage = oneTotal
+                            .divide(BigDecimal.valueOf(freeBeds), 2, RoundingMode.HALF_EVEN);
                     roomStatusReportDTO.setOneRoomsCount(freeBeds);
                     roomStatusReportDTO.setBaiLingAverageRoomRate(bailingAverage);
                     roomStatusReportDTO.setBaiLingOccupancy(decimalFormat.format(bailingRate.multiply(BigDecimal
@@ -633,7 +638,8 @@ public class ReportService {
             if (null == startDate && null == endDate) {
                 checkinInfoList = checkinInfoRepo.monthRateReport(storeInfo.getId());
             } else {
-                checkinInfoList = checkinInfoRepo.monthRateReport(storeInfo.getId(), startDate.atStartOfDay(), endDate.atTime(Constants.TIME_MAX));
+                checkinInfoList = checkinInfoRepo.monthRateReport(storeInfo.getId(), startDate.atStartOfDay(), endDate
+                        .atTime(Constants.TIME_MAX));
                 checkinBedCount = checkinInfoList.size();
                 freeBedCount = bedCount - checkinBedCount;
             }
@@ -676,7 +682,8 @@ public class ReportService {
                         .map(RoomInfo::getId)
                         .collect(Collectors.toList());
                 long freeBeds = bedInfoRepo
-                        .countAllByStoreIdAndRoomIdInAndCheckInStatusAndEnabledTrue(storeInfo.getId(), roomIds, CheckInStatus.FREE);
+                        .countAllByStoreIdAndRoomIdInAndCheckInStatusAndEnabledTrue(storeInfo
+                                .getId(), roomIds, CheckInStatus.FREE);
 
                 RoomStatusReportDTO.Detail detail = RoomStatusReportDTO.Detail.builder()
                         .roomType(roomTypeInfo.getTypeName())
@@ -687,7 +694,8 @@ public class ReportService {
                 detailList.add(detail);
                 switch (roomTypeInfo.getTypeCode()) {
                     case "b-b1":
-                        long bailingCount = bedInfoRepo.countAllByStoreIdAndRoomIdInAndEnabledTrue(storeInfo.getId(), roomIds);
+                        long bailingCount = bedInfoRepo
+                                .countAllByStoreIdAndRoomIdInAndEnabledTrue(storeInfo.getId(), roomIds);
                         if (bailingCount > 0 && freeBeds > 0) {
                             BigDecimal bailingRate = BigDecimal.valueOf(bailingCount - freeBeds)
                                     .divide(BigDecimal.valueOf(bailingCount), 2, RoundingMode.HALF_EVEN);
@@ -697,7 +705,8 @@ public class ReportService {
                                     .map(CheckinInfoDTO::getMonthRate)
                                     .reduce(BigDecimal::add)
                                     .orElse(BigDecimal.ZERO);
-                            BigDecimal bailingAverage = oneTotal.divide(BigDecimal.valueOf(bailingCount - freeBeds), 2, RoundingMode.HALF_EVEN);
+                            BigDecimal bailingAverage = oneTotal
+                                    .divide(BigDecimal.valueOf(bailingCount - freeBeds), 2, RoundingMode.HALF_EVEN);
                             roomStatusReportDTO.setOneRoomsCount(freeBeds);
                             roomStatusReportDTO.setBaiLingAverageRoomRate(bailingAverage);
                             roomStatusReportDTO.setBaiLingOccupancy(decimalFormat.format(bailingRate.multiply(BigDecimal
@@ -739,7 +748,8 @@ public class ReportService {
     }
 
     public List<CheckinInfoDTO> checkinReport(Long storeId, LocalDateTime start, LocalDateTime end) {
-        List<CheckinInfo> checkinInfos = checkinInfoRepo.findByStoreIdAndCheckinTimeBetweenOrderByCheckinTime(storeId, start, end);
+        List<CheckinInfo> checkinInfos = checkinInfoRepo
+                .findByStoreIdAndCheckinTimeBetweenOrderByCheckinTime(storeId, start, end);
         if (SecurityUtils.hasRole(Authority.NAME.ROLE_SALE)) {
             checkinInfos.removeIf(checkinInfo -> !checkinInfo.getSaleId()
                     .equals(SecurityUtils.getAuthenticatedUser().getId()));
@@ -754,21 +764,22 @@ public class ReportService {
     }
 
     public List<CheckoutReport> checkoutReport(Long storeId, LocalDateTime start, LocalDateTime end, Long customerId, String name) {
-        List<CheckinInfo> checkinInfos = checkinInfoRepo.findAll((Specification<CheckinInfo>) (root, criteriaQuery, criteriaBuilder) -> {
-            List<Predicate> predicates = new ArrayList<>(Arrays.asList(
-                    criteriaBuilder.equal(root.get("checkout"), true),
-                    criteriaBuilder.between(root.get("checkoutTime"), start, end)));
-            if (storeId != null) {
-                predicates.add(criteriaBuilder.equal(root.get("storeId"), storeId));
-            }
-            if (customerId != null) {
-                predicates.add(criteriaBuilder.equal(root.get("customerId"), customerId));
-            }
-            if (name != null) {
-                predicates.add(criteriaBuilder.like(root.get("name"), "%" + name + "%"));
-            }
-            return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
-        });
+        List<CheckinInfo> checkinInfos = checkinInfoRepo
+                .findAll((Specification<CheckinInfo>) (root, criteriaQuery, criteriaBuilder) -> {
+                    List<Predicate> predicates = new ArrayList<>(Arrays.asList(
+                            criteriaBuilder.equal(root.get("checkout"), true),
+                            criteriaBuilder.between(root.get("checkoutTime"), start, end)));
+                    if (storeId != null) {
+                        predicates.add(criteriaBuilder.equal(root.get("storeId"), storeId));
+                    }
+                    if (customerId != null) {
+                        predicates.add(criteriaBuilder.equal(root.get("customerId"), customerId));
+                    }
+                    if (name != null) {
+                        predicates.add(criteriaBuilder.like(root.get("name"), "%" + name + "%"));
+                    }
+                    return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
+                });
         List<RoomInfo> roomInfos = roomInfoRepo.findAllById(checkinInfos.stream()
                 .map(CheckinInfo::getRoomId)
                 .filter(Objects::nonNull)
@@ -883,9 +894,10 @@ public class ReportService {
         List<List<String>> businessDepositReport = new ArrayList<>();
         List<StoreInfo> storeInfos = storeInfoRepo.findAll();
         storeInfos.removeIf(storeInfo -> !storeInfo.getStoreStatus().equals(StoreStatus.BUSINESS));
-        List<String> depositNames = feeNameRepo.findAll((Specification<FeeName>) (root, criteriaQuery, criteriaBuilder) ->
-                criteriaBuilder.like(root.get("name"), "%" + "押金" + "%")
-        ).stream().map(FeeName::getName).collect(Collectors.toList());
+        List<String> depositNames = feeNameRepo
+                .findAll((Specification<FeeName>) (root, criteriaQuery, criteriaBuilder) ->
+                        criteriaBuilder.like(root.get("name"), "%" + "押金" + "%")
+                ).stream().map(FeeName::getName).collect(Collectors.toList());
         List<String> head = new ArrayList<>(Arrays.asList("门店名称", "个人押金", "团队押金"));
         head.addAll(depositNames);
         head.add("总收入");
@@ -897,7 +909,8 @@ public class ReportService {
             //个人押金
             BigDecimal deposit = BigDecimal.ZERO;
             for (DepositRecord depositRecord : depositRecordRepo
-                    .findByCheckinInfoStoreIdAndCreatedAtBetween(storeInfo.getId(), start.atStartOfDay(), end.atTime(23, 59, 59, 99))) {
+                    .findByCheckinInfoStoreIdAndCreatedAtBetween(storeInfo.getId(), start.atStartOfDay(), end
+                            .atTime(23, 59, 59, 99))) {
                 deposit = deposit.add(depositRecord.getAmount());
             }
             list.add(deposit.toString());
@@ -905,22 +918,25 @@ public class ReportService {
 
             //团队押金
             BigDecimal contractDeposit = BigDecimal.ZERO;
-            for (Contract contract : contractRepo.findStoreContract(storeInfo.getId(), start.atStartOfDay(), end.atTime(23, 59, 59, 99))) {
+            for (Contract contract : contractRepo
+                    .findStoreContract(storeInfo.getId(), start.atStartOfDay(), end.atTime(23, 59, 59, 99))) {
                 contractDeposit = contractDeposit.add(contract.getFlowBet());
             }
             list.add(contractDeposit.toString());
             total = total.add(contractDeposit);
 
             //本门店的押金费用类型
-            List<PersonalFeeType> personalFeeTypes = personalFeeTypeRepo.findAll((Specification<PersonalFeeType>) (root, criteriaQuery, criteriaBuilder) ->
-                    criteriaQuery.where(
-                            root.get("name").in(depositNames),
-                            criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
-                    ).getRestriction());
+            List<PersonalFeeType> personalFeeTypes = personalFeeTypeRepo
+                    .findAll((Specification<PersonalFeeType>) (root, criteriaQuery, criteriaBuilder) ->
+                            criteriaQuery.where(
+                                    root.get("name").in(depositNames),
+                                    criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
+                            ).getRestriction());
 
             //本门店的个人押金费用
-            List<PersonalFee> personalFees = personalFeeRepo.findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start
-                    .atStartOfDay(), end.atTime(23, 59, 59, 99), true);
+            List<PersonalFee> personalFees = personalFeeRepo
+                    .findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start
+                            .atStartOfDay(), end.atTime(23, 59, 59, 99), true);
             for (String depositName : depositNames) {
                 Set<Long> personalFeeTypeSet = personalFeeTypes.stream()
                         .filter(personalFeeType -> personalFeeType.getName().equals(depositName))
@@ -959,21 +975,25 @@ public class ReportService {
             list.add(storeInfo.getStoreName());
             BigDecimal total = BigDecimal.ZERO;
 
-            List<PersonalFeeType> personalFeeTypes = personalFeeTypeRepo.findAll((Specification<PersonalFeeType>) (root, criteriaQuery, criteriaBuilder) ->
-                    criteriaQuery.where(
-                            root.get("name").in(feeNames),
-                            criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
-                    ).getRestriction());
-            List<FeeType> roomFeeTypes = feeTypeRepo.findAll((Specification<FeeType>) (root, criteriaQuery, criteriaBuilder) ->
-                    criteriaQuery.where(
-                            root.get("name").in(feeNames),
-                            criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
-                    ).getRestriction());
+            List<PersonalFeeType> personalFeeTypes = personalFeeTypeRepo
+                    .findAll((Specification<PersonalFeeType>) (root, criteriaQuery, criteriaBuilder) ->
+                            criteriaQuery.where(
+                                    root.get("name").in(feeNames),
+                                    criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
+                            ).getRestriction());
+            List<FeeType> roomFeeTypes = feeTypeRepo
+                    .findAll((Specification<FeeType>) (root, criteriaQuery, criteriaBuilder) ->
+                            criteriaQuery.where(
+                                    root.get("name").in(feeNames),
+                                    criteriaBuilder.equal(root.get("storeId"), storeInfo.getId())
+                            ).getRestriction());
             //本门店的个人押金费用
-            List<PersonalFee> personalFees = personalFeeRepo.findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start
-                    .atStartOfDay(), end.atTime(23, 59, 59, 99), true);
-            List<RoomFee> roomFees = roomFeeRepo.findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start.atStartOfDay(), end
-                    .atTime(23, 59, 59, 99), true);
+            List<PersonalFee> personalFees = personalFeeRepo
+                    .findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start
+                            .atStartOfDay(), end.atTime(23, 59, 59, 99), true);
+            List<RoomFee> roomFees = roomFeeRepo
+                    .findByStoreIdAndSettleTimeBetweenAndEnabled(storeInfo.getId(), start.atStartOfDay(), end
+                            .atTime(23, 59, 59, 99), true);
 
             for (String feeTypeName : feeNames) {
                 Set<Long> personalFeeTypeSet = personalFeeTypes.stream()
@@ -999,8 +1019,9 @@ public class ReportService {
     }
 
     public List<RevokedFeeReportDTO> revokedFeeReport(LocalDate start, LocalDate end) {
-        List<PersonalFee> revokedPersonalFees = personalFeeRepo.findAllByRefundFromAndSettleTimeBetween(true, start.atStartOfDay(), end
-                .atTime(LocalTime.MAX));
+        List<PersonalFee> revokedPersonalFees = personalFeeRepo
+                .findAllByRefundFromAndSettleTimeBetween(true, start.atStartOfDay(), end
+                        .atTime(LocalTime.MAX));
         List<RevokedFeeReportDTO> revokedFeeReportDTOs = new ArrayList<>();
         revokedPersonalFees.forEach(personalFee -> {
             RevokedFeeReportDTO revokedFeeReportDTO = new RevokedFeeReportDTO();
@@ -1022,24 +1043,29 @@ public class ReportService {
     }
 
     public Page<ReceivableCreditReportDTO> receivableCreditReport(LocalDate start, LocalDate end, Long customerId, Long storeId, Pageable pageable) {
-        Page<ContractBill> contractBills = contractBillRepo.findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) ->
-        {
-            List<Predicate> predicates = new ArrayList<>(Arrays.asList(
-                    criteriaBuilder.lessThanOrEqualTo(root.get("startTime"), end.atTime(23, 59, 59, 99)),
-                    criteriaBuilder.greaterThanOrEqualTo(root.get("startTime"), start.atStartOfDay())
-            ));
-            if (storeId != null) {
-                Set<Long> contractIds = contractStoreRepo.findByStoreId(storeId)
-                        .stream()
-                        .map(ContractStore::getContractId)
-                        .collect(Collectors.toSet());
-                predicates.add(root.get("contractId").in(contractIds));
-            }
-            if (customerId != null) {
-                predicates.add(criteriaBuilder.equal(root.get("customerId"), customerId));
-            }
-            return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
-        }, pageable);
+        Page<ContractBill> contractBills = contractBillRepo
+                .findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) ->
+                {
+                    List<Predicate> predicates = new ArrayList<>(Arrays.asList(
+                            criteriaBuilder.lessThanOrEqualTo(root.get("startTime"), end.atTime(23, 59, 59, 99)),
+                            criteriaBuilder.greaterThanOrEqualTo(root.get("startTime"), start.atStartOfDay())
+                    ));
+                    List<Long> notStayInIds = new ArrayList<>();
+                    contractRepo.findByStatusNot(ContractStatus.STAY_IN)
+                            .forEach(contract -> notStayInIds.add(contract.getId()));
+                    predicates.add(criteriaBuilder.not(root.get("contractId").in(notStayInIds)));
+                    if (storeId != null) {
+                        Set<Long> contractIds = contractStoreRepo.findByStoreId(storeId)
+                                .stream()
+                                .map(ContractStore::getContractId)
+                                .collect(Collectors.toSet());
+                        predicates.add(root.get("contractId").in(contractIds));
+                    }
+                    if (customerId != null) {
+                        predicates.add(criteriaBuilder.equal(root.get("customerId"), customerId));
+                    }
+                    return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
+                }, pageable);
         Set<Long> contractIds = contractStoreRepo.findByStoreId((long) 433)
                 .stream()
                 .map(ContractStore::getContractId)
@@ -1111,27 +1137,28 @@ public class ReportService {
         yearMonths.forEach(yearMonth -> {
             LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
             LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
-            long customerCount = customerRepo.count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(intention)) {
-                    predicates.add(criteriaBuilder.like(root.get("intention"), "%" + intention + "%"));
-                }
-                predicates.add(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
-                );
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            long customerCount = customerRepo
+                    .count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                            if (!"all".equals(city)) {
+                                predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
+                            }
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(intention)) {
+                            predicates.add(criteriaBuilder.like(root.get("intention"), "%" + intention + "%"));
+                        }
+                        predicates.add(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
+                        );
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             customerCountDTOS.add(CustomerCountDTO.builder()
                     .enabled(customerCount)
                     .total(customerCount)
@@ -1166,25 +1193,26 @@ public class ReportService {
         yearMonths.forEach(yearMonth -> {
             LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
             LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
-            long customerCount = customerRepo.count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                predicates.add(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
-                );
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            long customerCount = customerRepo
+                    .count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                            if (!"all".equals(city)) {
+                                predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
+                            }
+                        }
+                        predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
+                        predicates.add(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
+                        );
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             customerCountDTOS.add(CustomerCountDTO.builder()
                     .enabled(customerCount)
                     .total(customerCount)
@@ -1222,46 +1250,48 @@ public class ReportService {
             Map<String, Object> result = new HashMap<>();
             LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
             LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
-            List<Customer> customers = customerRepo.findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
-            long customerCount = customerRepo.count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            List<Customer> customers = customerRepo
+                    .findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                            if (!"all".equals(city)) {
+                                predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
+                            }
+                        }
+                        predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
+                        ));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
+            long customerCount = customerRepo
+                    .count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                            if (!"all".equals(city)) {
+                                predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
+                            }
+                        }
+                        predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
+                        ));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             Map<CustomerSource, List<Customer>> countBySource = customers.stream()
                     .filter(customer -> customer.getCustomerSource() != null)
                     .collect(Collectors.groupingBy(Customer::getCustomerSource));
@@ -1320,25 +1350,26 @@ public class ReportService {
                     .map(Contract::getCustomer)
                     .collect(Collectors.toList());
             List<Long> customerId = new ArrayList<>();
-            long allCustomerCount = customerRepo.count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                predicates.add(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate)
-                );
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            long allCustomerCount = customerRepo
+                    .count((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                            if (!"all".equals(city)) {
+                                predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
+                            }
+                        }
+                        predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
+                        predicates.add(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate)
+                        );
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             long customerCount = 0;
             for (Customer customer : customers) {
                 if (customer == null) {
@@ -1443,20 +1474,21 @@ public class ReportService {
         yearMonths.forEach(yearMonth -> {
             LocalDateTime startDate = yearMonth.atDay(1).atStartOfDay();
             LocalDateTime endDate = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
-            List<Contract> contracts = contractRepo.findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startDate)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            List<Contract> contracts = contractRepo
+                    .findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startDate)
+                        ));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             if (StringUtils.isNotBlank(city)) {
                 List<Long> storeIds = storeInfoRepo.findAllByCity(city)
                         .stream()
@@ -1553,7 +1585,8 @@ public class ReportService {
                         .map(Contract::getMonthlyRent)
                         .reduce(BigDecimal::add)
                         .orElse(BigDecimal.ZERO);
-                BigDecimal averageMonthRate = totalMonthRate.divide(BigDecimal.valueOf(contracts.size()), 2, RoundingMode.HALF_EVEN);
+                BigDecimal averageMonthRate = totalMonthRate
+                        .divide(BigDecimal.valueOf(contracts.size()), 2, RoundingMode.HALF_EVEN);
                 resultMap.put(yearMonth, averageMonthRate);
                 break;
             case 8:
@@ -1611,36 +1644,40 @@ public class ReportService {
             LocalDate endDate = yearMonth.atEndOfMonth();
             //当月所有续签
             PageQuery pageQuery = new PageQuery();
-            List<Contract> renewals = contractRepo.findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate.atTime(LocalTime.MAX)),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startDate.atStartOfDay())
-                ));
-                predicates.add(criteriaBuilder.equal(root.get("contractSource"), ContractSource.RENEWAL));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            List<Contract> renewals = contractRepo
+                    .findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endDate.atTime(LocalTime.MAX)),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startDate.atStartOfDay())
+                        ));
+                        predicates.add(criteriaBuilder.equal(root.get("contractSource"), ContractSource.RENEWAL));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             //当月到期合同
-            List<Contract> contracts = contractRepo.findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("contractEndTime"), endDate.atTime(LocalTime.MAX)),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("contractEndTime"), startDate.atStartOfDay())
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            List<Contract> contracts = contractRepo
+                    .findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder
+                                        .lessThanOrEqualTo(root.get("contractEndTime"), endDate.atTime(LocalTime.MAX)),
+                                criteriaBuilder
+                                        .greaterThanOrEqualTo(root.get("contractEndTime"), startDate.atStartOfDay())
+                        ));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             if (StringUtils.isNotBlank(city)) {
                 List<Long> storeIds = storeInfoRepo.findAllByCity(city)
                         .stream()
@@ -1750,54 +1787,8 @@ public class ReportService {
             PageQuery pageQuery = new PageQuery();
             LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
             LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
-            List<Customer> customers = customerRepo.findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                if (!org.springframework.util.StringUtils.isEmpty(city)) {
-                    if (!"all".equals(city)) {
-                        predicates.add(criteriaBuilder.like(root.get("contactAddress"), "%" + city + "%"));
-                    }
-                }
-                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
-            List<Residence> residences = residenceRepo.findAll((Specification<Residence>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Residence.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                predicates.add(criteriaBuilder.equal(root.get("customerLoss"), CustomerLoss.YES));
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
-            List<String> lossCustomers = new ArrayList<>();
-            residences.forEach(residence -> {
-                Contract contract = contractRepo.findById(residence.getContractId()).orElse(null);
-                if (contract != null) {
-                    if (!lossCustomers.contains(contract.getCustomer().getCoFullName())) {
-                        lossCustomers.add(contract.getCustomer().getCoFullName());
-                    }
-                }
-            });
-            int growthCustomer = customers.size() - lossCustomers.size();
-            switch (type) {
-                case 1:
-                    List<Customer> allCustomer = customerRepo.findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+            List<Customer> customers = customerRepo
+                    .findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
                         List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
                         if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
                             List<Long> saleIds = Arrays.stream(saleId.split(","))
@@ -1811,12 +1802,14 @@ public class ReportService {
                             }
                         }
                         predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
-                        predicates.add(
-                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), startTime)
-                        );
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
+                        ));
                         return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
                     });
-                    List<Residence> pastResidence = residenceRepo.findAll((Specification<Residence>) (root, criteriaQuery, criteriaBuilder) -> {
+            List<Residence> residences = residenceRepo
+                    .findAll((Specification<Residence>) (root, criteriaQuery, criteriaBuilder) -> {
                         List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Residence.class, root, criteriaQuery, criteriaBuilder);
                         if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
                             List<Long> saleIds = Arrays.stream(saleId.split(","))
@@ -1825,11 +1818,62 @@ public class ReportService {
                             predicates.add(root.get("saleId").in(saleIds));
                         }
                         predicates.add(criteriaBuilder.equal(root.get("customerLoss"), CustomerLoss.YES));
-                        predicates.add(
-                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
-                        );
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("createdAt"), startTime)
+                        ));
                         return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
                     });
+            List<String> lossCustomers = new ArrayList<>();
+            residences.forEach(residence -> {
+                Contract contract = contractRepo.findById(residence.getContractId()).orElse(null);
+                if (contract != null) {
+                    if (!lossCustomers.contains(contract.getCustomer().getCoFullName())) {
+                        lossCustomers.add(contract.getCustomer().getCoFullName());
+                    }
+                }
+            });
+            int growthCustomer = customers.size() - lossCustomers.size();
+            switch (type) {
+                case 1:
+                    List<Customer> allCustomer = customerRepo
+                            .findAll((Specification<Customer>) (root, criteriaQuery, criteriaBuilder) -> {
+                                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Customer.class, root, criteriaQuery, criteriaBuilder);
+                                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                                    List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                            .map(Long::valueOf)
+                                            .collect(Collectors.toList());
+                                    predicates.add(root.get("saleId").in(saleIds));
+                                }
+                                if (!org.springframework.util.StringUtils.isEmpty(city)) {
+                                    if (!"all".equals(city)) {
+                                        predicates.add(criteriaBuilder
+                                                .like(root.get("contactAddress"), "%" + city + "%"));
+                                    }
+                                }
+                                predicates.add(criteriaBuilder.like(root.get("intention"), "FORMAL"));
+                                predicates.add(
+                                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), startTime)
+                                );
+                                return criteriaBuilder
+                                        .and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                            });
+                    List<Residence> pastResidence = residenceRepo
+                            .findAll((Specification<Residence>) (root, criteriaQuery, criteriaBuilder) -> {
+                                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Residence.class, root, criteriaQuery, criteriaBuilder);
+                                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                                    List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                            .map(Long::valueOf)
+                                            .collect(Collectors.toList());
+                                    predicates.add(root.get("saleId").in(saleIds));
+                                }
+                                predicates.add(criteriaBuilder.equal(root.get("customerLoss"), CustomerLoss.YES));
+                                predicates.add(
+                                        criteriaBuilder.lessThanOrEqualTo(root.get("createdAt"), endTime)
+                                );
+                                return criteriaBuilder
+                                        .and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                            });
                     List<String> customerNames = new ArrayList<>();
                     pastResidence.forEach(residence -> {
                         Contract contract = contractRepo.findById(residence.getContractId()).orElse(null);
@@ -1913,7 +1957,8 @@ public class ReportService {
                                 and.add(criteriaBuilder.or(
                                         criteriaBuilder.and(
                                                 criteriaBuilder.lessThanOrEqualTo(root.get("checkinTime"), endTime),
-                                                criteriaBuilder.greaterThanOrEqualTo(root.get("checkoutTime"), startTime),
+                                                criteriaBuilder
+                                                        .greaterThanOrEqualTo(root.get("checkoutTime"), startTime),
                                                 criteriaBuilder.equal(root.get("checkout"), true)
                                         ),
                                         criteriaBuilder.and(
@@ -1941,13 +1986,15 @@ public class ReportService {
                                 }
                                 and.add(criteriaBuilder.or(
                                         criteriaBuilder.and(
-                                                criteriaBuilder.lessThanOrEqualTo(root.get("checkinTime"), endTime.minusMonths(1)),
+                                                criteriaBuilder.lessThanOrEqualTo(root.get("checkinTime"), endTime
+                                                        .minusMonths(1)),
                                                 criteriaBuilder.greaterThanOrEqualTo(root.get("checkoutTime"), startTime
                                                         .minusMonths(1)),
                                                 criteriaBuilder.equal(root.get("checkout"), true)
                                         ),
                                         criteriaBuilder.and(
-                                                criteriaBuilder.lessThanOrEqualTo(root.get("checkinTime"), endTime.minusMonths(1)),
+                                                criteriaBuilder.lessThanOrEqualTo(root.get("checkinTime"), endTime
+                                                        .minusMonths(1)),
                                                 criteriaBuilder.equal(root.get("checkout"), false)
                                         )
                                 ));
@@ -1988,20 +2035,21 @@ public class ReportService {
         Map<YearMonth, Object> result = new HashMap<>();
         PageQuery pageQuery = new PageQuery();
         yearMonths.forEach(yearMonth -> {
-            List<Contract> contracts = contractRepo.findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
-                if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
-                    List<Long> saleIds = Arrays.stream(saleId.split(","))
-                            .map(Long::valueOf)
-                            .collect(Collectors.toList());
-                    predicates.add(root.get("saleId").in(saleIds));
-                }
-                predicates.add(criteriaBuilder.and(
-                        criteriaBuilder.lessThanOrEqualTo(root.get("contractBeginTime"), endTime),
-                        criteriaBuilder.greaterThanOrEqualTo(root.get("contractEndTime"), endTime)
-                ));
-                return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
-            });
+            List<Contract> contracts = contractRepo
+                    .findAll((Specification<Contract>) (root, criteriaQuery, criteriaBuilder) -> {
+                        List<javax.persistence.criteria.Predicate> predicates = toPredicates(pageQuery, Contract.class, root, criteriaQuery, criteriaBuilder);
+                        if (!org.springframework.util.StringUtils.isEmpty(saleId)) {
+                            List<Long> saleIds = Arrays.stream(saleId.split(","))
+                                    .map(Long::valueOf)
+                                    .collect(Collectors.toList());
+                            predicates.add(root.get("saleId").in(saleIds));
+                        }
+                        predicates.add(criteriaBuilder.and(
+                                criteriaBuilder.lessThanOrEqualTo(root.get("contractBeginTime"), endTime),
+                                criteriaBuilder.greaterThanOrEqualTo(root.get("contractEndTime"), endTime)
+                        ));
+                        return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[0]));
+                    });
             Set<Customer> customers = contracts.stream().map(Contract::getCustomer).collect(Collectors.toSet());
 
             switch (type) {

+ 16 - 14
src/main/java/com/izouma/zhumj/service/sale/ContractBillService.java

@@ -56,7 +56,8 @@ public class ContractBillService {
             List<ReceiptStatus> receiptStatuses = new ArrayList<>();
             receiptStatuses.add(ReceiptStatus.COMPLETED);
             receiptStatuses.add(ReceiptStatus.APPLY);
-            BillReceipt billReceipt = billReceiptRepo.findByBillIdAndStatusInAndBillTypeNot(contractBill.getId(), receiptStatuses, ReceiptType.DEPOSIT);
+            BillReceipt billReceipt = billReceiptRepo
+                    .findByBillIdAndStatusInAndBillTypeNot(contractBill.getId(), receiptStatuses, ReceiptType.DEPOSIT);
             if (billReceipt == null) {
                 paymentReportDTO.setReceiptStatus(ReceiptStatus.UNDO);
                 paymentReportDTO.setReceiptAmount(BigDecimal.ZERO.toString());
@@ -336,7 +337,7 @@ public class ContractBillService {
         return contractBillRepo.queryCustomerPostPaidDueTimes(customerId);
     }
 
-    public Page<ContractBill> arrearsContractBill(String search, Pageable pageable) {
+    public Page<ContractBill> arrearsContractBill(String search, LocalDate start, LocalDate end, Pageable pageable) {
         List<Long> breaks = new ArrayList<>();
         List<Long> customerIds = customerRepo.findByCoFullNameLikeOrCoSimpleNameLike(search, search)
                 .stream()
@@ -347,18 +348,6 @@ public class ContractBillService {
                 .map(Contract::getId)
                 .collect(Collectors.toList());
         contractRepo.findByStatus(ContractStatus.BREAK).forEach(contract -> breaks.add(contract.getId()));
-        if (SecurityUtils.hasRole(Authority.NAME.ROLE_SALE)) {
-            return contractBillRepo.findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) -> {
-                List<Predicate> and = new ArrayList<>();
-                and.add(criteriaBuilder.lessThan(root.get("rest"), BigDecimal.ZERO));
-                and.add(criteriaBuilder.not(root.get("contractId").in(breaks)));
-                if (StringUtils.isNotBlank(search)) {
-                    and.add(root.get("contractId").in(contracts));
-                }
-                and.add(criteriaBuilder.equal(root.get("saleId"), SecurityUtils.getAuthenticatedUser().getId()));
-                return criteriaBuilder.and(and.toArray(new Predicate[0]));
-            }, pageable);
-        }
         return contractBillRepo.findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) -> {
             List<Predicate> and = new ArrayList<>();
             and.add(criteriaBuilder.not(root.get("contractId").in(breaks)));
@@ -366,6 +355,19 @@ public class ContractBillService {
             if (StringUtils.isNotBlank(search)) {
                 and.add(root.get("contractId").in(contracts));
             }
+            and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("status"), BillStatus.COMPLETED)));
+            if (SecurityUtils.hasRole(Authority.NAME.ROLE_SALE)) {
+                and.add(criteriaBuilder.equal(root.get("saleId"), SecurityUtils.getAuthenticatedUser().getId()));
+            }
+            and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("recharged"), root.get("money"))));
+            if (start != null & end != null) {
+                and.add(criteriaBuilder
+                        .between(root.get("startTime"), start.atStartOfDay(), end.atTime(LocalTime.MAX)));
+            }
+            if (start == null) {
+                and.add(criteriaBuilder
+                        .lessThanOrEqualTo(root.get("startTime"), LocalDate.now().atTime(LocalTime.MAX)));
+            }
             return criteriaBuilder.and(and.toArray(new Predicate[0]));
         }, pageable);
     }

+ 3 - 3
src/main/java/com/izouma/zhumj/service/sale/ContractStaffService.java

@@ -27,9 +27,9 @@ import java.util.stream.Collectors;
 @Slf4j
 public class ContractStaffService {
 
-    private ContractStaffRepo contractStaffRepo;
-    private ContractRepo contractRepo;
-    private ApplicationContext applicationContext;
+    private final ContractStaffRepo contractStaffRepo;
+    private final ContractRepo      contractRepo;
+    private final ApplicationContext applicationContext;
 
     public Page<ContractStaff> findContractStaff(Long contractId, Long customerId, Pageable pageable) {
         List<Long> contractIds = new ArrayList<>();

+ 3 - 2
src/main/java/com/izouma/zhumj/web/sale/ContractBillController.java

@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -136,8 +137,8 @@ public class ContractBillController {
     }
 
     @GetMapping("/arrearsContractBill")
-    public Page<ContractBill> arrearsContractBill(String search, Pageable pageable) {
-        return contractBillService.arrearsContractBill(search, pageable);
+    public Page<ContractBill> arrearsContractBill(String search, @RequestParam(required = false) LocalDate start, @RequestParam(required = false) LocalDate end, Pageable pageable) {
+        return contractBillService.arrearsContractBill(search, start, end, pageable);
     }
 
     @GetMapping("/getContractBill")

+ 6 - 5
src/main/java/com/izouma/zhumj/web/sale/ContractStaffController.java

@@ -26,10 +26,10 @@ import java.util.List;
 @RequestMapping("/contractStaff")
 @AllArgsConstructor
 public class ContractStaffController extends BaseController {
-    private ContractStaffService contractStaffService;
-    private ContractStaffRepo    contractStaffRepo;
-    private ContractRepo         contractRepo;
-    private ApplicationContext   applicationContext;
+    private final ContractStaffService contractStaffService;
+    private final ContractStaffRepo    contractStaffRepo;
+    private final ContractRepo         contractRepo;
+    private final ApplicationContext   applicationContext;
 
     @PostMapping("/save")
     public ContractStaff save(@RequestBody ContractStaff record) {
@@ -82,7 +82,8 @@ public class ContractStaffController extends BaseController {
     }
 
     @PostMapping("/setCheckoutDate")
-    public void seCheckoutDate(@RequestParam(required = true) Long id, @RequestParam(required = true) LocalDate checkoutDate) {
+    public void seCheckoutDate(@RequestParam(required = true) Long id,
+                               @RequestParam(required = true) LocalDate checkoutDate) {
         contractStaffService.setCheckOutDate(id, checkoutDate);
     }
 }

+ 1 - 0
src/main/vue/src/views/ArrearsContractBill.vue

@@ -9,6 +9,7 @@
                 end-placeholder="结束日期"
             >
             </el-date-picker>
+            <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
             <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索</el-button>
         </div>
         <el-table