Commit 4c40302a zshaohui

系统设置-数据备份月数 修正

1 个父辈 6bdfa9f8
...@@ -144,4 +144,14 @@ public class Constants { ...@@ -144,4 +144,14 @@ public class Constants {
public static final String CACHE_outLotInfoMap = "outLotInfoMap"; public static final String CACHE_outLotInfoMap = "outLotInfoMap";
public static final String CACHE_outLotInfos = "outLotInfos"; public static final String CACHE_outLotInfos = "outLotInfos";
/**
* 自动存档间隔Key
*/
public static final String BACKUP_MONTH_KEY = "db.backup.month";
/**
* 上次自动存档时间
*/
public static final String LAST_BACKUP_TIME_KEY = "db.backup.lastTime";
} }
...@@ -25,6 +25,7 @@ import com.neotel.smfcore.security.service.po.Menu; ...@@ -25,6 +25,7 @@ import com.neotel.smfcore.security.service.po.Menu;
import com.neotel.smfcore.security.service.po.User; import com.neotel.smfcore.security.service.po.User;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -70,9 +71,11 @@ public class SettingsController { ...@@ -70,9 +71,11 @@ public class SettingsController {
Settings settings = dataCache.getSettings(); Settings settings = dataCache.getSettings();
boolean stopOut = dataCache.getCache(Constants.CACHE_StopOut); boolean stopOut = dataCache.getCache(Constants.CACHE_StopOut);
boolean startJob = dataCache.getCache(Constants.CACHE_StartJob); boolean startJob = dataCache.getCache(Constants.CACHE_StartJob);
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.setBackUpMonth(backUpMonth);
return dto; return dto;
} }
...@@ -82,7 +85,8 @@ public class SettingsController { ...@@ -82,7 +85,8 @@ public class SettingsController {
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());
log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()); dataCache.updateCache(Constants.BACKUP_MONTH_KEY,sysSettingsDto.getBackUpMonth());
log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()+",backUpMonth="+sysSettingsDto.getBackUpMonth());
return ResultBean.newOkResult("保存成功"); return ResultBean.newOkResult("保存成功");
} }
...@@ -180,19 +184,6 @@ public class SettingsController { ...@@ -180,19 +184,6 @@ public class SettingsController {
downloadOrderModel(response); downloadOrderModel(response);
} }
@ApiOperation("修改数据备份时间")
@PutMapping("/dbBackup")
@PreAuthorize("@el.check('dbBackupSetting')")
@AnonymousAccess
public ResultBean updateDbBackupSetting(@RequestBody Map<String,Integer> paramMap) {
Integer months = paramMap.get("months");
if (months == null || months < 1) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"存档月数"});
}
dbBackupService.updateDbBackupSetting(months);
return ResultBean.newOkResult("");
}
public void downloadOrderModel( HttpServletResponse response) throws IOException { public void downloadOrderModel( HttpServletResponse response) throws IOException {
try { try {
List<Map<String, Object>> maps = new ArrayList<>(); List<Map<String, Object>> maps = new ArrayList<>();
......
...@@ -15,4 +15,7 @@ public class SysSettingsDto implements Serializable { ...@@ -15,4 +15,7 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("开启自动任务") @ApiModelProperty("开启自动任务")
private boolean startJob = false; private boolean startJob = false;
@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,10 +91,10 @@ public class DbBackupService { ...@@ -99,10 +91,10 @@ 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);
} }
backupTable(dbBackupMonth, backupTable(dbBackupMonth,
DataLog.class, DataLog.class,
...@@ -114,7 +106,7 @@ public class DbBackupService { ...@@ -114,7 +106,7 @@ public class DbBackupService {
Message.class, Message.class,
AlarmInfo.class AlarmInfo.class
); );
dataCache.updateCache(LAST_BACKUP_TIME_KEY,new Date()); dataCache.updateCache(Constants.LAST_BACKUP_TIME_KEY,new Date());
processing = false; processing = false;
return true; return true;
} }
...@@ -151,8 +143,4 @@ public class DbBackupService { ...@@ -151,8 +143,4 @@ public class DbBackupService {
} }
} }
} }
public void updateDbBackupSetting(Integer months) {
dataCache.updateCache(BACKUP_MONTH_KEY,months);
}
} }
package com.neotel.smfcore.custom.lizhen.kanban.service.dao;
import com.neotel.smfcore.common.base.IBaseDao;
import com.neotel.smfcore.custom.lizhen.kanban.common.bean.dto.InOutDataDto;
import java.util.Date;
public interface InOutDataDtoDao extends IBaseDao {
}
package com.neotel.smfcore.custom.lizhen.kanban.service.dao.impl;
import com.neotel.smfcore.common.base.AbstractBaseDao;
import com.neotel.smfcore.custom.lizhen.agvBox.bean.WareHouseCode;
import com.neotel.smfcore.custom.lizhen.agvBox.service.dao.WareHouseCodeDao;
import com.neotel.smfcore.custom.lizhen.kanban.common.bean.dto.InOutDataDto;
import com.neotel.smfcore.custom.lizhen.kanban.service.dao.InOutDataDtoDao;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class InOutDataDtoImpl extends AbstractBaseDao implements InOutDataDtoDao {
@Override
public Class getEntityClass() {
return InOutDataDto.class;
}
}
package com.neotel.smfcore.custom.lizhen.kanban.service.manager;
import com.neotel.smfcore.common.base.IBaseManager;
import com.neotel.smfcore.core.equipment.service.po.Equipment;
import com.neotel.smfcore.custom.lizhen.agvBox.bean.WareHouseCode;
import com.neotel.smfcore.custom.lizhen.kanban.common.bean.dto.InOutDataDto;
import java.util.Date;
import java.util.List;
public interface InOutDataDtoManager extends IBaseManager<InOutDataDto> {
InOutDataDto getSixDaysAgoData(Date currentDate);
}
package com.neotel.smfcore.custom.lizhen.kanban.service.manager.impl;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.custom.lizhen.kanban.common.bean.dto.InOutDataDto;
import com.neotel.smfcore.custom.lizhen.kanban.service.dao.InOutDataDtoDao;
import com.neotel.smfcore.custom.lizhen.kanban.service.manager.InOutDataDtoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class InOutDataDtoManagerImpl implements InOutDataDtoManager {
@Autowired
private InOutDataDtoDao inOutDataDtoDao;
@Override
public InOutDataDto get(String id) {
return null;
}
@Override
public InOutDataDto save(InOutDataDto object) throws ValidateException {
return inOutDataDtoDao.save(object);
}
@Override
public void delete(InOutDataDto object) throws ValidateException {
}
@Override
public PageData<InOutDataDto> findByPage(Query query, Pageable pageable) {
return null;
}
@Override
public List<InOutDataDto> findByQuery(Query query) {
return null;
}
@Override
public InOutDataDto getSixDaysAgoData(Date currentDate) {
Query query = Query.query(Criteria.where("createDate").gte(currentDate));
return inOutDataDtoDao.findOne(query);
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!