sgj
2026-02-26 d0b93ade5d7a25f5b4a413c16bcc1c1b3d154b92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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(), -90));
        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);
                }
            }
        }
    }
}