218 lines
12 KiB
Java
218 lines
12 KiB
Java
package com.ydw.bat.wkflow.config;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.ydw.bat.wkflow.business_auth.LawsUserInfoService;
|
|
import com.ydw.bat.wkflow.business_main.datas.entity.BusProcessNew;
|
|
import com.ydw.bat.wkflow.business_main.datas.entity.EsPrcRelation;
|
|
import com.ydw.bat.wkflow.business_main.datas.entity.EsRevisePlanDTO;
|
|
import com.ydw.bat.wkflow.business_main.datas.mapper.BusProcessNameMapper;
|
|
import com.ydw.bat.wkflow.business_main.datas.service.IBusProcessNewService;
|
|
import com.ydw.bat.wkflow.business_main.datas.service.IEsPrcRelationService;
|
|
import com.ydw.bat.wkflow.business_mq.service.CreateMQService;
|
|
import com.ydw.bat.wkflow.business_oa.webService.service.impl.WebServiceOAServiceImpl;
|
|
import com.ydw.bat.wkflow.util.SpringContextUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.activiti.engine.TaskService;
|
|
import org.activiti.engine.task.Task;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
@EnableScheduling
|
|
@Component
|
|
@Slf4j
|
|
public class ScheduledJobEsPlan {
|
|
Logger logger = LoggerFactory.getLogger(ScheduledJobEsPlan.class);
|
|
|
|
@Value("${isNotScheduled}")
|
|
private boolean isNotScheduled; //是否开启定时器
|
|
|
|
@Autowired
|
|
WebServiceOAServiceImpl webServiceOAService;
|
|
|
|
// @Scheduled(cron = "0 0 2 * * ?") //每天的凌晨2点执行
|
|
// @Async
|
|
// public void SchedulingTask() {
|
|
// if(isNotScheduled) {
|
|
// logger.info("============企标计划定时任务开始===========");
|
|
// LawsUserInfoService lawsUserInfoService = SpringContextUtil.getBean(LawsUserInfoService.class);
|
|
// IEsPrcRelationService esPrcRelationService = SpringContextUtil.getBean(IEsPrcRelationService.class);
|
|
// TaskService taskService = SpringContextUtil.getBean(TaskService.class);
|
|
//
|
|
// List<EsRevisePlanDTO> esRevisePlanDTOList = lawsUserInfoService.getAllPlansByWk(null); // 查询 制定中,修订中的企标计划
|
|
// // 计划标准初稿时间前一个月的企标计划
|
|
// SimpleDateFormat sdfQuery = new SimpleDateFormat("yyyy-MM-dd");
|
|
// Calendar calendar = Calendar.getInstance();
|
|
// calendar.add(Calendar.MONTH, 1);
|
|
// String endDate = sdfQuery.format(calendar.getTime());
|
|
// List<EsRevisePlanDTO> esRevisePlanDTOList2 = esRevisePlanDTOList.stream()
|
|
// .filter(e -> endDate.equals(sdfQuery.format(e.getDraftTime())))
|
|
// .collect(Collectors.toList());
|
|
// if (!esRevisePlanDTOList2.isEmpty()) {
|
|
// for (EsRevisePlanDTO esRevisePlanDTO : esRevisePlanDTOList2) {
|
|
// List<EsPrcRelation> esPrcRelationList = esPrcRelationService.list(esRevisePlanDTO.getId());
|
|
// if (esPrcRelationList.isEmpty()) {
|
|
// continue;
|
|
// }
|
|
// String esId = esPrcRelationList.get(0).getEsId();
|
|
// String prcIdGk = esPrcRelationList.get(0).getPrcIdGk();
|
|
// String oaFlag = esPrcRelationList.get(0).getOaFlag();
|
|
// // 判断对应 管控流程是否还在 技术标准起草节点, 且之前点过接受任务
|
|
// if (StringUtils.isNotBlank(prcIdGk)) {
|
|
// List<Task> list2 = taskService.createTaskQuery().processInstanceId(prcIdGk).active().list();
|
|
// if (!list2.isEmpty()) {
|
|
// String nowTaskInfo = list2.get(0).getName();
|
|
// if ("技术标准起草".equals(nowTaskInfo) && "0".equals(oaFlag)) {
|
|
// // 再次发送待办
|
|
// logger.info("============再次发送待办的企标计划" + esRevisePlanDTO.getEsName() +"===========");
|
|
// sendOATodo(list2.get(0));
|
|
//
|
|
// // 更新 状态为待办
|
|
// esPrcRelationService.modifyEsPrcRelation(esId, null, "1", null);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// logger.info("============企标计划定时任务结束===========");
|
|
// }
|
|
// }
|
|
|
|
@Scheduled(cron = "0 0 2 * * ?") //每天的凌晨2点执行
|
|
@Async
|
|
public void SchedulingTaskInfo() {
|
|
if(isNotScheduled) {
|
|
logger.info("============企标计划定时任务开始===========");
|
|
LawsUserInfoService lawsUserInfoService = SpringContextUtil.getBean(LawsUserInfoService.class);
|
|
IEsPrcRelationService esPrcRelationService = SpringContextUtil.getBean(IEsPrcRelationService.class);
|
|
TaskService taskService = SpringContextUtil.getBean(TaskService.class);
|
|
|
|
List<EsRevisePlanDTO> esRevisePlanDTOList = lawsUserInfoService.getAllPlansByWk(null); // 查询 制定中,修订中的企标计划
|
|
//esRevisePlanDTOList 如果 计划标准初稿时间前一个月的企标计划 以前发送过,
|
|
if(!esRevisePlanDTOList.isEmpty()){
|
|
// 三天时间的时间戳 86400000 * 3
|
|
long threeDay = 3 * 24 * 60 * 60 * 1000L; //3天
|
|
for (EsRevisePlanDTO data : esRevisePlanDTOList) {
|
|
if(StringUtils.isNotBlank(data.getOaIsSend()) && data.getOaIsSend().equals("1")){
|
|
//等于1 则证明已经发送了 三十天的OA信息 判断是否是已经发送三天 如果是 则撤回发送
|
|
//只撤回一个月前发送的 发布时间-当前时间 相比,小于3天(包含负的),证明是最近3天发送的数据,不撤回
|
|
// 发布时间
|
|
long publishTime = data.getReleaseTime().getTime();
|
|
long time = new Date().getTime();
|
|
long outcomeTime = publishTime - time;
|
|
if(outcomeTime < threeDay){
|
|
continue;
|
|
}
|
|
if(data.getOaDateIime()!=null){
|
|
long curTimestamp = new Date().getTime();
|
|
long oaTime = data.getOaDateIime().getTime();
|
|
long diffTimpstamp = curTimestamp - oaTime;
|
|
if( diffTimpstamp >= threeDay){
|
|
//证明已经过了三天 则发送撤回信息
|
|
List<EsPrcRelation> esPrcRelationList = esPrcRelationService.list(data.getId());
|
|
if (!esPrcRelationList.isEmpty()) {
|
|
EsPrcRelation esPrcRelation = esPrcRelationList.get(0);
|
|
String esId = esPrcRelation.getEsId();
|
|
lawsUserInfoService.updateEsRevisePlan(esId, new Date(),"0");
|
|
if(StringUtils.isNotBlank(esPrcRelation.getPrcId())) {
|
|
logger.info("============撤销OA待办消息===========");
|
|
webServiceOAService.deleteOAByPid(esPrcRelation.getPrcId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 计划标准初稿时间前(30天)的企标计划
|
|
SimpleDateFormat sdfQuery = new SimpleDateFormat("yyyy-MM-dd");
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.add(Calendar.DATE,30);
|
|
long TodayTime = new Date().getTime();
|
|
List<EsRevisePlanDTO> lastOneMonthEsRevisePlanDTOList = new ArrayList<>();
|
|
if(esRevisePlanDTOList!=null) {
|
|
|
|
for (EsRevisePlanDTO data : esRevisePlanDTOList) {
|
|
if (data.getDraftTime() != null) {
|
|
//当前时间 是不是在 发布时间的一个月内
|
|
long time = data.getDraftTime().getTime();
|
|
//最后的时间-三十天前的时间
|
|
long outcome = TodayTime + 30 * 24 * 60 * 60 * 1000L;
|
|
//初稿时间如果比当前时间小 则证明是过期的
|
|
if(time > TodayTime){
|
|
//今+30大于初
|
|
if(time <= outcome){
|
|
lastOneMonthEsRevisePlanDTOList.add(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (!lastOneMonthEsRevisePlanDTOList.isEmpty()) {
|
|
for (EsRevisePlanDTO esRevisePlanDTO : lastOneMonthEsRevisePlanDTOList) {
|
|
List<EsPrcRelation> esPrcRelationList = esPrcRelationService.list(esRevisePlanDTO.getId());
|
|
if (esPrcRelationList.isEmpty()) {
|
|
continue;
|
|
}
|
|
String esId = esPrcRelationList.get(0).getEsId();
|
|
String prcIdGk = esPrcRelationList.get(0).getPrcIdGk();
|
|
String oaFlag = esPrcRelationList.get(0).getOaFlag();
|
|
// 判断对应 管控流程是否还在 技术标准起草节点, 且之前点过接受任务
|
|
if (StringUtils.isNotBlank(prcIdGk)) {
|
|
List<Task> processlist = taskService.createTaskQuery().processInstanceId(prcIdGk).active().list();
|
|
if (!processlist.isEmpty()) {
|
|
// String nowTaskInfo = processlist.get(0).getName();
|
|
if ("0".equals(oaFlag) && !esRevisePlanDTO.getOaIsSend().equals("1")) {
|
|
// 再次发送待办
|
|
this.sendOATodo(processlist.get(0));
|
|
// 更新 状态为待办
|
|
esPrcRelationService.modifyEsPrcRelation(esId, null, "1", null);
|
|
//存储 OA发的时间 和 修改是否发送过
|
|
lawsUserInfoService.updateEsRevisePlan(esId, new Date(), "1");
|
|
logger.info("============再次发送待办的企标计划" + esRevisePlanDTO.getEsName() + "===========");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
logger.info("============企标计划定时任务结束===========");
|
|
}
|
|
}
|
|
|
|
public void sendOATodo(Task delegateTask) {
|
|
IBusProcessNewService busBean = SpringContextUtil.getBean(IBusProcessNewService.class);
|
|
QueryWrapper busProcessNewQueryWrapper = new QueryWrapper<BusProcessNew>();
|
|
busProcessNewQueryWrapper.eq("P_ID",delegateTask.getProcessInstanceId());
|
|
busProcessNewQueryWrapper.eq("USER_ID",delegateTask.getAssignee());
|
|
busProcessNewQueryWrapper.isNull("TASK_ID");
|
|
List<BusProcessNew> list = busBean.list(busProcessNewQueryWrapper);
|
|
if(!list.isEmpty()) {
|
|
BusProcessNew busProcessNew = list.get(0);
|
|
busProcessNew.setTaskId(delegateTask.getId());
|
|
busBean.saveOrUpdate(busProcessNew);
|
|
|
|
CreateMQService oaService = SpringContextUtil.getBean(CreateMQService.class);
|
|
// 发送 oa 待办 设置 跳转页面 router ? 后面流程类型
|
|
busProcessNew.setLink("qbzxdjhgkStep6?prcType=25");
|
|
busProcessNew.setTaskInfo(delegateTask.getName());
|
|
oaService.sendTodoMq(busProcessNew);
|
|
}
|
|
|
|
}
|
|
}
|