Browse Source

自动结算

wangqifan 3 years ago
parent
commit
ee22cfd9b9
1 changed files with 22 additions and 2 deletions
  1. 22 2
      src/main/java/com/izouma/zhumj/service/sale/ContractService.java

+ 22 - 2
src/main/java/com/izouma/zhumj/service/sale/ContractService.java

@@ -1046,15 +1046,35 @@ public class ContractService {
     @Scheduled(cron = "0 0 4 * * ?")
     @Scheduled(cron = "0 0 4 * * ?")
     public void checkContractRoom() {
     public void checkContractRoom() {
         List<ContractBill> contractBills = contractBillRepo.findByRestLessThan(BigDecimal.ZERO);
         List<ContractBill> contractBills = contractBillRepo.findByRestLessThan(BigDecimal.ZERO);
+        List<RoomInfo> saveRecords = new ArrayList<>();
         contractBills.forEach(contractBill -> {
         contractBills.forEach(contractBill -> {
             Set<Long> roomIds = checkinInfoRepo.findAllRoomIdByOrderId(contractBill.getContractId());
             Set<Long> roomIds = checkinInfoRepo.findAllRoomIdByOrderId(contractBill.getContractId());
             List<RoomInfo> roomInfos = roomInfoRepo.findAllById(roomIds);
             List<RoomInfo> roomInfos = roomInfoRepo.findAllById(roomIds);
-            List<RoomInfo> saveRecords = new ArrayList<>();
             roomInfos.forEach(roomInfo -> {
             roomInfos.forEach(roomInfo -> {
                 roomInfo.setPaymentStatus(true);
                 roomInfo.setPaymentStatus(true);
                 saveRecords.add(roomInfo);
                 saveRecords.add(roomInfo);
             });
             });
-            roomInfoRepo.saveAll(saveRecords);
         });
         });
+        Set<Long> ids = saveRecords.stream().map(RoomInfo::getId).collect(Collectors.toSet());
+        List<RoomInfo> noArrears = roomInfoRepo.findAllByIdNotInAndPaymentStatus(ids, true);
+        noArrears.forEach(roomInfo -> {
+            roomInfo.setPaymentStatus(false);
+            saveRecords.add(roomInfo);
+        });
+        roomInfoRepo.saveAll(saveRecords);
+    }
+
+    //    @Scheduled(cron = "0 0 4 * * ?")
+    public void checkRoom(Long cusId) {
+        List<Contract> contracts = contractRepo.findAllByCustomerId(cusId);
+        Set<Long> ids = contracts.stream().map(Contract::getId).collect(Collectors.toSet());
+        Set<Long> roomIds = checkinInfoRepo.findAllRoomIdByOrderIdIn(ids);
+        List<RoomInfo> roomInfos = roomInfoRepo.findAllByIdIn(roomIds);
+        List<RoomInfo> news = new ArrayList<>();
+        roomInfos.forEach(roomInfo -> {
+            roomInfo.setPaymentStatus(false);
+            news.add(roomInfo);
+        });
+        roomInfoRepo.saveAll(news);
     }
     }
 }
 }