Lius
2024-08-12 16e35b191d910e5e586a9eae5678324bfa679408
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.jeecg.modules.mdc.job;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.mdc.entity.MdcFeedback;
import org.jeecg.modules.mdc.entity.PcAppRunRealData;
import org.jeecg.modules.mdc.service.IMdcFeedbackService;
import org.jeecg.modules.mdc.service.IPcAppRunRealDataService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.ThrowableUtil;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.entity.SysQuartzLog;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.quartz.service.ISysQuartzLogService;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * 跳板机状态监控
 *
 * @author Lius
 * @date 2024/7/17 10:33
 */
@Slf4j
public class PcAppRunScanJob implements Job {
 
    @Resource
    private ISysQuartzLogService sysQuartzLogService;
 
    @Resource
    private IQuartzJobService quartzJobService;
 
    @Resource
    private ISysAnnouncementService sysAnnouncementService;
 
    @Resource
    private IMdcFeedbackService mdcFeedbackService;
 
    @Resource
    private IPcAppRunRealDataService pcAppRunRealDataService;
 
    @Resource
    private IMdcProductionService mdcProductionService;
 
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        SysQuartzLog quartzLog = new SysQuartzLog();
        quartzLog.setCreateTime(new Date());
        List<QuartzJob> byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName());
        if (byJobClassName != null && !byJobClassName.isEmpty()) {
            quartzLog.setJobId(byJobClassName.get(0).getId());
        }
        log.info("定时监控跳板机状态任务 PcAppRunScanJob start!  时间:" + DateUtils.getNow());
        long startTime = System.currentTimeMillis();
        try {
            // step.1 查询状态为O
            List<PcAppRunRealData> pcAppRunRealDataList = pcAppRunRealDataService.list();
            if (pcAppRunRealDataList != null && !pcAppRunRealDataList.isEmpty()) {
                for (PcAppRunRealData pcAppRunRealData : pcAppRunRealDataList) {
                    MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getProductionName, pcAppRunRealData.getMachineid()));
                    if (mdcProduction == null) {
                        continue;
                    }
                    Integer oporation = pcAppRunRealData.getOporation();
                    Date collectTime = pcAppRunRealData.getCollecttime();
                    long second = DateUtils.differentSecond(collectTime, DateUtils.getNow());
                    MdcFeedback mdcFeedback = new MdcFeedback();
                    if (oporation.equals(CommonConstant.DEL_FLAG_1)) {
                        // 超过10分钟则报警
                        if (second > 600) {
                            //状态异常插入问题反馈记录
                            List<MdcFeedback> list = mdcFeedbackService.list(new LambdaQueryWrapper<MdcFeedback>().like(MdcFeedback::getContent, pcAppRunRealData.getAppdescribe()));
                            if (list == null || list.isEmpty()) {
                                mdcFeedback.setProductionId(mdcProduction.getId());
                                mdcFeedback.setContent(pcAppRunRealData.getAppdescribe() + "连接异常!");
                            }
                        } else {
                            //状态正常查询问题反馈删除记录
                            mdcFeedbackService.remove(new LambdaQueryWrapper<MdcFeedback>().like(MdcFeedback::getContent, pcAppRunRealData.getAppdescribe()));
                        }
                    } else {
                        //状态异常插入问题反馈记录
                        List<MdcFeedback> list = mdcFeedbackService.list(new LambdaQueryWrapper<MdcFeedback>().like(MdcFeedback::getContent, pcAppRunRealData.getAppdescribe()));
                        if (list == null || list.isEmpty()) {
                            mdcFeedback.setProductionId(mdcProduction.getId());
                            mdcFeedback.setContent(pcAppRunRealData.getAppdescribe() + "连接异常!");
                        }
                    }
                    if (StringUtils.isNotBlank(mdcFeedback.getProductionId())) {
                        mdcFeedbackService.save(mdcFeedback);
                    }
                }
            }
            quartzLog.setIsSuccess(0);
        } catch (Exception e) {
            quartzLog.setIsSuccess(-1);
            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
            // 发送消息通知
            sysAnnouncementService.jobSendMessage("定时监控跳板机状态任务", quartzLog.getExceptionDetail());
        }
        long endTime = System.currentTimeMillis();
        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
        sysQuartzLogService.save(quartzLog);
    }
}