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);
|
}
|
}
|