危化品全生命周期管理后端
kongzy
2024-08-22 0c73654f55844e34772732914af8cc1e247aab63
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
package com.gkhy.hazmat.framework.job;
 
import com.gkhy.hazmat.common.enums.OperateStatusEnum;
import com.gkhy.hazmat.system.domain.HzHazmat;
import com.gkhy.hazmat.system.domain.HzHazmatFlow;
import com.gkhy.hazmat.system.domain.HzWarning;
import com.gkhy.hazmat.system.mapper.HzHazmatFlowMapper;
import com.gkhy.hazmat.system.mapper.HzHazmatMapper;
import com.gkhy.hazmat.system.mapper.HzWarningMapper;
import com.gkhy.hazmat.system.service.HzWarningService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 考生考试超时处理job
 */
@Slf4j
@Component
public class WarningJob {
    @Autowired
    private HzHazmatMapper hazmatMapper;
    @Autowired
    private HzWarningMapper warningMapper;
    @Autowired
    private HzHazmatFlowMapper hazmatFlowMapper;
    @Autowired
    private HzWarningService warningService;
 
    /**
     * 建议:每天23点执行一次
     */
    @Scheduled(cron = "0 0 23 * * ?")
  // @Scheduled(cron = "0 37 17 * * ?")
    public void checkWarning() {
        for(int i=0;i<20;i++){
            doCheckWarning(i);
        }
    }
 
 
    public void doCheckWarning(Integer slice) {
        Integer pageIndex=1;
        Integer pageSize=100;
        List<HzWarning> warningList=new ArrayList<>();
        try {
            while (true){
                List<HzHazmat> hazmatList = hazmatMapper.selectWarningHazmatList(slice,(pageIndex - 1) * pageSize, pageSize);
                if(hazmatList.isEmpty()){
                    break;
                }
                for(HzHazmat hazmat:hazmatList){
                    HzWarning warning=new HzWarning();
                    warning.setHazmatId(hazmat.getId());
                    warning.setBasicId(hazmat.getBasicId());
                    HzHazmatFlow flow=hazmatFlowMapper.selectLastFlow(slice,hazmat.getId(), OperateStatusEnum.USING.getCode());
                    if(flow!=null){
                        warning.setUseTime(flow.getCreateTime());
                        warning.setCreateId(flow.getCreateId());
                    }
                    warning.setCompanyId(hazmat.getCompanyId());
                    warning.setState(0);
                    warningList.add(warning);
                }
                warningService.saveBatch(warningList);
                warningList.clear();
                pageIndex++;
            }
        }catch (Exception e){
            log.error("WarningJob checkWarning slice={}, error={}",slice,e.getMessage());
        }
    }
 
}