package com.fzzy.igds.timer;
|
|
import com.fzzy.common.constant.BizTypeEnum;
|
import com.fzzy.igds.utils.DateUtil;
|
import com.ruoyi.common.config.FrameworkConfig;
|
import com.ruoyi.common.enums.BusinessStatus;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.OperatorType;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.system.domain.SysCompany;
|
import com.ruoyi.system.domain.SysOperLog;
|
import com.ruoyi.system.service.ISysCompanyService;
|
import com.ruoyi.system.service.ISysOperLogService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@EnableScheduling
|
@Slf4j
|
@Component
|
public class SystemScheduled {
|
|
|
@Resource
|
private ISysOperLogService operLogService;
|
|
@Resource
|
private ISysCompanyService companyService;
|
|
@Resource
|
private ISysOperLogService sysOperLogService;
|
|
/**
|
*
|
*/
|
@Scheduled(cron = "0 0 1 1 * ?")
|
public void cronJob1() {
|
try {
|
log.info("------------每30天的凌晨1点执行清除操作日志开始------------");
|
//执行清除日志方法
|
doCronHob1();
|
//添加清除日志记录
|
SysOperLog operLog = new SysOperLog();
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
operLog.setMethod("com.fzzy.igds.timer.SystemScheduled.cronJob1()");
|
operLog.setCompanyId(FrameworkConfig.getCompanyId());
|
operLog.setBusinessType(BusinessType.CLEAN.ordinal());
|
operLog.setTitle("定时任务,定时清除操作日志");
|
operLog.setOperatorType(OperatorType.MANAGE.ordinal());
|
operLog.setBizType(BizTypeEnum.SYS.getCode());
|
operLog.setOperName(FrameworkConfig.getName());
|
operLog.setOperTime(new Date());
|
sysOperLogService.insertOperlog(operLog);
|
log.info("------------每30天的凌晨1点执行清除操作日志结束------------");
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
}
|
|
}
|
|
public void doCronHob1() {
|
|
//获取系统中所有的companyId
|
List<SysCompany> sysCompanies = companyService.selectAll();
|
//设置删除参数
|
SysOperLog deleteOperLog = new SysOperLog();
|
//设置删除截止时间
|
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtil.getNewByDay(new Date(), -30));
|
Map<String, Object> params = new HashMap<>();
|
params.put("endTime", endTime);
|
deleteOperLog.setParams(params);
|
//需要删除的业务类型
|
String[] bizTypes = new String[]{
|
BizTypeEnum.SCREEN.getCode(),
|
BizTypeEnum.SUPERVISION.getCode(),
|
BizTypeEnum.SECURITY.getCode(),
|
BizTypeEnum.GRAIN.getCode(),
|
BizTypeEnum.INOUT.getCode()
|
};
|
for (SysCompany sysCompany : sysCompanies) {
|
if (StringUtils.isNotBlank(sysCompany.getCompanyId())) {
|
//设置删除企业编码
|
deleteOperLog.setCompanyId(sysCompany.getCompanyId());
|
log.info("------------清除组织编码【{}】操作日志------------", sysCompany.getCompanyId());
|
for (int i = 0; i < bizTypes.length; i++) {
|
deleteOperLog.setBizType( bizTypes[i]);
|
operLogService.cleanOperLogByEntity(deleteOperLog);
|
}
|
}
|
}
|
}
|
}
|