From 5fa6e6f8410ef9d057174bcff2a3c5038c54a551 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期日, 27 四月 2025 18:41:20 +0800
Subject: [PATCH] bug修改

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java |  122 ++++++++++++++++++++++++++++------------
 1 files changed, 86 insertions(+), 36 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
index 94a394a..52f1852 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
@@ -91,19 +91,22 @@
     private final THouseService houseService;
 
     public static void main(String[] args) {
-        LocalDate localDate1 = LocalDate.now().withYear(2025).withMonth(1).withDayOfMonth(31);
-        System.err.println(localDate1.plusMonths(1));
+//        LocalDate localDate1 = LocalDate.now().withYear(2025).withMonth(2).withDayOfMonth(10).with;
+//        System.err.println(localDate1.plusMonths(1));
 
 ////        LocalDate localDate2 = LocalDate.now().withYear(2025).withMonth(4).withDayOfMonth(16);
-//        LocalDateTime localDate1 = LocalDateTime.now().withYear(2025).withMonth(4).withDayOfMonth(16);
-//        LocalDateTime localDate2 = LocalDateTime.now().withYear(2025).withMonth(10).withDayOfMonth(24);
-//
+//        LocalDateTime localDate1 = LocalDateTime.now().withYear(2025).withMonth(2).withDayOfMonth(10).withHour(00).withMinute(00).withSecond(00);
+//        LocalDateTime localDate2 = LocalDateTime.now().withYear(2025).withMonth(3).withDayOfMonth(31).withHour(00).withMinute(00).withSecond(00);
+//        LocalDateTime with = localDate1.plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
+//        boolean before = with.isBefore(localDate2);
+//        System.err.println(before);
 //        long between = ChronoUnit.DAYS.between(localDate1, localDate2)+1;
-        int monthValue = LocalDateTime.now().getMonthValue();
-         LocalDateTime.now();
-         LocalDateTime.now();
-
-        System.err.println(LocalDateTime.now().isBefore(LocalDateTime.now()));
+//        int monthValue = LocalDateTime.now().getMonthValue();
+//         LocalDateTime.now();
+//         LocalDateTime.now();
+        int dayOfMonth = LocalDateTime.now().getMonthValue();
+        System.err.println(dayOfMonth);
+//        System.err.println(LocalDateTime.now().isBefore(LocalDateTime.now()));
     }
 
     @Override
@@ -269,6 +272,7 @@
     }
 
 
+
     /**
      * 业务状态变更
      */
@@ -301,9 +305,9 @@
                     }
                     List<TContractRentType> contractRentTypes = contractRentTypeService.list();
                     TContractRentType tContractRentType = contractRentTypes.stream().filter(e -> e.getContractId().equals(contract.getId())).findFirst().orElse(null);
-
                     // 生成第一笔账单
                     // 第一次应缴费日期
+
                     LocalDateTime firstPayTime = contract.getStartTime().plusDays(10).withHour(0).withMinute(0).withSecond(0);
                     TBill rentBill = new TBill();
                     rentBill.setContractId(contract.getId());
@@ -425,22 +429,41 @@
                             // 第一个月计算天
                             int dayOfMonth = rentBill.getStartTime().getDayOfMonth();
                             if (dayOfMonth == 1) {
+                                System.err.println("第一笔账单 1号计算整月:");
                                 money = money.add(contract.getMonthRent());
                             } else {
-                                long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), contract.getStartPayTime().with(TemporalAdjusters.lastDayOfMonth())) + 1;
+                                long allDays = Math.abs(ChronoUnit.DAYS.between(rentBill.getStartTime(), rentBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())) + 1);
+                                System.err.println("第一笔账单 计算天数"+allDays);
                                 money =money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays)));
+                                System.err.println("第一笔账单 计算天数金额"+money);
                             }
                             // 后续
                             if (contract.getStartPayTime().getMonthValue()==3||contract.getStartPayTime().getMonthValue()==6||contract.getStartPayTime().getMonthValue()==9||contract.getStartPayTime().getMonthValue()==12){
+                                System.err.println("后续账单 月为3 6 9 12金额"+money);
                                 rentBill.setPayableFeesMoney(money);
                                 rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney());
                             }else{
+
                                 LocalDateTime localDateTime = rentBill.getStartTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
+                                System.err.println("后续账单逻辑时间"+localDateTime);
                                 while (true){
-                                    if (localDateTime.isBefore(rentBill.getEndTime())){
+                                    if (localDateTime.toLocalDate().isBefore(rentBill.getEndTime().toLocalDate())){
+                                        System.err.println("后续while 在结束之前");
                                         money = money.add(contract.getMonthRent());
-                                    }else{
-                                        money = money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(ChronoUnit.DAYS.between(rentBill.getEndTime(),localDateTime.with(TemporalAdjusters.firstDayOfMonth()))+1)));
+                                    }else if(localDateTime.toLocalDate().equals(rentBill.getEndTime().toLocalDate())){
+                                        System.err.println("后续while 结束");
+                                        money = money.add(contract.getMonthRent());
+                                        break;
+                                    }else {
+                                        System.err.println("后续while 加一个月大于结束时间");
+                                        if (localDateTime.with(TemporalAdjusters.firstDayOfMonth()).isBefore(rentBill.getEndTime())){
+                                            long a = ChronoUnit.DAYS.between(localDateTime.with(TemporalAdjusters.firstDayOfMonth()),rentBill.getEndTime())+1;
+                                            System.err.println("后续while 加一个月大于结束时间 计算天数"+a);
+                                            money = money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(
+                                                    new BigDecimal(ChronoUnit.DAYS.between(localDateTime.with(TemporalAdjusters.firstDayOfMonth()),rentBill.getEndTime())+1))
+                                            );
+                                        }
+
                                         break;
                                     }
                                     localDateTime = localDateTime.plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
@@ -455,7 +478,7 @@
                             if (dayOfMonth == 1) {
                                 money = money.add(contract.getMonthRent());
                             } else {
-                                long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), contract.getStartPayTime().with(TemporalAdjusters.lastDayOfMonth())) + 1;
+                                long allDays = ChronoUnit.DAYS.between(rentBill.getStartTime(), rentBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())) ;
                                 money =money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays)));
                             }
                             // 后续
@@ -463,15 +486,16 @@
                                 rentBill.setPayableFeesMoney(money);
                                 rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney());
                             }else{
-                                LocalDateTime localDateTime = rentBill.getStartTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
+//                                LocalDateTime localDateTime = rentBill.getStartTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
+                                LocalDateTime localDateTime = rentBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).plusDays(1);
                                 while (true){
                                     if (localDateTime.isBefore(rentBill.getEndTime())){
+                                        localDateTime = localDateTime.plusMonths(1);
                                         money = money.add(contract.getMonthRent());
                                     }else{
-                                        money = money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(ChronoUnit.DAYS.between(rentBill.getEndTime(),localDateTime.with(TemporalAdjusters.firstDayOfMonth()))+1)));
+                                        money = money.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(ChronoUnit.DAYS.between(rentBill.getEndTime(),localDateTime.with(TemporalAdjusters.firstDayOfMonth())))));
                                         break;
                                     }
-                                    localDateTime = localDateTime.plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
                                 }
                                 rentBill.setPayableFeesMoney(money);
                                 rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney());
@@ -502,6 +526,8 @@
 
                     depositBill.setBillType("2");
                     contractService.updateById(contract);
+                    rentBill.setBusinessDeptId(contract.getBusinessDeptId());
+                    depositBill.setBusinessDeptId(contract.getBusinessDeptId());
                     billService.save(rentBill);
                     billService.save(depositBill);
                     // 生成后续账单
@@ -721,6 +747,7 @@
                                 tBill.setContractNumber(contract.getContractNumber());
                                 tBill.setPayFeesStatus("1");
                                 tBill.setBillType("1");
+                                tBill.setBusinessDeptId(contract.getBusinessDeptId());
 
                                 billService.save(tBill);
                                 beforeBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
@@ -929,10 +956,16 @@
                                 BigDecimal originalMoney = new BigDecimal("0");
                                 // 不需要涨租金的时间段
                                 long originalDays = 0;
-                                if (tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).isBefore(tBill.getEndTime())){
-                                    originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())));
+                                if (tBill.getStartTime().getDayOfMonth()==1&&(tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).toLocalDate().isAfter(tBill.getEndTime().toLocalDate())||tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).toLocalDate().equals(tBill.getEndTime().toLocalDate()))){
+                                    // 计算整月
+                                    originalMoney = originalMoney.add(contract.getChangeRent());
                                 }else{
-                                    originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getEndTime()));
+                                    // 计算天
+                                    if (tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).isBefore(tBill.getEndTime())){
+                                        originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())))+1;
+                                    }else{
+                                        originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getEndTime()))+1;
+                                    }
                                 }
                                 originalMoney = originalMoney.add(contract.getChangeRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(originalDays)));
                                 LocalDateTime originalTime = tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).plusDays(1);
@@ -957,12 +990,24 @@
                             BigDecimal originalMoney = new BigDecimal("0");
                             // 不需要涨租金的时间段
                             long originalDays = 0;
-                            if (tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).isBefore(tBill.getEndTime())){
-                                originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())))+1;
+                            if (tBill.getStartTime().getDayOfMonth()==1
+                                    &&
+                                    (
+                                            tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).toLocalDate().isBefore(tBill.getEndTime().toLocalDate())
+                                            ||tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).toLocalDate().equals(tBill.getEndTime().toLocalDate())
+                                    )
+                            ){
+                                // 计算整月
+                                originalMoney = originalMoney.add(contract.getChangeRent());
                             }else{
-                                originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getEndTime()))+1;
+                                // 计算天
+                                if (tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).isBefore(tBill.getEndTime())){
+                                    originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth())))+1;
+                                }else{
+                                    originalDays = Math.abs(ChronoUnit.DAYS.between(tBill.getStartTime(), tBill.getEndTime()))+1;
+                                }
+                                originalMoney = originalMoney.add(contract.getChangeRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(originalDays)));
                             }
-                            originalMoney = originalMoney.add(contract.getChangeRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(originalDays)));
                             LocalDateTime originalTime = tBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).plusDays(1);
                             while(true){
                                 if (originalTime.isBefore(tBill.getEndTime())){
@@ -976,21 +1021,22 @@
                                     break;
                                 }
                             }
-                            if (originalTime.isBefore(tBill.getEndTime())){
-                                long tempOriginal  = ChronoUnit.DAYS.between(originalTime,tBill.getEndTime());
+                            if (originalTime.isBefore(tBill.getEndTime())||originalTime.toLocalDate().equals(tBill.getEndTime().toLocalDate())){
+                                long tempOriginal  = ChronoUnit.DAYS.between(originalTime,tBill.getEndTime())+1;
                                 originalMoney = originalMoney.add(contract.getChangeRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(tempOriginal)));
                             }
                             tBill.setPayableFeesMoney(originalMoney);
                             tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                         }
-                        if (tBill.getEndTime().getDayOfMonth() >= 15) {
+//                        if (tBill.getEndTime().getDayOfMonth() >= 15) {
+//                            tBill.setPayableFeesTime(tBill.getStartTime().withDayOfMonth(15).toLocalDate());
+//                        } else if (tBill.getStartTime().getYear() == tBill.getEndTime().getYear() && tBill.getStartTime().getMonthValue() == tBill.getEndTime().getMonthValue()) {
+//                            // 如果同年同月 且日小于15 缴费时间取合同
+//                            tBill.setPayableFeesTime(tBill.getStartTime().toLocalDate());
+//                        } else {
                             tBill.setPayableFeesTime(tBill.getStartTime().withDayOfMonth(15).toLocalDate());
-                        } else if (tBill.getStartTime().getYear() == tBill.getEndTime().getYear() && tBill.getStartTime().getMonthValue() == tBill.getEndTime().getMonthValue()) {
-                            // 如果同年同月 且日小于15 缴费时间取合同
-                            tBill.setPayableFeesTime(tBill.getStartTime().toLocalDate());
-                        } else {
-                            tBill.setPayableFeesTime(tBill.getStartTime().withDayOfMonth(15).toLocalDate());
-                        }
+//                        }
+                        tBill.setBusinessDeptId(contract.getBusinessDeptId());
                         billService.save(tBill);
                     }
                 }
@@ -998,13 +1044,17 @@
             }
             case CATEGORY3: {
                 // 合同提前终止审批
-                int submitStatus = status == 0 ? 4 : (status == 1 ? 7 : 5);
+                int submitStatus = status == 0 ? 4 : (status == 1 ? 7 : 4);
                 contractService.updateContractAuditStatus(processParameter.getString("projectId"), submitStatus);
                 // 生成验收记录
                 TContract contract = contractService.getById(processParameter.getString("projectId"));
                 //更新合同结束时间
                 contract.setEndTime(contract.getTerminateTime());
                 contractService.updateById(contract);
+                // 修改房屋状态
+                THouse house = houseService.getById(contract.getHouseId());
+                house.setLeaseStatus("1");
+                houseService.updateById(house);
 
                 TCheckAcceptRecord tCheckAcceptRecord = new TCheckAcceptRecord();
                 tCheckAcceptRecord.setContractId(contract.getId());

--
Gitblit v1.7.1