From 68be7464913fd0512b4e223968b3b1dd57164d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Tue, 29 Jul 2025 15:28:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=BC=80=E5=A7=8B=E9=A2=84=E5=85=85?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E3=80=81=E5=81=9C=E6=AD=A2=E9=A2=84=E5=85=85?= =?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/SolutionAddStartCommand.java | 2 - .../control/SolutionPreFillStartCommand.java | 63 ++++++++++++++++++++++ .../control/SolutionPreFillStopCommand.java | 55 +++++++++++++++++++ .../handacid/app/service/ChannelCtrlService.java | 12 +++++ 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java create mode 100644 src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java 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 369ab52..fd1302a 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 @@ -68,7 +68,6 @@ public class SolutionAddStartCommand extends BaseCommandHandler { JSONObject jsonObject = jsonArray.getJSONObject(i); String channelCodeStr = jsonObject.getStr("channelCode"); ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); - Double volume = jsonObject.getDouble("volume"); DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelCode, volume); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); @@ -82,7 +81,6 @@ public class SolutionAddStartCommand extends BaseCommandHandler { JSONObject jsonObject = jsonArray.getJSONObject(i); String channelCodeStr = jsonObject.getStr("channelCode"); ChannelCode channelCode = ChannelCode.valueOf(channelCodeStr); - deviceState.getChannelStateMap().get(channelCode).setStateCode(ChannelStateCode.ADD); Double volume = jsonObject.getDouble("volume"); DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelCode, volume); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); 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 new file mode 100644 index 0000000..ba50c1b --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java @@ -0,0 +1,63 @@ +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); + }); + } +} + diff --git a/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java new file mode 100644 index 0000000..2e2a15e --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java @@ -0,0 +1,55 @@ +package com.iflytop.handacid.app.command.control; + +import com.iflytop.handacid.app.common.annotation.CommandMapping; +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.ChannelState; +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_stop") +public class SolutionPreFillStopCommand extends BaseCommandHandler { + private final DeviceCommandService deviceCommandService; + private final ChannelCtrlService channelCtrlService; + private final DeviceState deviceState; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + + return runAsync(() -> { + List channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.PRE); + deviceState.setSolutionAddStop(true); + try { + List commandFutureList = new ArrayList<>(); + for (ChannelState channelState : channelCodeList) { + DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode()); + commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); + } + CommandUtil.wait(commandFutureList); + } finally { + for (ChannelState channelCode : channelCodeList) { + channelCode.setStateCode(ChannelStateCode.IDLE); + } + } + }); + } +} + diff --git a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java index ca25f40..47b548c 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -33,6 +33,18 @@ public class ChannelCtrlService { } /** + * 根据通道code获取泵正转指令 + */ + public DeviceCommand getPumpForwardRotateCommandByChannel(ChannelCode channelCode) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.pump1ForwardRotate(); + case CHANNEL_2 -> DeviceCommandGenerator.pump2ForwardRotate(); + case CHANNEL_3 -> DeviceCommandGenerator.pump3ForwardRotate(); + case CHANNEL_4 -> DeviceCommandGenerator.pump4ForwardRotate(); + }; + } + + /** * 根据通道code获取停止泵指令 */ public DeviceCommand getPumpStopCommandByChannel(ChannelCode channelCode) {