Commit 8d668e69 zshaohui

系统设置-数据备份月数

1 个父辈 9f602532
...@@ -148,4 +148,14 @@ public class Constants { ...@@ -148,4 +148,14 @@ public class Constants {
*/ */
public static final String CACHE_languageType="CACHE_languageType"; public static final String CACHE_languageType="CACHE_languageType";
/**
* 自动存档间隔Key
*/
public static final String BACKUP_MONTH_KEY = "db.backup.month";
/**
* 上次自动存档时间
*/
public static final String LAST_BACKUP_TIME_KEY = "db.backup.lastTime";
} }
...@@ -18,6 +18,7 @@ import com.neotel.smfcore.core.system.rest.bean.dto.SettingsDto; ...@@ -18,6 +18,7 @@ import com.neotel.smfcore.core.system.rest.bean.dto.SettingsDto;
import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto; import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto;
import com.neotel.smfcore.core.system.rest.bean.mapstruct.SettingsMapper; import com.neotel.smfcore.core.system.rest.bean.mapstruct.SettingsMapper;
import com.neotel.smfcore.core.system.service.po.Settings; import com.neotel.smfcore.core.system.service.po.Settings;
import com.neotel.smfcore.core.system.util.DbBackupService;
import com.neotel.smfcore.security.annotation.AnonymousAccess; import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.bean.FileProperties; import com.neotel.smfcore.security.bean.FileProperties;
import com.neotel.smfcore.security.rest.bean.dto.MenuDto; import com.neotel.smfcore.security.rest.bean.dto.MenuDto;
...@@ -57,6 +58,10 @@ public class SettingsController { ...@@ -57,6 +58,10 @@ public class SettingsController {
@Autowired @Autowired
private final FileProperties properties; private final FileProperties properties;
@Autowired
private DbBackupService dbBackupService;
/** /**
* 当前版本 * 当前版本
*/ */
...@@ -74,26 +79,30 @@ public class SettingsController { ...@@ -74,26 +79,30 @@ public class SettingsController {
Integer sluggishDay=dataCache.getCache(Constants.CACHE_SluggishDay); Integer sluggishDay=dataCache.getCache(Constants.CACHE_SluggishDay);
Integer expiresDay=dataCache.getCache(Constants.CACHE_ExpiresDay); Integer expiresDay=dataCache.getCache(Constants.CACHE_ExpiresDay);
Integer caWarn=dataCache.getCache(Constants.CACHE_CapacityWarn); Integer caWarn=dataCache.getCache(Constants.CACHE_CapacityWarn);
Integer backUpMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
SysSettingsDto dto = new SysSettingsDto(); SysSettingsDto dto = new SysSettingsDto();
dto.setStartJob(startJob); dto.setStartJob(startJob);
dto.setStopOut(stopOut); dto.setStopOut(stopOut);
dto.setSluggishDay(sluggishDay); dto.setSluggishDay(sluggishDay);
dto.setExpiresDay(expiresDay); dto.setExpiresDay(expiresDay);
dto.setCapacityWarn(caWarn); dto.setCapacityWarn(caWarn);
dto.setBackUpMonth(backUpMonth);
return dto; return dto;
} }
@ApiOperation("修改系统设置信息") @ApiOperation("修改系统设置信息")
@PutMapping("/sysSettings") @PutMapping("/sysSettings")
@PreAuthorize("@el.check('sysSetting')") @PreAuthorize("@el.check('sysSetting')")
@AnonymousAccess
public ResultBean updateSysSettings(@Validated @RequestBody SysSettingsDto sysSettingsDto) { public ResultBean updateSysSettings(@Validated @RequestBody SysSettingsDto sysSettingsDto) {
dataCache.updateCache(Constants.CACHE_StopOut, sysSettingsDto.isStopOut()); dataCache.updateCache(Constants.CACHE_StopOut, sysSettingsDto.isStopOut());
dataCache.updateCache(Constants.CACHE_StartJob, sysSettingsDto.isStartJob()); dataCache.updateCache(Constants.CACHE_StartJob, sysSettingsDto.isStartJob());
dataCache.updateCache(Constants.CACHE_SluggishDay,sysSettingsDto.getSluggishDay()); dataCache.updateCache(Constants.CACHE_SluggishDay,sysSettingsDto.getSluggishDay());
dataCache.updateCache(Constants.CACHE_ExpiresDay,sysSettingsDto.getExpiresDay()); dataCache.updateCache(Constants.CACHE_ExpiresDay,sysSettingsDto.getExpiresDay());
dataCache.updateCache(Constants.CACHE_CapacityWarn,sysSettingsDto.getCapacityWarn()); dataCache.updateCache(Constants.CACHE_CapacityWarn,sysSettingsDto.getCapacityWarn());
dataCache.updateCache(Constants.BACKUP_MONTH_KEY,sysSettingsDto.getBackUpMonth());
log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()+",sluggishDay="+sysSettingsDto.getSluggishDay() log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()+",sluggishDay="+sysSettingsDto.getSluggishDay()
+",expiresDay="+sysSettingsDto.getExpiresDay()+",capacityWarn="+sysSettingsDto.getCapacityWarn()); +",expiresDay="+sysSettingsDto.getExpiresDay()+",capacityWarn="+sysSettingsDto.getCapacityWarn()+",backUpMonth="+sysSettingsDto.getBackUpMonth());
return ResultBean.newOkResult("保存成功"); return ResultBean.newOkResult("保存成功");
} }
......
...@@ -24,4 +24,7 @@ public class SysSettingsDto implements Serializable { ...@@ -24,4 +24,7 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("容量预警") @ApiModelProperty("容量预警")
private Integer capacityWarn=0; private Integer capacityWarn=0;
@ApiModelProperty("备份时间")
private Integer backUpMonth=0;
} }
package com.neotel.smfcore.core.system.util; package com.neotel.smfcore.core.system.util;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.DateUtil; import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.inList.service.po.InList; import com.neotel.smfcore.core.inList.service.po.InList;
...@@ -36,15 +37,6 @@ import java.util.concurrent.TimeUnit; ...@@ -36,15 +37,6 @@ import java.util.concurrent.TimeUnit;
@Service @Service
public class DbBackupService { public class DbBackupService {
/**
* 自动存档间隔Key
*/
private String BACKUP_MONTH_KEY = "db.backup.month";
/**
* 上次自动存档时间
*/
private String LAST_BACKUP_TIME_KEY = "db.backup.lastTime";
@Autowired @Autowired
DataCache dataCache; DataCache dataCache;
...@@ -62,10 +54,10 @@ public class DbBackupService { ...@@ -62,10 +54,10 @@ public class DbBackupService {
log.info("开启数据库定时存档任务"); log.info("开启数据库定时存档任务");
while(true){ while(true){
try{ try{
Integer dbBackupMonth = dataCache.getCache(BACKUP_MONTH_KEY); Integer dbBackupMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
dbBackupMonth = 1; //dbBackupMonth = 1;
if(dbBackupMonth != null && dbBackupMonth > 0){ if(dbBackupMonth != null && dbBackupMonth > 0){
Date lastBackupTime = dataCache.getCache(LAST_BACKUP_TIME_KEY); Date lastBackupTime = dataCache.getCache(Constants.LAST_BACKUP_TIME_KEY);
boolean needBackup = false; boolean needBackup = false;
if(lastBackupTime == null){ if(lastBackupTime == null){
needBackup = true; needBackup = true;
...@@ -99,12 +91,11 @@ public class DbBackupService { ...@@ -99,12 +91,11 @@ public class DbBackupService {
return false; return false;
} }
processing = true; processing = true;
Integer dbBackupMonth = dataCache.getCache(BACKUP_MONTH_KEY); Integer dbBackupMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
if(dbBackupMonth == null){ if(dbBackupMonth == null){
dbBackupMonth = 12;//默认备份12个月前的数据 dbBackupMonth = 12;//默认备份12个月前的数据
dataCache.updateCache(BACKUP_MONTH_KEY,dbBackupMonth); dataCache.updateCache(Constants.BACKUP_MONTH_KEY,dbBackupMonth);
} }
dataCache.updateCache(LAST_BACKUP_TIME_KEY,new Date());
backupTable(dbBackupMonth, backupTable(dbBackupMonth,
DataLog.class, DataLog.class,
Humiture.class, Humiture.class,
...@@ -115,6 +106,7 @@ public class DbBackupService { ...@@ -115,6 +106,7 @@ public class DbBackupService {
Message.class, Message.class,
AlarmInfo.class AlarmInfo.class
); );
dataCache.updateCache(Constants.LAST_BACKUP_TIME_KEY,new Date());
processing = false; processing = false;
return true; return true;
} }
...@@ -151,5 +143,4 @@ public class DbBackupService { ...@@ -151,5 +143,4 @@ public class DbBackupService {
} }
} }
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!