Fixed send command failed

This commit is contained in:
wangshilong 2024-12-01 15:45:27 +08:00
parent 539efbbf18
commit 552192772f
1 changed files with 11 additions and 5 deletions

View File

@ -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;
@ -53,8 +54,9 @@ public class CommandServiceImpl implements CommandService {
flag = 1;
} 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"),