Browse Source
Merge branch 'master' of http://192.168.1.3:3000/project_boditech_vidas_a8000_v3/a8k_app
master
Merge branch 'master' of http://192.168.1.3:3000/project_boditech_vidas_a8000_v3/a8k_app
master
2 changed files with 181 additions and 126 deletions
-
5src/main/java/a8k/app/controler/api/v1/app/setting/DeviceSettingControler.java
-
302src/main/java/a8k/app/service/setting/AppSettingsMgrService.java
@ -1,155 +1,211 @@ |
|||||
package a8k.app.service.setting; |
package a8k.app.service.setting; |
||||
|
|
||||
import a8k.app.service.data.AppUserMgrService; |
|
||||
import a8k.app.type.exception.AppException; |
|
||||
import a8k.app.dao.DeviceSettingDao; |
import a8k.app.dao.DeviceSettingDao; |
||||
import a8k.app.dao.LISSettingDao; |
import a8k.app.dao.LISSettingDao; |
||||
|
|
||||
import a8k.app.dao.type.db.DeviceSetting; |
import a8k.app.dao.type.db.DeviceSetting; |
||||
import a8k.app.dao.type.db.LISSetting; |
import a8k.app.dao.type.db.LISSetting; |
||||
import a8k.app.hardware.type.A8kEcode; |
import a8k.app.hardware.type.A8kEcode; |
||||
|
import a8k.app.service.data.AppUserMgrService; |
||||
|
import a8k.app.type.exception.AppException; |
||||
import a8k.app.utils.IPAddressValidator; |
import a8k.app.utils.IPAddressValidator; |
||||
import jakarta.annotation.PostConstruct; |
import jakarta.annotation.PostConstruct; |
||||
import jakarta.annotation.Resource; |
import jakarta.annotation.Resource; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
import org.slf4j.Logger; |
import org.slf4j.Logger; |
||||
import org.springframework.stereotype.Component; |
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.io.BufferedReader; |
||||
|
import java.io.InputStreamReader; |
||||
|
|
||||
|
@Slf4j |
||||
@Component |
@Component |
||||
public class AppSettingsMgrService { |
public class AppSettingsMgrService { |
||||
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgrService.class); |
|
||||
@Resource |
|
||||
AppUserMgrService appUserMgrService; |
|
||||
|
|
||||
@Resource |
|
||||
DeviceSettingDao deviceSettingDao; |
|
||||
|
|
||||
@Resource |
|
||||
LISSettingDao lisSettingDao; |
|
||||
|
|
||||
@PostConstruct |
|
||||
public void init() { |
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
||||
// EXT FUNC |
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
||||
|
|
||||
|
|
||||
public DeviceSetting getDeviceSetting() { |
|
||||
return deviceSettingDao.get(); |
|
||||
} |
|
||||
|
|
||||
public LISSetting getLISSetting() { |
|
||||
return lisSettingDao.get(); |
|
||||
} |
|
||||
|
|
||||
public void setLanguage(DeviceSetting.LanguageType val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.language = val; |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public void setAutoPrint(Boolean val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.autoPrint = val; |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public void setAutoLogoutTimeout(Integer val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.autoLogoutTimeout = val; |
|
||||
deviceSettingDao.update(setting); |
|
||||
appUserMgrService.updateAutoLogoutTimeout(val); |
|
||||
} |
|
||||
|
|
||||
public void setAutoLogout(Boolean val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.autoLogout = val; |
|
||||
deviceSettingDao.update(setting); |
|
||||
appUserMgrService.updateAutoLogout(val); |
|
||||
} |
|
||||
|
|
||||
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgrService.class); |
||||
|
@Resource |
||||
|
AppUserMgrService appUserMgrService; |
||||
|
|
||||
public void setLISType(LISSetting.LISTypeEnum val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISType = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
@Resource |
||||
|
DeviceSettingDao deviceSettingDao; |
||||
|
|
||||
|
@Resource |
||||
|
LISSettingDao lisSettingDao; |
||||
|
|
||||
public void setLISProtocol(LISSetting.LISProtocolEnum val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISProtocol = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
@PostConstruct |
||||
|
public void init() { |
||||
|
|
||||
|
} |
||||
|
|
||||
public void setLIFIf(LISSetting.LISIFType val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LIFIf = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
// EXT FUNC |
||||
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||||
|
|
||||
public void setLISAutoExport(Boolean val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISAutoExport = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
|
public DeviceSetting getDeviceSetting() { |
||||
|
return deviceSettingDao.get(); |
||||
|
} |
||||
|
|
||||
public void setLISSerialBaudrate(LISSetting.LISSerialBaudrateType val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISSerialBaudrate = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
public LISSetting getLISSetting() { |
||||
|
return lisSettingDao.get(); |
||||
|
} |
||||
|
|
||||
|
public void setLanguage(DeviceSetting.LanguageType val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.language = val; |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
public void setLISNetIp(String val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISNetIp = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
|
public void setAutoPrint(Boolean val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.autoPrint = val; |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
public void setLISNetPort(Integer val) { |
|
||||
LISSetting setting = lisSettingDao.get(); |
|
||||
setting.LISNetPort = val; |
|
||||
lisSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
public void setIncubateBoxTemperature(Integer val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.setIncubateBoxTemperature(val); |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
public void setAutoLogoutTimeout(Integer val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.autoLogoutTimeout = val; |
||||
|
deviceSettingDao.update(setting); |
||||
|
appUserMgrService.updateAutoLogoutTimeout(val); |
||||
|
} |
||||
|
|
||||
|
public void setAutoLogout(Boolean val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.autoLogout = val; |
||||
|
deviceSettingDao.update(setting); |
||||
|
appUserMgrService.updateAutoLogout(val); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISType(LISSetting.LISTypeEnum val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISType = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISProtocol(LISSetting.LISProtocolEnum val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISProtocol = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLIFIf(LISSetting.LISIFType val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LIFIf = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISAutoExport(Boolean val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISAutoExport = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISSerialBaudrate(LISSetting.LISSerialBaudrateType val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISSerialBaudrate = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISNetIp(String val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISNetIp = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setLISNetPort(Integer val) { |
||||
|
LISSetting setting = lisSettingDao.get(); |
||||
|
setting.LISNetPort = val; |
||||
|
lisSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
public void setIncubateBoxTemperature(Integer val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.setIncubateBoxTemperature(val); |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
public void setPlateBoxTemperature(Integer val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.setPlateBoxTemperature(val); |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
public void setDHCP(Boolean val) { |
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.setDHCP(val); |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
public void setLocalIp(String val) throws AppException { |
||||
|
//检查IP格式 是否是点分十进制 |
||||
|
if (!IPAddressValidator.isValidIPv4(val)) { |
||||
|
throw new AppException(A8kEcode.IP_FORMAT_ERROR); |
||||
|
} |
||||
|
|
||||
|
DeviceSetting setting = deviceSettingDao.get(); |
||||
|
setting.setLocalIp(val); |
||||
|
deviceSettingDao.update(setting); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set the system date and time. |
||||
|
* |
||||
|
* @param datetime date-time string in the format "yyyy-MM-dd HH:mm:ss" |
||||
|
*/ |
||||
|
public void setDateAndTime(String datetime) { |
||||
|
String os = System.getProperty("os.name").toLowerCase(); |
||||
|
if (os.contains("windows")) { |
||||
|
log.info("Windows detected, skipping system time update. Received datetime: {}", datetime); |
||||
|
return; |
||||
|
} |
||||
|
try { |
||||
|
ProcessBuilder pbNtp = new ProcessBuilder("timedatectl", "set-ntp", "false").redirectErrorStream(true); |
||||
|
Process procNtp = pbNtp.start(); |
||||
|
StringBuilder ntpOut = new StringBuilder(); |
||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(procNtp.getInputStream()))) { |
||||
|
String line; |
||||
|
while ((line = reader.readLine()) != null) { |
||||
|
ntpOut.append(line).append("\n"); |
||||
|
} |
||||
|
} |
||||
|
int ntpExit = procNtp.waitFor(); |
||||
|
if (ntpExit != 0) { |
||||
|
log.error("Failed to disable NTP (exit={}):\n{}", ntpExit, ntpOut.toString().trim()); |
||||
|
} else { |
||||
|
log.info("Automatic time synchronization disabled"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("Error disabling NTP before setting time", e); |
||||
|
} |
||||
|
|
||||
|
ProcessBuilder pbTime = new ProcessBuilder("timedatectl", "set-time", datetime).redirectErrorStream(true); |
||||
|
try { |
||||
|
Process procTime = pbTime.start(); |
||||
|
StringBuilder timeOut = new StringBuilder(); |
||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(procTime.getInputStream()))) { |
||||
|
String line; |
||||
|
while ((line = reader.readLine()) != null) { |
||||
|
timeOut.append(line).append("\n"); |
||||
|
} |
||||
|
} |
||||
|
int timeExit = procTime.waitFor(); |
||||
|
if (timeExit != 0) { |
||||
|
log.error("Failed to update system time (exit={}):\n{}", timeExit, timeOut.toString().trim()); |
||||
|
return; |
||||
|
} |
||||
|
log.info("System time successfully updated to {}", datetime); |
||||
|
} catch (Exception e) { |
||||
|
log.error("Error executing system time update command", e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
public void setPlateBoxTemperature(Integer val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.setPlateBoxTemperature(val); |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
public void setDHCP(Boolean val) { |
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.setDHCP(val); |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
public void setLocalIp(String val) throws AppException { |
|
||||
//检查IP格式 是否是点分十进制 |
|
||||
if(!IPAddressValidator.isValidIPv4(val)) { |
|
||||
throw new AppException(A8kEcode.IP_FORMAT_ERROR); |
|
||||
} |
|
||||
|
|
||||
DeviceSetting setting = deviceSettingDao.get(); |
|
||||
setting.setLocalIp(val); |
|
||||
deviceSettingDao.update(setting); |
|
||||
} |
|
||||
|
|
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue