| | |
| | | |
| | | /** |
| | | * 添加充电算账单汇总数据 |
| | | * 生成上个月账单,避免月末最后一天 00:30 之后结算的订单漏统计(与账户结算账单 addAccountSettlementStatement 保持一致)。 |
| | | */ |
| | | public void addChargingSettlementBill(){ |
| | | int day = LocalDate.now().getDayOfMonth(); |
| | | int lastDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); |
| | | if (2 <= day && day <= lastDay) { |
| | | refreshChargingSettlementBill(LocalDate.now()); |
| | | refreshChargingSettlementBill(LocalDate.now().minusMonths(1)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 主动刷新指定月份的充电结算账单。只重建该月未出账数据,已出账数据不受影响。 |
| | | * 主动刷新指定月份的充电结算账单。重建该月全部数据(含已出账),并保持已出账月份状态不回退。 |
| | | */ |
| | | public synchronized void refreshChargingSettlementBill(LocalDate billingMonth){ |
| | | try { |
| | |
| | | LocalDateTime createTime = LocalDateTime.now(); |
| | | |
| | | //删除之前生成的汇总数据,在添加最新的汇总数据 |
| | | //重建时删除该月全部记录(含已出账),避免重建已冻结月份时旧数据残留造成重复;并保留已出账状态 |
| | | String format = firstDayOfBillingMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")); |
| | | chargingSettlementBillService.remove(new QueryWrapper<TChargingSettlementBill>().eq("status", 1).last(" and DATE_FORMAT(billing_cycle, '%Y-%m') = '" + format + "'")); |
| | | boolean targetFrozen = chargingSettlementBillService.count(new QueryWrapper<TChargingSettlementBill>() |
| | | .eq("status", 2) |
| | | .last(" and DATE_FORMAT(billing_cycle, '%Y-%m') = '" + format + "'")) > 0; |
| | | chargingSettlementBillService.remove(new QueryWrapper<TChargingSettlementBill>().last(" and DATE_FORMAT(billing_cycle, '%Y-%m') = '" + format + "'")); |
| | | int targetStatus = targetFrozen ? 2 : 1; |
| | | |
| | | //循环生成按照开始时间和结束时间分别统计的汇总数据 |
| | | for (int i = 1; i < 3; i++) { |
| | |
| | | chargingSettlementBill.setSiteId(0); |
| | | chargingSettlementBill.setStatisticalDateType(i); |
| | | chargingSettlementBill.setBillingCycle(firstDayOfBillingMonth); |
| | | chargingSettlementBill.setStatus(1); |
| | | chargingSettlementBill.setStatus(targetStatus); |
| | | chargingSettlementBill.setCode("JSD"+string+randomDigits); |
| | | |
| | | //根据业务订单查询汇总数据 |
| | |
| | | chargingSettlementBill1.setSiteId(Integer.valueOf(map.get("siteId").toString())); |
| | | chargingSettlementBill1.setStatisticalDateType(i); |
| | | chargingSettlementBill1.setBillingCycle(firstDayOfBillingMonth); |
| | | chargingSettlementBill1.setStatus(1); |
| | | chargingSettlementBill1.setStatus(targetStatus); |
| | | chargingSettlementBill1.setCode("JSD"+string+randomDigits1); |
| | | chargingSettlementBill1.setChargingDuration(charging_duration); |
| | | chargingSettlementBill1.setOrderNumber(order_number); |