diff --git a/build.gradle b/build.gradle index 1e6d483..c026c9c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'com.iflytop' -version = '0.0.1-SNAPSHOT' +version = '0.0.1' java { toolchain { @@ -13,6 +13,10 @@ java { } } +springBoot { + buildInfo() +} + repositories { maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/central' } diff --git a/src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java b/src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java index 035c09c..82801f7 100644 --- a/src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java +++ b/src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java @@ -1,6 +1,20 @@ package com.iflytop.handacid.app.common.enums; public enum SystemConfigKey { + /** + * 加液模式 + */ SOLUTION_ADD_MODE, - SOLUTION_ADD_DELAY + /** + * 自动加液间隔 + */ + SOLUTION_ADD_DELAY, + /** + * 蠕动泵转数与泵位置换算系数 + */ + PUMP_CONVERSION_FACTOR, + /** + * 设备SN码 + */ + DEVICE_SN, } diff --git a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java index 2960545..349a472 100644 --- a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java +++ b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java @@ -14,7 +14,8 @@ import org.springframework.stereotype.Component; @Component @Scope("prototype") @RequiredArgsConstructor -@JsonIgnoreProperties(value = {"advisors", "frozen", "preFiltered", "proxyTargetClass", "targetSource", "exposeProxy", "advisorCount", "proxiedInterfaces", "targetClass"}) +@JsonIgnoreProperties(value = {"advisors", "frozen", "preFiltered", "proxyTargetClass", "targetSource", "exposeProxy", "advisorCount", "proxiedInterfaces", "targetClass", + "pumpPositionCache"}) public class ChannelState { @Schema(description = "通道code") private volatile ChannelCode channelCode; @@ -53,4 +54,9 @@ public class ChannelState { this.receivedVolume = receivedVolume; this.currentVolume = currentVolume; } + + //==============================私有===================================================================== + @Schema(description = "泵位置缓存") + private Double pumpPositionCache; + } 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 ef00170..9093a7d 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 @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; 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.model.bo.DeviceInfo; import com.iflytop.handacid.common.model.entity.User; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -43,6 +44,9 @@ public class DeviceState { @Schema(description = "当前登录用户") private volatile User currentUser; + @Schema(description = "设备基础信息") + private final DeviceInfo deviceInfo = new DeviceInfo(); + /** * 获得当前设备的json快照,增加synchronized保证强一致 */ @@ -56,6 +60,7 @@ public class DeviceState { json.putOnce("emergencyStop", emergencyStop); json.putOnce("remoteControlState", remoteControlState); json.putOnce("currentUser", currentUser); + json.putOnce("deviceInfo", deviceInfo); return json; } diff --git a/src/main/java/com/iflytop/handacid/app/model/bo/DeviceInfo.java b/src/main/java/com/iflytop/handacid/app/model/bo/DeviceInfo.java new file mode 100644 index 0000000..edb5120 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/model/bo/DeviceInfo.java @@ -0,0 +1,19 @@ +package com.iflytop.handacid.app.model.bo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class DeviceInfo { + @Schema(description = "后台软件版本") + private String backendSoftwareVersion; + + @Schema(description = "设备软件版本") + private String deviceSoftwareVersion; + + @Schema(description = "遥控器软件版本") + private String remoteControlSoftwareVersion; + + @Schema(description = "设备SN码") + private String deviceSn; +} 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 fa05f2a..dcbb6f0 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -48,6 +48,12 @@ public class ChannelCtrlService { while (!deviceState.isSolutionAddStop()) { List commandFutureList = new ArrayList<>(); for (ChannelState channelState : channelStateList) { + DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); + CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); + CommandUtil.wait(currentPositionCommandFuture); + Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); + channelState.setPumpPositionCache(currentPosition); + Formulation formulation = formulationService.getOne(new LambdaQueryWrapper().eq(Formulation::getSolutionId, channelState.getSolutionId())); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); @@ -56,6 +62,14 @@ public class ChannelCtrlService { auditRecordService.saveOrUpdate(auditRecord); } CommandUtil.wait(commandFutureList); + for (ChannelState channelState : channelStateList) {//与缓存的位置比较计算加液量 + DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); + CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); + CommandUtil.wait(currentPositionCommandFuture); + Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); + + } + Thread.sleep(deviceState.getDelay() * 1000L); } } else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式 diff --git a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 9d7b467..145e823 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -29,6 +29,7 @@ import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.info.BuildProperties; import org.springframework.context.SmartLifecycle; import org.springframework.stereotype.Service; @@ -49,6 +50,7 @@ public class DeviceInitService { private final A8kCanBusService canBusService; private final SolutionService solutionService; private final SystemConfigService systemConfigService; + private final BuildProperties buildProperties; @PostConstruct public void init() { @@ -110,6 +112,11 @@ public class DeviceInitService { deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKeyToString(SystemConfigKey.SOLUTION_ADD_MODE))); deviceState.setDelay(systemConfigService.getValueByKeyToInteger(SystemConfigKey.SOLUTION_ADD_DELAY)); deviceState.setRemoteControlState(remoteControlStateObjectProvider.getObject()); + + deviceState.getDeviceInfo().setBackendSoftwareVersion(buildProperties.getVersion()); + deviceState.getDeviceInfo().setDeviceSoftwareVersion("ABCDEFG202507312000000001"); + deviceState.getDeviceInfo().setRemoteControlSoftwareVersion("ABCDEFG202507312000000001"); + deviceState.getDeviceInfo().setDeviceSn(systemConfigService.getValueByKeyToString(SystemConfigKey.DEVICE_SN)); log.info("初始化 initDeviceState完毕"); } diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 1ee8373..134dc8c 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -85,9 +85,11 @@ CREATE TABLE IF NOT EXISTS system_config ( update_time TEXT DEFAULT CURRENT_TIMESTAMP ); -INSERT OR IGNORE INTO system_config (id, key, value) VALUES - (1, 'SOLUTION_ADD_MODE','AUTO'), - (2, 'SOLUTION_ADD_DELAY','3'); +INSERT OR IGNORE INTO system_config (id, key, value, description) VALUES + (1, 'SOLUTION_ADD_MODE','AUTO', '加液模式'), + (2, 'SOLUTION_ADD_DELAY','3', '自动加液间隔'), + (3, 'PUMP_CONVERSION_FACTOR','100', '蠕动泵转数与泵位置换算系数'), + (4, 'DEVICE_SN','ABCDEFG202507312000000001', '设备SN码'); -- 系统日志 CREATE TABLE IF NOT EXISTS system_log (