From 00fd7ffa212eef12bbf0215bb91b69cd822c29aa 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:42:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=A0=95=E5=8A=A8=E6=B3=B5=E6=97=8B?= =?UTF-8?q?=E8=BD=AC=E3=80=81=E5=81=9C=E6=AD=A2=E6=97=8B=E8=BD=AC=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/control/PumpRotateStartCommand.java | 55 ++++++++++++++++++++++ .../app/command/control/PumpRotateStopCommand.java | 42 +++++++++++++++++ .../handacid/app/common/enums/Direction.java | 5 ++ 3 files changed, 102 insertions(+) create mode 100644 src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java create mode 100644 src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java create mode 100644 src/main/java/com/iflytop/handacid/app/common/enums/Direction.java 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 new file mode 100644 index 0000000..bb9a378 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.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.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/PumpRotateStopCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java new file mode 100644 index 0000000..336759d --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java @@ -0,0 +1,42 @@ +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.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.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_stop") +public class PumpRotateStopCommand 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 不能为空"); + } + return runAsync(() -> { + DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelCode); + CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); + CommandUtil.wait(commandFuture); + }); + } +} + diff --git a/src/main/java/com/iflytop/handacid/app/common/enums/Direction.java b/src/main/java/com/iflytop/handacid/app/common/enums/Direction.java new file mode 100644 index 0000000..6897df4 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/common/enums/Direction.java @@ -0,0 +1,5 @@ +package com.iflytop.handacid.app.common.enums; + +public enum Direction { + FORWARD, BACKWARD; +}