From 68d08036806de8011a3bd3478355f1bc3f7cd2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Mon, 17 Mar 2025 11:25:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BAcommandName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/command/DeviceCommandGenerator.java | 52 +++++++++++----------- .../com/qyft/ms/system/model/bo/DeviceCommand.java | 4 +- .../service/device/DeviceCommandService.java | 13 +++--- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java b/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java index 1ac1560..3178aec 100644 --- a/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java +++ b/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java @@ -35,9 +35,9 @@ public class DeviceCommandGenerator { /** * 控制三通阀 */ - public static DeviceCommand threeWayValveControl(String action, String description) { + public static DeviceCommand threeWayValveControl(String action, String commandName) { // 调用中层 controlCmd 时,直接用方法注释固定描述"控制三通阀" - return controlCmd("three_way_valve", action, null, description != null ? description : "控制三通阀"); + return controlCmd("three_way_valve", action, null, commandName != null ? commandName : "控制三通阀"); } /** @@ -57,8 +57,8 @@ public class DeviceCommandGenerator { /** * 控制清洗阀 */ - public static DeviceCommand washValveControl(String action, String description) { - return controlCmd("wash_valve", action, null, description != null ? description : "控制清洗阀"); + public static DeviceCommand washValveControl(String action, String commandName) { + return controlCmd("wash_valve", action, null, commandName != null ? commandName : "控制清洗阀"); } /** @@ -78,8 +78,8 @@ public class DeviceCommandGenerator { /** * 控制喷嘴阀 */ - public static DeviceCommand nozzleValveControl(String action, String description) { - return controlCmd("nozzle_valve", action, null, description != null ? description : "控制喷嘴阀"); + public static DeviceCommand nozzleValveControl(String action, String commandName) { + return controlCmd("nozzle_valve", action, null, commandName != null ? commandName : "控制喷嘴阀"); } /** @@ -99,8 +99,8 @@ public class DeviceCommandGenerator { /** * 控制除湿阀 */ - public static DeviceCommand dehumidifierValveControl(String action, String description) { - return controlCmd("dehumidifier_valve", action, null, description != null ? description : "控制除湿阀"); + public static DeviceCommand dehumidifierValveControl(String action, String commandName) { + return controlCmd("dehumidifier_valve", action, null, commandName != null ? commandName : "控制除湿阀"); } /** @@ -120,8 +120,8 @@ public class DeviceCommandGenerator { /** * 控制照明灯板 */ - public static DeviceCommand lightingPanelControl(String action, String description) { - return controlCmd("lighting_panel", action, null, description != null ? description : "控制照明灯板"); + public static DeviceCommand lightingPanelControl(String action, String commandName) { + return controlCmd("lighting_panel", action, null, commandName != null ? commandName : "控制照明灯板"); } /** @@ -358,22 +358,22 @@ public class DeviceCommandGenerator { /** * 移动x轴到指定位置 */ - private static DeviceCommand motorXPositionSet(Double position, Double speed, String description) { - return controlMotorCmd("x", "move", null, "forward", position, speed, description); + private static DeviceCommand motorXPositionSet(Double position, Double speed, String commandName) { + return controlMotorCmd("x", "move", null, "forward", position, speed, commandName); } /** * 移动y轴到指定位置 */ - private static DeviceCommand motorYPositionSet(Double position, Double speed, String description) { - return controlMotorCmd("y", "move", null, "forward", position, speed, description); + private static DeviceCommand motorYPositionSet(Double position, Double speed, String commandName) { + return controlMotorCmd("y", "move", null, "forward", position, speed, commandName); } /** * 移动z轴到指定位置 */ - private static DeviceCommand motorZPositionSet(Double position, Double speed, String description) { - return controlMotorCmd("z", "move", null, "forward", position, speed, description); + private static DeviceCommand motorZPositionSet(Double position, Double speed, String commandName) { + return controlMotorCmd("z", "move", null, "forward", position, speed, commandName); } /** @@ -463,16 +463,16 @@ public class DeviceCommandGenerator { /** * 控制设备电机 */ - public static DeviceCommand controlMotorCmd(String device, String action, Double current, String direction, Double position, Double speed, String description) { - if (description == null) { - description = "控制设备电机"; + public static DeviceCommand controlMotorCmd(String device, String action, Double current, String direction, Double position, Double speed, String commandName) { + if (commandName == null) { + commandName = "控制设备电机"; } Map params = new HashMap<>(); params.put("current", current); params.put("direction", direction); params.put("position", position); params.put("speed", speed); - return deviceCmd("controlMotorCmd", device, action, params, description); + return deviceCmd("controlMotorCmd", device, action, params, commandName); } /** @@ -485,21 +485,21 @@ public class DeviceCommandGenerator { /** * 设备控制指令包装 */ - private static DeviceCommand controlCmd(String device, String action, Map params, String description) { - return deviceCmd("controlCmd", device, action, params, description); + private static DeviceCommand controlCmd(String device, String action, Map params, String commandName) { + return deviceCmd("controlCmd", device, action, params, commandName); } /** * 获取设备信息指令包装 */ - private static DeviceCommand getInfoCmd(String device, String description) { - return deviceCmd("getInfoCmd", device, "get", null, description); + private static DeviceCommand getInfoCmd(String device, String commandName) { + return deviceCmd("getInfoCmd", device, "get", null, commandName); } /** * 设备指令包装 */ - private static DeviceCommand deviceCmd(String code, String device, String action, Map params, String description) { + private static DeviceCommand deviceCmd(String code, String device, String action, Map params, String commandName) { int cmdId = CyclicNumberGenerator.getInstance().generateNumber(); DeviceCommand cmdToDevice = new DeviceCommand(); cmdToDevice.setCommandId(cmdId); @@ -507,7 +507,7 @@ public class DeviceCommandGenerator { cmdToDevice.setTargetDevice(device); cmdToDevice.setAction(action); cmdToDevice.setParams(params); - cmdToDevice.setDescription(description); + cmdToDevice.setCommandName(commandName); return cmdToDevice; } } diff --git a/src/main/java/com/qyft/ms/system/model/bo/DeviceCommand.java b/src/main/java/com/qyft/ms/system/model/bo/DeviceCommand.java index 571901a..516a408 100644 --- a/src/main/java/com/qyft/ms/system/model/bo/DeviceCommand.java +++ b/src/main/java/com/qyft/ms/system/model/bo/DeviceCommand.java @@ -12,9 +12,9 @@ public class DeviceCommand { private Integer commandId; /** - * 指令描述 + * 指令名称 */ - private String description; + private String commandName; /** * 指令代码 例如 "device_status_get" diff --git a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java index ce78e20..19b0ade 100644 --- a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java +++ b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java @@ -15,7 +15,6 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; @Service @Slf4j @@ -48,19 +47,19 @@ public class DeviceCommandService { */ public CommandFuture sendCommand(DeviceCommand deviceCommand, FrontCmdControlForm form, ResponseBodyEmitter emitter) throws IOException { CommandFuture commandFuture = executeCommand(deviceCommand); - sendFeedback(emitter, form, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getDescription() + "指令", deviceCommand); + sendFeedback(emitter, form, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getCommandName() + "指令", deviceCommand); commandFuture.getAckFuture().thenApply(result -> { try { if (result.containsKey("error")) { - sendFeedback(emitter, form, CommandStatus.ERROR, deviceCommand.getDescription() + "指令设备返回错误", result); - throw new RuntimeException(deviceCommand.getDescription() + "指令设备返回错误"); + sendFeedback(emitter, form, CommandStatus.ERROR, deviceCommand.getCommandName() + "指令设备返回错误", result); + throw new RuntimeException(deviceCommand.getCommandName() + "指令设备返回错误"); } Object resultStatus = result.getObj("result"); if (resultStatus instanceof Boolean && !((Boolean) resultStatus)) { - sendFeedback(emitter, form, CommandStatus.ERROR, deviceCommand.getDescription() + "指令设备返回失败", result); - throw new RuntimeException(deviceCommand.getDescription() + "指令设备返回失败"); + sendFeedback(emitter, form, CommandStatus.ERROR, deviceCommand.getCommandName() + "指令设备返回失败", result); + throw new RuntimeException(deviceCommand.getCommandName() + "指令设备返回失败"); } - sendFeedback(emitter, form, CommandStatus.RESULT, deviceCommand.getDescription() + "指令正常反馈", result); + sendFeedback(emitter, form, CommandStatus.RESULT, deviceCommand.getCommandName() + "指令正常反馈", result); return result; } catch (IOException e) { throw new RuntimeException(e);