| | |
| | | private TContractService contractService; |
| | | @Autowired |
| | | private TBillService billService; |
| | | @Autowired |
| | | private TContractRentTypeService contractRentTypeService; |
| | | |
| | | // 每天凌晨00点执行的定时任务 用于生成违约金 |
| | | // 用于更新违约金账单 |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void dayOfProportionBill() { |
| | | try { |
| | | // 查询所有未缴费账单 |
| | | List<TBill> list = billService.lambdaQuery().eq(TBill::getPayFeesStatus, 1).list(); |
| | | for (TBill tBill : list) { |
| | | if (tBill.getPayableFeesTime().isAfter(LocalDate.now())){ |
| | | tBill.setPayFeesStatus("4"); |
| | | } |
| | | TContract contract = contractService.getById(tBill.getContractId()); |
| | | LocalDateTime payableFeesTime = tBill.getPayableFeesTime(); |
| | | LocalDate payableFeesTime = tBill.getPayableFeesTime(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 计算两个时间相差多少个小时 |
| | | long hours = ChronoUnit.HOURS.between(payableFeesTime, now); |
| | | long l = hours / 72; |
| | | if (l>0){ |
| | | long l = hours / 24; |
| | | if (l>3){ |
| | | // 违约金比例 |
| | | 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); |
| | | // 按每天 待缴费金额 * XX% 增加违约金费用 |
| | | if (tBill.getOutstandingMoney().compareTo(new BigDecimal("0"))==0){ |
| | | tBill.setPayFeesStatus("3"); |
| | | billService.updateById(tBill); |
| | | continue; |
| | | } |
| | | BigDecimal money = tBill.getOutstandingMoney().multiply(proportion).setScale(2, BigDecimal.ROUND_DOWN); |
| | | tBill.setOverDays((int) l); |
| | | tBill.setPayableFeesPenalty((tBill.getPayableFeesPenalty()!=null?tBill.getPayableFeesPenalty():BigDecimal.ZERO).add(money)); |
| | | } |
| | | billService.updateById(tBill); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // 每天凌晨00点执行的定时任务 根据应缴费日期修改账单状态 |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void dayOfEndBill() { |
| | | try { |
| | | List<TBill> list = billService.lambdaQuery().eq(TBill::getPayFeesStatus, "2").list(); |
| | | for (TBill tBill : list) { |
| | | if (tBill.getPayableFeesTime().toLocalDate().equals(LocalDate.now())){ |
| | | tBill.setPayFeesStatus("1"); |
| | | } |
| | | } |
| | | billService.updateBatchById(list); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | |