From 9de7e12682a7a56d042c10a52df1f91fa99a0c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Sat, 26 Jul 2025 20:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=A0=E6=B6=B2=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/command/control/solution/ShakeStartCommand.java | 3 +++ .../app/command/control/solution/SolutionAddCommand.java | 13 ++++++++----- .../app/websocket/server/WebSocketMessageType.java | 4 ++++ .../app/websocket/server/WebSocketSender.java | 13 +++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java index 01e4a41..f6a653a 100644 --- a/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java @@ -5,6 +5,7 @@ import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; import com.iflytop.colortitration.app.core.command.BaseCommandHandler; import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.websocket.server.WebSocketSender; import com.iflytop.colortitration.common.exception.AppException; import com.iflytop.colortitration.common.result.ResultCode; import lombok.RequiredArgsConstructor; @@ -23,6 +24,7 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("shake_start") public class ShakeStartCommand extends BaseCommandHandler { private final TitrationModuleService titrationModuleService; + private final WebSocketSender webSocketSender; @Override public CompletableFuture handle(CommandDTO commandDTO) { @@ -34,6 +36,7 @@ public class ShakeStartCommand extends BaseCommandHandler { } MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(motorCode); return runAsync(() -> { + webSocketSender.pushLog(titrationModuleCode.name(), "摇匀:", time + "秒"); titrationModuleService.shakeStart(titrationModuleCode, speed, time); }); } diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java index afc4142..5689cc5 100644 --- a/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java @@ -5,8 +5,11 @@ import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; import com.iflytop.colortitration.app.core.command.BaseCommandHandler; import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.websocket.server.WebSocketSender; import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.model.entity.Solutions; import com.iflytop.colortitration.common.result.ResultCode; +import com.iflytop.colortitration.common.service.SolutionsService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -23,23 +26,23 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("solution_add_start") public class SolutionAddCommand extends BaseCommandHandler { private final TitrationModuleService titrationModuleService; + private final WebSocketSender webSocketSender; + private final SolutionsService solutionService; @Override public CompletableFuture handle(CommandDTO commandDTO) { String moduleCodeStr = commandDTO.getStringParam("titrationModuleCode"); Long solutionId = commandDTO.getLongParam("solutionId"); + Solutions solution = solutionService.getById(solutionId); Double volume = commandDTO.getDoubleParam("volume"); - String type = commandDTO.getStringParam("type"); - if (type.equals("drop")) { - volume = 0.5; - } - if (StringUtils.isEmpty(moduleCodeStr) || solutionId == null || StringUtils.isEmpty(type)) { + if (StringUtils.isEmpty(moduleCodeStr) || solutionId == null) { throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 } MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(moduleCodeStr); Double finalVolume = volume; return runAsync(() -> { //移动滴定电机到滴定位 + webSocketSender.pushLog(titrationModuleCode.name(), "加液:", solution.getName() + " " + finalVolume + "ml"); titrationModuleService.titrationMotorMoveToSolution(titrationModuleCode); titrationModuleService.addSolutionStart(titrationModuleCode, solutionId, finalVolume); }); diff --git a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketMessageType.java b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketMessageType.java index 8ebf122..4d94f14 100644 --- a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketMessageType.java +++ b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketMessageType.java @@ -10,6 +10,10 @@ public class WebSocketMessageType { */ public static final String ALARM = "alarm"; /** + * 滴定日志 + */ + public static final String LOG = "log"; + /** * 自检移动电机测试 */ public static final String SELF_MOVE_TEST = "self_move_test"; diff --git a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java index cf02051..dece98b 100644 --- a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java +++ b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java @@ -2,9 +2,12 @@ package com.iflytop.colortitration.app.websocket.server; import cn.hutool.json.JSONUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import java.time.Instant; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; @Slf4j @Component @@ -27,6 +30,16 @@ public class WebSocketSender { push(WebSocketMessageType.CMD_DEBUG, data); } + public void pushLog(String code, String type, String content) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedDate = LocalDateTime.now().format(formatter); + WebsocketResult websocketResult = new WebsocketResult(); + websocketResult.setType(WebSocketMessageType.LOG); + websocketResult.setData(formattedDate + "模块" + StringUtils.substring(code, code.length() - 1) + type + content); + websocketResult.setTimestamp(Instant.now().toEpochMilli()); + WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); + } + public void pushCMDResponse(Object data) { push(WebSocketMessageType.CMD_RESPONSE, data); }