|
@@ -1,7 +1,19 @@
|
|
package com.xxl.job.executor.service.jobhandler;
|
|
package com.xxl.job.executor.service.jobhandler;
|
|
|
|
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
|
+import com.jeeplus.domain.MyNoticeList;
|
|
|
|
+import com.jeeplus.domain.ProgramProjectListInfo;
|
|
|
|
+import com.jeeplus.flowable.feign.IAssessApi;
|
|
|
|
+import com.jeeplus.flowable.feign.IFlowableApi;
|
|
|
|
+import com.jeeplus.sys.feign.IUserApi;
|
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
+import com.xxl.job.executor.feign.AssessFeignApi;
|
|
|
|
+import com.xxl.job.executor.feign.UserFeignApi;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -12,7 +24,8 @@ import java.io.DataOutputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
-import java.util.Arrays;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -30,7 +43,6 @@ import java.util.concurrent.TimeUnit;
|
|
public class SampleXxlJob {
|
|
public class SampleXxlJob {
|
|
private static Logger logger = LoggerFactory.getLogger ( SampleXxlJob.class );
|
|
private static Logger logger = LoggerFactory.getLogger ( SampleXxlJob.class );
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 1、简单任务示例(Bean模式)
|
|
* 1、简单任务示例(Bean模式)
|
|
*/
|
|
*/
|
|
@@ -45,6 +57,141 @@ public class SampleXxlJob {
|
|
// default success
|
|
// default success
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 1、简单任务示例(Bean模式)
|
|
|
|
+ */
|
|
|
|
+ @XxlJob("projectArchiveTask")
|
|
|
|
+ public void projectArchiveTask() throws Exception {
|
|
|
|
+ System.out.println("进来了---");
|
|
|
|
+ String json = SpringUtil.getBean ( AssessFeignApi.class ).getOverdueFilingProjectList();
|
|
|
|
+ List<ProgramProjectListInfo> projectList = JSON.parseObject(json, new TypeReference<List<ProgramProjectListInfo>>() {});
|
|
|
|
+
|
|
|
|
+// List<ProgramProjectListInfo> projectList = pgProjectListService.getOverdueFilingProjectList();
|
|
|
|
+ //遍历查询的项目,对所有项目的归档状态进行调整。添加超期归档状态值(over_archive_status:0:未超期;1:已超期),归档状态,若是0或者空值则调整为6。若为其他值则不进行调整
|
|
|
|
+ for (ProgramProjectListInfo info : projectList) {
|
|
|
|
+ //判定是否以发起归档申请(即归档状态是否为空或者0)
|
|
|
|
+ String archiveStatus = "";
|
|
|
|
+ if(StringUtils.isBlank(info.getArchiveStatus()) || "0".equals(info.getArchiveStatus())){
|
|
|
|
+ archiveStatus = "6";
|
|
|
|
+ }else{
|
|
|
|
+ archiveStatus = info.getArchiveStatus();
|
|
|
|
+ }
|
|
|
|
+ //修改报告归档 归档状态信息
|
|
|
|
+ SpringUtil.getBean ( IAssessApi.class ).updateArchiveStatus(info.getArchiveId(),archiveStatus,"1");
|
|
|
|
+ //对数据进行发送通知
|
|
|
|
+ String taskName = null;
|
|
|
|
+ String titleStr = null;
|
|
|
|
+
|
|
|
|
+ //如果当前时间大于过期时间
|
|
|
|
+ //Date类的一个方法,如果info.getAdventDateDate()早于 new Date() 返回true,否则返回false
|
|
|
|
+ if(info.getAgreeTime().before(new Date())){
|
|
|
|
+ taskName = "评估-超期归档";
|
|
|
|
+ titleStr = "项目【"+ info.getName()+"】归档已超期。超期时间:"+dateToString(info.getAgreeTime()) +"。";
|
|
|
|
+ }else{
|
|
|
|
+ taskName = "评估-超期归档";
|
|
|
|
+ titleStr = "项目【"+ info.getName()+"】即将归档超期。超期时间:"+dateToString(info.getAgreeTime());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //计算两日期之间的天数
|
|
|
|
+ int interval = Integer.parseInt(this.getInterval(info.getAgreeTime(), new Date()));
|
|
|
|
+ if(interval > 0){
|
|
|
|
+ titleStr = titleStr + "已超期:" + interval + "天。请尽快归还";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Set<String> noticeUserSet = new HashSet<String>();
|
|
|
|
+ if(StringUtils.isNotBlank(info.getCreateBy())){
|
|
|
|
+
|
|
|
|
+ String byIdForXXL = SpringUtil.getBean(IUserApi.class).getByIdForXXL(info.getCreateBy());
|
|
|
|
+ UserDTO createUser = JSON.parseObject(byIdForXXL, new TypeReference<UserDTO>() {});
|
|
|
|
+// UserDTO createUser = SpringUtil.getBean ( IUserApi.class ).getById(info.getCreateBy());
|
|
|
|
+ if(null != createUser && StringUtils.isNotBlank(createUser.getId())){
|
|
|
|
+ noticeUserSet.add(createUser.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<String> noticeUserList = new ArrayList<String>(noticeUserSet);
|
|
|
|
+ if(noticeUserList.size()>0){
|
|
|
|
+ MyNoticeList myNotice = new MyNoticeList();
|
|
|
|
+ myNotice.setCreateById("1");
|
|
|
|
+ myNotice.setCreateTime(new Date());
|
|
|
|
+ myNotice.setUpdateById("1");
|
|
|
|
+ myNotice.setUpdateTime(new Date());
|
|
|
|
+ myNotice.setDelFlag(0);
|
|
|
|
+ //根据procInsId获取taskId
|
|
|
|
+ String currentTask = SpringUtil.getBean(IFlowableApi.class).getTaskIdByprocInstId(info.getProcInsId());
|
|
|
|
+ myNotice.setTaskId(currentTask);
|
|
|
|
+ myNotice.setDefId(info.getProcessDefinitionId());
|
|
|
|
+ myNotice.setTitle(titleStr);
|
|
|
|
+ myNotice.setTaskName(taskName);
|
|
|
|
+ myNotice.setLink("结束");
|
|
|
|
+ myNotice.setType("0");
|
|
|
|
+ myNotice.setCreateUser("管理员");
|
|
|
|
+ myNotice.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ for (String noticeUserId : noticeUserList) {
|
|
|
|
+ myNotice.setNoticeId(noticeUserId);
|
|
|
|
+ String byIdForXXL = SpringUtil.getBean(IUserApi.class).getByIdForXXL(info.getCreateBy());
|
|
|
|
+ UserDTO createUser = JSON.parseObject(byIdForXXL, new TypeReference<UserDTO>() {});
|
|
|
|
+ myNotice.setNoticeName(createUser.getName());
|
|
|
|
+ //根据taskName和通知人 查询重复数量
|
|
|
|
+ String myNoticeInfo = JSON.toJSONString(myNotice);
|
|
|
|
+ Map<String,String> map = new HashMap();
|
|
|
|
+ map.put("myNoticeInfo", myNoticeInfo);
|
|
|
|
+ String jsonInfo = SpringUtil.getBean(IFlowableApi.class).getRepetitionCountBymyNoticeTitle(map);
|
|
|
|
+ MyNoticeList repetitionCountBymyNotice = JSON.parseObject(jsonInfo, new TypeReference<MyNoticeList>() {});
|
|
|
|
+
|
|
|
|
+ if(null == repetitionCountBymyNotice){
|
|
|
|
+ // 生成id
|
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
+ myNotice.setId(id);
|
|
|
|
+ myNotice.setRepetitionCount(0);
|
|
|
|
+
|
|
|
|
+ myNoticeInfo = JSON.toJSONString(myNotice);
|
|
|
|
+ map.put("myNoticeInfo", myNoticeInfo);
|
|
|
|
+ SpringUtil.getBean ( IFlowableApi.class ).insertMyNotice(map);
|
|
|
|
+ }else{
|
|
|
|
+ myNotice.setId(repetitionCountBymyNotice.getId());
|
|
|
|
+ myNotice.setRepetitionCount(repetitionCountBymyNotice.getRepetitionCount()+1);
|
|
|
|
+
|
|
|
|
+ myNoticeInfo = JSON.toJSONString(myNotice);
|
|
|
|
+ map.put("myNoticeInfo", myNoticeInfo);
|
|
|
|
+ SpringUtil.getBean ( IFlowableApi.class ).updateMyNotice(map);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String dateToString(Date date) {
|
|
|
|
+ SimpleDateFormat sformat = new SimpleDateFormat("yyyy-MM-dd");//日期格式
|
|
|
|
+ return sformat.format(date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算两日期相差天数
|
|
|
|
+ * @param beginDate
|
|
|
|
+ * @param endDate
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public String getInterval(Date beginDate, Date endDate){
|
|
|
|
+ long day = 0;
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
+ try {
|
|
|
|
+ if(beginDate != null){
|
|
|
|
+ String begin = sdf.format(beginDate);
|
|
|
|
+ beginDate = sdf.parse(begin);
|
|
|
|
+ }
|
|
|
|
+ if(endDate!= null){
|
|
|
|
+ String end= sdf.format(endDate);
|
|
|
|
+ endDate= sdf.parse(end);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.getMessage();
|
|
|
|
+ }
|
|
|
|
+ day = (endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
|
|
|
|
+ return String.valueOf(day);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 2、分片广播任务
|
|
* 2、分片广播任务
|