wisdomisite-java/src/main/java/com/zhgd/xmgl/task/ProgressPanoramaNodePlanAlarmTask.java
2024-12-25 16:14:04 +08:00

88 lines
3.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhgd.xmgl.async.AsyncCommon;
import com.zhgd.xmgl.call.SanjiangDataCall;
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService;
import com.zhgd.xmgl.modules.project.constants.ProgressTaskConstant;
import com.zhgd.xmgl.modules.project.entity.ProgressPanoramaNodePlan;
import com.zhgd.xmgl.modules.project.entity.ProgressPanoramaNodePlanAlarm;
import com.zhgd.xmgl.modules.project.entity.ProgressTask;
import com.zhgd.xmgl.modules.project.entity.ProgressTaskAlarm;
import com.zhgd.xmgl.modules.project.enums.ProgressAlarmTypeEnum;
import com.zhgd.xmgl.modules.project.service.IProgressPanoramaNodePlanAlarmService;
import com.zhgd.xmgl.modules.project.service.IProgressPanoramaNodePlanService;
import com.zhgd.xmgl.modules.project.service.ProgressTaskAlarmService;
import com.zhgd.xmgl.modules.project.service.ProgressTaskService;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author 邱平毅
* @ClassName ProgressTask
* @date 2022/11/2 11:25
* @Version 1.0
* 甘特图任务调度
*/
@Slf4j
@Component
public class ProgressPanoramaNodePlanAlarmTask {
@Autowired
private IProgressPanoramaNodePlanService progressPanoramaNodePlanService;
@Autowired
private IProgressPanoramaNodePlanAlarmService progressPanoramaNodePlanAlarmService;
/**
* 每天0点5分处理报警数据
*/
@Scheduled(cron = "0 0 10 * * ?")
public void manageAlarmData() {
log.info("定时处理项目计划任务");
String today = DateUtil.today();
// 预计开始时间已过未开始、预计结束时间已过进行中任务
List<ProgressPanoramaNodePlan> planList = progressPanoramaNodePlanService.list(Wrappers.lambdaQuery(ProgressPanoramaNodePlan.class)
.eq(ProgressPanoramaNodePlan::getApprovalStatue, 2)
.eq(ProgressPanoramaNodePlan::getStatus, 0).lt(ProgressPanoramaNodePlan::getPlanStartDate, today)
.or(wrapper -> wrapper.eq(ProgressPanoramaNodePlan::getStatus, 1).lt(ProgressPanoramaNodePlan::getPlanFinishDate, today)));
// 判断是否有逾期任务
if (CollUtil.isNotEmpty(planList)) {
List<ProgressPanoramaNodePlanAlarm> alarmList = new LinkedList<>();
// 根据状态分组
planList.forEach(p -> {
ProgressPanoramaNodePlanAlarm progressPanoramaNodePlanAlarm = new ProgressPanoramaNodePlanAlarm();
progressPanoramaNodePlanAlarm.setNodeId(p.getId());
if (p.getStatus() == 1) {
progressPanoramaNodePlanAlarm.setAlarmDetails("当前任务预计开始时间为:" + p.getPlanStartDate() + "" + "目前任务未开始");
} else {
progressPanoramaNodePlanAlarm.setAlarmDetails("当前任务预计完成时间为:" + p.getPlanFinishDate() + "" + "目前任务未完成");
}
progressPanoramaNodePlanAlarm.setCreateDate(new Date());
progressPanoramaNodePlanAlarm.setAlarmType(p.getStatus());
progressPanoramaNodePlanAlarm.setProjectSn(p.getProjectSn());
progressPanoramaNodePlanAlarm.setNodeName(p.getNodeName());
progressPanoramaNodePlanAlarm.setChargerId(p.getChargerId());
progressPanoramaNodePlanAlarm.setChargerName(p.getChargerName());
alarmList.add(progressPanoramaNodePlanAlarm);
});
log.info("当前逾期数据:{}", alarmList);
progressPanoramaNodePlanAlarmService.saveBatch(alarmList);
}
}
}