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 new file mode 100644 index 0000000..5b5fae6 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java @@ -0,0 +1,5 @@ +package com.iflytop.handacid.app.common.enums; + +public enum SystemConfigKey { + SOLUTION_ADD_MODE +} 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 cb2e7b3..c4365ea 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -2,12 +2,15 @@ package com.iflytop.handacid.app.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.iflytop.handacid.app.common.enums.ChannelCode; +import com.iflytop.handacid.app.common.enums.SolutionAddMode; +import com.iflytop.handacid.app.common.enums.SystemConfigKey; import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.model.entity.Solution; import com.iflytop.handacid.common.service.ChannelService; import com.iflytop.handacid.common.service.SolutionService; +import com.iflytop.handacid.common.service.SystemConfigService; import com.iflytop.handacid.hardware.service.AppEventBusService; import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent; import com.iflytop.handacid.hardware.type.appevent.AppEvent; @@ -27,6 +30,7 @@ public class DeviceInitService { private final ObjectProvider channelStateObjectProvider; private final ChannelService channelService; private final SolutionService solutionService; + private final SystemConfigService systemConfigService; @PostConstruct @@ -60,6 +64,8 @@ public class DeviceInitService { ChannelState channelState = channelStateObjectProvider.getObject(code, solution.getId(), solution.getName(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); deviceState.getChannelStateMap().put(code, channelState); } + SolutionAddMode mode = SolutionAddMode.valueOf(systemConfigService.getValueByKey(SystemConfigKey.SOLUTION_ADD_MODE)); + deviceState.setMode(mode); log.info("初始化 initDeviceState完毕"); } diff --git a/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java b/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java index 2d11e5c..f7eb634 100644 --- a/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java +++ b/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java @@ -1,8 +1,11 @@ package com.iflytop.handacid.common.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.iflytop.handacid.app.common.enums.SystemConfigKey; import com.iflytop.handacid.common.mapper.SystemConfigMapper; import com.iflytop.handacid.common.model.entity.SystemConfig; +import com.iflytop.handacid.common.model.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -13,4 +16,9 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class SystemConfigService extends ServiceImpl { + + public String getValueByKey(SystemConfigKey key){ + SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key)); + return systemConfig != null ? systemConfig.getValue() : null; + } } \ No newline at end of file diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 6d81403..73047f4 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -85,6 +85,9 @@ 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'); + -- 系统日志 CREATE TABLE IF NOT EXISTS system_log ( id INTEGER PRIMARY KEY AUTOINCREMENT,