From 1fe1ac0e09132e0147e48007986be235e4130aa1 Mon Sep 17 00:00:00 2001 From: zhangmei <645025773@qq.com> Date: 星期五, 28 二月 2025 12:54:12 +0800 Subject: [PATCH] 分页查询更改 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java | 159 ++++++++++++++-------------------------------------- 1 files changed, 43 insertions(+), 116 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java index 34d7837..6db2c4f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java @@ -3,7 +3,9 @@ import com.ruoyi.system.model.TBill; import com.ruoyi.system.model.TContract; +import com.ruoyi.system.model.TContractRentType; import com.ruoyi.system.service.TBillService; +import com.ruoyi.system.service.TContractRentTypeService; import com.ruoyi.system.service.TContractService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -32,148 +34,73 @@ private TContractService contractService; @Autowired private TBillService billService; + @Autowired + private TContractRentTypeService contractRentTypeService; - - - - // 每天凌晨00点执行的定时任务 用于合同生成第一笔账单 + // 每天凌晨00点执行的定时任务 用于生成违约金 @Scheduled(cron = "0 0 0 * * ?") - public void dayOfFirstBill() { + public void dayOfProportionBill() { try { - // 查询所有已签订的合同并且未生成第一笔账单的 - List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4).isNull(TContract::getFirstPayTime).list(); - List<TBill> bills = new ArrayList<>(); - for (TContract contract : list) { - contract.setFirstPayTime(contract.getStartTime().plusDays(10)); - // 第一次应缴费日期 - LocalDateTime firstPayTime = contract.getStartTime().plusDays(10); - LocalDate localDate = contract.getStartTime().plusDays(10).toLocalDate(); - LocalDate now = LocalDate.now(); - // 如果应缴费日期和当前时间不相同 跳过 - if (!localDate.equals(now)) { - continue; + // 查询所有未缴费账单 + List<TBill> list = billService.lambdaQuery().eq(TBill::getPayFeesStatus, 1).list(); + for (TBill tBill : list) { + TContract contract = contractService.getById(tBill.getContractId()); + LocalDate payableFeesTime = tBill.getPayableFeesTime(); + LocalDateTime now = LocalDateTime.now(); + // 计算两个时间相差多少个小时 + long hours = ChronoUnit.HOURS.between(payableFeesTime, now); + long l = hours / 72; + if (l>0){ + // 违约金比例 + BigDecimal proportion = contract.getProportion(); + // 应缴违约金 + BigDecimal money = tBill.getOutstandingMoney().multiply(proportion); + TBill changeBill = new TBill(); + changeBill.setId(tBill.getId()); + changeBill.setPayableFeesPenalty(money); + billService.lockAndUpdateInfo(changeBill,2); } - TBill rentBill = new TBill(); - rentBill.setContractId(contract.getId()); - rentBill.setContractNumber(contract.getContractNumber()); - LocalDateTime startPayTime = contract.getStartPayTime(); - LocalDateTime endTime1 = contract.getEndTime(); - // 计算两个时间相差多少天 - long days = ChronoUnit.DAYS.between(startPayTime, endTime1)+1L; - // 如果时间小于30天 需要计算每日租金 - if (days<30){ - rentBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(days))); - }else{ - rentBill.setPayableFeesMoney(contract.getPayType().equals("1")?contract.getMonthRent(): - contract.getPayType().equals("2")?contract.getMonthRent().multiply(new BigDecimal("3")):contract.getMonthRent().multiply(new BigDecimal("12")).setScale(2,BigDecimal.ROUND_DOWN)); - } - rentBill.setPayableFeesTime(firstPayTime); - rentBill.setPayFeesStatus("1"); - rentBill.setBillType("1"); - rentBill.setStartTime(contract.getStartPayTime()); - if ((contract.getEndTime().getYear() == contract.getStartTime().getYear()) && (contract.getEndTime().getMonth() == contract.getStartTime().getMonth())) { - // 如果同年同月 那么账单周期为合同结束时间 - rentBill.setEndTime(contract.getEndTime()); - } else { - // 否则 取当月最后一天 - LocalDateTime endTime = contract.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).withSecond(59).withHour(23).withMinute(59); - rentBill.setEndTime(endTime); - } - // 租金账单 - bills.add(rentBill); - // 押金账单 - TBill depositBill = new TBill(); - depositBill.setContractId(contract.getId()); - depositBill.setContractNumber(contract.getContractNumber()); - depositBill.setPayableFeesMoney(contract.getDeposit()); - depositBill.setPayableFeesTime(firstPayTime); - depositBill.setPayFeesStatus("1"); - depositBill.setBillType("2"); - bills.add(depositBill); } - contractService.updateBatchById(list); - billService.saveBatch(bills); + } catch (Exception e) { e.printStackTrace(); } } - // 每天凌晨00点执行的定时任务 用于生成合同期最后一笔账单 + + + // 每天凌晨00点执行的定时任务 根据应缴费日期修改账单状态 @Scheduled(cron = "0 0 0 * * ?") public void dayOfEndBill() { try { - // 查询所有已签订的合同并且已经生成第一笔账单的 - List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4).isNotNull(TContract::getFirstPayTime).list(); - List<TBill> bills = new ArrayList<>(); - for (TContract contract : list) { - TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime) - .last("limit 1").one(); - if (!(beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate()))&&beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).isAfter(contract.getEndTime())){ - TBill tBill = new TBill(); - tBill.setContractId(contract.getId()); - tBill.setContractNumber(contract.getContractNumber()); - tBill.setPayableFeesMoney(contract.getMonthRent()); - tBill.setPayableFeesTime(LocalDateTime.now()); + List<TBill> list = billService.lambdaQuery().eq(TBill::getPayFeesStatus, "2").list(); + for (TBill tBill : list) { + if (tBill.getPayableFeesTime().equals(LocalDate.now())){ tBill.setPayFeesStatus("1"); - tBill.setBillType("1"); - tBill.setStartTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth())); - tBill.setEndTime(contract.getEndTime()); - bills.add(tBill); } } - billService.saveBatch(bills); + billService.updateBatchById(list); } catch (Exception e) { e.printStackTrace(); } } - // 每月15号凌晨执行的定时任务 用于生成租金账单 - @Scheduled(cron = "0 0 0 15 * ?") - public void monthOfBill() { - try { - // 查询所有已签订的合同 且合同时间大于15号 - List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4) - .isNotNull(TContract::getFirstPayTime) - .ge(TContract::getEndTime, LocalDateTime.now()) - .list(); - List<TBill> bills = new ArrayList<>(); - for (TContract contract : list) { - TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime) - .last("limit 1").one(); - if (beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate()))continue; - if (beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).isBefore(contract.getEndTime())){ - TBill tBill = new TBill(); - tBill.setContractId(contract.getId()); - tBill.setContractNumber(contract.getContractNumber()); - tBill.setPayableFeesMoney(contract.getMonthRent()); - tBill.setPayableFeesTime(LocalDateTime.now()); - tBill.setPayFeesStatus("1"); - tBill.setBillType("1"); - tBill.setStartTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth())); - tBill.setEndTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth())); - bills.add(tBill); - } - } - billService.saveBatch(bills); - } catch (Exception e) { - e.printStackTrace(); - } - } public static void main(String[] args) { - LocalDateTime now = LocalDateTime.now().minusMonths(1).withDayOfMonth(31); - System.err.println(now); - LocalDateTime now2 = now.plusMonths(1); - System.err.println(now2); - LocalDateTime now1 = LocalDateTime.now(); - long days = ChronoUnit.DAYS.between(now, now1); - long days2 = ChronoUnit.DAYS.between(now.plusDays(1), now1); - - System.err.println(days); - System.err.println(days2); +// LocalDateTime now = LocalDateTime.now().minusMonths(1).withDayOfMonth(31); +// System.err.println(now); +// LocalDateTime now2 = now.plusMonths(1); +// System.err.println(now2); +// +// LocalDateTime now1 = LocalDateTime.now(); +// long days = ChronoUnit.DAYS.between(now, now1); +// long days2 = ChronoUnit.DAYS.between(now.plusDays(1), now1); +// +// System.err.println(days); +// System.err.println(days2); // LocalDateTime endTime = now.with(TemporalAdjusters.lastDayOfMonth()).withSecond(59).withHour(23).withMinute(59); // // System.err.println(endTime); -- Gitblit v1.7.1