|
@ -5,6 +5,8 @@ import com.qyft.gd.common.constant.Commands; |
|
|
import com.qyft.gd.common.constant.WebSocketMessageType; |
|
|
import com.qyft.gd.common.constant.WebSocketMessageType; |
|
|
import com.qyft.gd.common.result.CMDResultCode; |
|
|
import com.qyft.gd.common.result.CMDResultCode; |
|
|
import com.qyft.gd.device.service.DeviceService; |
|
|
import com.qyft.gd.device.service.DeviceService; |
|
|
|
|
|
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.form.CMDForm; |
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -18,19 +20,43 @@ import java.util.function.Supplier; |
|
|
@Service |
|
|
@Service |
|
|
public class CMDService { |
|
|
public class CMDService { |
|
|
|
|
|
|
|
|
|
|
|
private final TasksService tasksService; |
|
|
|
|
|
private final TaskStepsService taskStepsService; |
|
|
DeviceService deviceService; |
|
|
DeviceService deviceService; |
|
|
WebSocketService webSocketService; |
|
|
WebSocketService webSocketService; |
|
|
BaseDataService baseDataService; |
|
|
BaseDataService baseDataService; |
|
|
Map<String, Function<Map<String, Object>, List<Supplier<Boolean>>>> commandMap; |
|
|
Map<String, Function<Map<String, Object>, List<Supplier<Boolean>>>> commandMap; |
|
|
CMDForm form; |
|
|
CMDForm form; |
|
|
|
|
|
Map<String, String> cmdMap; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
public CMDService(DeviceService deviceService , WebSocketService webSocketService, BaseDataService baseDataService) { |
|
|
|
|
|
|
|
|
public CMDService(DeviceService deviceService , WebSocketService webSocketService, BaseDataService baseDataService, TasksService tasksService, TaskStepsService taskStepsService) { |
|
|
this.deviceService = deviceService; |
|
|
this.deviceService = deviceService; |
|
|
this.webSocketService = webSocketService; |
|
|
this.webSocketService = webSocketService; |
|
|
this.baseDataService = baseDataService; |
|
|
this.baseDataService = baseDataService; |
|
|
|
|
|
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<>(); |
|
|
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.UP_TRAY, this::upTray); |
|
|
commandMap.put(Commands.DOWN_TRAY, this::downTray); |
|
|
commandMap.put(Commands.DOWN_TRAY, this::downTray); |
|
|
commandMap.put(Commands.INJECT_FLUID, this::injectFluid); |
|
|
commandMap.put(Commands.INJECT_FLUID, this::injectFluid); |
|
@ -47,6 +73,22 @@ public class CMDService { |
|
|
commandMap.put(Commands.MOVE_TO_HEAT_AREA, this::moveToHeatArea); |
|
|
commandMap.put(Commands.MOVE_TO_HEAT_AREA, this::moveToHeatArea); |
|
|
commandMap.put(Commands.OPEN_CLAW, this::openClaw); |
|
|
commandMap.put(Commands.OPEN_CLAW, this::openClaw); |
|
|
commandMap.put(Commands.CLOSE_CLAW, this::closeClaw); |
|
|
commandMap.put(Commands.CLOSE_CLAW, this::closeClaw); |
|
|
|
|
|
this.tasksService = tasksService; |
|
|
|
|
|
this.taskStepsService = taskStepsService; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 开门 |
|
|
|
|
|
public List<Supplier<Boolean>> openDoor(Map<String, Object> params) { |
|
|
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
|
|
cmdList.add(() -> deviceService.openDoor()); |
|
|
|
|
|
return cmdList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 关门 |
|
|
|
|
|
public List<Supplier<Boolean>> closeDoor(Map<String, Object> params) { |
|
|
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
|
|
cmdList.add(() -> deviceService.closeDoor()); |
|
|
|
|
|
return cmdList; |
|
|
} |
|
|
} |
|
|
// 机械臂爪子开启 |
|
|
// 机械臂爪子开启 |
|
|
public List<Supplier<Boolean>> openClaw(Map<String, Object> params) { |
|
|
public List<Supplier<Boolean>> openClaw(Map<String, Object> params) { |
|
@ -293,6 +335,9 @@ public class CMDService { |
|
|
int z = Integer.parseInt(tubePositionArr[2]); |
|
|
int z = Integer.parseInt(tubePositionArr[2]); |
|
|
// 泵id |
|
|
// 泵id |
|
|
String pumpId = baseDataService.getPumpIdBySolutionId((Integer) params.get("solutionId")); |
|
|
String pumpId = baseDataService.getPumpIdBySolutionId((Integer) params.get("solutionId")); |
|
|
|
|
|
if(params.get("flowRate") != null) { |
|
|
|
|
|
cmdList.add(() -> deviceService.setFlowRate(Integer.parseInt(pumpId), (Integer) params.get("flowRate"))); |
|
|
|
|
|
} |
|
|
cmdList.add(() -> deviceService.moveLiquidArmToPoint(x,y,z)); |
|
|
cmdList.add(() -> deviceService.moveLiquidArmToPoint(x,y,z)); |
|
|
cmdList.add(() -> deviceService.addLiquid(Long.valueOf(pumpId), ((Integer)params.get("volume")))); |
|
|
cmdList.add(() -> deviceService.addLiquid(Long.valueOf(pumpId), ((Integer)params.get("volume")))); |
|
|
return cmdList; |
|
|
return cmdList; |
|
@ -352,6 +397,13 @@ public class CMDService { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
List<Supplier<Boolean>> cmdList = command.apply(form.getParams()); |
|
|
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); |
|
|
initExecutorThread(cmdList); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|