From 285a844fe860d1ddfdf1f2af64d10c99215603be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?= <14103883+leaf-phos@user.noreply.gitee.com> Date: Mon, 6 Jan 2025 17:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=94=B5=E9=87=8F=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BillEleRecordConverterImpl.java | 3 +++ .../service/impl/TransactionBillServiceImpl.java | 14 +++++++++++--- .../java/com/ruoyi/task/bill/BillMonitorTask.java | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/billEleRecord/service/impl/BillEleRecordConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/billEleRecord/service/impl/BillEleRecordConverterImpl.java index 1d6a3560..c7576939 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/billEleRecord/service/impl/BillEleRecordConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/billEleRecord/service/impl/BillEleRecordConverterImpl.java @@ -41,6 +41,9 @@ public class BillEleRecordConverterImpl implements BillEleRecordConverter { if (bill.getSuitEndTime() != null && timeEnd.isAfter(bill.getSuitEndTime())) { timeEnd = bill.getSuitEndTime(); } + if (time != null && timeEnd.isAfter(time)) { + timeEnd = time; + } // 当前时间段的单价(元/度) BigDecimal price = RechargeUtils.getGearAmount(bill, chargeTime.getHour()); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java index b0ffd619..04304e62 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java @@ -18,6 +18,7 @@ import com.ruoyi.dashboard.domain.vo.BillCountVo; import com.ruoyi.iot.domain.response.CommandResponse; import com.ruoyi.iot.service.IotService; import com.ruoyi.ss.account.domain.AccountVO; +import com.ruoyi.ss.billEleRecord.domain.BillEleRecord; import com.ruoyi.ss.billEleRecord.domain.BillEleRecordQuery; import com.ruoyi.ss.billEleRecord.service.BillEleRecordConverter; import com.ruoyi.ss.billEleRecord.service.BillEleRecordService; @@ -1087,7 +1088,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(order.getStatus()), "当前订单状态不允许结束"); ServiceUtil.assertion(device == null, "设备不存在"); - LocalDateTime endTime = LocalDateTime.now(); // 结束使用的时间 + LocalDateTime now = LocalDateTime.now(); // 结束使用的时间 // 结束使用的电量:若蓝牙传过来的值为空或者小于当前电量,则使用当前电量,否则使用蓝牙传输的电量(谁大用谁) BigDecimal totalEle = this.calcTotalEle(device, bo.getTotalEle()); @@ -1098,7 +1099,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After Integer result = transactionTemplate.execute(status -> { // 修改结束使用的时间 TransactionBill data = new TransactionBill(); - data.setSuitEndTime(endTime); + data.setSuitEndTime(now); data.setSuitEndEle(totalEle); TransactionBillQuery query = new TransactionBillQuery(); query.setBillId(order.getBillId()); @@ -1107,6 +1108,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After int update = this.updateByQuery(data, query); ServiceUtil.assertion(update != 1, "修改订单信息失败,请重试:" + order.getBillNo()); + // 若是分时段电量,则记录一次电量金额 + if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) { + BillEleRecord record = billEleRecordConverter.toPo(order, device, now, now); + int insertRecord = billEleRecordService.insertBillEleRecord(record); + ServiceUtil.assertion(insertRecord != 1, "记录分时段订单%s用电量失败", order.getBillNo()); + } + return update; }); @@ -1114,7 +1122,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After // 若成功,且为智能模式,则计算需要退款的金额, 若金额 > 0.01 则申请退款 if ( success && SuitFeeMode.SMART.getMode().equals(order.getSuitFeeMode())) { - BigDecimal refundAmount = this.calcRefundAmount(order, endTime, totalEle); + BigDecimal refundAmount = this.calcRefundAmount(order, now, totalEle); if (BigDecimal.valueOf(0.01).compareTo(refundAmount) < 0) { scheduledExecutorService.schedule(() -> { // 申请退款 diff --git a/smart-switch-service/src/main/java/com/ruoyi/task/bill/BillMonitorTask.java b/smart-switch-service/src/main/java/com/ruoyi/task/bill/BillMonitorTask.java index 915262f1..7a468a5d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/task/bill/BillMonitorTask.java +++ b/smart-switch-service/src/main/java/com/ruoyi/task/bill/BillMonitorTask.java @@ -100,7 +100,7 @@ public class BillMonitorTask { query.setType(TransactionBillType.RECHARGE.getType()); query.setCreateTimeStart(DateUtils.toLocalDateTime(startTime)); query.setIsFinished(true); - query.setSuitFeeType(SuitFeeType.COUNT.getType()); + query.setSuitFeeTypes(SuitFeeType.rechargeEleList()); query.setIsNullSuitEndTime(true); List list = transactionBillService.selectSmTransactionBillList(query);