|
|
@@ -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<WflowEarlyWarning> 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<Project> projects = projectService.list(Wrappers.lambdaQuery(Project.class) |
|
|
|
.eq(Project::getAreaCode, areaCode) |
|
|
|
.eq(Project::getNewest, Boolean.TRUE) |
|
|
|
.eq(Project::getStatus,projectStutas)); |
|
|
|
List<Long> 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()); |
|
|
|
} |
|
|
|
|
|
|
|
} |