21 changed files with 390 additions and 635 deletions
-
8sql/demo.sql
-
27src/main/java/com/qyft/gd/controller/CMDController.java
-
5src/main/java/com/qyft/gd/device/common/constant/DeviceCommands.java
-
38src/main/java/com/qyft/gd/device/controller/DeviceController.java
-
19src/main/java/com/qyft/gd/device/controller/DeviceCtrlController.java
-
4src/main/java/com/qyft/gd/device/model/bo/DeviceCtrlFuncCMD.java
-
38src/main/java/com/qyft/gd/device/model/bo/DeviceOperationalStatus.java
-
2src/main/java/com/qyft/gd/device/model/bo/DeviceStatus.java
-
4src/main/java/com/qyft/gd/device/model/entity/CtrlFuncStep.java
-
26src/main/java/com/qyft/gd/device/model/vo/DeviceCtrlFuncVO.java
-
49src/main/java/com/qyft/gd/device/service/DeviceCtrlService.java
-
14src/main/java/com/qyft/gd/device/service/DeviceService.java
-
13src/main/java/com/qyft/gd/device/service/DeviceStatusService.java
-
86src/main/java/com/qyft/gd/device/service/DeviceStepService.java
-
15src/main/java/com/qyft/gd/device/service/DeviceTcpCMDService.java
-
8src/main/java/com/qyft/gd/device/service/ICtrlFuncService.java
-
4src/main/java/com/qyft/gd/device/service/ICtrlFuncStepService.java
-
51src/main/java/com/qyft/gd/device/service/impl/CtrlFuncServiceImpl.java
-
14src/main/java/com/qyft/gd/device/service/impl/CtrlFuncStepServiceImpl.java
-
558src/main/java/com/qyft/gd/service/CMDService.java
@ -0,0 +1,38 @@ |
|||
package com.qyft.gd.device.controller; |
|||
|
|||
import com.qyft.gd.device.model.bo.DeviceOperationalStatus; |
|||
import com.qyft.gd.device.model.bo.DeviceStatus; |
|||
import com.qyft.gd.device.service.DeviceService; |
|||
import com.qyft.gd.device.service.DeviceStatusService; |
|||
import com.qyft.gd.system.common.result.Result; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@Tag(name = "设备控制") |
|||
@RestController |
|||
@RequestMapping("/api/device") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class DeviceController { |
|||
private final DeviceStatusService deviceStatusService; |
|||
|
|||
@Operation(summary = "获取设备业务操作状态") |
|||
@GetMapping("/operational/status") |
|||
public Result<DeviceOperationalStatus> getDeviceOperationalStatus() { |
|||
DeviceOperationalStatus deviceOperationalStatus = deviceStatusService.getDeviceOperationalStatus(); |
|||
return Result.success(deviceOperationalStatus); |
|||
} |
|||
|
|||
|
|||
@Operation(summary = "获取当前设备状态") |
|||
@GetMapping("/status") |
|||
public Result<DeviceStatus> getDeviceStatus() { |
|||
DeviceStatus deviceStatus = deviceStatusService.getDeviceStatus(); |
|||
return Result.success(deviceStatus); |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
package com.qyft.gd.device.model.bo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Schema(description = "设备业务操作状态") |
|||
@Data |
|||
public class DeviceOperationalStatus { |
|||
@Schema(description = "托盘列表") |
|||
private List<Tray> trayList = new ArrayList<>(); |
|||
|
|||
/** |
|||
* 托盘 |
|||
*/ |
|||
@Data |
|||
static class Tray { |
|||
@Schema(description = "所在加热区id") |
|||
private Long heatId; |
|||
@Schema(description = "是否在加液区") |
|||
private boolean isSolutionArea; |
|||
@Schema(description = "试管列表") |
|||
private List<Tube> tubeList; |
|||
} |
|||
|
|||
/** |
|||
* 试管 |
|||
*/ |
|||
@Data |
|||
static class Tube { |
|||
@Schema(description = "试管编号") |
|||
private Integer tubeNum; |
|||
@Schema(description = "试管内是否有样品") |
|||
private boolean isSample; |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
package com.qyft.gd.device.model.vo; |
|||
|
|||
import com.qyft.gd.device.model.entity.CtrlFuncStep; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Schema(description = "获取所有设备控制方法返回数据") |
|||
@Data |
|||
public class DeviceCtrlFuncVO { |
|||
|
|||
private Long id; |
|||
|
|||
@Schema(description = "控制方法的名称") |
|||
private String name; |
|||
|
|||
@Schema(description = "控制方法的指令") |
|||
private String funcCmd; |
|||
|
|||
@Schema(description = "设备控制方法步骤列表") |
|||
private List<CtrlFuncStep> ctrlFuncStepList; |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.qyft.gd.device.service; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* 设备操作 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class DeviceService { |
|||
|
|||
|
|||
} |
@ -1,513 +1,123 @@ |
|||
package com.qyft.gd.service; |
|||
|
|||
import cn.hutool.json.JSONUtil; |
|||
import com.qyft.gd.common.constant.Commands; |
|||
import com.qyft.gd.common.constant.WebSocketMessageType; |
|||
import com.qyft.gd.common.result.CMDResultCode; |
|||
import com.qyft.gd.device.service.DeviceTcpCMDService; |
|||
import com.qyft.gd.model.dto.CmdInjectFluidDTO; |
|||
import com.qyft.gd.model.dto.InjectFluid; |
|||
import com.qyft.gd.model.dto.StartHeatDTO; |
|||
import com.qyft.gd.device.model.bo.DeviceCtrlFuncCMD; |
|||
import com.qyft.gd.device.model.entity.CtrlFuncStep; |
|||
import com.qyft.gd.device.service.DeviceCtrlService; |
|||
import com.qyft.gd.device.service.ICtrlFuncService; |
|||
import com.qyft.gd.device.service.ICtrlFuncStepService; |
|||
import com.qyft.gd.model.entity.TaskSteps; |
|||
import com.qyft.gd.model.entity.Tasks; |
|||
import com.qyft.gd.model.form.CMDForm; |
|||
import com.qyft.gd.model.vo.ContainerListVO; |
|||
import com.qyft.gd.model.vo.ExecutionResult; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.lang.reflect.Method; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.function.Function; |
|||
import java.util.function.Supplier; |
|||
|
|||
@Slf4j |
|||
@RequiredArgsConstructor |
|||
@Service |
|||
public class CMDService { |
|||
|
|||
private final ITasksService tasksService; |
|||
private final ITaskStepsService taskStepsService; |
|||
DeviceTcpCMDService deviceTcpCMDService; |
|||
WebSocketService webSocketService; |
|||
BaseDataService baseDataService; |
|||
IContainerService containerService; |
|||
Map<String, Function<Map<String, Object>, List<Supplier<Boolean>>>> commandMap; |
|||
CMDForm form; |
|||
Map<String, String> cmdMap; |
|||
|
|||
@Autowired |
|||
public CMDService(DeviceTcpCMDService deviceTcpCMDService, WebSocketService webSocketService, BaseDataService baseDataService, ITasksService tasksService, ITaskStepsService taskStepsService, IContainerService containerService) { |
|||
this.deviceTcpCMDService = deviceTcpCMDService; |
|||
this.webSocketService = webSocketService; |
|||
this.baseDataService = baseDataService; |
|||
this.tasksService = tasksService; |
|||
this.taskStepsService = taskStepsService; |
|||
this.containerService = containerService; |
|||
this.cmdMap = new HashMap<>(); |
|||
cmdMap.put("openDoor", "开门"); |
|||
cmdMap.put("closeDoor", "关门"); |
|||
cmdMap.put("upTray", "抬起托盘"); |
|||
cmdMap.put("downTray", "降下托盘"); |
|||
cmdMap.put("injectFluid", "添加溶液"); |
|||
cmdMap.put("moveToActionArea", "移至加液"); |
|||
cmdMap.put("startShakeUp", "摇匀试管架"); |
|||
cmdMap.put("stopShakeUp", "停止摇匀试管架"); |
|||
cmdMap.put("startHeat", "开始加热"); |
|||
cmdMap.put("stopHeat", "停止加热"); |
|||
cmdMap.put("takePhoto", "拍照"); |
|||
cmdMap.put("takeOffCap", "取试管架盖"); |
|||
cmdMap.put("putBackCap", "装回试管架盖"); |
|||
cmdMap.put("moveMachineArm", "机械臂移动至指定坐标"); |
|||
cmdMap.put("moveTube", "移动单个试管"); |
|||
cmdMap.put("moveToHeatArea", "移至加热区"); |
|||
cmdMap.put("openClaw", "机械臂爪子开启"); |
|||
cmdMap.put("closeClaw", "机械臂爪子关闭"); |
|||
// 初始化命令映射 |
|||
this.commandMap = new HashMap<>(); |
|||
commandMap.put(Commands.OPEN_DOOR, this::openDoor); |
|||
commandMap.put(Commands.CLOSE_DOOR, this::closeDoor); |
|||
commandMap.put(Commands.UP_TRAY, this::upTray); |
|||
commandMap.put(Commands.DOWN_TRAY, this::downTray); |
|||
commandMap.put(Commands.INJECT_FLUID, this::injectFluid); |
|||
commandMap.put(Commands.MOVE_TO_ACTION_AREA, this::moveToActionArea); |
|||
commandMap.put(Commands.START_SHAKE_UP, this::startShakeUp); |
|||
commandMap.put(Commands.STOP_SHAKE_UP, this::stopShakeUp); |
|||
commandMap.put(Commands.START_HEAT, this::startHeat); |
|||
commandMap.put(Commands.STOP_HEAT, this::stopHeat); |
|||
commandMap.put(Commands.TAKE_PHOTO, this::takePhoto); |
|||
commandMap.put(Commands.TAKE_OFF_CAP, this::takeOffCap); |
|||
commandMap.put(Commands.PUT_BACK_CAP, this::putBackCap); |
|||
commandMap.put(Commands.MOVE_MACHINE_ARM, this::moveMachineArm); |
|||
commandMap.put(Commands.MOVE_TUBE, this::moveTube); |
|||
commandMap.put(Commands.MOVE_TO_HEAT_AREA, this::moveToHeatArea); |
|||
commandMap.put(Commands.OPEN_CLAW, this::openClaw); |
|||
commandMap.put(Commands.CLOSE_CLAW, this::closeClaw); |
|||
|
|||
} |
|||
|
|||
// 开门 |
|||
public List<Supplier<Boolean>> openDoor(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.openDoor()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 关门 |
|||
public List<Supplier<Boolean>> closeDoor(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.closeDoor()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 机械臂爪子开启 |
|||
public List<Supplier<Boolean>> openClaw(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 机械臂爪子闭合 |
|||
public List<Supplier<Boolean>> closeClaw(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 移至加热 |
|||
public List<Supplier<Boolean>> moveToHeatArea(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
Map<String, Object> map = baseDataService.getOffsetMap(); |
|||
String heatAreaPosition = baseDataService.getHeatAreaPositionById((Integer) params.get("heatId")); |
|||
String[] heatAreaPositionArr = heatAreaPosition.split(","); |
|||
int x1 = Integer.parseInt(heatAreaPositionArr[0]); |
|||
int y1 = Integer.parseInt(heatAreaPositionArr[1]); |
|||
int z1 = Integer.parseInt(heatAreaPositionArr[2]); |
|||
|
|||
String solutionAreaPosition = baseDataService.getSolutionAreaPosition(); |
|||
String[] solutionAreaPositionArr = solutionAreaPosition.split(","); |
|||
int x2 = Integer.parseInt(solutionAreaPositionArr[0]); |
|||
int y2 = Integer.parseInt(solutionAreaPositionArr[1]); |
|||
int z2 = Integer.parseInt(solutionAreaPositionArr[2]); |
|||
// 机械臂移动到加液位 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 下降高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2 - Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")))); |
|||
// 闭合钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 机械臂抬起高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")) + Integer.parseInt((String) map.get("sys_offset_tube_height")))); |
|||
// 机械臂移动到指定加热位 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z2 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")) + Integer.parseInt((String) map.get("sys_offset_tube_height")))); |
|||
// 机械臂下降高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 机械臂打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂上升高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")))); |
|||
// 关闭钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
|
|||
return cmdList; |
|||
} |
|||
|
|||
// 移动单个试管 |
|||
public List<Supplier<Boolean>> moveTube(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
|
|||
return cmdList; |
|||
} |
|||
|
|||
// 机械臂 |
|||
public List<Supplier<Boolean>> moveMachineArm(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
String position = (String) params.get("position"); |
|||
String[] positionArr = position.split(","); |
|||
int x = Integer.parseInt(positionArr[0]); |
|||
int y = Integer.parseInt(positionArr[1]); |
|||
int z = Integer.parseInt(positionArr[2]); |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x, y, z)); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 装回盖子 |
|||
public List<Supplier<Boolean>> putBackCap(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
// 加热位机器代码 |
|||
String heatId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
String lidPosition = baseDataService.getLidPosition(); |
|||
String[] lidPositionArr = lidPosition.split(","); |
|||
int x1 = Integer.parseInt(lidPositionArr[0]); |
|||
int y1 = Integer.parseInt(lidPositionArr[1]); |
|||
int z1 = Integer.parseInt(lidPositionArr[2]); |
|||
|
|||
String position = baseDataService.getHeatAreaLidPositionById((Integer) params.get("heatId")); |
|||
Map<String, Object> map = baseDataService.getOffsetMap(); |
|||
String[] positionArr = position.split(","); |
|||
int x2 = Integer.parseInt(positionArr[0]); |
|||
int y2 = Integer.parseInt(positionArr[1]); |
|||
int z2 = Integer.parseInt(positionArr[2]); |
|||
//机械臂移动到拍子存放位坐标 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂下移位置 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 - (Integer) map.get("sys_offset_lid_take_height"))); |
|||
// 闭合钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 机械臂抬起指定高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 机械臂移至指定试管架 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂上移指定位置 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 + (Integer) map.get("sys_offset_lid_take_height"))); |
|||
// 关闭钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 密封 |
|||
// 解除密封 |
|||
cmdList.add(() -> deviceTcpCMDService.setSealLid(Integer.parseInt(heatId), true)); |
|||
// 机械臂复位 |
|||
return cmdList; |
|||
} |
|||
|
|||
// 取试管架盖 |
|||
public List<Supplier<Boolean>> takeOffCap(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
// 拍子坐标 |
|||
String position = baseDataService.getHeatAreaLidPositionById((Integer) params.get("heatId")); |
|||
// 加热位机器代码 |
|||
String hardwareId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
|
|||
Map<String, Object> map = baseDataService.getOffsetMap(); |
|||
String[] positionArr = position.split(","); |
|||
int x1 = Integer.parseInt(positionArr[0]); |
|||
int y1 = Integer.parseInt(positionArr[1]); |
|||
int z1 = Integer.parseInt(positionArr[2]); |
|||
|
|||
String lidPosition = baseDataService.getLidPosition(); |
|||
String[] lidPositionArr = lidPosition.split(","); |
|||
int x2 = Integer.parseInt(lidPositionArr[0]); |
|||
int y2 = Integer.parseInt(lidPositionArr[1]); |
|||
int z2 = Integer.parseInt(lidPositionArr[2]); |
|||
|
|||
//机械臂移动到拍子坐标 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 解除密封 |
|||
cmdList.add(() -> deviceTcpCMDService.setSealLid(Integer.parseInt(hardwareId), false)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂下移位置 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 - (Integer) map.get("sys_offset_lid_take_height"))); |
|||
// 闭合钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 机械臂抬起指定高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 机械臂移至拍子存放区 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂上移指定位置 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2 + (Integer) map.get("sys_offset_lid_take_height"))); |
|||
// 关闭钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 机械臂复位 |
|||
return cmdList; |
|||
} |
|||
|
|||
// 拍照 |
|||
public List<Supplier<Boolean>> takePhoto(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.takePhoto()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 停止加热 |
|||
public List<Supplier<Boolean>> stopHeat(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
String hardwareId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
cmdList.add(() -> deviceTcpCMDService.stopHeating(hardwareId)); |
|||
return cmdList; |
|||
} |
|||
private final WebSocketService webSocketService; |
|||
private final DeviceCtrlService deviceCtrlService; |
|||
private final ICtrlFuncStepService ctrlFuncStepService; |
|||
private final ICtrlFuncService ctrlFuncService; |
|||
|
|||
@SuppressWarnings("unchecked") |
|||
private void run(CMDForm cmdForm) { |
|||
String commandName = cmdForm.getCommand(); |
|||
ExecutionResult executionResult = new ExecutionResult(); |
|||
executionResult.setCommandId(cmdForm.getCommandId()); |
|||
executionResult.setCommandName(commandName); |
|||
|
|||
try { |
|||
List<Object> paramsList = cmdForm.getParams(); |
|||
List<CtrlFuncStep> ctrlFuncStepList = ctrlFuncStepService.selectListByFuncCmd(commandName); |
|||
|
|||
int index = 0; |
|||
for (CtrlFuncStep ctrlFuncStep : ctrlFuncStepList) { |
|||
Map<String, Object> params = null; |
|||
if (ctrlFuncStep.getParams() == null) { // 如果没有参数定义,使用传入的参数 |
|||
try { |
|||
params = (Map<String, Object>) paramsList.get(index); |
|||
} catch (IndexOutOfBoundsException e) { |
|||
log.error("指令执行错误,传参错误: {}", JSONUtil.toJsonStr(cmdForm)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
return; |
|||
} |
|||
index++; // 移动到下一个参数 |
|||
} |
|||
|
|||
// 批量加热 |
|||
public void startHeats(StartHeatDTO dto) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
for (Integer i : dto.getHeatIds()) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("heatId", i); |
|||
cmdList.addAll(startHeat(map)); |
|||
} |
|||
new Thread(() -> { |
|||
ExecutionResult executionResult = new ExecutionResult(); |
|||
executionResult.setCommandId(dto.getCommandId()); |
|||
// 执行所有命令 |
|||
for (Supplier<Boolean> command : cmdList) { |
|||
boolean result = command.get(); |
|||
if (!result) { |
|||
log.error("指令执行异常: {}", JSONUtil.toJsonStr(dto)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
return; |
|||
String deviceCmd = ctrlFuncStep.getDeviceCmd(); |
|||
Method method = getMethodByName(deviceCmd); |
|||
if (method != null) { |
|||
boolean success = (boolean) method.invoke(deviceCtrlService, params); |
|||
if (!success) { |
|||
log.error("指令执行错误,执行{}返回false: {}", deviceCmd, JSONUtil.toJsonStr(cmdForm)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|||
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
}).start(); |
|||
} |
|||
|
|||
// 开始加热 |
|||
public List<Supplier<Boolean>> startHeat(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
String hardwareId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
Double temperature; |
|||
if (params.get("temperature") == null) { |
|||
temperature = Double.parseDouble(baseDataService.getHeatAreaTemperatureById((Integer) params.get("heatId"))); |
|||
} else { |
|||
temperature = Double.parseDouble((String) params.get("temperature")); |
|||
} |
|||
cmdList.add(() -> deviceTcpCMDService.startHeating(hardwareId, temperature)); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 开始摇匀 |
|||
public List<Supplier<Boolean>> startShakeUp(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
if (params.get("speed") != null) { |
|||
cmdList.add(() -> deviceTcpCMDService.setShakingSpeed((Integer) params.get("speed"))); |
|||
return; |
|||
} catch (Exception e) { |
|||
log.error("指令执行错误: {}", JSONUtil.toJsonStr(cmdForm), e); |
|||
} |
|||
cmdList.add(() -> deviceTcpCMDService.startShaking()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 结束摇匀 |
|||
public List<Supplier<Boolean>> stopShakeUp(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
cmdList.add(() -> deviceTcpCMDService.stopShaking()); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 移至加液 |
|||
public List<Supplier<Boolean>> moveToActionArea(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
Map<String, Object> map = baseDataService.getOffsetMap(); |
|||
String heatAreaPosition = baseDataService.getHeatAreaPositionById((Integer) params.get("heatId")); |
|||
String[] heatAreaPositionArr = heatAreaPosition.split(","); |
|||
int x1 = Integer.parseInt(heatAreaPositionArr[0]); |
|||
int y1 = Integer.parseInt(heatAreaPositionArr[1]); |
|||
int z1 = Integer.parseInt(heatAreaPositionArr[2]); |
|||
|
|||
String solutionAreaPosition = baseDataService.getSolutionAreaPosition(); |
|||
String[] solutionAreaPositionArr = solutionAreaPosition.split(","); |
|||
int x2 = Integer.parseInt(solutionAreaPositionArr[0]); |
|||
int y2 = Integer.parseInt(solutionAreaPositionArr[1]); |
|||
int z2 = Integer.parseInt(solutionAreaPositionArr[2]); |
|||
// 机械臂移动到指定的加热位坐标 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1)); |
|||
// 打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 下降高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 - Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")))); |
|||
// 闭合钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
// 机械臂抬起高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x1, y1, z1 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")) + Integer.parseInt((String) map.get("sys_offset_tube_height")))); |
|||
// 机械臂移动到加液位高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z1 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")) + Integer.parseInt((String) map.get("sys_offset_tube_height")))); |
|||
// 机械臂下降高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2)); |
|||
// 机械臂打开钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.openClaw()); |
|||
// 机械臂上升高度 |
|||
cmdList.add(() -> deviceTcpCMDService.moveRailArmToPoint(x2, y2, z2 + Integer.parseInt((String) map.get("sys_offset_tube_rack_take_height")))); |
|||
// 关闭钩子 |
|||
cmdList.add(() -> deviceTcpCMDService.closeClaw()); |
|||
|
|||
return cmdList; |
|||
|
|||
// 如果执行到这里,说明没有成功的步骤,返回失败 |
|||
log.error("指令执行错误: {}", JSONUtil.toJsonStr(cmdForm)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
} |
|||
|
|||
// 批量加液 |
|||
public void injectFluids(CmdInjectFluidDTO dto) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
for (InjectFluid injectFluid : dto.getInjectFluids()) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("tubeNum", injectFluid.getTubeNum()); |
|||
map.put("solutionId", injectFluid.getSolutionId()); |
|||
map.put("volume", injectFluid.getVolume()); |
|||
cmdList.addAll(injectFluid(map)); |
|||
} |
|||
|
|||
new Thread(() -> { |
|||
ExecutionResult executionResult = new ExecutionResult(); |
|||
executionResult.setCommandId(dto.getCommandId()); |
|||
// 执行所有命令 |
|||
for (Supplier<Boolean> command : cmdList) { |
|||
boolean result = command.get(); |
|||
if (!result) { |
|||
log.error("指令执行异常: {}", JSONUtil.toJsonStr(dto)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
return; |
|||
public boolean executeCommand(CMDForm cmdForm) { |
|||
String commandName = cmdForm.getCommand(); |
|||
List<DeviceCtrlFuncCMD> deviceCtrlFuncCMDList = ctrlFuncService.findAllStepCMD(); |
|||
for (DeviceCtrlFuncCMD deviceCtrlFuncCMD : deviceCtrlFuncCMDList) { |
|||
if (deviceCtrlFuncCMD.getDeviceCmd().equals(commandName)) { |
|||
Tasks tasks = tasksService.getIngTask(); |
|||
if (tasks != null) { |
|||
TaskSteps taskSteps = new TaskSteps(); |
|||
taskSteps.setTaskId(tasks.getId()); |
|||
taskSteps.setStepDescription("执行指令:" + commandName); |
|||
taskStepsService.addTaskSteps(taskSteps); |
|||
} |
|||
new Thread(() -> run(cmdForm)).start(); |
|||
return true; |
|||
} |
|||
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|||
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
}).start(); |
|||
} |
|||
|
|||
// 加液 |
|||
public List<Supplier<Boolean>> injectFluid(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
// 获取容器信息 |
|||
ContainerListVO container = baseDataService.getContainerBySolutionId((Integer) params.get("solutionId")); |
|||
if (container.getCapacityTotal() - container.getCapacityUsed() < (Integer) params.get("volume")) { |
|||
cmdList.add(() -> false); |
|||
} |
|||
|
|||
// 试管的坐标 |
|||
String tubePosition = baseDataService.getTubePositionBySolutionArea((Integer) params.get("tubeNum")); |
|||
String[] tubePositionArr = tubePosition.split(","); |
|||
int x = Integer.parseInt(tubePositionArr[0]); |
|||
int y = Integer.parseInt(tubePositionArr[1]); |
|||
int z = Integer.parseInt(tubePositionArr[2]); |
|||
// 泵id |
|||
String pumpId = baseDataService.getPumpIdBySolutionId((Long) params.get("solutionId")); |
|||
if (params.get("flowRate") != null) { |
|||
cmdList.add(() -> deviceTcpCMDService.setFlowRate(pumpId, (Integer) params.get("flowRate"))); |
|||
} |
|||
cmdList.add(() -> deviceTcpCMDService.moveLiquidArmToPoint(x, y, z)); |
|||
cmdList.add(() -> deviceTcpCMDService.addLiquid(pumpId, ((Integer) params.get("volume")))); |
|||
cmdList.add(() -> updateVolume(params)); |
|||
|
|||
return cmdList; |
|||
} |
|||
|
|||
// 放下托盘 |
|||
public List<Supplier<Boolean>> downTray(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
String hardwareId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
if (params.get("height") != null && params.get("speed") != null) { |
|||
cmdList.add(() -> deviceTcpCMDService.setTrayParams(hardwareId, (Integer) params.get("speed"), (Integer) params.get("height"))); |
|||
} |
|||
cmdList.add(() -> deviceTcpCMDService.lowerTray(hardwareId)); |
|||
return cmdList; |
|||
} |
|||
|
|||
// 抬起托盘 |
|||
public List<Supplier<Boolean>> upTray(Map<String, Object> params) { |
|||
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|||
String hardwareId = baseDataService.getHeatAreaHardwareIdById((Integer) params.get("heatId")); |
|||
if (params.get("height") != null && params.get("speed") != null) { |
|||
cmdList.add(() -> deviceTcpCMDService.setTrayParams(hardwareId, (Integer) params.get("speed"), (Integer) params.get("height"))); |
|||
} |
|||
cmdList.add(() -> deviceTcpCMDService.raiseTray(hardwareId)); |
|||
|
|||
return cmdList; |
|||
} |
|||
|
|||
private boolean updateVolume(Map<String, Object> params) { |
|||
// 获取容器信息 |
|||
ContainerListVO container = baseDataService.getContainerBySolutionId((Integer) params.get("solutionId")); |
|||
container.setCapacityUsed(container.getCapacityUsed() + (Integer) params.get("volume")); |
|||
containerService.updateById(container); |
|||
baseDataService.updateConfig(); |
|||
List<ContainerListVO> list = containerService.getAllContainer(); |
|||
Map<String, Object> containerMap = new HashMap<>(); |
|||
containerMap.put("containerList", list); |
|||
webSocketService.pushMsg(WebSocketMessageType.CONTAINER, containerMap); |
|||
return true; |
|||
return false; |
|||
} |
|||
|
|||
private void initExecutorThread(List<Supplier<Boolean>> cmdList) { |
|||
new Thread(() -> run(cmdList)).start(); |
|||
} |
|||
|
|||
private void run(List<Supplier<Boolean>> cmdList) { |
|||
ExecutionResult executionResult = new ExecutionResult(); |
|||
executionResult.setCommandId(form.getCommandId()); |
|||
executionResult.setCommandName(form.getCommand()); |
|||
|
|||
// 执行所有命令 |
|||
for (Supplier<Boolean> command : cmdList) { |
|||
boolean result = command.get(); |
|||
if (!result) { |
|||
log.error("指令执行异常: {}", JSONUtil.toJsonStr(form)); |
|||
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|||
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
return; |
|||
private Method getMethodByName(String methodName) { |
|||
try { |
|||
Class<?> clazz = deviceCtrlService.getClass(); |
|||
for (Method method : clazz.getDeclaredMethods()) { |
|||
if (method.getName().equals(methodName)) { |
|||
return method; |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("执行指令没有找到对应的方法:{}", methodName, e); |
|||
} |
|||
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|||
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|||
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|||
} |
|||
|
|||
public boolean executeCommand(CMDForm cmdForm) { |
|||
// form = cmdForm; |
|||
// String commandName = cmdForm.getCommand(); |
|||
// Function<Map<String, Object>, List<Supplier<Boolean>>> command = commandMap.get(commandName); |
|||
// if (command == null) { |
|||
// return false; |
|||
// } |
|||
// List<Supplier<Boolean>> cmdList = command.apply(form.getParams()); |
|||
// Tasks tasks = tasksService.getIngTask(); |
|||
// if (tasks != null) { |
|||
// TaskSteps taskSteps = new TaskSteps(); |
|||
// taskSteps.setTaskId(tasks.getId()); |
|||
// taskSteps.setStepDescription("执行指令:" + cmdMap.get(commandName)); |
|||
// taskStepsService.addTaskSteps(taskSteps); |
|||
// } |
|||
// initExecutorThread(cmdList); |
|||
return true; |
|||
return null; |
|||
} |
|||
|
|||
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue