diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java index 6cad08ce..30316a8d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java @@ -473,7 +473,7 @@ public class DeviceServiceImpl implements DeviceService Integer result = transactionTemplate.execute(status -> { // 更新剩余电量 - int update = this.resetUpdateDbEle(device.getDeviceId()); + int update = this.resetUpdateDbEle(device.getDeviceId(), device.getTotalElectriQuantity()); ServiceUtil.assertion(update != 1, "更新剩余电量失败"); // 直接设置电量为0 @@ -518,10 +518,11 @@ public class DeviceServiceImpl implements DeviceService } } - private int resetUpdateDbEle(Long deviceId) { + private int resetUpdateDbEle(Long deviceId, BigDecimal expireEle) { Device data = new Device(); data.setDeviceId(deviceId); data.setSurplusEle(BigDecimal.ZERO); + data.setExpireEle(expireEle); return deviceMapper.updateSmDevice(data); } @@ -529,6 +530,7 @@ public class DeviceServiceImpl implements DeviceService public int resetEle(Long deviceId, boolean required) { // 获取设备信息 DeviceVO device = selectById(deviceId); + this.pullDeviceInfo(device); return resetEle(device, required); } @@ -570,9 +572,9 @@ public class DeviceServiceImpl implements DeviceService return 0; } // 拉取设备信息 - pullDeviceInfo(deviceId); DeviceVO device = selectById(deviceId); + pullDeviceInfo(device); ServiceUtil.assertion(device == null, "设备不存在"); // 尝试关闭该设备未结束的所有订单 @@ -1259,12 +1261,10 @@ public class DeviceServiceImpl implements DeviceService // 修改设备信息 int timeUpdate = this.resetUpdateDbTime(deviceId); ServiceUtil.assertion(timeUpdate != 1, "修改设备时间失败"); - int eleUpdate = this.resetUpdateDbEle(deviceId); + int eleUpdate = this.resetUpdateDbEle(deviceId, device.getTotalElectriQuantity()); ServiceUtil.assertion(eleUpdate != 1, "修改设备电量失败"); // 发送命令 -// int reset = iotService.setTimeAndEle(device, 0L, BigDecimal.ZERO); -// ServiceUtil.assertion(reset != 1, "归零失败"); CommandResponse res1 = iotService.setTime(device, 0L); ServiceUtil.assertion(!res1.isSuccess(), "设备时长归零失败:" + res1.getMsg()); try { diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillConverterImpl.java index 8acd9f66..044e45b9 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillConverterImpl.java @@ -195,8 +195,9 @@ public class TransactionBillConverterImpl implements TransactionBillConverter { bo.setOrder(order); bo.setTotalEle(dto.getTotalEle()); if (order != null) { - deviceService.pullDeviceInfo(order.getDeviceId()); - bo.setDevice(deviceService.selectById(order.getDeviceId())); + DeviceVO device = deviceService.selectById(order.getDeviceId()); + deviceService.pullDeviceInfo(device); + bo.setDevice(device); } return bo; }