diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningInstanceNotStartTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningInstanceNotStartTask.java new file mode 100644 index 0000000..11d1cfe --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningInstanceNotStartTask.java @@ -0,0 +1,97 @@ +package com.ningdatech.pmapi.scheduler.task; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.StopWatch; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.common.enumeration.CommonEnum; +import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; +import com.wflow.bean.entity.WflowEarlyWarning; +import com.wflow.enums.WarningRuleTypeEnum; +import com.wflow.service.IEarlyWarningService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; +import java.util.Objects; + +/** + * @author ZPF + * @date 2023/8/3 上午9:53 + * 预警填报 超时任务 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class EarlyWarningInstanceNotStartTask { + + @Value("${hostname}") + private String HOST_NAME; + + private final IEarlyWarningService earlyWarningService; + + @Scheduled(cron = "0 2 * * * ?") + public void doTask() throws UnknownHostException { + if (!HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) { + return; + } + + log.info("=========== 预警填报超时任务开始 ========"); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + + // 1.查询 填报的 预警规则 填报类型的 每个区域 每个规则 + List warnings = earlyWarningService.list(Wrappers.lambdaQuery(WflowEarlyWarning.class) + .eq(WflowEarlyWarning::getRuleType, WarningRuleTypeEnum.DECLARED_WARNING.getCode())); + for(WflowEarlyWarning warning : warnings){ + //2. 取出rule的数据 + if(!warning.getIsOpen()){ + log.info(warning.getId() + " 此规则关闭了"); + continue; + } + + String noticeMethod = warning.getNoticeMethod(); + if(StringUtils.isBlank(noticeMethod) || + (!noticeMethod.contains(String.valueOf(CommonEnum.ZWDD.getCode())) && + !noticeMethod.contains(String.valueOf(CommonEnum.MOBILE.getCode())))){ + log.info("通知方式为空或者错误!"); + return; + } + + String rule = warning.getRule(); + if(StringUtils.isNotBlank(rule)){ + JSONArray ruleArray = JSON.parseArray(rule); + if(CollUtil.isNotEmpty(ruleArray)){ + ruleArray.forEach(r -> { + JSONObject rJson = JSON.parseObject(JSON.toJSONString(r)); + Integer time = rJson.getInteger("time"); + Integer biz = rJson.getInteger("biz"); + if(Objects.isNull(time) || Objects.isNull(biz)){ + log.info("规则数据 错误 :{}",rJson); + return; + } + + InstTypeEnum instTypeEnum = InstTypeEnum.getByCode(biz); + if(Objects.isNull(instTypeEnum)){ + log.info("匹配不到 流程类型"); + return; + } + + + }); + } + } + } + + stopWatch.stop(); + log.info("=========== 预警填报超时任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); + } + +}