From ca9f29e63f4bd4f293e06f93778b5a3a34172580 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, 3 Mar 2025 09:37:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=8F=8D=E8=BD=AC=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/constant/IotConstants.java | 5 +++++ .../com/ruoyi/iot/service/IotService.java | 5 +++++ .../iot/service/impl/IotConverterImpl.java | 14 ++++++++++++- .../iot/service/impl/IotServiceImpl.java | 21 +++++++++++++++++++ .../ss/device/domain/dto/DeviceSetDTO.java | 15 +++++++++++++ .../ss/device/service/DeviceService.java | 5 +++++ .../service/impl/DeviceServiceImpl.java | 21 +++++++++++++++++++ .../controller/mch/MchDeviceController.java | 14 ++++++++----- .../web/controller/ss/SmDeviceController.java | 13 +++++++++--- 9 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/dto/DeviceSetDTO.java diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/constant/IotConstants.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/constant/IotConstants.java index 8345cd22..e0faaca2 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/constant/IotConstants.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/constant/IotConstants.java @@ -121,6 +121,11 @@ public class IotConstants { */ public static final String COMMAND_SET_WXS = "w_xs"; + /** + * 命令 设置反转参数 + */ + public static final String COMMAND_SET_SET = "set"; + /**----------------------------命令end----------------------------*/ 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 f08a4ade..133f99be 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 @@ -155,4 +155,9 @@ public interface IotService { * 设置电量系数 */ CommandResponse setWxs(IotDevice device, BigDecimal wxs, String reason); + + /** + * 设置反转参数 + */ + CommandResponse setSet(IotDevice device, String set, String reason); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotConverterImpl.java index 5e1f16cf..71a0ccc7 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotConverterImpl.java @@ -7,6 +7,7 @@ import java.util.Comparator; import java.util.Date; import java.util.List; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import com.ruoyi.common.utils.NumberUtils; @@ -22,6 +23,7 @@ import com.ruoyi.iot.service.IotConverter; * 2024/9/29 */ @Service +@Slf4j public class IotConverterImpl implements IotConverter { @Override public IotDeviceInfo toIotDeviceInfo(CurrentDeviceData data1, CurrentDeviceData data2) { @@ -86,7 +88,7 @@ public class IotConverterImpl implements IotConverter { device.setM(NumberUtils.nonNullDecimal(value).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP)); break; case ReceiveConstants.DS_SET: - device.setSet(value); + device.setSet(this.toSetValue(value)); break; case ReceiveConstants.DS_TIME: device.setTime(NumberUtils.nonNullDecimal(value)); @@ -116,4 +118,14 @@ public class IotConverterImpl implements IotConverter { } return device; } + + + public String toSetValue(String value) { + try { + return String.valueOf(Integer.parseInt(value)); + } catch (Exception e) { + log.error("转换为SetValue时出错:value={}, e={}", value, e.getMessage()); + return null; + } + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java index bafc1b45..bcd2a7d7 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java @@ -759,4 +759,25 @@ public class IotServiceImpl implements IotService { return sendCommand(mac, IotConstants.COMMAND_SET_WXS + wxs + IotConstants.COMMAND_SEPARATOR, productId, reason); } + @Override + public CommandResponse setSet(IotDevice device, String set, String reason) { + if (device == null || StringUtils.isBlank(device.getProductId())) { + return null; + } + CommandResponse res = null; + if (StringUtils.hasText(device.iotMac2())) { + res = setSet(device.iotMac2(), device.getProductId(), set, reason); + } + if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) { + res = setSet(device.iotMac1(), device.getProductId(), set, reason); + } + return res; + } + + private CommandResponse setSet(String mac, String productId, String set, String reason) { + if (StringUtils.hasBlank(mac, productId)) { + return null; + } + return sendCommand(mac, IotConstants.COMMAND_SET_SET + set + IotConstants.COMMAND_SEPARATOR, productId, reason); + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/dto/DeviceSetDTO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/dto/DeviceSetDTO.java new file mode 100644 index 00000000..46a960b0 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/dto/DeviceSetDTO.java @@ -0,0 +1,15 @@ +package com.ruoyi.ss.device.domain.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class DeviceSetDTO { + + @ApiModelProperty("设备id") + private Long deviceId; + + @ApiModelProperty("反转参数") + private String set; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceService.java index 6891c4c0..57a02056 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceService.java @@ -451,4 +451,9 @@ public interface DeviceService * 设置电量系数 */ boolean setWxs(DeviceVO device, BigDecimal wxs, String reason); + + /** + * 设置反转参数 + */ + boolean setSet(Long deviceId, String set, String reason); } 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 81717eba..a36100e2 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 @@ -1652,4 +1652,25 @@ public class DeviceServiceImpl implements DeviceService } return true; } + + @Override + public boolean setSet(Long deviceId, String set, String reason) { + if (deviceId == null || StringUtils.isBlank(set)) { + return false; + } + DeviceVO device = selectById(deviceId); + ServiceUtil.assertion(device == null, "ID为" + deviceId + "的设备不存在"); + return setSet(device, set, reason); + } + + public boolean setSet(DeviceVO device, String set, String reason) { + if (device == null || StringUtils.isBlank(set)) { + return false; + } + CommandResponse res = iotService.setSet(device, set, reason); + if (res == null || !res.isSuccess()) { + return false; + } + return true; + } } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchDeviceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchDeviceController.java index 300962b1..d37ab569 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchDeviceController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchDeviceController.java @@ -1,15 +1,19 @@ package com.ruoyi.web.controller.mch; -import java.math.BigDecimal; import java.util.List; -import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.device.service.DeviceValidator; @@ -42,10 +46,10 @@ public class MchDeviceController extends BaseController { @PutMapping("/setWxs") public AjaxResult setWxs(@RequestBody @Validated DeviceWxsDTO dto) { DeviceVO device = deviceService.selectById(dto.getDeviceId()); - if (deviceValidator.canOpera(device, getUserId())) { + if (!deviceValidator.canOpera(device, getUserId())) { return error("您无权操作ID为" + dto.getDeviceId() + "的设备"); } - return toAjax(deviceService.setWxs(device, dto.getWxs(), "商户设置电量系数")); + return toAjax(deviceService.setWxs(device, dto.getWxs(), "商户设置电量系数:" + dto.getWxs())); } } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java index ab77d7fa..653addf8 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java @@ -6,7 +6,6 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; -import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -31,7 +30,9 @@ import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.ss.device.domain.DeviceBO; import com.ruoyi.ss.device.domain.DeviceQuery; import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO; +import com.ruoyi.ss.device.domain.dto.DeviceSetDTO; import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO; +import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceAssembler; import com.ruoyi.ss.device.service.DeviceService; @@ -273,7 +274,13 @@ public class SmDeviceController extends BaseController @ApiOperation("设置电量系数") @PutMapping("/setWxs") public AjaxResult setWxs(@RequestBody @Validated DeviceWxsDTO dto) { - return toAjax(deviceService.setWxs(dto.getDeviceId(), dto.getWxs(), "管理员设置电量系数")); + return toAjax(deviceService.setWxs(dto.getDeviceId(), dto.getWxs(), "管理员设置电量系数:" + dto.getWxs())); + } + + @ApiOperation("设置设备反转参数") + @PutMapping("/setSet") + public AjaxResult setSet(@RequestBody @Validated DeviceSetDTO dto) { + return toAjax(deviceService.setSet(dto.getDeviceId(), dto.getSet(), "管理员设置设备反转参数:" + dto.getSet())); } - } +