diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/WarningFlowTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/WarningFlowTypeEnum.java new file mode 100644 index 0000000..891d926 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/WarningFlowTypeEnum.java @@ -0,0 +1,58 @@ +package com.ningdatech.pmapi.projectlib.enumeration; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; + +import java.util.Objects; + +/** + * + * 预警填报类型枚举 + * @author CMM + * @since 2023/02/24 16:14 + */ +@Getter +@NoArgsConstructor +@AllArgsConstructor +public enum WarningFlowTypeEnum { + /** + * 预警填报类型枚举 + */ + UNIT_INNER_AUDIT(1, "预审申报",ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode()), + PRELIMINARY_PREVIEW(2, "建设方案申报",ProjectStatusEnum.PLAN_TO_BE_DECLARED.getCode()), + DEPT_UNITED_REVIEW(3,"采购结果备案",ProjectStatusEnum.TO_BE_PURCHASED.getCode()), + CONSTRUCTION_PLAN_REVIEW(4,"初验备案",ProjectStatusEnum.UNDER_CONSTRUCTION.getCode()), + PROJECT_FINAL_INSPECTION(5,"验收申报",ProjectStatusEnum.TO_BE_FINALLY_INSPECTED.getCode()); + + private Integer code; + private String desc; + + //对应的 待提交时的项目状态 + private Integer projectStutas; + + public static String getDescByCode(Integer code) { + if (Objects.isNull(code)) { + return StringUtils.EMPTY; + } + for (WarningFlowTypeEnum t : WarningFlowTypeEnum.values()) { + if (code.equals(t.getCode())) { + return t.desc; + } + } + return StringUtils.EMPTY; + } + + public static WarningFlowTypeEnum getByCode(Integer code) { + if (Objects.isNull(code)) { + return null; + } + for (WarningFlowTypeEnum t : WarningFlowTypeEnum.values()) { + if (code.equals(t.getCode())) { + return t; + } + } + return null; + } +} 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..c941c8b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningInstanceNotStartTask.java @@ -0,0 +1,119 @@ +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.WarningFlowTypeEnum; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +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; +import java.util.stream.Collectors; + +/** + * @author ZPF + * @date 2023/8/3 上午9:53 + * 预警填报 超时任务 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class EarlyWarningInstanceNotStartTask { + + @Value("${hostname}") + private String HOST_NAME; + + private final IEarlyWarningService earlyWarningService; + + private final IProjectService projectService; + + private final IProjectInstService projectInstService; + + @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; + } + + WarningFlowTypeEnum flowTypeEnum = WarningFlowTypeEnum.getByCode(biz); + if(Objects.isNull(flowTypeEnum)){ + log.info("匹配不到 流程类型"); + return; + } + + //得出 对应待提交的项目状态 + Integer projectStutas = flowTypeEnum.getProjectStutas(); + String areaCode = warning.getAreaCode(); + //测试先用分钟 + //查询 所有这个区域的项目 未提交的项目 + List projects = projectService.list(Wrappers.lambdaQuery(Project.class) + .eq(Project::getAreaCode, areaCode) + .eq(Project::getNewest, Boolean.TRUE) + .eq(Project::getStatus,projectStutas)); + List projectIds = projects.stream().map(Project::getId) + .collect(Collectors.toList()); + projectInstService.list(Wrappers.lambdaQuery(ProjectInst.class) + .in(ProjectInst::getProjectId,projectIds) + .eq(ProjectInst::getInstType,biz)); + }); + } + } + } + + stopWatch.stop(); + log.info("=========== 预警填报超时任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); + } + +}