From 40896cae18ec846b0111336f6da6dc8c69152d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Mon, 26 May 2025 13:38:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sgs/app/cmd/debug/DebugFanStopCommand.java | 14 +++++------ .../sgs/app/cmd/debug/DebugHeaterStartCommand.java | 14 +++++------ .../sgs/app/cmd/debug/DebugHeaterStopCommand.java | 14 +++++------ .../app/cmd/debug/DebugLiquidPumpAddCommand.java | 9 +++++-- .../sgs/app/model/bo/status/device/ValveState.java | 28 ++++++++++++++++++++++ .../sgs/app/service/api/SystemConfigService.java | 7 ++++++ .../iflytop/sgs/common/enums/SystemConfigCode.java | 24 +++++++++++++++++++ src/main/resources/sql/init.sql | 12 +++++++--- 8 files changed, 93 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/iflytop/sgs/app/model/bo/status/device/ValveState.java create mode 100644 src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java index 6d69186..ec9551c 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java @@ -30,14 +30,12 @@ public class DebugFanStopCommand extends BaseCommandHandler { String heatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode"); HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatModuleCodeStr); return runAsync(() -> { - DeviceCommandBundle deviceCommand; - switch (heatModuleCode) { - case heat_module_01 -> deviceCommand = DeviceCommandGenerator.fan1Close(); - case heat_module_02 -> deviceCommand = DeviceCommandGenerator.fan2Close(); - case heat_module_03 -> deviceCommand = DeviceCommandGenerator.fan3Close(); - case heat_module_04 -> deviceCommand = DeviceCommandGenerator.fan4Close(); - default -> throw new RuntimeException("heatModuleCode 未找到"); - } + DeviceCommandBundle deviceCommand= switch (heatModuleCode) { + case heat_module_01 -> DeviceCommandGenerator.fan1Close(); + case heat_module_02 -> DeviceCommandGenerator.fan2Close(); + case heat_module_03 -> DeviceCommandGenerator.fan3Close(); + case heat_module_04 -> DeviceCommandGenerator.fan4Close(); + }; CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand); CommandUtil.wait(deviceCommandFuture); }); diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java index d26394a..a22ec3e 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java @@ -31,14 +31,12 @@ public class DebugHeaterStartCommand extends BaseCommandHandler { Double temperature = cmdDTO.getDoubleParam("temperature"); HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatModuleCodeStr); return runAsync(() -> { - DeviceCommandBundle deviceCommand; - switch (heatModuleCode) { - case heat_module_01 -> deviceCommand = DeviceCommandGenerator.heatRod1Open(temperature); - case heat_module_02 -> deviceCommand = DeviceCommandGenerator.heatRod2Open(temperature); - case heat_module_03 -> deviceCommand = DeviceCommandGenerator.heatRod3Open(temperature); - case heat_module_04 -> deviceCommand = DeviceCommandGenerator.heatRod4Open(temperature); - default -> throw new RuntimeException("heatModuleCode 未找到"); - } + DeviceCommandBundle deviceCommand=switch (heatModuleCode) { + case heat_module_01 -> DeviceCommandGenerator.heatRod1Open(temperature); + case heat_module_02 -> DeviceCommandGenerator.heatRod2Open(temperature); + case heat_module_03 -> DeviceCommandGenerator.heatRod3Open(temperature); + case heat_module_04 -> DeviceCommandGenerator.heatRod4Open(temperature); + }; CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand); CommandUtil.wait(deviceCommandFuture); }); diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java index 10abf13..e50ebc1 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java @@ -30,14 +30,12 @@ public class DebugHeaterStopCommand extends BaseCommandHandler { String heatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode"); HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatModuleCodeStr); return runAsync(() -> { - DeviceCommandBundle deviceCommand; - switch (heatModuleCode) { - case heat_module_01 -> deviceCommand = DeviceCommandGenerator.heatRod1Close(); - case heat_module_02 -> deviceCommand = DeviceCommandGenerator.heatRod2Close(); - case heat_module_03 -> deviceCommand = DeviceCommandGenerator.heatRod3Close(); - case heat_module_04 -> deviceCommand = DeviceCommandGenerator.heatRod4Close(); - default -> throw new RuntimeException("heatModuleCode 未找到"); - } + DeviceCommandBundle deviceCommand= switch (heatModuleCode) { + case heat_module_01 -> DeviceCommandGenerator.heatRod1Close(); + case heat_module_02 -> DeviceCommandGenerator.heatRod2Close(); + case heat_module_03 -> DeviceCommandGenerator.heatRod3Close(); + case heat_module_04 -> DeviceCommandGenerator.heatRod4Close(); + }; CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand); CommandUtil.wait(deviceCommandFuture); }); diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpAddCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpAddCommand.java index 82cacf2..7deb96c 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpAddCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpAddCommand.java @@ -2,11 +2,13 @@ package com.iflytop.sgs.app.cmd.debug; import com.iflytop.sgs.app.core.BaseCommandHandler; import com.iflytop.sgs.app.model.dto.CmdDTO; +import com.iflytop.sgs.app.service.api.SystemConfigService; import com.iflytop.sgs.app.service.device.DeviceCommandService; import com.iflytop.sgs.common.annotation.CommandMapping; import com.iflytop.sgs.common.cmd.CommandFuture; import com.iflytop.sgs.common.cmd.DeviceCommandBundle; import com.iflytop.sgs.common.cmd.DeviceCommandGenerator; +import com.iflytop.sgs.common.enums.SystemConfigCode; import com.iflytop.sgs.common.enums.cmd.CmdDirection; import com.iflytop.sgs.common.utils.CommandUtil; import lombok.RequiredArgsConstructor; @@ -24,12 +26,15 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("liquid_pump_add") public class DebugLiquidPumpAddCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; + private final SystemConfigService systemConfigService; @Override public CompletableFuture handle(CmdDTO cmdDTO) { Double volume = cmdDTO.getDoubleParam("volume"); - //todo 量转换成转数 - Double position = Double.valueOf(1000); + //todo 监测阀门开启状态 将加液量转换成电机转数 + + Double scale = Double.valueOf(systemConfigService.getSystemConfig(SystemConfigCode.scale_thin)); + Double position = volume * scale; Double speed = cmdDTO.getDoubleParam("speed"); return runAsync(() -> { diff --git a/src/main/java/com/iflytop/sgs/app/model/bo/status/device/ValveState.java b/src/main/java/com/iflytop/sgs/app/model/bo/status/device/ValveState.java new file mode 100644 index 0000000..6d440e8 --- /dev/null +++ b/src/main/java/com/iflytop/sgs/app/model/bo/status/device/ValveState.java @@ -0,0 +1,28 @@ +package com.iflytop.sgs.app.model.bo.status.device; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "电磁转换阀") +@Data +public class ValveState { + + @Schema(description = "稀硝酸开关 true开") + private boolean thin = false; + + @Schema(description = "浓硝酸开关 true开") + private boolean thick = false; + + @Schema(description = "废水开关 true开") + private boolean waste = false; + + @Schema(description = "蒸馏水开关 true开") + private boolean water = false; + + + + + + + +} diff --git a/src/main/java/com/iflytop/sgs/app/service/api/SystemConfigService.java b/src/main/java/com/iflytop/sgs/app/service/api/SystemConfigService.java index 6df19b6..d63f682 100644 --- a/src/main/java/com/iflytop/sgs/app/service/api/SystemConfigService.java +++ b/src/main/java/com/iflytop/sgs/app/service/api/SystemConfigService.java @@ -1,9 +1,12 @@ package com.iflytop.sgs.app.service.api; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iflytop.sgs.app.mapper.SystemConfigMapper; import com.iflytop.sgs.app.model.entity.SystemConfig; import com.iflytop.sgs.app.service.device.DeviceStateService; +import com.iflytop.sgs.common.enums.ScaleCode; +import com.iflytop.sgs.common.enums.SystemConfigCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -81,4 +84,8 @@ public class SystemConfigService extends ServiceImpl().eq(SystemConfig::getKey, systemConfigCode.name())); + return systemConfig.getValue(); + } } diff --git a/src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java b/src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java new file mode 100644 index 0000000..faa5d23 --- /dev/null +++ b/src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java @@ -0,0 +1,24 @@ +package com.iflytop.sgs.common.enums; + +import lombok.Getter; + +/** + * 加热模块code枚举 + * 格式为 "heat_module_01" ~ "heat_module_06" + */ +@Getter +public enum SystemConfigCode { + //加液时 液量的转换系数 + scale_thin("稀硝酸转换系数"), + scale_thick("浓硝酸转换系数"), + scale_water("水转换系数"), + scale_waste("废水转换系数"); + + private String description; + + SystemConfigCode(String description) { + this.description = description; + } +} + + diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 0201cd0..1642f89 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -45,6 +45,12 @@ CREATE TABLE IF NOT EXISTS system_config create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); +INSERT OR IGNORE INTO system_config (id, key, value) +VALUES ('1', 'scale_thin', '100'), + ('2', 'scale_thick', '100'), + ('3', 'scale_water', '100'), + ('4', 'scale_waste', '100'); + -- 系统日志 表 CREATE TABLE IF NOT EXISTS system_log @@ -60,9 +66,9 @@ CREATE TABLE IF NOT EXISTS system_log CREATE TABLE IF NOT EXISTS device_param_config ( id INTEGER PRIMARY KEY AUTOINCREMENT, - mid text, - reg_index text, - reg_val INTEGER, + mid text, + reg_index text, + reg_val INTEGER, create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP