From 13cfb74758611f86cbfbced011b4f2b561a70a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Wed, 30 Jul 2025 14:41:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E9=80=9A=E9=81=93?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=8A=A0=E6=B6=B2=E3=80=81=E9=A2=84=E5=85=85?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/control/SolutionAddStartCommand.java | 2 +- .../control/SolutionPreFillStartCommand.java | 2 +- .../handacid/app/core/state/DeviceState.java | 13 ++++ .../handacid/app/model/dto/SyncOperationsDTO.java | 3 + .../handacid/app/service/ChannelCtrlService.java | 77 ++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) 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 b8242f0..63af35f 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 @@ -25,7 +25,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; /** - * 开始加液 + * 开始加液(废弃) */ @Slf4j @Component 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 ba50c1b..b2c8865 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 @@ -22,7 +22,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; /** - * 开始预充 + * 开始预充(废弃) */ @Slf4j @Component diff --git a/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java b/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java index 6048e08..9c14e74 100644 --- a/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java +++ b/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java @@ -28,6 +28,9 @@ public class DeviceState { @Schema(description = "加液模式") private volatile SolutionAddMode mode; + @Schema(description = "加液间隔") + private volatile int delay = 0; + @Schema(description = "虚拟模式,true为虚拟") private volatile boolean virtual = false; @@ -41,6 +44,7 @@ public class DeviceState { JSONObject json = new JSONObject(); json.putOnce("channelState", new ArrayList<>(channelStateMap.values())); json.putOnce("mode", mode); + json.putOnce("delay", delay); json.putOnce("virtual", virtual); json.putOnce("emergencyStop", emergencyStop); json.putOnce("currentUser", currentUser); @@ -64,4 +68,13 @@ public class DeviceState { .filter(ChannelState::isPre) .collect(Collectors.toList()); } + + /** + * 获取选中的通道 + */ + public List filterChannelStatesIsSelected() { + return channelStateMap.values().stream() + .filter(ChannelState::isSelected) + .collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java b/src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java index d4e26f1..3e820cf 100644 --- a/src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java +++ b/src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java @@ -18,6 +18,9 @@ public class SyncOperationsDTO { @Schema(description = "加液模式") private SolutionAddMode mode; + @Schema(description = "加液间隔") + private Integer delay; + @Schema(description = "通道") private List channels; 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 9c75284..e2478ec 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -1,14 +1,26 @@ package com.iflytop.handacid.app.service; +import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.CommandFuture; import com.iflytop.handacid.app.core.command.DeviceCommand; import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; +import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.DeviceState; +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.Service; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + /** * 通道控制 */ @@ -16,9 +28,73 @@ import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class ChannelCtrlService { + private final FormulationService formulationService; + private final ChannelCtrlService channelCtrlService; private final DeviceCommandService deviceCommandService; private final DeviceState deviceState; + /** + * 开始加液 + */ + public void solutionAddStart() { + CompletableFuture.runAsync(() -> { + List channelStateList = deviceState.filterChannelStatesIsSelected(); + try { + for (ChannelState channelState : channelStateList) { + channelState.setStateCode(ChannelStateCode.ADD); + } + if (SolutionAddMode.AUTO.equals(deviceState.getMode())) {//自动模式 + while (!deviceState.isSolutionAddStop()) { + List commandFutureList = new ArrayList<>(); + for (ChannelState channelState : channelStateList) { + Formulation formulation = formulationService.getOne(new LambdaQueryWrapper().eq(Formulation::getSolutionId, channelState.getSolutionId())); + DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); + commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); + } + CommandUtil.wait(commandFutureList); + Thread.sleep(deviceState.getDelay() * 1000L); + } + } else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式 + List commandFutureList = new ArrayList<>(); + for (ChannelState channelState : channelStateList) { + Formulation formulation = formulationService.getOne(new LambdaQueryWrapper().eq(Formulation::getSolutionId, channelState.getSolutionId())); + DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); + commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); + } + CommandUtil.wait(commandFutureList); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + for (ChannelState channelState : channelStateList) { + channelState.setStateCode(ChannelStateCode.IDLE); + } + deviceState.setSolutionAddStop(false); + } + }); + } + + /** + * 开始预充 + */ + public void solutionPreFillStart() { + CompletableFuture.runAsync(() -> { + List channelStateList = deviceState.filterChannelStatesIsSelected(); + try { + for (ChannelState channelState : channelStateList) { + channelState.setStateCode(ChannelStateCode.PRE); + } + List commandFutureList = new ArrayList<>(); + for (ChannelState channelState : channelStateList) { + DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelState.getChannelCode()); + commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); + } + CommandUtil.wait(commandFutureList); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } /** * 根据通道code获取泵相对移动指令 @@ -80,6 +156,7 @@ public class ChannelCtrlService { /** * 停止加液 + * * @param channelCode 通道code */ public void solutionAddStop(ChannelCode channelCode) {