14 changed files with 189 additions and 350 deletions
-
BINapp.db
-
2src/main/java/a8k/extapi_controler/pagecontrol/ExtApiTabConfig.java
-
23src/main/java/a8k/service/app/appctrl/AppDeviceCtrlService.java
-
159src/main/java/a8k/service/app/appsetting/AppSettingsMgr.java
-
23src/main/java/a8k/service/bases/FrontEndEventRouter.java
-
8src/main/java/a8k/service/bases/appevent/A8kStateChangeEvent.java
-
2src/main/java/a8k/service/bases/appevent/AppEvent.java
-
5src/main/java/a8k/service/bases/appevent/AppIDCardMountEvent.java
-
15src/main/java/a8k/service/bases/appevent/AppStepNotifyEvent.java
-
212src/main/java/a8k/service/db/AppSettingDBService.java
-
61src/main/java/a8k/service/db/type/AppSetting.java
-
2src/main/java/a8k/service/db/type/appsetting/settingenum/LISSerialBaudrateType.java
-
3src/main/java/a8k/utils/ZSqliteJdbcHelper.java
@ -1,8 +0,0 @@ |
|||||
package a8k.service.bases.appevent; |
|
||||
|
|
||||
public class A8kStateChangeEvent extends AppEvent { |
|
||||
|
|
||||
A8kStateChangeEvent(String displayInfo) { |
|
||||
super(A8kStateChangeEvent.class.getSimpleName()); |
|
||||
} |
|
||||
} |
|
@ -1,14 +1,15 @@ |
|||||
package a8k.service.bases.appevent; |
package a8k.service.bases.appevent; |
||||
|
|
||||
|
|
||||
|
import a8k.service.db.type.A8kIdCardBreifInfo; |
||||
import a8k.service.db.type.A8kIdCardInfo; |
import a8k.service.db.type.A8kIdCardInfo; |
||||
|
|
||||
public class AppIDCardMountEvent extends AppEvent { |
public class AppIDCardMountEvent extends AppEvent { |
||||
public A8kIdCardInfo projectInfo; |
|
||||
|
public A8kIdCardBreifInfo projectInfo; |
||||
|
|
||||
public AppIDCardMountEvent(A8kIdCardInfo projectInfo) { |
public AppIDCardMountEvent(A8kIdCardInfo projectInfo) { |
||||
super(AppIDCardMountEvent.class.getSimpleName()); |
super(AppIDCardMountEvent.class.getSimpleName()); |
||||
this.projectInfo = projectInfo; |
|
||||
|
this.projectInfo = projectInfo.toBreif(); |
||||
} |
} |
||||
|
|
||||
} |
} |
@ -1,15 +0,0 @@ |
|||||
package a8k.service.bases.appevent; |
|
||||
|
|
||||
|
|
||||
public class AppStepNotifyEvent extends AppEvent { |
|
||||
String displayInfo; |
|
||||
|
|
||||
AppStepNotifyEvent(String displayInfo) { |
|
||||
super(AppStepNotifyEvent.class.getSimpleName()); |
|
||||
this.displayInfo = displayInfo; |
|
||||
} |
|
||||
|
|
||||
public String getDisplayInfo() { |
|
||||
return displayInfo; |
|
||||
} |
|
||||
} |
|
@ -1,218 +1,70 @@ |
|||||
package a8k.service.db; |
package a8k.service.db; |
||||
|
|
||||
|
import a8k.service.app.appdata.UtilsProjectColorAllocer; |
||||
import a8k.service.db.type.AppSetting; |
import a8k.service.db.type.AppSetting; |
||||
import a8k.service.db.type.appsetting.AppSettingName; |
|
||||
import a8k.service.db.type.appsetting.AppSettingTab; |
|
||||
import a8k.service.db.type.appsetting.AppSettingType; |
|
||||
import a8k.utils.ZEnumHelper; |
|
||||
|
import a8k.service.debug.AppDebugHelperService; |
||||
import a8k.utils.ZSqliteJdbcHelper; |
import a8k.utils.ZSqliteJdbcHelper; |
||||
import jakarta.annotation.PostConstruct; |
import jakarta.annotation.PostConstruct; |
||||
import jakarta.annotation.Resource; |
import jakarta.annotation.Resource; |
||||
|
import lombok.SneakyThrows; |
||||
import org.slf4j.Logger; |
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
import org.slf4j.LoggerFactory; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.stereotype.Component; |
import org.springframework.stereotype.Component; |
||||
|
|
||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
|
||||
import java.util.List; |
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* ID卡数据库服务 |
||||
|
*/ |
||||
@Component |
@Component |
||||
public class AppSettingDBService { |
public class AppSettingDBService { |
||||
private static final Logger logger = LoggerFactory.getLogger(AppSettingDBService.class); |
private static final Logger logger = LoggerFactory.getLogger(AppSettingDBService.class); |
||||
private static final String tableName = "zapp_setting"; |
|
||||
|
private static final String tableName = "zapp_a8k_appsetting"; |
||||
|
private static Class<?> tClass = AppSetting.class; |
||||
|
|
||||
|
|
||||
@Resource |
@Resource |
||||
JdbcTemplate jdbcTemplate; |
JdbcTemplate jdbcTemplate; |
||||
|
|
||||
@PostConstruct |
|
||||
void init() { |
|
||||
if (!ZSqliteJdbcHelper.isTableExist(jdbcTemplate, tableName)) { |
|
||||
createTable(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private AppSetting rowMapper(ResultSet rs, int rowNum) throws SQLException { |
|
||||
AppSetting obj = new AppSetting(); |
|
||||
obj.id = rs.getInt("id"); |
|
||||
obj.type = rs.getString("type") != null ? AppSettingType.valueOf(rs.getString("type")) : null; |
|
||||
obj.tab = rs.getString("tab") != null ? AppSettingTab.valueOf(rs.getString("tab")) : null; |
|
||||
obj.name = rs.getString("name") != null ? AppSettingName.valueOf(rs.getString("name")) : null; |
|
||||
obj.display = rs.getBoolean("display"); |
|
||||
|
|
||||
obj.minVal = rs.getDouble("minVal"); |
|
||||
obj.maxVal = rs.getDouble("maxVal"); |
|
||||
String valueEnumRange = rs.getString("valueEnumRange"); |
|
||||
if (valueEnumRange != null) |
|
||||
obj.valueEnumRange = valueEnumRange.split(","); |
|
||||
|
|
||||
obj.value = rs.getString("value"); |
|
||||
return obj; |
|
||||
} |
|
||||
|
|
||||
private void createTable() { |
|
||||
jdbcTemplate.execute("create table " + tableName + " ('id' integer," |
|
||||
+ " 'type' text," |
|
||||
+ " 'tab' text," |
|
||||
+ " 'name' text," |
|
||||
+ " 'display' integer," |
|
||||
+ " 'minVal' real," |
|
||||
+ " 'maxVal' real," |
|
||||
+ " 'valueEnumRange' text, " |
|
||||
+ "'value' text," |
|
||||
+ " PRIMARY KEY ('id' DESC));"); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public List<AppSetting> getAllSettings() { |
|
||||
return jdbcTemplate.query("select * from " + tableName, this::rowMapper); |
|
||||
} |
|
||||
|
|
||||
public AppSetting getSettingByName(AppSettingName name) { |
|
||||
List<AppSetting> settings = jdbcTemplate.query("select * from " + tableName + " where name = ?;", this::rowMapper, name.name()); |
|
||||
if (settings.isEmpty()) { |
|
||||
return null; |
|
||||
} |
|
||||
return settings.get(0); |
|
||||
} |
|
||||
|
|
||||
public List<AppSetting> getSettingsByTab(AppSettingTab tab) { |
|
||||
return jdbcTemplate.query("select * from " + tableName + " where tab = ?;", this::rowMapper, tab.name()); |
|
||||
} |
|
||||
|
|
||||
public void clearAllSettings() { |
|
||||
jdbcTemplate.execute("delete from " + tableName); |
|
||||
} |
|
||||
|
|
||||
public void updateSetting(AppSettingName name, String val) { |
|
||||
jdbcTemplate.update("update " + tableName + " set value = ? where name = ?;", val, name.name()); |
|
||||
} |
|
||||
|
|
||||
public void addSetting(AppSetting setting) { |
|
||||
jdbcTemplate.update("insert into " + tableName + " (type, tab, name, display, minVal, maxVal, valueEnumRange, value) values (?, ?, ?, ?, ?, ?, ?, ?);", |
|
||||
setting.type != null ? setting.type.name() : null, |
|
||||
setting.tab != null ? setting.tab.name() : null, |
|
||||
setting.name != null ? setting.name.name() : null, |
|
||||
setting.display ? 1 : 0, |
|
||||
setting.minVal, |
|
||||
setting.maxVal, |
|
||||
setting.valueEnumRange != null ? String.join(",", setting.valueEnumRange) : null, |
|
||||
setting.value); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public void addIntegerSetting(AppSettingTab tab, AppSettingName name, Integer value, Integer minVal, Integer maxVal) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.INTEGER; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value.toString(); |
|
||||
setting.minVal = minVal.doubleValue(); |
|
||||
setting.maxVal = maxVal.doubleValue(); |
|
||||
addSetting(setting); |
|
||||
} |
|
||||
|
|
||||
public void addDoubleSetting(AppSettingTab tab, AppSettingName name, Double value, Double minVal, Double maxVal) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.DOUBLE; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value.toString(); |
|
||||
setting.minVal = minVal; |
|
||||
setting.maxVal = maxVal; |
|
||||
addSetting(setting); |
|
||||
} |
|
||||
|
|
||||
public void addStringSetting(AppSettingTab tab, AppSettingName name, String value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.STRING; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value; |
|
||||
addSetting(setting); |
|
||||
} |
|
||||
|
@Resource |
||||
|
UtilsProjectColorAllocer colorAllocer; |
||||
|
|
||||
public void addBooleanSetting(AppSettingTab tab, AppSettingName name, Boolean value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.BOOLEAN; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value.toString(); |
|
||||
addSetting(setting); |
|
||||
} |
|
||||
|
@Resource |
||||
|
AppDebugHelperService appDebugHelper; |
||||
|
|
||||
public void addEnumSetting(AppSettingTab tab, AppSettingName name, Class<?> valueEnumRange, Enum<?> value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.ENUM; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.valueEnumRange = ZEnumHelper.enum2strs(valueEnumRange); |
|
||||
setting.value = value.name(); |
|
||||
addSetting(setting); |
|
||||
|
@PostConstruct |
||||
|
void init() { |
||||
|
if (appDebugHelper.isDebug()) { |
||||
|
ZSqliteJdbcHelper.forceDeleteTable(jdbcTemplate, tableName); |
||||
|
ZSqliteJdbcHelper.createTable(jdbcTemplate, tableName, tClass); |
||||
|
ZSqliteJdbcHelper.addObj(jdbcTemplate, tableName, AppSetting.class, new AppSetting()); |
||||
|
return; |
||||
} |
} |
||||
|
|
||||
public void addDateSetting(AppSettingTab tab, AppSettingName name) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.DATE; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = ""; |
|
||||
addSetting(setting); |
|
||||
|
if (!ZSqliteJdbcHelper.isTableExist(jdbcTemplate, tableName)) { |
||||
|
ZSqliteJdbcHelper.createTable(jdbcTemplate, tableName, tClass); |
||||
} |
} |
||||
|
|
||||
public void addTimeSetting(AppSettingTab tab, AppSettingName name) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.TIME; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = ""; |
|
||||
addSetting(setting); |
|
||||
} |
} |
||||
|
|
||||
public void addTimeZoneSetting(AppSettingTab tab, AppSettingName name) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.TIMEZONE; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = ""; |
|
||||
addSetting(setting); |
|
||||
|
@SneakyThrows private AppSetting rowMapper(ResultSet rs, int rowNum) { |
||||
|
return (AppSetting) ZSqliteJdbcHelper.rowMapper(rs, tClass); |
||||
} |
} |
||||
|
|
||||
public void addIpSetting(AppSettingTab tab, AppSettingName name, String value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.IP; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value; |
|
||||
addSetting(setting); |
|
||||
|
public AppSetting get() { |
||||
|
List<AppSetting> list = jdbcTemplate.query("select * from " + tableName, this::rowMapper); |
||||
|
if (list.isEmpty()) { |
||||
|
AppSetting appSetting = new AppSetting(); |
||||
|
jdbcTemplate.update("insert into " + tableName + " values(?)", appSetting); |
||||
|
return appSetting; |
||||
} |
} |
||||
|
|
||||
public void addPortSetting(AppSettingTab tab, AppSettingName name, Integer value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.PORT; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value.toString(); |
|
||||
addSetting(setting); |
|
||||
|
return list.get(0); |
||||
} |
} |
||||
|
|
||||
public void addFixStringSetting(AppSettingTab tab, AppSettingName name, String value) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.FIX_STRING; |
|
||||
setting.tab = tab; |
|
||||
setting.name = name; |
|
||||
setting.value = value; |
|
||||
addSetting(setting); |
|
||||
|
public void update(AppSetting appSetting) { |
||||
|
ZSqliteJdbcHelper.updateObj(jdbcTemplate, tableName, AppSetting.class, appSetting); |
||||
} |
} |
||||
|
|
||||
public void addSettingVersion(Integer version) { |
|
||||
AppSetting setting = new AppSetting(); |
|
||||
setting.type = AppSettingType.INTEGER; |
|
||||
setting.name = AppSettingName.SETTING_PAGE_VERSION; |
|
||||
setting.value = version.toString(); |
|
||||
setting.display = false; |
|
||||
addSetting(setting); |
|
||||
} |
|
||||
|
|
||||
} |
} |
@ -1,54 +1,17 @@ |
|||||
package a8k.service.db.type; |
package a8k.service.db.type; |
||||
|
|
||||
|
|
||||
import a8k.service.db.type.appsetting.AppSettingName; |
|
||||
import a8k.service.db.type.appsetting.AppSettingTab; |
|
||||
import a8k.service.db.type.appsetting.AppSettingType; |
|
||||
import a8k.utils.ZJsonHelper; |
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
||||
|
import a8k.service.db.type.appsetting.settingenum.*; |
||||
|
|
||||
public class AppSetting { |
public class AppSetting { |
||||
public int id = 0; |
|
||||
// |
|
||||
// 基础属性 |
|
||||
// |
|
||||
public AppSettingType type; // 支持类型范围 AppSettingType |
|
||||
public AppSettingTab tab; // 返回名字为英文,前端需要根据英文名字进行翻译 |
|
||||
public AppSettingName name; // 返回名字为英文,前端需要根据英文名字进行翻译 |
|
||||
public Boolean display = true;// 是否显示 |
|
||||
|
|
||||
// |
|
||||
//整形和浮点型的单位数值范围 |
|
||||
// |
|
||||
public Double minVal = 0.0; //最小值 |
|
||||
public Double maxVal = 0.0; //最大值 |
|
||||
|
|
||||
// |
|
||||
// 枚举单位数值范围 |
|
||||
// |
|
||||
public String[] valueEnumRange = {}; //枚举范围,用逗号分隔 |
|
||||
|
|
||||
// |
|
||||
//值 |
|
||||
// |
|
||||
public String value; //Value |
|
||||
|
|
||||
@Override |
|
||||
public String toString() { |
|
||||
return ZJsonHelper.objectToJson(this); |
|
||||
} |
|
||||
|
|
||||
@JsonIgnore |
|
||||
public Integer getValueAsInt() {return Integer.parseInt(value);} |
|
||||
|
|
||||
@JsonIgnore |
|
||||
public String getValueAsStr() {return value;} |
|
||||
|
|
||||
@JsonIgnore |
|
||||
public Boolean getValueAsBool() {return Boolean.parseBoolean(value);} |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public int id =0; |
||||
|
public LanguageType language = LanguageType.zh_CN; |
||||
|
public Boolean autoPrint = false; |
||||
|
public Boolean autoLogout = false; |
||||
|
public LISTypeEnum LISType = LISTypeEnum.SINGLE_TRACK; |
||||
|
public LISProtocolEnum LISProtocol = LISProtocolEnum.Boditech; |
||||
|
public LISIFType LIFIf = LISIFType.NETWORK; |
||||
|
public Boolean LISAutoExport = true; |
||||
|
public LISSerialBaudrateType LISSerialBaudrate = LISSerialBaudrateType.B9600; |
||||
|
public String LISNetIp = "127.0.0.1"; |
||||
|
public Integer LISNetPort = 9973; |
||||
} |
} |
@ -1,6 +1,6 @@ |
|||||
package a8k.service.db.type.appsetting.settingenum; |
package a8k.service.db.type.appsetting.settingenum; |
||||
|
|
||||
public enum LISSerialBaudrate { |
|
||||
|
public enum LISSerialBaudrateType { |
||||
B9600, |
B9600, |
||||
B115200, |
B115200, |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue