package com.adc.da.Timer; import com.adc.da.FeignClient.workFlowFeignClient; import com.adc.da.common.BusMes; import com.adc.da.common.BusProcessName; import com.adc.da.common.BusProcessNew; import com.adc.da.common.Wrapper; import com.adc.da.http.ResponseMessage; import com.adc.da.sys.common.EmailUtils; import com.adc.da.sys.entity.UserEO; import com.adc.da.sys.service.IUserEOService; import com.adc.da.workFlow.controller.WorkFlowController; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @Description: 流程相关定时任务 * @Author: yangxuenan * date: 2020/12/11 10:18 */ @Component @EnableScheduling @Slf4j public class ProcessTimer { @Autowired private workFlowFeignClient workFlowFeignClient; @Autowired private EmailUtils mailUtil; @Autowired private IUserEOService userEOService; @Autowired private WorkFlowController workFlowController; /*** * @Description: 自动催办,任务截至时间前3天开始每天催办 * @Author: yangxuenan * @Date: 2020/12/11 10:29 * @Param: [] * @Return: void */ @Scheduled(cron = "0 30-30 0 * * ? ")//每天凌晨半点执行 // @Scheduled(cron = "*/5 * * * * ?")//每5秒执行一次 // @Scheduled(cron = "0/20 * * * * ?") public void urging() { List busProcessNames = workFlowFeignClient.queryBusProcessNameForEnd(null); if (null != busProcessNames && 0 < busProcessNames.size()) { for (BusProcessName busProcessName : busProcessNames) { String type = busProcessName.getPrcType(); Integer typeInt = 99; if (StringUtils.isNotEmpty(type)) { typeInt = Integer.valueOf(type); } type = chooseType(typeInt, type); UserEO userEO = userEOService.selectByPrimaryKey(busProcessName.getCreatUserName()); String[] array = userEO.getEmail().split(","); String overTime = busProcessName.getOverTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date dateTime = null; Integer num = 3; try { dateTime = simpleDateFormat.parse(overTime); Date now = new Date(); long daysBetween = (dateTime.getTime() - now.getTime() + 1000000) / (60 * 60 * 24 * 1000); num = Integer.valueOf(String.valueOf(daysBetween)); } catch (ParseException e) { SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); try { dateTime = simpleDateFormat1.parse(overTime); Date now = new Date(); long daysBetween = (dateTime.getTime() - now.getTime() + 1000000) / (60 * 60 * 24 * 1000); num = Integer.valueOf(String.valueOf(daysBetween)); } catch (ParseException e1) { e.getMessage(); } } String msg = "您好,[" + busProcessName.getPrcNum() + "]-[" + busProcessName.getPrcName() + "] 您有待办任务未及时办理,距离截至日期还有[" + String.valueOf(num) + "]天 请及时办理,请登录全球标准法规管理系统 ( http://39.98.140.126:10005/#/login ) 办理:链接 ( http://39.98.140.126:10005/#/processCenter?tabsName=ProcessCenter ) 。\n" + " ——来自 全球标准法规管理系统"; String title = "GSRM——【待办任务】[" + type + "] 您有未完成的待办任务"; mailUtil.sendMsgFeign(array, title, msg); } } } public String chooseType(Integer typeInt, String type) { switch (typeInt) { case 1: type = "法规入库及评估流程"; break; case 2: type = "标准法规技术储备评估流程"; break; case 3: type = "项目评估流程"; break; case 4: type = "企标制修订流程"; break; case 5: type = "未符合项跟踪流程"; break; case 6: type = "企标制修订申请流程"; break; case 7: type = "企标废止流程"; break; case 8: type = "企标延期制修订申请流程"; break; case 9: type = "标准采购流程"; break; case 10: type = "工作组会前申请流程"; break; case 11: type = "企标制修订评估流程"; break; case 12: type = "企标勘误流程"; break; case 13: type = "行政管理要求评估流程"; break; case 14: type = "政策入库及评估流程"; break; case 15: type = "标准翻译申请流程"; break; case 16: type = "工作组会后管理流程"; break; case 17: type = "企标备案流程"; break; case 18: type = "标准法规清单发布/更新流程"; break; case 19: type = "企标复审流程"; break; default: break; } return type; } @Scheduled(cron = "0 0 10 * * ? ")//每天十点执行 // @Scheduled(cron = "*/20 * * * * ? ")//每天十点执行 public void everyDayTenOlockScan() { List busProcessNews=new ArrayList<>(); busProcessNews=workFlowFeignClient.everyDayTenOlock(); if (!busProcessNews.isEmpty()){ for (BusProcessNew bus:busProcessNews) { JSONObject jsonObject= JSON.parseObject(bus.getMesg()); jsonObject.put("auto","1"); ResponseMessage responseMessage = workFlowController.startProcessNew("19",jsonObject.getString("revisionId"),null); BusMes busMes=new BusMes(); busMes.setTaskIds(String.valueOf(responseMessage.getData())); busMes.setJson(jsonObject.toJSONString()); busMes.setUserId(jsonObject.getString("revisionId")); Wrapper wrapper=workFlowFeignClient.completeTaskByUserId(busMes); log.info("政策课题组会后流程已发起"); } } } @Scheduled(cron = "0 0 10 * * ? ")//每天十点执行 // @Scheduled(cron = "0 0 0/1 * * ? ")//每天十点执行 // @Scheduled(cron = "*/40 * * * * ? ")//20s public void everyDayTenOlockScanSAM() { List busProcessNews=new ArrayList<>(); busProcessNews=workFlowFeignClient.everyDayTenOlockSAM(); if (!busProcessNews.isEmpty()){ for (BusProcessNew bus:busProcessNews) { JSONObject jsonObject= JSON.parseObject(bus.getMesg()); String taskInfo = bus.getTaskInfo(); String result = jsonObject.getJSONObject("roleList").getString("dockUser"); result = result.split(",")[0]; jsonObject.put("member",result); if(taskInfo.equals("标准化活动参会流程-流程结束")){ jsonObject.put("auto","1"); ResponseMessage responseMessage = workFlowController.startProcessNew("22",result,null); BusMes busMes=new BusMes(); busMes.setTaskIds(String.valueOf(responseMessage.getData())); busMes.setJson(jsonObject.toJSONString()); busMes.setUserId(result); Wrapper wrapper=workFlowFeignClient.completeTaskByUserId(busMes); System.out.println("标准化活动会后流程自动发起"); } } } } public static void main(String[]args){ ProcessTimer processTimer = new ProcessTimer(); processTimer.everyDayTenOlockScan(); processTimer.everyDayTenOlockScanSAM(); } }