Commit 4c40302a zshaohui

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

1 个父辈 6bdfa9f8
......@@ -144,4 +144,14 @@ public class Constants {
public static final String CACHE_outLotInfoMap = "outLotInfoMap";
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;
import com.neotel.smfcore.security.service.po.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -70,9 +71,11 @@ public class SettingsController {
Settings settings = dataCache.getSettings();
boolean stopOut = dataCache.getCache(Constants.CACHE_StopOut);
boolean startJob = dataCache.getCache(Constants.CACHE_StartJob);
Integer backUpMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
SysSettingsDto dto = new SysSettingsDto();
dto.setStartJob(startJob);
dto.setStopOut(stopOut);
dto.setBackUpMonth(backUpMonth);
return dto;
}
......@@ -82,7 +85,8 @@ public class SettingsController {
public ResultBean updateSysSettings(@Validated @RequestBody SysSettingsDto sysSettingsDto) {
dataCache.updateCache(Constants.CACHE_StopOut, sysSettingsDto.isStopOut());
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("保存成功");
}
......@@ -180,19 +184,6 @@ public class SettingsController {
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 {
try {
List<Map<String, Object>> maps = new ArrayList<>();
......
......@@ -15,4 +15,7 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("开启自动任务")
private boolean startJob = false;
@ApiModelProperty("备份时间")
private Integer backUpMonth=0;
}
package com.neotel.smfcore.core.system.util;
import com.google.common.base.Strings;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.inList.service.po.InList;
......@@ -36,15 +37,6 @@ import java.util.concurrent.TimeUnit;
@Service
public class DbBackupService {
/**
* 自动存档间隔Key
*/
private String BACKUP_MONTH_KEY = "db.backup.month";
/**
* 上次自动存档时间
*/
private String LAST_BACKUP_TIME_KEY = "db.backup.lastTime";
@Autowired
DataCache dataCache;
......@@ -62,10 +54,10 @@ public class DbBackupService {
log.info("开启数据库定时存档任务");
while(true){
try{
Integer dbBackupMonth = dataCache.getCache(BACKUP_MONTH_KEY);
Integer dbBackupMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
//dbBackupMonth = 1;
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;
if(lastBackupTime == null){
needBackup = true;
......@@ -99,10 +91,10 @@ public class DbBackupService {
return false;
}
processing = true;
Integer dbBackupMonth = dataCache.getCache(BACKUP_MONTH_KEY);
Integer dbBackupMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
if(dbBackupMonth == null){
dbBackupMonth = 12;//默认备份12个月前的数据
dataCache.updateCache(BACKUP_MONTH_KEY,dbBackupMonth);
dataCache.updateCache(Constants.BACKUP_MONTH_KEY,dbBackupMonth);
}
backupTable(dbBackupMonth,
DataLog.class,
......@@ -114,7 +106,7 @@ public class DbBackupService {
Message.class,
AlarmInfo.class
);
dataCache.updateCache(LAST_BACKUP_TIME_KEY,new Date());
dataCache.updateCache(Constants.LAST_BACKUP_TIME_KEY,new Date());
processing = false;
return true;
}
......@@ -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!