package com.fzzy.igds.timer; import com.fzzy.common.constant.BizTypeEnum; 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.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.Date; import java.util.List; @EnableScheduling @Slf4j @Component public class SystemScheduled { @Resource private ISysOperLogService operLogService; @Resource private ISysCompanyService companyService; @Resource private ISysOperLogService sysOperLogService; /** * */ @Scheduled(cron = "0 0 1 */30 * ?") 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 sysCompanies = companyService.selectAll(); for (SysCompany sysCompany : sysCompanies) { if (StringUtils.isNotBlank(sysCompany.getCompanyId())) { log.info("------------清除组织编码【{}】操作日志------------", sysCompany.getCompanyId()); operLogService.cleanOperLog(sysCompany.getCompanyId()); } } } }