|
@ -5,9 +5,12 @@ 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.dto.CmdInjectFluidDTO; |
|
|
|
|
|
import com.qyft.gd.model.dto.InjectFluid; |
|
|
import com.qyft.gd.model.entity.TaskSteps; |
|
|
import com.qyft.gd.model.entity.TaskSteps; |
|
|
import com.qyft.gd.model.entity.Tasks; |
|
|
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.ContainerListVO; |
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
@ -29,15 +32,19 @@ public class CMDService { |
|
|
DeviceService deviceService; |
|
|
DeviceService deviceService; |
|
|
WebSocketService webSocketService; |
|
|
WebSocketService webSocketService; |
|
|
BaseDataService baseDataService; |
|
|
BaseDataService baseDataService; |
|
|
|
|
|
ContainerService containerService; |
|
|
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; |
|
|
Map<String, String> cmdMap; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
public CMDService(DeviceService deviceService, WebSocketService webSocketService, BaseDataService baseDataService, TasksService tasksService, TaskStepsService taskStepsService) { |
|
|
|
|
|
|
|
|
public CMDService(DeviceService deviceService, WebSocketService webSocketService, BaseDataService baseDataService, TasksService tasksService, TaskStepsService taskStepsService, ContainerService containerService) { |
|
|
this.deviceService = deviceService; |
|
|
this.deviceService = deviceService; |
|
|
this.webSocketService = webSocketService; |
|
|
this.webSocketService = webSocketService; |
|
|
this.baseDataService = baseDataService; |
|
|
this.baseDataService = baseDataService; |
|
|
|
|
|
this.tasksService = tasksService; |
|
|
|
|
|
this.taskStepsService = taskStepsService; |
|
|
|
|
|
this.containerService = containerService; |
|
|
this.cmdMap = new HashMap<>(); |
|
|
this.cmdMap = new HashMap<>(); |
|
|
cmdMap.put("openDoor", "开门"); |
|
|
cmdMap.put("openDoor", "开门"); |
|
|
cmdMap.put("closeDoor", "关门"); |
|
|
cmdMap.put("closeDoor", "关门"); |
|
@ -77,8 +84,7 @@ 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; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 开门 |
|
|
// 开门 |
|
@ -339,9 +345,46 @@ public class CMDService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 批量加液 |
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
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) { |
|
|
public List<Supplier<Boolean>> injectFluid(Map<String, Object> params) { |
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
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 tubePosition = baseDataService.getTubePositionBySolutionArea((Integer) params.get("tubeNum")); |
|
|
String[] tubePositionArr = tubePosition.split(","); |
|
|
String[] tubePositionArr = tubePosition.split(","); |
|
@ -355,6 +398,8 @@ public class CMDService { |
|
|
} |
|
|
} |
|
|
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")))); |
|
|
|
|
|
cmdList.add(() -> updateVolume(params)); |
|
|
|
|
|
|
|
|
return cmdList; |
|
|
return cmdList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -381,6 +426,19 @@ public class CMDService { |
|
|
return cmdList; |
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList) { |
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList) { |
|
|
new Thread(() -> run(cmdList)).start(); |
|
|
new Thread(() -> run(cmdList)).start(); |
|
|
} |
|
|
} |
|
@ -424,4 +482,6 @@ public class CMDService { |
|
|
initExecutorThread(cmdList); |
|
|
initExecutorThread(cmdList); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |