13 changed files with 505 additions and 10 deletions
-
2src/main/java/a8k/appbase/appret/AppRet.java
-
202src/main/java/a8k/db/AppSetting.java
-
18src/main/java/a8k/db/LanguageDictIterm.java
-
30src/main/java/a8k/service/LanguageDictService.java
-
116src/main/java/a8k/service/appsettings/AppSettingsMgr.java
-
35src/main/java/a8k/service/appsettings/base/AppOptionName.java
-
9src/main/java/a8k/service/appsettings/base/AppSettingGroup.java
-
16src/main/java/a8k/service/appsettings/base/AppSettingType.java
-
22src/main/java/a8k/service/appsettings/settingenum/AutoLogoutTime.java
-
14src/main/java/a8k/service/appsettings/settingenum/LISProtocol.java
-
17src/main/java/a8k/service/appsettings/settingenum/LISType.java
-
19src/main/java/a8k/service/usermgr/AppUserMgrService.java
-
15src/main/resources/db/migration/V100_4__create_table_AppSettingTable.sql
@ -0,0 +1,202 @@ |
|||||
|
package a8k.db; |
||||
|
|
||||
|
import a8k.service.appsettings.base.AppSettingGroup; |
||||
|
import a8k.service.appsettings.base.AppOptionName; |
||||
|
import a8k.service.appsettings.base.AppSettingType; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.iflytop.uf.UfActiveRecord; |
||||
|
import com.iflytop.uf.UfActiveRecordField; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
|
||||
|
public class AppSetting extends UfActiveRecord { |
||||
|
@UfActiveRecordField |
||||
|
public String type; //支持类型范围 AppSettingType |
||||
|
@UfActiveRecordField |
||||
|
public String group; //返回名字为英文,前端需要根据英文名字进行翻译 |
||||
|
@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 AppSettingGroup currentBuildGroup; |
||||
|
@JsonIgnore |
||||
|
static Integer buildPriority = 0; |
||||
|
static Boolean buildHidden = false; |
||||
|
|
||||
|
static public void setBuildGroup(AppSettingGroup 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.group = 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.group = 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.group = 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.group = 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.group = 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.group = 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.group = 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.group = 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.group = currentBuildGroup.name(); |
||||
|
option.name = name.name(); |
||||
|
option.valueEnumRange = Arrays.toString(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.group = 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,18 @@ |
|||||
|
package a8k.db; |
||||
|
|
||||
|
import com.iflytop.uf.UfActiveRecord; |
||||
|
import com.iflytop.uf.UfActiveRecordField; |
||||
|
|
||||
|
public class LanguageDictIterm extends UfActiveRecord { |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String key; |
||||
|
@UfActiveRecordField |
||||
|
public String country; |
||||
|
@UfActiveRecordField |
||||
|
public String value; |
||||
|
// get table name |
||||
|
public static String getTableName() { |
||||
|
return String.format("%sTable", LanguageDictIterm.class.getSimpleName()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package a8k.service; |
||||
|
|
||||
|
import a8k.appbase.appret.AppRet; |
||||
|
import a8k.db.LanguageDictIterm; |
||||
|
import com.iflytop.uf.UfActiveRecord; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Component |
||||
|
public class LanguageDictService { |
||||
|
|
||||
|
List<LanguageDictIterm> dbGetLanguageDict() { |
||||
|
return UfActiveRecord.find(LanguageDictIterm.class); |
||||
|
} |
||||
|
|
||||
|
List<LanguageDictIterm> dbGetLanguageDict(String country) { |
||||
|
return UfActiveRecord.find(LanguageDictIterm.class, Map.of("country", country)); |
||||
|
} |
||||
|
|
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
// PUBLIC |
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
|
||||
|
public AppRet<List<LanguageDictIterm>> getLanguageDict(String country) { |
||||
|
return AppRet.success(dbGetLanguageDict(country)); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,116 @@ |
|||||
|
package a8k.service.appsettings; |
||||
|
|
||||
|
import a8k.appbase.appret.AppRet; |
||||
|
import a8k.controler.engineer.utils.EngineerPageTab; |
||||
|
import a8k.controler.engineer.utils.EnginnerPageAction; |
||||
|
import a8k.db.AppSetting; |
||||
|
import a8k.service.appsettings.base.AppSettingGroup; |
||||
|
import a8k.service.appsettings.base.AppOptionName; |
||||
|
import a8k.service.appsettings.settingenum.AutoLogoutTime; |
||||
|
import a8k.service.appsettings.settingenum.LISProtocol; |
||||
|
import a8k.service.appsettings.settingenum.LISType; |
||||
|
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 |
||||
|
@EngineerPageTab(name = "AppSettings") |
||||
|
public class AppSettingsMgr { |
||||
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgr.class); |
||||
|
static Integer settingPageVersion = 1; |
||||
|
|
||||
|
List<AppSetting> dbGetAppSettings() { |
||||
|
return UfActiveRecord.find(AppSetting.class); |
||||
|
} |
||||
|
|
||||
|
AppSetting dbGetAppSetting(AppOptionName name) { |
||||
|
return UfActiveRecord.findOne(AppSetting.class, Map.of("name", name.name())); |
||||
|
} |
||||
|
|
||||
|
void dbClearAppSettings() { |
||||
|
var items = dbGetAppSettings(); |
||||
|
for (var item : items) { |
||||
|
item.delete(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@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(AppSettingGroup.DEVICE); |
||||
|
AppSetting.addIntegerOption(AppOptionName.SETTING_PAGE_VERSION, settingPageVersion); |
||||
|
AppSetting.addDateOption(AppOptionName.DATE, ""); |
||||
|
AppSetting.addTimeOption(AppOptionName.TIME, ""); |
||||
|
AppSetting.addTimezoneOption(AppOptionName.TIMEZONE, ""); |
||||
|
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(AppSettingGroup.LIS); |
||||
|
AppSetting.addEnumOption(AppOptionName.LIS_TYPE, LISType.getValues(), LISType.SINGLE_TRACK.name()); |
||||
|
AppSetting.addEnumOption(AppOptionName.LIS_PROTOCOL, LISProtocol.getValues(), LISProtocol.Boditech.name()); |
||||
|
|
||||
|
AppSetting.setBuildGroup(AppSettingGroup.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"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@EnginnerPageAction(name = "getAppSettings") |
||||
|
public AppRet<List<AppSetting>> getAppSettings() { |
||||
|
return AppRet.success(dbGetAppSettings()); |
||||
|
} |
||||
|
|
||||
|
@EnginnerPageAction(name = "getAppSetting") |
||||
|
public AppRet<List<String>> getGroups() { |
||||
|
List<String> groups = new ArrayList<>(); |
||||
|
for (AppSettingGroup group : AppSettingGroup.values()) { |
||||
|
groups.add(group.name()); |
||||
|
} |
||||
|
return AppRet.success(groups); |
||||
|
} |
||||
|
|
||||
|
@EnginnerPageAction(name = "setSysDate") |
||||
|
public void setSysDate(Integer Year, Integer Month, Integer Day) { |
||||
|
logger.info("setSysDate {}-{}-{}", Year, Month, Day); |
||||
|
} |
||||
|
|
||||
|
@EnginnerPageAction(name = "setSysTime") |
||||
|
public void setSysTime(Integer Hour, Integer Minute, Integer Second) { |
||||
|
logger.info("setSysTime {}:{}:{}", Hour, Minute, Second); |
||||
|
} |
||||
|
|
||||
|
@EnginnerPageAction(name = "setSysTimezone") |
||||
|
public void setSysTimezone(String timezone) { |
||||
|
logger.info("setSysTimezone {}", timezone); |
||||
|
} |
||||
|
|
||||
|
@EnginnerPageAction(name = "setOptionVal") |
||||
|
public void setOptionVal(AppOptionName optionName,String val){ |
||||
|
logger.info("setOptionVal {}={}", optionName, val); |
||||
|
AppSetting appSetting = dbGetAppSetting(optionName); |
||||
|
if(appSetting != null){ |
||||
|
appSetting.value = val; |
||||
|
appSetting.save(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package a8k.service.appsettings.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, |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,9 @@ |
|||||
|
package a8k.service.appsettings.base; |
||||
|
|
||||
|
public enum AppSettingGroup { |
||||
|
DEVICE, |
||||
|
USRMGR, |
||||
|
LIS, |
||||
|
NETWORK, |
||||
|
RELEASE, |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package a8k.service.appsettings.base; |
||||
|
|
||||
|
public enum AppSettingType { |
||||
|
INTEGER,//整数 |
||||
|
DOUBLE,//浮点,前端一律显示两位小数 |
||||
|
STRING,//字符串 |
||||
|
BOOLEAN,//布尔 |
||||
|
DATE,//日期, |
||||
|
TIME,//时间, |
||||
|
TIMEZONE,//时区 |
||||
|
IP,//点分十进制字符串存入数据库,前端显示为字符串 |
||||
|
ENUM,//枚举 |
||||
|
SPECIAL_PAGE,//只是起到占位符的作用,相当于添加一个空白页面,页面中的内容,前端根据GROUP_NAME进行填充 |
||||
|
FIX_STRING,//固定字符串,不可编辑 |
||||
|
; |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
package a8k.service.appsettings.settingenum; |
||||
|
|
||||
|
public enum AutoLogoutTime { |
||||
|
T00_00, |
||||
|
T01_00, |
||||
|
T02_00, |
||||
|
T03_00, |
||||
|
T04_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; |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package a8k.service.appsettings.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; |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package a8k.service.appsettings.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,15 @@ |
|||||
|
CREATE TABLE "AppSettingTable" |
||||
|
( |
||||
|
"id" text NOT NULL, |
||||
|
"type" text, |
||||
|
"group" text, |
||||
|
"name" text, |
||||
|
"display" integer, |
||||
|
"priority" integer, |
||||
|
"checkValRange" integer, |
||||
|
"minVal" real, |
||||
|
"maxVal" real, |
||||
|
"valueEnumRange" text, |
||||
|
"value" text, |
||||
|
PRIMARY KEY ("id") |
||||
|
); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue