订单电量记录

This commit is contained in:
磷叶 2025-01-06 17:36:31 +08:00
parent 6dbe881081
commit 285a844fe8
3 changed files with 15 additions and 4 deletions

View File

@ -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());

View File

@ -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(() -> {
// 申请退款

View File

@ -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<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(query);