|
|
@ -3,12 +3,14 @@ package a8k.service.appsettings; |
|
|
|
import a8k.appbase.appret.AppRet; |
|
|
|
import a8k.controler.engineer.utils.EngineerPageTab; |
|
|
|
import a8k.controler.engineer.utils.EnginnerPageAction; |
|
|
|
import a8k.controler.engineer.utils.EnginnerPageTabOrder; |
|
|
|
import a8k.db.AppSetting; |
|
|
|
import a8k.service.appsettings.base.AppSettingTab; |
|
|
|
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 a8k.service.hardware.canbus.protocol.A8kEcode; |
|
|
|
import com.iflytop.uf.UfActiveRecord; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import org.slf4j.Logger; |
|
|
@ -20,25 +22,20 @@ import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Component |
|
|
|
@EngineerPageTab(name = "AppSettings") |
|
|
|
@EngineerPageTab(name = "应用-系统设置", order = EnginnerPageTabOrder.AppSettingsMgr) |
|
|
|
public class AppSettingsMgr { |
|
|
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgr.class); |
|
|
|
static Integer settingPageVersion = 1; |
|
|
|
|
|
|
|
List<AppSetting> dbGetAppSettings() { |
|
|
|
return UfActiveRecord.find(AppSetting.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; |
|
|
|
} |
|
|
|
|
|
|
|
AppSetting dbGetAppSetting(AppOptionName name) { |
|
|
|
return UfActiveRecord.findOne(AppSetting.class, Map.of("name", name.name())); |
|
|
|
} |
|
|
|
static Integer settingPageVersion = 2; |
|
|
|
|
|
|
|
void dbClearAppSettings() { |
|
|
|
var items = dbGetAppSettings(); |
|
|
|
for (var item : items) { |
|
|
|
item.delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
@ -51,12 +48,12 @@ public class AppSettingsMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void initsettingdb() { |
|
|
|
AppSetting.setBuildGroup(AppSettingTab.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()); |
|
|
@ -72,13 +69,36 @@ public class AppSettingsMgr { |
|
|
|
AppSetting.addFixStringOption(AppOptionName.MCU_VERSION, "v1.0.0"); |
|
|
|
} |
|
|
|
|
|
|
|
List<AppSetting> dbGetAppSettings() { |
|
|
|
return UfActiveRecord.find(AppSetting.class); |
|
|
|
} |
|
|
|
|
|
|
|
@EnginnerPageAction(name = "getAppSettings") |
|
|
|
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 |
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
|
|
|
|
|
|
@EnginnerPageAction(name = "getAppSettings", order = ORDER.getAppSettings) |
|
|
|
public AppRet<List<AppSetting>> getAppSettings() { |
|
|
|
return AppRet.success(dbGetAppSettings()); |
|
|
|
} |
|
|
|
|
|
|
|
@EnginnerPageAction(name = "getTabs") |
|
|
|
@EnginnerPageAction(name = "getTabs", order = ORDER.getTabs) |
|
|
|
public AppRet<List<String>> getTabs() { |
|
|
|
List<String> groups = new ArrayList<>(); |
|
|
|
for (AppSettingTab group : AppSettingTab.values()) { |
|
|
@ -87,30 +107,28 @@ public class AppSettingsMgr { |
|
|
|
return AppRet.success(groups); |
|
|
|
} |
|
|
|
|
|
|
|
@EnginnerPageAction(name = "setSysDate") |
|
|
|
@EnginnerPageAction(name = "setSysDate", order = ORDER.setSysDate) |
|
|
|
public void setSysDate(Integer Year, Integer Month, Integer Day) { |
|
|
|
logger.info("setSysDate {}-{}-{}", Year, Month, Day); |
|
|
|
} |
|
|
|
|
|
|
|
@EnginnerPageAction(name = "setSysTime") |
|
|
|
@EnginnerPageAction(name = "setSysTime", order = ORDER.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){ |
|
|
|
@EnginnerPageAction(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(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |