From 89601c118674d53539dbcb21dc0d27c42d32be46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 09:36:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=87=8D=E5=86=99=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E9=A2=84=E5=85=85=E3=80=81=E5=BC=80=E5=A7=8B=E5=8A=A0=E6=B6=B2?= =?UTF-8?q?=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/control/PumpRotateStartCommand.java | 110 ++++++++++----------- .../command/control/SolutionAddStartCommand.java | 76 +------------- .../control/SolutionPreFillStartCommand.java | 97 +++++++----------- 3 files changed, 90 insertions(+), 193 deletions(-) diff --git a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java index 9c8dc67..bb9a378 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java @@ -1,55 +1,55 @@ -//package com.iflytop.handacid.app.command.control; -// -//import com.iflytop.handacid.app.common.annotation.CommandMapping; -//import com.iflytop.handacid.app.common.enums.ChannelCode; -//import com.iflytop.handacid.app.common.enums.Direction; -//import com.iflytop.handacid.app.common.utils.CommandUtil; -//import com.iflytop.handacid.app.core.command.BaseCommandHandler; -//import com.iflytop.handacid.app.core.command.CommandFuture; -//import com.iflytop.handacid.app.core.command.DeviceCommand; -//import com.iflytop.handacid.app.core.state.DeviceState; -//import com.iflytop.handacid.app.model.dto.CommandDTO; -//import com.iflytop.handacid.app.service.ChannelCtrlService; -//import com.iflytop.handacid.app.service.DeviceCommandService; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Component; -// -//import java.util.concurrent.CompletableFuture; -// -///** -// * 蠕动泵旋转 -// */ -//@Slf4j -//@Component -//@RequiredArgsConstructor -//@CommandMapping("pump_rotate_start") -//public class PumpRotateStartCommand extends BaseCommandHandler { -// private final DeviceCommandService deviceCommandService; -// private final ChannelCtrlService channelCtrlService; -// -// @Override -// public CompletableFuture handle(CommandDTO commandDTO) { -// ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class); -// if (channelCode == null) { -// throw new IllegalArgumentException("参数 channelCode 不能为空"); -// } -// Direction direction = commandDTO.getEnumParam("direction", Direction.class); -// if (direction == null) { -// throw new IllegalArgumentException("参数 direction 不能为空"); -// } -// return runAsync(() -> { -// if(Direction.FORWARD.equals(direction)) { -// DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); -// CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); -// CommandUtil.wait(commandFuture); -// }else{ -// DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); -// CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); -// CommandUtil.wait(commandFuture); -// } -// -// }); -// } -//} -// +package com.iflytop.handacid.app.command.control; + +import com.iflytop.handacid.app.common.annotation.CommandMapping; +import com.iflytop.handacid.app.common.enums.ChannelCode; +import com.iflytop.handacid.app.common.enums.Direction; +import com.iflytop.handacid.app.common.utils.CommandUtil; +import com.iflytop.handacid.app.core.command.BaseCommandHandler; +import com.iflytop.handacid.app.core.command.CommandFuture; +import com.iflytop.handacid.app.core.command.DeviceCommand; +import com.iflytop.handacid.app.core.state.DeviceState; +import com.iflytop.handacid.app.model.dto.CommandDTO; +import com.iflytop.handacid.app.service.ChannelCtrlService; +import com.iflytop.handacid.app.service.DeviceCommandService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 蠕动泵旋转 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("pump_rotate_start") +public class PumpRotateStartCommand extends BaseCommandHandler { + private final DeviceCommandService deviceCommandService; + private final ChannelCtrlService channelCtrlService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class); + if (channelCode == null) { + throw new IllegalArgumentException("参数 channelCode 不能为空"); + } + Direction direction = commandDTO.getEnumParam("direction", Direction.class); + if (direction == null) { + throw new IllegalArgumentException("参数 direction 不能为空"); + } + return runAsync(() -> { + if(Direction.FORWARD.equals(direction)) { + DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); + CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); + CommandUtil.wait(commandFuture); + }else{ + DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); + CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); + CommandUtil.wait(commandFuture); + } + + }); + } +} + diff --git a/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java index caec699..132a75e 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java @@ -1,27 +1,13 @@ package com.iflytop.handacid.app.command.control; -import cn.hutool.json.JSONArray; -import cn.hutool.json.JSONObject; import com.iflytop.handacid.app.common.annotation.CommandMapping; -import com.iflytop.handacid.app.common.enums.ChannelCode; -import com.iflytop.handacid.app.common.enums.ChannelStateCode; -import com.iflytop.handacid.app.common.enums.SolutionAddMode; -import com.iflytop.handacid.app.common.utils.CommandUtil; import com.iflytop.handacid.app.core.command.BaseCommandHandler; -import com.iflytop.handacid.app.core.command.CommandFuture; -import com.iflytop.handacid.app.core.command.DeviceCommand; -import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.app.model.dto.CommandDTO; import com.iflytop.handacid.app.service.ChannelCtrlService; -import com.iflytop.handacid.app.service.DeviceCommandService; -import com.iflytop.handacid.common.model.entity.Formulation; -import com.iflytop.handacid.common.service.FormulationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -32,72 +18,12 @@ import java.util.concurrent.CompletableFuture; @RequiredArgsConstructor @CommandMapping("solution_add_start") public class SolutionAddStartCommand extends BaseCommandHandler { - private final DeviceCommandService deviceCommandService; - private final FormulationService formulationService; private final ChannelCtrlService channelCtrlService; - private final DeviceState deviceState; @Override public CompletableFuture handle(CommandDTO commandDTO) { - JSONArray jsonArray = commandDTO.getJSONArrayParam("channelArray"); - List channelCodeList = new ArrayList<>(); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - String channelCodeStr = jsonObject.getStr("channelCode"); - if (channelCodeStr == null) { - throw new IllegalArgumentException("参数 channelCode 不能为空"); - } - ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); - channelCodeList.add(channelCode); - Double formulationId = jsonObject.getDouble("formulationId"); - if (formulationId == null) { - throw new IllegalArgumentException("参数 formulationId 不能为空"); - } - } - SolutionAddMode mode = commandDTO.getEnumParam("mode", SolutionAddMode.class); - Integer delay = commandDTO.getIntegerParam("delay"); - if (mode == null) { - throw new IllegalArgumentException("参数 mode 不能为空"); - } return runAsync(() -> { - try { - for (ChannelCode channelCode : channelCodeList) { - deviceState.getChannelStateMap().get(channelCode).setStateCode(ChannelStateCode.ADD); - } - if (SolutionAddMode.AUTO.equals(mode)) {//自动模式 - while (!deviceState.isSolutionAddStop()) { - List commandFutureList = new ArrayList<>(); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - String channelCodeStr = jsonObject.getStr("channelCode"); - ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); - Long formulationId = jsonObject.getLong("formulationId"); - Formulation formulation = formulationService.getById(formulationId); - DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelCode, formulation.getRevolutions()); - commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); - } - CommandUtil.wait(commandFutureList); - Thread.sleep(delay * 1000L); - } - } else if (SolutionAddMode.CLICK.equals(mode)) {//点动模式 - List commandFutureList = new ArrayList<>(); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - String channelCodeStr = jsonObject.getStr("channelCode"); - ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); - Double formulationId = jsonObject.getDouble("formulationId"); - Formulation formulation = formulationService.getById(formulationId); - DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelCode, formulation.getRevolutions()); - commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); - } - CommandUtil.wait(commandFutureList); - } - } finally { - for (ChannelCode channelCode : channelCodeList) { - deviceState.getChannelStateMap().get(channelCode).setStateCode(ChannelStateCode.IDLE); - } - deviceState. setSolutionAddStop(false); - } + channelCtrlService.solutionAddStart(); }); } } diff --git a/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java index fc18216..8521422 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java @@ -1,63 +1,34 @@ -//package com.iflytop.handacid.app.command.control; -// -//import cn.hutool.json.JSONArray; -//import cn.hutool.json.JSONObject; -//import com.iflytop.handacid.app.common.annotation.CommandMapping; -//import com.iflytop.handacid.app.common.enums.ChannelCode; -//import com.iflytop.handacid.app.common.enums.ChannelStateCode; -//import com.iflytop.handacid.app.common.utils.CommandUtil; -//import com.iflytop.handacid.app.core.command.BaseCommandHandler; -//import com.iflytop.handacid.app.core.command.CommandFuture; -//import com.iflytop.handacid.app.core.command.DeviceCommand; -//import com.iflytop.handacid.app.core.state.DeviceState; -//import com.iflytop.handacid.app.model.dto.CommandDTO; -//import com.iflytop.handacid.app.service.ChannelCtrlService; -//import com.iflytop.handacid.app.service.DeviceCommandService; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Component; -// -//import java.util.ArrayList; -//import java.util.List; -//import java.util.concurrent.CompletableFuture; -// -///** -// * 开始预充(废弃) -// */ -//@Slf4j -//@Component -//@RequiredArgsConstructor -//@CommandMapping("solution_pre_fill_start") -//public class SolutionPreFillStartCommand extends BaseCommandHandler { -// private final DeviceCommandService deviceCommandService; -// private final ChannelCtrlService channelCtrlService; -// private final DeviceState deviceState; -// -// @Override -// public CompletableFuture handle(CommandDTO commandDTO) { -// JSONArray jsonArray = commandDTO.getJSONArrayParam("channelArray"); -// List channelCodeList = new ArrayList<>(); -// for (int i = 0; i < jsonArray.size(); i++) { -// JSONObject jsonObject = jsonArray.getJSONObject(i); -// String channelCodeStr = jsonObject.getStr("channelCode"); -// if (channelCodeStr == null) { -// throw new IllegalArgumentException("参数 channelCode 不能为空"); -// } -// } -// return runAsync(() -> { -// for (ChannelCode channelCode : channelCodeList) { -// deviceState.getChannelStateMap().get(channelCode).setStateCode(ChannelStateCode.PRE); -// } -// List commandFutureList = new ArrayList<>(); -// for (int i = 0; i < jsonArray.size(); i++) { -// JSONObject jsonObject = jsonArray.getJSONObject(i); -// String channelCodeStr = jsonObject.getStr("channelCode"); -// ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); -// DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); -// commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); -// } -// CommandUtil.wait(commandFutureList); -// }); -// } -//} -// +package com.iflytop.handacid.app.command.control; + +import com.iflytop.handacid.app.common.annotation.CommandMapping; +import com.iflytop.handacid.app.core.command.BaseCommandHandler; +import com.iflytop.handacid.app.core.state.DeviceState; +import com.iflytop.handacid.app.model.dto.CommandDTO; +import com.iflytop.handacid.app.service.ChannelCtrlService; +import com.iflytop.handacid.app.service.DeviceCommandService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始预充(废弃) + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("solution_pre_fill_start") +public class SolutionPreFillStartCommand extends BaseCommandHandler { + private final DeviceCommandService deviceCommandService; + private final ChannelCtrlService channelCtrlService; + private final DeviceState deviceState; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(() -> { + channelCtrlService.solutionPreFillStart(); + }); + } +} +