|
|
@ -8,39 +8,150 @@ import com.qyft.gd.device.service.DeviceService; |
|
|
|
import com.qyft.gd.model.form.CMDForm; |
|
|
|
import com.qyft.gd.model.vo.ExecutionResult; |
|
|
|
import com.qyft.gd.model.vo.WebsocketResult; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class CMDService { |
|
|
|
|
|
|
|
DeviceService deviceService; |
|
|
|
Map<String, Function<CMDForm, Boolean>> commandMap; |
|
|
|
|
|
|
|
public boolean executeCommand(CMDForm cmdForm) { |
|
|
|
switch (cmdForm.getCommand()) { |
|
|
|
case Commands.UP_TRAY: |
|
|
|
upTray(cmdForm); |
|
|
|
break; |
|
|
|
case Commands.DOWN_TRAY: |
|
|
|
break; |
|
|
|
default: |
|
|
|
return false; |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
public CMDService(DeviceService deviceService) { |
|
|
|
this.deviceService = deviceService; |
|
|
|
// 初始化命令映射 |
|
|
|
this.commandMap = new HashMap<>(); |
|
|
|
commandMap.put(Commands.UP_TRAY, this::upTray); |
|
|
|
commandMap.put(Commands.DOWN_TRAY, this::downTray); |
|
|
|
commandMap.put(Commands.INJECT_FLUID, this::injectFluid); |
|
|
|
commandMap.put(Commands.KEEP_HEAT, this::keepHeat); |
|
|
|
commandMap.put(Commands.MOVE_TO_ACTION_AREA, this::moveToActionArea); |
|
|
|
commandMap.put(Commands.CHECK_ACTION_AREA, this::checkActionArea); |
|
|
|
commandMap.put(Commands.SHAKE_UP, this::shakeUp); |
|
|
|
commandMap.put(Commands.START_HEAT, this::startHeat); |
|
|
|
commandMap.put(Commands.STOP_HEAT, this::stopHeat); |
|
|
|
commandMap.put(Commands.TAKE_PHOTO, this::takePhoto); |
|
|
|
commandMap.put(Commands.MOVE_TO_UNUSUAL, this::moveToUnusual); |
|
|
|
commandMap.put(Commands.MOVE_TO_HEAT_AREA, this::moveToHeatArea); |
|
|
|
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.GET_LIQUID_AMOUNT, this::getLiquidAmount); |
|
|
|
commandMap.put(Commands.MOVE_TUBE, this::moveTube); |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean moveTube(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean getLiquidAmount(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean moveMachineArm(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean putBackCap(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean takeOffCap(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean moveToHeatArea(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean moveToUnusual(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean takePhoto(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean stopHeat(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private void upTray(CMDForm cmdForm) { |
|
|
|
private Boolean startHeat(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean shakeUp(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean checkActionArea(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean moveToActionArea(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean keepHeat(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean injectFluid(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean downTray(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean upTray(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean executeCommand(CMDForm cmdForm) { |
|
|
|
String commandName = cmdForm.getCommand(); |
|
|
|
Function<CMDForm, Boolean> command = commandMap.get(commandName); |
|
|
|
if (command == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
WebsocketResult websocketResult = new WebsocketResult(); |
|
|
|
websocketResult.setType("cmd"); |
|
|
|
// TODO 执行指令 |
|
|
|
ExecutionResult executionResult = new ExecutionResult(); |
|
|
|
executionResult.setCommandId(cmdForm.getCommandId()); |
|
|
|
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|
|
|
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|
|
|
executionResult.setCommandName(cmdForm.getCommand()); |
|
|
|
boolean result =command.apply(cmdForm); |
|
|
|
if(result) { |
|
|
|
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|
|
|
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|
|
|
}else { |
|
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|
|
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|
|
|
} |
|
|
|
websocketResult.setData(executionResult); |
|
|
|
// 发送消息给客户端 |
|
|
|
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
} |