From 552192772f96cf072cf1c807864951315b3b0260 Mon Sep 17 00:00:00 2001 From: wangshilong Date: Sun, 1 Dec 2024 15:45:27 +0800 Subject: [PATCH] Fixed send command failed --- .../modbus/impl/CommandServiceImpl.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java b/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java index 1821b2c..8956255 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java @@ -4,9 +4,10 @@ import cn.hutool.core.map.MapUtil; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.modbus.CommandService; -import com.isu.gaswellwatch.service.DeviceOptLogService; import com.isu.gaswellwatch.modbus.data.PersistenceHandler; import com.isu.gaswellwatch.modbus.data.Redis2DBPersistenceService; +import com.isu.gaswellwatch.service.DeviceOptLogService; +import com.isu.gaswellwatch.utils.HexUtil; import com.isu.gaswellwatch.vo.command.Command; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; @@ -49,12 +50,13 @@ public class CommandServiceImpl implements CommandService { //记录用户保存控制指令日志 Integer flag = null; - if(Command.KNPCV1_TURN_ON_THE_WELL.equals(command.getCode())){ + if (Command.KNPCV1_TURN_ON_THE_WELL.equals(command.getCode())) { flag = 1; - }else if(Command.KNPCV1_TURN_OFF_THE_WELL.equals(command.getCode())){ + } else if (Command.KNPCV1_TURN_OFF_THE_WELL.equals(command.getCode())) { flag = 0; - }; - deviceOptLogService.saveGasWellOptLog(flag,command.getDeviceId()); + } + ; + this.deviceOptLogService.saveGasWellOptLog(flag, command.getDeviceId()); return result; } @@ -96,6 +98,10 @@ public class CommandServiceImpl implements CommandService { return Response.failed("Modbus command return message length failed"); } identifier = MapUtil.getStr(deviceInfoMap, "gateway_sn"); + if (StringUtils.isBlank(identifier)) { + return Response.failed("Device gateway SN is empty"); + } + identifier = HexUtil.bytesToHexString(identifier.getBytes()); item.setKey(StringUtils.joinWith("/", identifier, MapUtil.getStr(deviceInfoMap, "deviceId"), MapUtil.getStr(deviceInfoMap, "commandId"),