From 5162eb39c2b4953737b00dd8b0ff4da2f21cc916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Thu, 23 May 2024 09:31:16 +0800 Subject: [PATCH] debug --- .../java/com/ruoyi/iot/service/IotService.java | 7 ++++--- .../com/ruoyi/iot/service/IotServiceImpl.java | 15 ++++++++------- .../device/service/impl/SmDeviceServiceImpl.java | 12 +++++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java index f25aeedb..6150f43d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java @@ -71,11 +71,12 @@ public interface IotService { IotDeviceDetail getDeviceDetail(String deviceName); /** - * 设备电量充值 + * 设置剩余时长 + * * @param deviceName 设备名称 - * @param num 充值度数(度) + * @param seconds 时长(秒) */ - boolean recharge(String deviceName, BigDecimal num); + boolean setTime(String deviceName, BigDecimal seconds); /** * 更新设备信息 diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java index 474f7790..66c8b867 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java @@ -168,21 +168,22 @@ public class IotServiceImpl implements IotService { } /** - * 充值设备 + * 设置剩余时长 + * * @param deviceName 设备名称 - * @param num 充值度数(度) + * @param seconds 时长(秒) * @return 是否成功 */ @Override @Transactional - public boolean recharge(String deviceName, BigDecimal num) { - if (num == null || BigDecimal.ZERO.compareTo(num) > 0) { - log.error("充值设备参数错误:读数不允许为空或者小于0"); + public boolean setTime(String deviceName, BigDecimal seconds) { + if (seconds == null || BigDecimal.ZERO.compareTo(seconds) > 0) { + log.error("设置剩余时长参数错误:读数不允许为空或者小于0"); return false; } - CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + num.multiply(new BigDecimal(60)) + IotConstants.COMMAND_SEPARATOR); + CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR); if (!Objects.equals(HttpStatus.IOT_SUCCESS, response.getCode())) { - log.error("充值设备发生异常:" + response.getMsg()); + log.error("设置剩余时长发生异常:" + response.getMsg()); return false; } return true; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java index 1dc14c8b..0e21542a 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java @@ -280,8 +280,12 @@ public class SmDeviceServiceImpl implements ISmDeviceService changeStatus(deviceId, DeviceStatus.USING); // 物联网设备增加时长 - boolean rechargeResult = iotService.recharge(device.getMac(), num); - ServiceUtil.assertion(!rechargeResult, "设备充值失败"); + SmDeviceVo newDevice = selectSmDeviceByDeviceId(deviceId); + long seconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds(); + if (seconds > 0) { + boolean rechargeResult = iotService.setTime(device.getMac(), new BigDecimal(seconds)); + ServiceUtil.assertion(!rechargeResult, "设备充值失败"); + } return Boolean.TRUE; }); @@ -539,7 +543,9 @@ public class SmDeviceServiceImpl implements ISmDeviceService form.setStatus(DeviceStatus.NORMAL.getStatus()); smDeviceMapper.updateSmDevice(form); - // TODO 物联网设备归零 + // 物联网设备归零 + boolean b = iotService.setTime(device.getMac(), BigDecimal.ONE); + ServiceUtil.assertion(!b, "操作设备发生异常"); // 归零记录 scheduledExecutorService.schedule(() -> {