25 changed files with 575 additions and 455 deletions
-
2README.md
-
BINapp.db
-
6src/main/java/a8k/controler/extapi/pagecontrol/ExtApiTabConfig.java
-
218src/main/java/a8k/dbservice/AppSettingDBService.java
-
55src/main/java/a8k/dbservice/type/AppSetting.java
-
35src/main/java/a8k/dbservice/type/appsetting/AppSettingName.java
-
12src/main/java/a8k/dbservice/type/appsetting/AppSettingTab.java
-
7src/main/java/a8k/dbservice/type/appsetting/AppSettingType.java
-
21src/main/java/a8k/dbservice/type/appsetting/settingenum/AutoLogoutOption.java
-
16src/main/java/a8k/dbservice/type/appsetting/settingenum/LISIFType.java
-
14src/main/java/a8k/dbservice/type/appsetting/settingenum/LISProtocolEnum.java
-
6src/main/java/a8k/dbservice/type/appsetting/settingenum/LISSerialBaudrate.java
-
17src/main/java/a8k/dbservice/type/appsetting/settingenum/LISTypeEnum.java
-
5src/main/java/a8k/dbservice/type/appsetting/settingenum/LanguageType.java
-
201src/main/java/a8k/olddbservice/AppSetting.java
-
138src/main/java/a8k/service/app/AppSettingsMgr.java
-
135src/main/java/a8k/service/app/app_settings_mgr/AppSettingsMgr.java
-
35src/main/java/a8k/service/app/app_settings_mgr/base/AppOptionName.java
-
9src/main/java/a8k/service/app/app_settings_mgr/base/AppSettingTab.java
-
23src/main/java/a8k/service/app/app_settings_mgr/settingenum/AutoLogoutTime.java
-
14src/main/java/a8k/service/app/app_settings_mgr/settingenum/LISProtocol.java
-
17src/main/java/a8k/service/app/app_settings_mgr/settingenum/LISType.java
-
14src/main/java/a8k/utils/ZEnumHelper.java
-
2src/main/java/com/iflytop/a800/BoditechA800Application.java
@ -0,0 +1,218 @@ |
|||||
|
package a8k.dbservice; |
||||
|
|
||||
|
import a8k.dbservice.type.AppSetting; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingName; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingTab; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingType; |
||||
|
import a8k.utils.ZEnumHelper; |
||||
|
import a8k.utils.ZSqliteJdbcHelper; |
||||
|
import jakarta.annotation.PostConstruct; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.sql.ResultSet; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Component |
||||
|
public class AppSettingDBService { |
||||
|
private static final Logger logger = LoggerFactory.getLogger(AppSettingDBService.class); |
||||
|
private static final String tableName = "zapp_setting"; |
||||
|
|
||||
|
|
||||
|
@Resource |
||||
|
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 = AppSettingType.valueOf(rs.getString("type")); |
||||
|
obj.tab = AppSettingTab.valueOf(rs.getString("tab")); |
||||
|
obj.name = AppSettingName.valueOf(rs.getString("name")); |
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
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 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); |
||||
|
} |
||||
|
|
||||
|
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 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); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package a8k.dbservice.type; |
||||
|
|
||||
|
|
||||
|
import a8k.dbservice.type.appsetting.AppSettingName; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingTab; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingType; |
||||
|
import a8k.utils.ZEnumHelper; |
||||
|
import a8k.utils.ZJsonHelper; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
|
||||
|
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);} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package a8k.dbservice.type.appsetting; |
||||
|
|
||||
|
public enum AppSettingName { |
||||
|
SETTING_PAGE_VERSION,// 用来更新配置项目 |
||||
|
//DEVICE |
||||
|
DATE,//日期 |
||||
|
TIME,//时间 |
||||
|
TIMEZONE,//时区 |
||||
|
LANGUAGE,//语言 |
||||
|
AUTO_PRINT,//是否自动打印 |
||||
|
AUTO_LOGOUT,//自动登出 |
||||
|
|
||||
|
//USR_MGR |
||||
|
|
||||
|
//RELEASE |
||||
|
DEVICE_SERIAL, |
||||
|
OS_VERSION, |
||||
|
APP_VERSION, |
||||
|
MCU_VERSION, |
||||
|
|
||||
|
//LIS |
||||
|
LIS_TYPE, |
||||
|
LIS_PROTOCOL, |
||||
|
LIS_IF, |
||||
|
LIS_AUTO_EXPORT, |
||||
|
LIS_SERIAL_BAUDRATE, |
||||
|
LIS_NET_IP, |
||||
|
LIS_NET_PORT, |
||||
|
|
||||
|
//NET |
||||
|
NET_IP, |
||||
|
NET_PORT, |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,12 @@ |
|||||
|
package a8k.dbservice.type.appsetting; |
||||
|
|
||||
|
/** |
||||
|
* 配置页面 |
||||
|
*/ |
||||
|
public enum AppSettingTab { |
||||
|
DEVICE, //设备配置页面 |
||||
|
USRMGR, //用户管理页面 |
||||
|
LIS, //LIS配置页面 |
||||
|
NETWORK,//网络管理页面 |
||||
|
RELEASE,//版本信息页面 |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum AutoLogoutOption { |
||||
|
T00_00, |
||||
|
T00_10, |
||||
|
T00_30, |
||||
|
T01_00, |
||||
|
T02_00, |
||||
|
T03_00 |
||||
|
; |
||||
|
|
||||
|
public static String[] cgetValues() { |
||||
|
String[] values = new String[AutoLogoutOption.values().length]; |
||||
|
int i = 0; |
||||
|
for (AutoLogoutOption value : AutoLogoutOption.values()) { |
||||
|
values[i] = value.name(); |
||||
|
i++; |
||||
|
} |
||||
|
return values; |
||||
|
} |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum LISIFType { |
||||
|
SERIAL, |
||||
|
NETWORK; |
||||
|
|
||||
|
public static String[] getValues() { |
||||
|
String[] values = new String[LISIFType.values().length]; |
||||
|
int i = 0; |
||||
|
for (LISIFType value : LISIFType.values()) { |
||||
|
values[i] = value.name(); |
||||
|
i++; |
||||
|
} |
||||
|
return values; |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum LISProtocolEnum { |
||||
|
Boditech, Simens; |
||||
|
|
||||
|
public static String[] getValues() { |
||||
|
String[] values = new String[LISProtocolEnum.values().length]; |
||||
|
int i = 0; |
||||
|
for (LISProtocolEnum value : LISProtocolEnum.values()) { |
||||
|
values[i++] = value.name(); |
||||
|
} |
||||
|
return values; |
||||
|
} |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum LISSerialBaudrate { |
||||
|
B9600, |
||||
|
B115200, |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum LISTypeEnum { |
||||
|
//单向,双向 |
||||
|
SINGLE_TRACK, |
||||
|
DOUBLE_TRACK, |
||||
|
; |
||||
|
|
||||
|
public static String[] getValues() { |
||||
|
String[] values = new String[LISTypeEnum.values().length]; |
||||
|
int i = 0; |
||||
|
for (LISTypeEnum value : LISTypeEnum.values()) { |
||||
|
values[i++] = value.name(); |
||||
|
} |
||||
|
return values; |
||||
|
} |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
package a8k.dbservice.type.appsetting.settingenum; |
||||
|
|
||||
|
public enum LanguageType { |
||||
|
zh_CN, en_US |
||||
|
} |
@ -1,201 +0,0 @@ |
|||||
package a8k.olddbservice; |
|
||||
|
|
||||
import a8k.service.app.app_settings_mgr.base.AppSettingTab; |
|
||||
import a8k.service.app.app_settings_mgr.base.AppOptionName; |
|
||||
import a8k.service.app.app_settings_mgr.base.AppSettingType; |
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
||||
import com.iflytop.uf.UfActiveRecord; |
|
||||
import com.iflytop.uf.UfActiveRecordField; |
|
||||
import com.iflytop.uf.util.UfJsonHelper; |
|
||||
|
|
||||
|
|
||||
public class AppSetting extends UfActiveRecord { |
|
||||
@UfActiveRecordField |
|
||||
public String type; //支持类型范围 AppSettingType |
|
||||
@UfActiveRecordField |
|
||||
public String tab; //返回名字为英文,前端需要根据英文名字进行翻译 |
|
||||
@UfActiveRecordField |
|
||||
public String name; //返回名字为英文,前端需要根据英文名字进行翻译 |
|
||||
@UfActiveRecordField |
|
||||
public Integer display = 1;// 是否显示 |
|
||||
@UfActiveRecordField |
|
||||
public Integer priority;// 优先级 数值越大越靠后 |
|
||||
|
|
||||
// |
|
||||
//整形和浮点型的单位数值范围 |
|
||||
// |
|
||||
@UfActiveRecordField |
|
||||
public Integer checkValRange;//是否检查输入参数范围 |
|
||||
@UfActiveRecordField |
|
||||
public Double minVal; //最小值 |
|
||||
@UfActiveRecordField |
|
||||
public Double maxVal; //最大值 |
|
||||
|
|
||||
//枚举单位数值范围 |
|
||||
@UfActiveRecordField |
|
||||
public String valueEnumRange; //枚举范围,用逗号分隔 |
|
||||
|
|
||||
//值 |
|
||||
@UfActiveRecordField |
|
||||
public String value; //Value |
|
||||
|
|
||||
@JsonIgnore |
|
||||
public static String getTableName() { |
|
||||
return "AppSetting" + "Table"; |
|
||||
} |
|
||||
|
|
||||
public void setPriority(Integer priority) { |
|
||||
this.priority = priority; |
|
||||
} |
|
||||
|
|
||||
@JsonIgnore |
|
||||
public Integer getIntegerValue() { |
|
||||
return Integer.parseInt(value); |
|
||||
} |
|
||||
|
|
||||
// |
|
||||
// BUILDER |
|
||||
// |
|
||||
|
|
||||
@JsonIgnore |
|
||||
static AppSettingTab currentBuildGroup; |
|
||||
@JsonIgnore |
|
||||
static Integer buildPriority = 0; |
|
||||
static Boolean buildHidden = false; |
|
||||
|
|
||||
static public void setBuildGroup(AppSettingTab group) { |
|
||||
currentBuildGroup = group; |
|
||||
buildPriority = 0; |
|
||||
buildHidden = false; |
|
||||
} |
|
||||
|
|
||||
static public void setBuildHidden(Boolean hidden) { |
|
||||
buildHidden = hidden; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public static void addIntegerOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Integer value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.INTEGER.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.checkValRange = checkValRange ? 1 : 0; |
|
||||
option.minVal = minVal; |
|
||||
option.maxVal = maxVal; |
|
||||
option.value = String.valueOf(value); |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addIntegerOption(AppOptionName name, Integer value) { |
|
||||
addIntegerOption(name, false, 0.0, 0.0, value); |
|
||||
} |
|
||||
|
|
||||
public static void addDoubleOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Double value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.DOUBLE.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.checkValRange = checkValRange ? 1 : 0; |
|
||||
option.minVal = minVal; |
|
||||
option.maxVal = maxVal; |
|
||||
option.value = String.valueOf(value); |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addDoubleOption(AppOptionName name, Double value) { |
|
||||
addDoubleOption(name, false, 0.0, 0.0, value); |
|
||||
} |
|
||||
|
|
||||
public static void addStringOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.STRING.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addBooleanOption(AppOptionName name, Boolean value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.BOOLEAN.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value ? "1" : "0"; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addDateOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.DATE.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addTimeOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.TIME.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addTimezoneOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.TIMEZONE.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addIpOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.IP.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addEnumOption(AppOptionName name, String[] valueEnumRange, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.ENUM.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.valueEnumRange = UfJsonHelper.objectToJson(valueEnumRange); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
|
|
||||
public static void addFixStringOption(AppOptionName name, String value) { |
|
||||
var option = new AppSetting(); |
|
||||
option.type = AppSettingType.FIX_STRING.name(); |
|
||||
option.tab = currentBuildGroup.name(); |
|
||||
option.name = name.name(); |
|
||||
option.value = value; |
|
||||
option.priority = buildPriority++; |
|
||||
option.save(); |
|
||||
} |
|
||||
// public static void addSpecialPageOption(AppSettingName name, String value) { |
|
||||
// var option = new AppSetting(); |
|
||||
// option.type = AppSettingType.SPECIAL_PAGE.name(); |
|
||||
// option.group = currentBuildGroup.name(); |
|
||||
// option.name = name.name(); |
|
||||
// option.value = value; |
|
||||
// option.priority = buildPriority++; |
|
||||
// option.save(); |
|
||||
// } |
|
||||
|
|
||||
} |
|
@ -0,0 +1,138 @@ |
|||||
|
package a8k.service.app; |
||||
|
|
||||
|
import a8k.dbservice.AppSettingDBService; |
||||
|
import a8k.dbservice.type.AppSetting; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingType; |
||||
|
import a8k.dbservice.type.appsetting.settingenum.*; |
||||
|
import a8k.type.appret.AppRet; |
||||
|
import a8k.controler.extapi.utils.ExtApiTab; |
||||
|
import a8k.controler.extapi.utils.ExtApiFn; |
||||
|
import a8k.controler.extapi.pagecontrol.ExtApiTabConfig; |
||||
|
|
||||
|
import a8k.dbservice.type.appsetting.AppSettingTab; |
||||
|
import a8k.dbservice.type.appsetting.AppSettingName; |
||||
|
import a8k.hardware.type.a8kcanprotocol.A8kEcode; |
||||
|
import jakarta.annotation.PostConstruct; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Component |
||||
|
@ExtApiTab(cfg = ExtApiTabConfig.AppSettingsMgr) |
||||
|
public class AppSettingsMgr { |
||||
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgr.class); |
||||
|
|
||||
|
static class ORDER { |
||||
|
static final int getAppSettings = 1; |
||||
|
static final int getAppSetting = 2; |
||||
|
static final int getTabs = 3; |
||||
|
static final int getAppSettingTypesRange = 4; |
||||
|
static final int getAppSettingNamesRange = 5; |
||||
|
static final int setOptionVal = 6; |
||||
|
static final int setSysDate = 7; |
||||
|
static final int setSysTime = 8; |
||||
|
} |
||||
|
|
||||
|
static Integer settingPageVersion = 4;// 如果配置项发生改变,修改这个数字,可以重置数据库 |
||||
|
|
||||
|
@Resource |
||||
|
AppSettingDBService appSettingDBService; |
||||
|
|
||||
|
@PostConstruct |
||||
|
public void init() { |
||||
|
logger.info("AppSettingsMgr init"); |
||||
|
var SETTING_PAGE_VERSION = appSettingDBService.getSettingByName(AppSettingName.SETTING_PAGE_VERSION); |
||||
|
if (SETTING_PAGE_VERSION == null || !SETTING_PAGE_VERSION.getValueAsInt().equals(settingPageVersion)) { |
||||
|
appSettingDBService.clearAllSettings(); |
||||
|
initsettingdb(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void initsettingdb() { |
||||
|
appSettingDBService.addSettingVersion(settingPageVersion); |
||||
|
|
||||
|
//AppSettingTab.DEVICE |
||||
|
appSettingDBService.addStringSetting(AppSettingTab.DEVICE, AppSettingName.DATE, ""); |
||||
|
appSettingDBService.addStringSetting(AppSettingTab.DEVICE, AppSettingName.TIME, ""); |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.DEVICE, AppSettingName.LANGUAGE, LanguageType.class, LanguageType.zh_CN); |
||||
|
appSettingDBService.addBooleanSetting(AppSettingTab.DEVICE, AppSettingName.AUTO_PRINT, false); |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.DEVICE, AppSettingName.AUTO_LOGOUT, AutoLogoutOption.class, AutoLogoutOption.T00_10); |
||||
|
|
||||
|
|
||||
|
// AppSettingTab.LIS |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.LIS, AppSettingName.LIS_TYPE, LISTypeEnum.class, LISTypeEnum.SINGLE_TRACK); |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.LIS, AppSettingName.LIS_PROTOCOL, LISProtocolEnum.class, LISProtocolEnum.Boditech); |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.LIS, AppSettingName.LIS_IF, LISIFType.class, LISIFType.NETWORK); |
||||
|
appSettingDBService.addEnumSetting(AppSettingTab.LIS, AppSettingName.LIS_SERIAL_BAUDRATE, LISSerialBaudrate.class, LISSerialBaudrate.B9600); |
||||
|
appSettingDBService.addIpSetting(AppSettingTab.LIS, AppSettingName.LIS_NET_IP, "127.0.0.1"); |
||||
|
appSettingDBService.addPortSetting(AppSettingTab.LIS, AppSettingName.LIS_NET_PORT, 8080); |
||||
|
|
||||
|
//RELEASE |
||||
|
appSettingDBService.addFixStringSetting(AppSettingTab.RELEASE, AppSettingName.DEVICE_SERIAL, "TEST-001"); |
||||
|
appSettingDBService.addFixStringSetting(AppSettingTab.RELEASE, AppSettingName.OS_VERSION, "v1.0.0"); |
||||
|
appSettingDBService.addFixStringSetting(AppSettingTab.RELEASE, AppSettingName.APP_VERSION, "v1.0.0"); |
||||
|
appSettingDBService.addFixStringSetting(AppSettingTab.RELEASE, AppSettingName.MCU_VERSION, "v1.0.0"); |
||||
|
} |
||||
|
|
||||
|
Boolean isOptionLegal(AppSettingName name, String val) { |
||||
|
// TODO:添加校验逻辑 |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
// EXT FUNC |
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
|
||||
|
@ExtApiFn(name = "getAppSettings", order = ORDER.getAppSettings) |
||||
|
public AppRet<List<AppSetting>> getAppSettings() { |
||||
|
return AppRet.success(appSettingDBService.getAllSettings()); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "getAppSetting", order = ORDER.getAppSetting) |
||||
|
public AppRet<AppSetting> getAppSetting(AppSettingName name) { |
||||
|
return AppRet.success(appSettingDBService.getSettingByName(name)); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "getTabs", order = ORDER.getTabs) |
||||
|
public AppRet<AppSettingTab[]> getTabs() { |
||||
|
return AppRet.success(AppSettingTab.values()); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "getAppSettingTypesRange", order = ORDER.getAppSettingTypesRange) |
||||
|
public AppRet<AppSettingType[]> getAppSettingTypesRange() { |
||||
|
return AppRet.success(AppSettingType.values()); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "getAppSettingNamesRange", order = ORDER.getAppSettingNamesRange) |
||||
|
public AppRet<AppSettingName[]> getAppSettingNamesRange() { |
||||
|
return AppRet.success(AppSettingName.values()); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "setOptionVal", order = ORDER.setOptionVal) |
||||
|
public AppRet<AppSetting> setOptionVal(AppSettingName optionName, String val) { |
||||
|
logger.info("setOptionVal {}={}", optionName, val); |
||||
|
if (!isOptionLegal(optionName, val)) { |
||||
|
return AppRet.fail(A8kEcode.AppOptionIsInvalid); |
||||
|
} |
||||
|
appSettingDBService.updateSetting(optionName, val); |
||||
|
return getAppSetting(optionName); |
||||
|
} |
||||
|
|
||||
|
// |
||||
|
// DATA API |
||||
|
// |
||||
|
|
||||
|
@ExtApiFn(name = "setSysDate", order = ORDER.setSysDate) |
||||
|
public void setSysDate(Integer Year, Integer Month, Integer Day) { |
||||
|
// TODO 完成它 |
||||
|
logger.info("setSysDate {}-{}-{}", Year, Month, Day); |
||||
|
} |
||||
|
|
||||
|
@ExtApiFn(name = "setSysTime", order = ORDER.setSysTime) |
||||
|
public void setSysTime(Integer Hour, Integer Minute, Integer Second) { |
||||
|
// TODO 完成它 |
||||
|
logger.info("setSysTime {}:{}:{}", Hour, Minute, Second); |
||||
|
} |
||||
|
} |
@ -1,135 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr; |
|
||||
|
|
||||
import a8k.type.appret.AppRet; |
|
||||
import a8k.controler.extapi.utils.ExtApiTab; |
|
||||
import a8k.controler.extapi.utils.ExtApiFn; |
|
||||
import a8k.controler.extapi.pagecontrol.ExtApiTabConfig; |
|
||||
|
|
||||
import a8k.olddbservice.AppSetting; |
|
||||
import a8k.service.app.app_settings_mgr.base.AppSettingTab; |
|
||||
import a8k.service.app.app_settings_mgr.base.AppOptionName; |
|
||||
import a8k.service.app.app_settings_mgr.settingenum.AutoLogoutTime; |
|
||||
import a8k.service.app.app_settings_mgr.settingenum.LISProtocol; |
|
||||
import a8k.service.app.app_settings_mgr.settingenum.LISType; |
|
||||
import a8k.hardware.type.a8kcanprotocol.A8kEcode; |
|
||||
import com.iflytop.uf.UfActiveRecord; |
|
||||
import jakarta.annotation.PostConstruct; |
|
||||
import org.slf4j.Logger; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.Objects; |
|
||||
|
|
||||
@Component |
|
||||
@ExtApiTab(cfg = ExtApiTabConfig.AppSettingsMgr) |
|
||||
public class AppSettingsMgr { |
|
||||
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgr.class); |
|
||||
|
|
||||
static class ORDER { |
|
||||
static final int getAppSettings = 1; |
|
||||
static final int getTabs = 2; |
|
||||
static final int setSysDate = 3; |
|
||||
static final int setSysTime = 4; |
|
||||
static final int setOptionVal = 5; |
|
||||
} |
|
||||
|
|
||||
static Integer settingPageVersion = 3; |
|
||||
|
|
||||
|
|
||||
@PostConstruct |
|
||||
public void init() { |
|
||||
logger.info("AppSettingsMgr init"); |
|
||||
|
|
||||
AppSetting spversion = dbGetAppSetting(AppOptionName.SETTING_PAGE_VERSION); |
|
||||
if (spversion == null || !Objects.equals(spversion.getIntegerValue(), settingPageVersion)) { |
|
||||
dbClearAppSettings(); |
|
||||
initsettingdb(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public void initsettingdb() { |
|
||||
AppSetting.setBuildGroup(AppSettingTab.DEVICE); |
|
||||
AppSetting.addIntegerOption(AppOptionName.SETTING_PAGE_VERSION, settingPageVersion); |
|
||||
AppSetting.addDateOption(AppOptionName.DATE, ""); |
|
||||
AppSetting.addTimeOption(AppOptionName.TIME, ""); |
|
||||
AppSetting.addEnumOption(AppOptionName.LANGUAGE, new String[]{"zh_CN", "en_US"}, "zh_CN"); |
|
||||
AppSetting.addBooleanOption(AppOptionName.AUTO_PRINT, false); |
|
||||
AppSetting.addEnumOption(AppOptionName.AUTO_LOGOUT, AutoLogoutTime.cgetValues(), AutoLogoutTime.T03_00.name()); |
|
||||
|
|
||||
AppSetting.setBuildGroup(AppSettingTab.LIS); |
|
||||
AppSetting.addEnumOption(AppOptionName.LIS_TYPE, LISType.getValues(), LISType.SINGLE_TRACK.name()); |
|
||||
AppSetting.addEnumOption(AppOptionName.LIS_PROTOCOL, LISProtocol.getValues(), LISProtocol.Boditech.name()); |
|
||||
|
|
||||
AppSetting.setBuildGroup(AppSettingTab.RELEASE); |
|
||||
AppSetting.addFixStringOption(AppOptionName.DEVICE_SERIAL, "TEST-001"); |
|
||||
AppSetting.addFixStringOption(AppOptionName.OS_VERSION, "v1.0.0"); |
|
||||
AppSetting.addFixStringOption(AppOptionName.APP_VERSION, "v1.0.0"); |
|
||||
AppSetting.addFixStringOption(AppOptionName.MCU_VERSION, "v1.0.0"); |
|
||||
} |
|
||||
|
|
||||
List<AppSetting> dbGetAppSettings() { |
|
||||
return UfActiveRecord.find(AppSetting.class); |
|
||||
} |
|
||||
|
|
||||
AppSetting dbGetAppSetting(AppOptionName name) { |
|
||||
return UfActiveRecord.findOne(AppSetting.class, Map.of("name", name.name())); |
|
||||
} |
|
||||
|
|
||||
Boolean isOptionLegal(AppOptionName name, String val) { |
|
||||
//TODO:添加校验逻辑 |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
void dbClearAppSettings() { |
|
||||
var items = dbGetAppSettings(); |
|
||||
for (var item : items) { |
|
||||
item.delete(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
||||
// EXT FUNC |
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
||||
|
|
||||
@ExtApiFn(name = "getAppSettings", order = ORDER.getAppSettings) |
|
||||
public AppRet<List<AppSetting>> getAppSettings() { |
|
||||
return AppRet.success(dbGetAppSettings()); |
|
||||
} |
|
||||
|
|
||||
@ExtApiFn(name = "getTabs", order = ORDER.getTabs) |
|
||||
public AppRet<List<String>> getTabs() { |
|
||||
List<String> groups = new ArrayList<>(); |
|
||||
for (AppSettingTab group : AppSettingTab.values()) { |
|
||||
groups.add(group.name()); |
|
||||
} |
|
||||
return AppRet.success(groups); |
|
||||
} |
|
||||
|
|
||||
@ExtApiFn(name = "setSysDate", order = ORDER.setSysDate) |
|
||||
public void setSysDate(Integer Year, Integer Month, Integer Day) { |
|
||||
logger.info("setSysDate {}-{}-{}", Year, Month, Day); |
|
||||
} |
|
||||
|
|
||||
@ExtApiFn(name = "setSysTime", order = ORDER.setSysTime) |
|
||||
public void setSysTime(Integer Hour, Integer Minute, Integer Second) { |
|
||||
logger.info("setSysTime {}:{}:{}", Hour, Minute, Second); |
|
||||
} |
|
||||
|
|
||||
@ExtApiFn(name = "setOptionVal", order = ORDER.setOptionVal) |
|
||||
public AppRet<Object> setOptionVal(AppOptionName optionName, String val) { |
|
||||
logger.info("setOptionVal {}={}", optionName, val); |
|
||||
if (!isOptionLegal(optionName, val)) { |
|
||||
return AppRet.fail(A8kEcode.AppOptionIsInvalid); |
|
||||
} |
|
||||
AppSetting appSetting = dbGetAppSetting(optionName); |
|
||||
if (appSetting != null) { |
|
||||
appSetting.value = val; |
|
||||
appSetting.save(); |
|
||||
} |
|
||||
return AppRet.success(); |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,35 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr.base; |
|
||||
|
|
||||
public enum AppOptionName { |
|
||||
//DEVICE |
|
||||
SETTING_PAGE_VERSION, |
|
||||
DATE, |
|
||||
TIME, |
|
||||
TIMEZONE, |
|
||||
LANGUAGE, |
|
||||
AUTO_PRINT, |
|
||||
AUTO_LOGOUT, |
|
||||
|
|
||||
//USR_MGR |
|
||||
|
|
||||
//RELEASE |
|
||||
DEVICE_SERIAL, |
|
||||
OS_VERSION, |
|
||||
APP_VERSION, |
|
||||
MCU_VERSION, |
|
||||
|
|
||||
//LIS |
|
||||
LIS_TYPE, |
|
||||
LIS_PROTOCOL, |
|
||||
LIS_IF, |
|
||||
LIS_AUTO_EXPORT, |
|
||||
LIS_SERIAL_BAUDRATE, |
|
||||
LIS_NET_IP, |
|
||||
LIS_NET_PORT, |
|
||||
|
|
||||
//NET |
|
||||
NET_IP, |
|
||||
NET_PORT, |
|
||||
|
|
||||
} |
|
||||
|
|
@ -1,9 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr.base; |
|
||||
|
|
||||
public enum AppSettingTab { |
|
||||
DEVICE, |
|
||||
USRMGR, |
|
||||
LIS, |
|
||||
NETWORK, |
|
||||
RELEASE, |
|
||||
} |
|
@ -1,23 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr.settingenum; |
|
||||
|
|
||||
public enum AutoLogoutTime { |
|
||||
T00_00, |
|
||||
T00_10, |
|
||||
T00_30, |
|
||||
T01_00, |
|
||||
T02_00, |
|
||||
T03_00 |
|
||||
; |
|
||||
|
|
||||
|
|
||||
|
|
||||
public static String[] cgetValues() { |
|
||||
String[] values = new String[AutoLogoutTime.values().length]; |
|
||||
int i = 0; |
|
||||
for (AutoLogoutTime value : AutoLogoutTime.values()) { |
|
||||
values[i] = value.name(); |
|
||||
i++; |
|
||||
} |
|
||||
return values; |
|
||||
} |
|
||||
} |
|
@ -1,14 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr.settingenum; |
|
||||
|
|
||||
public enum LISProtocol { |
|
||||
Boditech, Simens; |
|
||||
|
|
||||
public static String[] getValues() { |
|
||||
String[] values = new String[LISProtocol.values().length]; |
|
||||
int i = 0; |
|
||||
for (LISProtocol value : LISProtocol.values()) { |
|
||||
values[i++] = value.name(); |
|
||||
} |
|
||||
return values; |
|
||||
} |
|
||||
} |
|
@ -1,17 +0,0 @@ |
|||||
package a8k.service.app.app_settings_mgr.settingenum; |
|
||||
|
|
||||
public enum LISType { |
|
||||
//单向,双向 |
|
||||
SINGLE_TRACK, |
|
||||
DOUBLE_TRACK, |
|
||||
; |
|
||||
|
|
||||
public static String[] getValues() { |
|
||||
String[] values = new String[LISType.values().length]; |
|
||||
int i = 0; |
|
||||
for (LISType value : LISType.values()) { |
|
||||
values[i++] = value.name(); |
|
||||
} |
|
||||
return values; |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,14 @@ |
|||||
|
package a8k.utils; |
||||
|
|
||||
|
public class ZEnumHelper { |
||||
|
public static String[] enum2strs(Class<?> tClass) { |
||||
|
String[] values = new String[tClass.getEnumConstants().length]; |
||||
|
int i = 0; |
||||
|
for (var value : tClass.getEnumConstants()) { |
||||
|
Enum<?> e = (Enum<?>) value; |
||||
|
values[i] = e.name(); |
||||
|
i++; |
||||
|
} |
||||
|
return values; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue