Browse Source

feat:添加设备信息

master
白凤吉 3 days ago
parent
commit
69f14a8f28
  1. 6
      build.gradle
  2. 16
      src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java
  3. 8
      src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
  4. 5
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  5. 19
      src/main/java/com/iflytop/handacid/app/model/bo/DeviceInfo.java
  6. 14
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
  7. 7
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
  8. 8
      src/main/resources/sql/init.sql

6
build.gradle

@ -5,7 +5,7 @@ plugins {
} }
group = 'com.iflytop' group = 'com.iflytop'
version = '0.0.1-SNAPSHOT'
version = '0.0.1'
java { java {
toolchain { toolchain {
@ -13,6 +13,10 @@ java {
} }
} }
springBoot {
buildInfo()
}
repositories { repositories {
maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/central' }

16
src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java

@ -1,6 +1,20 @@
package com.iflytop.handacid.app.common.enums; package com.iflytop.handacid.app.common.enums;
public enum SystemConfigKey { public enum SystemConfigKey {
/**
* 加液模式
*/
SOLUTION_ADD_MODE, SOLUTION_ADD_MODE,
SOLUTION_ADD_DELAY
/**
* 自动加液间隔
*/
SOLUTION_ADD_DELAY,
/**
* 蠕动泵转数与泵位置换算系数
*/
PUMP_CONVERSION_FACTOR,
/**
* 设备SN码
*/
DEVICE_SN,
} }

8
src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java

@ -14,7 +14,8 @@ import org.springframework.stereotype.Component;
@Component @Component
@Scope("prototype") @Scope("prototype")
@RequiredArgsConstructor @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 { public class ChannelState {
@Schema(description = "通道code") @Schema(description = "通道code")
private volatile ChannelCode channelCode; private volatile ChannelCode channelCode;
@ -53,4 +54,9 @@ public class ChannelState {
this.receivedVolume = receivedVolume; this.receivedVolume = receivedVolume;
this.currentVolume = currentVolume; this.currentVolume = currentVolume;
} }
//==============================私有=====================================================================
@Schema(description = "泵位置缓存")
private Double pumpPositionCache;
} }

5
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.ChannelCode;
import com.iflytop.handacid.app.common.enums.ChannelStateCode; import com.iflytop.handacid.app.common.enums.ChannelStateCode;
import com.iflytop.handacid.app.common.enums.SolutionAddMode; 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 com.iflytop.handacid.common.model.entity.User;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -43,6 +44,9 @@ public class DeviceState {
@Schema(description = "当前登录用户") @Schema(description = "当前登录用户")
private volatile User currentUser; private volatile User currentUser;
@Schema(description = "设备基础信息")
private final DeviceInfo deviceInfo = new DeviceInfo();
/** /**
* 获得当前设备的json快照增加synchronized保证强一致 * 获得当前设备的json快照增加synchronized保证强一致
*/ */
@ -56,6 +60,7 @@ public class DeviceState {
json.putOnce("emergencyStop", emergencyStop); json.putOnce("emergencyStop", emergencyStop);
json.putOnce("remoteControlState", remoteControlState); json.putOnce("remoteControlState", remoteControlState);
json.putOnce("currentUser", currentUser); json.putOnce("currentUser", currentUser);
json.putOnce("deviceInfo", deviceInfo);
return json; return json;
} }

19
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;
}

14
src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

@ -48,6 +48,12 @@ public class ChannelCtrlService {
while (!deviceState.isSolutionAddStop()) { while (!deviceState.isSolutionAddStop()) {
List<CommandFuture> commandFutureList = new ArrayList<>(); List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) { 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<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId())); Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()));
DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
@ -56,6 +62,14 @@ public class ChannelCtrlService {
auditRecordService.saveOrUpdate(auditRecord); auditRecordService.saveOrUpdate(auditRecord);
} }
CommandUtil.wait(commandFutureList); 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); Thread.sleep(deviceState.getDelay() * 1000L);
} }
} else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式 } else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式

7
src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

@ -29,6 +29,7 @@ import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -49,6 +50,7 @@ public class DeviceInitService {
private final A8kCanBusService canBusService; private final A8kCanBusService canBusService;
private final SolutionService solutionService; private final SolutionService solutionService;
private final SystemConfigService systemConfigService; private final SystemConfigService systemConfigService;
private final BuildProperties buildProperties;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -110,6 +112,11 @@ public class DeviceInitService {
deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKeyToString(SystemConfigKey.SOLUTION_ADD_MODE))); deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKeyToString(SystemConfigKey.SOLUTION_ADD_MODE)));
deviceState.setDelay(systemConfigService.getValueByKeyToInteger(SystemConfigKey.SOLUTION_ADD_DELAY)); deviceState.setDelay(systemConfigService.getValueByKeyToInteger(SystemConfigKey.SOLUTION_ADD_DELAY));
deviceState.setRemoteControlState(remoteControlStateObjectProvider.getObject()); 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完毕"); log.info("初始化 initDeviceState完毕");
} }

8
src/main/resources/sql/init.sql

@ -85,9 +85,11 @@ CREATE TABLE IF NOT EXISTS system_config (
update_time TEXT DEFAULT CURRENT_TIMESTAMP 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 ( CREATE TABLE IF NOT EXISTS system_log (

Loading…
Cancel
Save