Browse Source

更改为commandName

tags/1.0
白凤吉 5 months ago
parent
commit
68d0803680
  1. 52
      src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java
  2. 4
      src/main/java/com/qyft/ms/system/model/bo/DeviceCommand.java
  3. 13
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

52
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<String, Object> 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<String, Object> params, String description) {
return deviceCmd("controlCmd", device, action, params, description);
private static DeviceCommand controlCmd(String device, String action, Map<String, Object> 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<String, Object> params, String description) {
private static DeviceCommand deviceCmd(String code, String device, String action, Map<String, Object> 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;
}
}

4
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"

13
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);

Loading…
Cancel
Save