diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelineWash.java b/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelineWash.java index 7d81570..9d67124 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelineWash.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelineWash.java @@ -1,96 +1,106 @@ -//package com.qyft.ms.app.front.cmd.business; -// -//import cn.hutool.json.JSONObject; -//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -//import com.qyft.ms.app.device.status.DeviceStatus; -//import com.qyft.ms.app.model.entity.Position; -//import com.qyft.ms.app.model.entity.SysSettings; -//import com.qyft.ms.app.service.PositionService; -//import com.qyft.ms.app.service.SysSettingsService; -//import com.qyft.ms.system.common.annotation.CommandMapping; -//import com.qyft.ms.system.common.constant.CommandStatus; -//import com.qyft.ms.system.common.device.command.CommandFuture; -//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; -//import com.qyft.ms.system.common.device.command.FrontResponseGenerator; -//import com.qyft.ms.system.core.handler.BaseCommandHandler; -//import com.qyft.ms.system.model.bo.DeviceCommand; -//import com.qyft.ms.system.model.form.FrontCmdControlForm; -//import com.qyft.ms.system.service.WebSocketService; -//import com.qyft.ms.system.service.device.DeviceCommandService; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Component; -// -//import java.util.concurrent.CompletableFuture; -// -///** -// * 喷嘴管路_清洗喷嘴管路 -// * 废弃 -// */ -//@Slf4j -//@Component -//@RequiredArgsConstructor -//@CommandMapping("nozzle_pipeline_wash")//业务指令注解 -//public class NozzlePipelineWash extends BaseCommandHandler { -// -// private final DeviceCommandService deviceCommandService; -// private final SysSettingsService sysSettingsService; -// private final PositionService positionService; -// private final DeviceStatus deviceStatus; -// private final WebSocketService webSocketService; -// -// @Override -// public CompletableFuture handle(FrontCmdControlForm form) { -// if (deviceStatus.isCleaningSyringePipeline() || deviceStatus.isCleaningNozzlePipeline()) { -// throw new RuntimeException("正在清洗喷嘴管路或注射器管路,无法开启清洗注射器管路"); -// } -// try { -// //1.判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴 -// DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); -// CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand); -// commandWait(motorXyzPositionGetCommandFuture); -// JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); -// Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition"); -// if (zAxisPosition == null) { -// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "获得电机XYZ相对原点坐标失败", motorXyzPositionGetCommandDeviceResult)); -// throw new RuntimeException("获得电机XYZ相对原点坐标失败"); -// } -// zAxisPosition = Math.abs(zAxisPosition); -// SysSettings safeZHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "safe_z_height")); -// double safeZHeight = Double.parseDouble(safeZHeightSysSettings.getValue()); -// if (zAxisPosition > safeZHeight) { //z轴超出安全距离,抬升z轴 -// DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(safeZHeight, 15.0); -// CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); -// commandWait(motorZPositionSetCommandFuture); -// } -// Position wasteLiquor = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "waste_liquor")); -// //2.轴移动到废液位置 -// DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(wasteLiquor.getX(), 20.0); -// CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXPositionSetCommand); -// commandWait(motorXPositionSetCommandFuture); -// //3.下降z轴高度,防止飞溅 -// DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(wasteLiquor.getZ(), 15.0); -// CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); -// commandWait(motorZPositionSetCommandFuture); -// //4.开启三通阀到喷嘴管路 -// DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline(); // 打开三通阀喷嘴管路 -// CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand); -// commandWait(threeWayValveOpenSyringePipelineCommandFuture); -// -// //6.打开清洗阀 -// DeviceCommand washValveOpenCommand = DeviceCommandGenerator.washValveOpen(); // 生成打开清洗阀指令 -// CommandFuture washValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveOpenCommand); -// commandWait(washValveOpenCommandFuture); -// -// deviceStatus.setCleaningNozzlePipeline(true); -// } catch (Exception e) { -// deviceStatus.setCleaningNozzlePipeline(false); -// throw new RuntimeException(e); -// } -// return runAsync(() -> { -// -// -// }); -// -// } -//} +package com.qyft.ms.app.front.cmd.business; + +import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.qyft.ms.app.device.status.DeviceStatus; +import com.qyft.ms.app.model.entity.Position; +import com.qyft.ms.app.model.entity.SysSettings; +import com.qyft.ms.app.service.PositionService; +import com.qyft.ms.app.service.SysSettingsService; +import com.qyft.ms.system.common.annotation.CommandMapping; +import com.qyft.ms.system.common.constant.CommandStatus; +import com.qyft.ms.system.common.device.command.CommandFuture; +import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; +import com.qyft.ms.system.common.device.command.FrontResponseGenerator; +import com.qyft.ms.system.core.handler.BaseCommandHandler; +import com.qyft.ms.system.model.bo.DeviceCommand; +import com.qyft.ms.system.model.form.FrontCmdControlForm; +import com.qyft.ms.system.service.WebSocketService; +import com.qyft.ms.system.service.device.DeviceCommandService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 清洗喷嘴管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("nozzle_pipeline_wash")//业务指令注解 +public class NozzlePipelineWash extends BaseCommandHandler { + + private final DeviceCommandService deviceCommandService; + private final SysSettingsService sysSettingsService; + private final PositionService positionService; + private final DeviceStatus deviceStatus; + private final WebSocketService webSocketService; + + @Override + public CompletableFuture handle(FrontCmdControlForm form) { + if(deviceStatus.isSpraying()){ + throw new RuntimeException("正在喷涂,无法开启清洗注射器管路"); + } + if (deviceStatus.isCleaningSyringePipeline() || deviceStatus.isCleaningNozzlePipeline()) { + throw new RuntimeException("正在清洗喷嘴管路或注射器管路,无法开启清洗注射器管路"); + } + try { + deviceStatus.setCleaningNozzlePipeline(true); + //1.判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴 + DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); + CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand); + commandWait(motorXyzPositionGetCommandFuture); + JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); + Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition"); + if (zAxisPosition == null) { + webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "获得电机XYZ相对原点坐标失败", motorXyzPositionGetCommandDeviceResult)); + throw new RuntimeException("获得电机XYZ相对原点坐标失败"); + } + zAxisPosition = Math.abs(zAxisPosition); + SysSettings safeZHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "safe_z_height")); + double safeZHeight = Double.parseDouble(safeZHeightSysSettings.getValue()); + if (zAxisPosition > safeZHeight) { //z轴超出安全距离,抬升z轴 + DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(safeZHeight, 15.0); + CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); + commandWait(motorZPositionSetCommandFuture); + } + Position wasteLiquor = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "waste_liquor")); + //2.轴移动到废液位置 + DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(wasteLiquor.getX(), 20.0); + CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXPositionSetCommand); + commandWait(motorXPositionSetCommandFuture); + //3.下降z轴高度,防止飞溅 + DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(wasteLiquor.getZ(), 15.0); + CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); + commandWait(motorZPositionSetCommandFuture); + //4.开启三通阀到喷嘴管路 + DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline(); // 打开三通阀喷嘴管路 + CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand); + commandWait(threeWayValveOpenSyringePipelineCommandFuture); + + //6.打开清洗阀 + DeviceCommand washValveOpenCommand = DeviceCommandGenerator.washValveOpen(); // 生成打开清洗阀指令 + CommandFuture washValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveOpenCommand); + commandWait(washValveOpenCommandFuture); + + DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); // 关闭喷嘴阀 + CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand); + commandWait(nozzleValveCloseCommandFuture); + + + DeviceCommand dehumidifierCloseCommand = DeviceCommandGenerator.dehumidifierValveClose(); // 关闭除湿阀门 + CommandFuture dehumidifierCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), dehumidifierCloseCommand); + commandWait(dehumidifierCloseCommandFuture); + } catch (Exception e) { + deviceStatus.setCleaningNozzlePipeline(false); + throw new RuntimeException(e); + } + return runAsync(() -> { + + + }); + + } +}