无关风月
2025-03-18 2e833e9cfd9ee9979f643b6ea363cfab0ee34eec
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
@@ -85,6 +85,15 @@
    private final TBillService billService;
    private final TCheckAcceptRecordMapper checkAcceptRecordMapper;
    public static void main(String[] args) {
//        LocalDate localDate1 = LocalDate.now().withYear(2025).withMonth(4).withDayOfMonth(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);
        long between = ChronoUnit.DAYS.between(localDate1, localDate2)+1;
        System.err.println(between);
    }
    @Override
    public boolean notify(EventType eventType, Supplier<FlwTask> supplier, NodeModel nodeModel, FlowCreator flowCreator) {
        FlwTask flwTask = supplier.get();
@@ -290,11 +299,11 @@
                        rentBill.setEndTime(rentBill.getStartTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
                    }
                } else {
                    rentBill.setEndTime(contract.getEndTime());
                    rentBill.setEndTime(rentBill.getStartTime().with(TemporalAdjusters.lastDayOfMonth()));
                }
                if (tContractRentType != null && rentBill.getEndTime().isAfter(tContractRentType.getChangeTime())) {
                    long moneyDays = 0;
                    moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), rentBill.getEndTime());
                    moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), rentBill.getEndTime())+1;
                    // 计算租金变动的天数
                    contract.setChangeTime(tContractRentType.getChangeTime());
                    // 递增递减的租金
@@ -306,12 +315,12 @@
                        case 1:
                            switch (tContractRentType.getIncreasingDecreasing()) {
                                case 1:
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                    // 变动后的每月租金
                                    contract.setChangeRent(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                    break;
                                case 2:
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                    contract.setChangeRent(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                    break;
                            }
@@ -319,11 +328,11 @@
                        case 2:
                            switch (tContractRentType.getIncreasingDecreasing()) {
                                case 1:
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                    contract.setChangeRent(contract.getChangeRent().add(tContractRentType.getNumericalValue()));
                                    break;
                                case 2:
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                    contract.setChangeRent(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()));
                                    break;
                            }
@@ -337,7 +346,7 @@
                    rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney());
                } else {
                    // 不走递增递减
                    long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), rentBill.getEndTime());
                    long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), rentBill.getEndTime())+1;
                    int dayOfMonth = rentBill.getStartTime().getDayOfMonth();
                    if (dayOfMonth == 1) {
                        rentBill.setPayableFeesMoney(contract.getMonthRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
@@ -365,12 +374,15 @@
                billService.save(depositBill);
                // 生成后续账单
                try {
                    TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime)
                    TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getStartTime)
                            .last("limit 1").one();
                    if (!beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate())) {
                        while (beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).isBefore(contract.getEndTime())) {
                            System.err.println("生成后续账单");
                            TBill tBill = new TBill();
                            tBill.setContractId(contract.getId());
                            tBill.setStartTime(beforeBill.getEndTime().plusDays(1));
                            tBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
                            tBill.setContractNumber(contract.getContractNumber());
                            if (beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).getDayOfMonth() <= 15) {
                                tBill.setPayableFeesTime(contract.getEndTime().toLocalDate());
@@ -379,9 +391,9 @@
                                        beforeBill.getEndTime().plusMonths(1).withDayOfMonth(15).toLocalDate() : contract.getPayType().equals("2") ?
                                        beforeBill.getEndTime().plusMonths(3).withDayOfMonth(15).toLocalDate() : beforeBill.getEndTime().withDayOfMonth(15).plusMonths(12).toLocalDate()));
                            }
                            // 根据支付方式判断需不需要生成订单
                            tBill.setContractId(contract.getId());
                            if (contract.getIsIncreasing()) {
                                System.err.println("执行递增递减");
                                if (tContractRentType != null) {
                                    // 如果变过 并且时间在递增递减时间段内
                                    if (contract.getChangeTime() != null) {
@@ -391,7 +403,7 @@
                                        if (changeTime.isBefore(tBill.getEndTime()) && changeTime.isAfter(tBill.getStartTime())) {
                                            contract.setChangeTime(changeTime);
                                            // 租金递增递减的时长 天
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), beforeBill.getEndTime()));
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                            // 递增递减的租金
                                            BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                            // 不递增递减的租金
@@ -401,12 +413,12 @@
                                                case 1:
                                                    switch (tContractRentType.getIncreasingDecreasing()) {
                                                        case 1:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                            // 变动后的每月租金
                                                            contract.setChangeRent(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                            break;
                                                        case 2:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                            contract.setChangeRent(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                            break;
                                                    }
@@ -414,20 +426,20 @@
                                                case 2:
                                                    switch (tContractRentType.getIncreasingDecreasing()) {
                                                        case 1:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                            contract.setChangeRent(contract.getChangeRent().add(tContractRentType.getNumericalValue()));
                                                            break;
                                                        case 2:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                            contract.setChangeRent(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()));
                                                            break;
                                                    }
                                                    break;
                                            }
                                            // 不需要涨租金的时间段
                                            long originalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), tContractRentType.getChangeTime());
                                            long originalDays = ChronoUnit.DAYS.between(tBill.getStartTime(), tContractRentType.getChangeTime());
                                            if (originalDays > 0) {
                                                originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                                originalMoney = originalMoney.add(contract.getChangeRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                                        .multiply(new BigDecimal(originalDays));
                                            }
                                            tBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
@@ -440,9 +452,10 @@
                                        }
                                    }else{
                                        if (tContractRentType.getChangeTime().isBefore(tBill.getEndTime()) && tContractRentType.getChangeTime().isAfter(tBill.getStartTime())) {
                                            System.err.println("首次递增递减");
                                            contract.setChangeTime(tContractRentType.getChangeTime());
                                            // 租金递增递减的时长 天
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), beforeBill.getEndTime()));
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                            // 递增递减的租金
                                            BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                            // 不递增递减的租金
@@ -452,12 +465,12 @@
                                                case 1:
                                                    switch (tContractRentType.getIncreasingDecreasing()) {
                                                        case 1:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                            // 变动后的每月租金
                                                            contract.setChangeRent(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                            break;
                                                        case 2:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                            contract.setChangeRent(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                            break;
                                                    }
@@ -465,41 +478,46 @@
                                                case 2:
                                                    switch (tContractRentType.getIncreasingDecreasing()) {
                                                        case 1:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                            contract.setChangeRent(contract.getChangeRent().add(tContractRentType.getNumericalValue()));
                                                            break;
                                                        case 2:
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                            contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                            contract.setChangeRent(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()));
                                                            break;
                                                    }
                                                    break;
                                            }
                                            // 不需要涨租金的时间段
                                            long originalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), tContractRentType.getChangeTime());
                                            long originalDays = ChronoUnit.DAYS.between(tBill.getStartTime(), tContractRentType.getChangeTime());
                                            System.err.println("不需要长租金时长"+originalDays);
                                            if (originalDays > 0) {
                                                originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                                        .multiply(new BigDecimal(originalDays));
                                            }
                                            tBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
                                            tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                            contractService.updateById(contract);
                                        }else{
                                            tBill.setPayableFeesMoney(contract.getChangeRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
                                            tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                        }
                                    }
                                } else {
                                    tBill.setPayableFeesMoney(contract.getMonthRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
                                    tBill.setPayableFeesMoney(contract.getChangeRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                }
                                tBill.setContractNumber(contract.getContractNumber());
                                tBill.setPayFeesStatus("1");
                                tBill.setBillType("1");
                                tBill.setStartTime(beforeBill.getEndTime().plusDays(1));
                                tBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
                                billService.save(tBill);
                                beforeBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
                            }else {
                                System.err.println("不执行递增递减");
                                tBill.setPayableFeesMoney(contract.getChangeRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
                                tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                            }
                            tBill.setContractNumber(contract.getContractNumber());
                            tBill.setPayFeesStatus("1");
                            tBill.setBillType("1");
                            billService.save(tBill);
                            beforeBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()));
                        }
                    }
                } catch (Exception e) {
@@ -517,67 +535,18 @@
                    tBill.setBillType("1");
                    tBill.setStartTime(beforeBill.getEndTime().plusDays(1));
                    tBill.setEndTime(contract.getEndTime());
                    tBill.setContractNumber(contract.getContractNumber());
                    if (contract.getIsIncreasing()) {
                        if (tContractRentType != null
                                && beforeBill.getEndTime().isBefore(tContractRentType.getChangeTime())
                                && beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).with(TemporalAdjusters.lastDayOfMonth()).isAfter(tContractRentType.getChangeTime())) {
                            // 如果没变过
                            if (contract.getChangeTime() == null) {
                                contract.setChangeTime(LocalDateTime.now());
                                // 租金递增递减的时长 天
                                long moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), contract.getEndTime());
                                // 递增递减的租金
                                BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                // 不递增递减的租金
                                BigDecimal originalMoney = new BigDecimal("0");
                                // 原租金
                                switch (tContractRentType.getIncreasingDecreasingType()) {
                                    case 1:
                                        switch (tContractRentType.getIncreasingDecreasing()) {
                                            case 1:
                                                contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                contract.setChangeRent(contractRentTypeMoney);
                                                break;
                                            case 2:
                                                contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).divide(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12), 2, BigDecimal.ROUND_DOWN));
                                                contract.setChangeRent(contractRentTypeMoney);
                                                break;
                                        }
                                        break;
                                    case 2:
                                        switch (tContractRentType.getIncreasingDecreasing()) {
                                            case 1:
                                                contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                contract.setChangeRent(contractRentTypeMoney);
                                                break;
                                            case 2:
                                                contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                contract.setChangeRent(contractRentTypeMoney);
                                                break;
                                        }
                                        break;
                                }
                                // 不需要涨租金的时间段
                                long originalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), tContractRentType.getChangeTime());
                                // 不需要涨租金的时间段
                                if (contract.getFirstPayTime().isBefore(tContractRentType.getChangeTime())) {
                                    originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                            .multiply(new BigDecimal(originalDays));
                                    tBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                } else {
                                    tBill.setPayableFeesMoney(contractRentTypeMoney);
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                }
                            } else {
                        if (tContractRentType != null) {
                            // 如果变过 并且时间在递增递减时间段内
                            if (contract.getChangeTime() != null) {
                                // 下次递增递减时间
                                LocalDateTime changeTime = contract.getChangeTime().plusYears(tContractRentType.getCycleTime());
                                // 之前已经涨、跌过租金了 需要判断周期是否还需要再涨、跌
                                if ((LocalDateTime.now().getYear() - contract.getChangeTime().getYear()) % tContractRentType.getCycleTime() == 0) {
                                    contract.setChangeTime(LocalDateTime.now());
                                if (changeTime.isBefore(tBill.getEndTime()) && changeTime.isAfter(tBill.getStartTime())) {
                                    contract.setChangeTime(changeTime);
                                    // 租金递增递减的时长 天
                                    long moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), contract.getEndTime());
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(changeTime, tBill.getEndTime()))+1;
                                    // 递增递减的租金
                                    BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                    // 不递增递减的租金
@@ -587,40 +556,48 @@
                                        case 1:
                                            switch (tContractRentType.getIncreasingDecreasing()) {
                                                case 1:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                    // 变动后的每月租金
                                                    contract.setChangeRent(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                    break;
                                                case 2:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).divide(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12), 2, BigDecimal.ROUND_DOWN));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                    contract.setChangeRent(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                    break;
                                            }
                                            break;
                                        case 2:
                                            switch (tContractRentType.getIncreasingDecreasing()) {
                                                case 1:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                    contract.setChangeRent(contract.getChangeRent().add(tContractRentType.getNumericalValue()));
                                                    break;
                                                case 2:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                    contract.setChangeRent(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()));
                                                    break;
                                            }
                                            break;
                                    }
                                    // 不需要涨租金的时间段
                                    long originalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), tContractRentType.getChangeTime());
                                    originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                            .multiply(new BigDecimal(originalDays));
                                    long originalDays = ChronoUnit.DAYS.between(tBill.getStartTime(), changeTime);
                                    if (originalDays > 0) {
                                        originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                                .multiply(new BigDecimal(originalDays));
                                    }
                                    tBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                    contractService.updateById(contract);
                                } else {
                                    // 不涨租金 用上次的
                                    long finalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), contract.getEndTime());
                                    tBill.setPayableFeesMoney(contract.getChangeRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(finalDays)));
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                }
                            }else{
                                if (tContractRentType.getChangeTime().isBefore(tBill.getEndTime()) && tContractRentType.getChangeTime().isAfter(tBill.getStartTime())) {
                                    contract.setChangeTime(tContractRentType.getChangeTime());
                                    // 租金递增递减的时长 天
                                    long moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), contract.getEndTime());
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                    // 递增递减的租金
                                    BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                    // 不递增递减的租金
@@ -630,54 +607,64 @@
                                        case 1:
                                            switch (tContractRentType.getIncreasingDecreasing()) {
                                                case 1:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                    // 变动后的每月租金
                                                    contract.setChangeRent(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                    break;
                                                case 2:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).divide(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12), 2, BigDecimal.ROUND_DOWN));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN));
                                                    contract.setChangeRent(contract.getChangeRent().multiply((new BigDecimal(100).subtract(tContractRentType.getNumericalValue()))).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN));
                                                    break;
                                            }
                                            break;
                                        case 2:
                                            switch (tContractRentType.getIncreasingDecreasing()) {
                                                case 1:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                    contract.setChangeRent(contract.getChangeRent().add(tContractRentType.getNumericalValue()));
                                                    break;
                                                case 2:
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays));
                                                    contract.setChangeRent(contractRentTypeMoney);
                                                    contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)).setScale(2, BigDecimal.ROUND_DOWN);
                                                    contract.setChangeRent(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()));
                                                    break;
                                            }
                                            break;
                                    }
                                    // 不需要涨租金的时间段
                                    long originalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), tContractRentType.getChangeTime());
                                    originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                            .multiply(new BigDecimal(originalDays));
                                    long originalDays = ChronoUnit.DAYS.between(tBill.getStartTime(), tContractRentType.getChangeTime());
                                    if (originalDays > 0) {
                                        originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                                                .multiply(new BigDecimal(originalDays)).setScale(2,BigDecimal.ROUND_DOWN);
                                    }
                                    tBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
                                    tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                                    contractService.updateById(contract);
                                }
                            }
                        } else {
                            if (tBill.getStartTime().getDayOfMonth()==1 && tBill.getEndTime().toLocalDate().equals(tBill.getEndTime().with(TemporalAdjusters.lastDayOfMonth()).toLocalDate())){
                                tBill.setPayableFeesMoney(contract.getChangeRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
                                tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                            }else{
                                // 最后一笔账单时间
                                long finalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), contract.getEndTime());
                                tBill.setPayableFeesMoney(contract.getChangeRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(finalDays)));
                                tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                            }
                        }
                    } else {
                        long allDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), contract.getEndTime());
                        tBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays)));
                    }else{
                        long finalDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), contract.getEndTime());
                        tBill.setPayableFeesMoney(contract.getChangeRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(finalDays)));
                        tBill.setOutstandingMoney(tBill.getPayableFeesMoney());
                    }
                    tBill.setContractNumber(contract.getContractNumber());
                    if (beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12).getDayOfMonth() <= 15) {
                        tBill.setPayableFeesTime(contract.getEndTime().withHour(0).withMinute(0).withSecond(0).toLocalDate());
                    } else {
                        tBill.setPayableFeesTime((contract.getPayType().equals("1") ?
                                beforeBill.getEndTime().plusMonths(1).withDayOfMonth(15).toLocalDate() : contract.getPayType().equals("2") ?
                                beforeBill.getEndTime().plusMonths(3).withDayOfMonth(15).toLocalDate() : beforeBill.getEndTime().withDayOfMonth(15).plusMonths(12).withHour(0).withMinute(0).withSecond(0).toLocalDate()));
                    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());
                    }
                    billService.save(tBill);
                }
                break;
@@ -692,7 +679,6 @@
                tCheckAcceptRecord.setContractId(contract.getId());
                tCheckAcceptRecord.setHouseId(contract.getHouseId());
                tCheckAcceptRecord.setLeaseReason("后台终止合同");
                tCheckAcceptRecord.setStatus(false);
                tCheckAcceptRecord.setAcceptanceTime(LocalDateTime.now());
                LocalDate now = LocalDate.now();
                String replace = (now + "").replace("-", "");
@@ -701,14 +687,7 @@
                tCheckAcceptRecord.setCode(replace.substring(2) + String.format("%03d", size + 1));
                checkAcceptRecordMapper.insert(tCheckAcceptRecord);
                // 将所有未缴费账单设置未已失效
                List<TBill> tBills = billService.list(new LambdaQueryWrapper<TBill>()
                        .in(TBill::getPayFeesStatus, Arrays.asList("1,2,4"))
                        .eq(TBill::getContractId, contract.getId()));
                for (TBill tBill : tBills) {
                    tBill.setPayFeesStatus("5");
                }
                billService.updateBatchById(tBills);
                break;
            }
            default: