|
|
@ -3,24 +3,24 @@ package com.qyft.gd.service; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.qyft.gd.common.constant.Commands; |
|
|
|
import com.qyft.gd.common.result.CMDResultCode; |
|
|
|
import com.qyft.gd.config.WebSocketServer; |
|
|
|
import com.qyft.gd.device.service.DeviceService; |
|
|
|
import com.qyft.gd.device.service.DeviceStateService; |
|
|
|
import com.qyft.gd.model.form.CMDForm; |
|
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
|
import com.qyft.gd.model.vo.WebsocketResult; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class CMDService { |
|
|
|
|
|
|
|
DeviceService deviceService; |
|
|
|
DeviceStateService deviceStateService; |
|
|
|
WebSocketService webSocketService; |
|
|
|
Map<String, Function<CMDForm, Boolean>> commandMap; |
|
|
|
|
|
|
|
@Autowired |
|
|
@ -52,7 +52,8 @@ public class CMDService { |
|
|
|
private Boolean moveMachineArm(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(11,22,33)); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 装回盖子 |
|
|
|
private Boolean putBackCap(CMDForm cmdForm) { |
|
|
@ -61,7 +62,8 @@ public class CMDService { |
|
|
|
cmdList.add(() -> deviceService.openClaw()); |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(4,54,6)); |
|
|
|
cmdList.add(() -> deviceService.closeClaw()); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 取试管架盖 |
|
|
|
private Boolean takeOffCap(CMDForm cmdForm) { |
|
|
@ -69,25 +71,29 @@ public class CMDService { |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(13,42,53)); |
|
|
|
cmdList.add(() -> deviceService.openClaw()); |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(4,5,6)); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 拍照 |
|
|
|
private Boolean takePhoto(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.takePhoto()); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 停止加热 |
|
|
|
private Boolean stopHeat(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.stopHeating((String) cmdForm.getParams().get("areaId"))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 开始加热 |
|
|
|
private Boolean startHeat(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.startHeating((String) cmdForm.getParams().get("areaId"),(Double) cmdForm.getParams().get("temperature"))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 开始摇匀 |
|
|
|
private Boolean startShakeUp(CMDForm cmdForm) { |
|
|
@ -104,13 +110,15 @@ public class CMDService { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.startShaking()); |
|
|
|
cmdList.add(() -> deviceService.setShakingSpeed((Integer) cmdForm.getParams().get("speed"))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 结束摇匀 |
|
|
|
private Boolean stopShakeUp(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.stopShaking()); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// 移至加液 |
|
|
@ -125,7 +133,8 @@ public class CMDService { |
|
|
|
cmdList.add(() -> deviceService.openClaw()); |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(4,5,6)); |
|
|
|
cmdList.add(() -> deviceService.closeClaw()); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
// 加液 |
|
|
@ -136,30 +145,46 @@ public class CMDService { |
|
|
|
Map<String, Object> params = cmdForm.getParams(); |
|
|
|
cmdList.add(() -> deviceService.moveLiquidArmToPoint(1,2,3)); |
|
|
|
cmdList.add(() -> deviceService.addLiquid((String) params.get("pumpId"), ((Integer)params.get("volume")))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 放下托盘 |
|
|
|
private boolean downTray(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.lowerTray((String) cmdForm.getParams().get("heaterId"))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 抬起托盘 |
|
|
|
private boolean upTray(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.raiseTray((String) cmdForm.getParams().get("heaterId"))); |
|
|
|
return run(cmdList); |
|
|
|
initExecutorThread(cmdList, cmdForm); |
|
|
|
return true; |
|
|
|
} |
|
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList, CMDForm cmdForm) { |
|
|
|
new Thread(() -> run(cmdList, cmdForm)).start(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean run(List<Supplier<Boolean>> cmdList) { |
|
|
|
private void run(List<Supplier<Boolean>> cmdList, CMDForm cmdForm) { |
|
|
|
ExecutionResult executionResult = new ExecutionResult(); |
|
|
|
executionResult.setCommandId(cmdForm.getCommandId()); |
|
|
|
executionResult.setCommandName(cmdForm.getCommand()); |
|
|
|
|
|
|
|
// 执行所有命令 |
|
|
|
for (Supplier<Boolean> command : cmdList) { |
|
|
|
boolean result = command.get(); |
|
|
|
if (!result) { |
|
|
|
return false; |
|
|
|
log.error("指令执行异常: {}", JSONUtil.toJsonStr(cmdForm)); |
|
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|
|
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|
|
|
webSocketService.pushMsg("cmd", executionResult); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|
|
|
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|
|
|
webSocketService.pushMsg("cmd", executionResult); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean executeCommand(CMDForm cmdForm) { |
|
|
|