|
|
@@ -0,0 +1,184 @@
|
|
|
+package com.lc.ibps.platform.plan.job;
|
|
|
+
|
|
|
+import com.lc.ibps.base.core.util.AppUtil;
|
|
|
+import com.lc.ibps.base.core.util.BeanUtils;
|
|
|
+import com.lc.ibps.base.framework.id.UniqueIdUtil;
|
|
|
+import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
+import com.lc.ibps.bpmn.api.constant.BpmConstants;
|
|
|
+import com.lc.ibps.cloud.message.util.MessageQueueProductorUtil;
|
|
|
+import com.lc.ibps.components.quartz.BaseJob2;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author gaozl
|
|
|
+ */
|
|
|
+public class ToDoMessagePushJob extends BaseJob2 {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ToDoMessagePushJob.class);
|
|
|
+
|
|
|
+ private final ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+
|
|
|
+ String sql = "select t.subject_,t.id_,t.create_time_,t.proc_def_name_,t.name_,t.status_,c.executor_ from ibps_bpm_tasks t " +
|
|
|
+ "left join ibps_bpm_task_assign c on t.id_=c.task_id_";
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Map<String, Object>> taskList = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if (BeanUtils.isNotEmpty(taskList)) {
|
|
|
+ try{
|
|
|
+ // 待办处理后 删除过期事务表数据
|
|
|
+ commonDao.execute("delete from t_gqswb where shi_wu_id_ not in (select id_ from ibps_bpm_tasks)");
|
|
|
+
|
|
|
+ for (Map<String, Object> task : taskList) {
|
|
|
+ // 0-未超时,不提醒 1-已超时 2-即将超时
|
|
|
+ int send = 0;
|
|
|
+ List<String> receiver = new ArrayList<>();
|
|
|
+ receiver.add(task.get("executor_").toString());
|
|
|
+ String subject = task.get("subject_").toString();
|
|
|
+ String createTime = task.get("create_time_").toString();
|
|
|
+ String taskId = task.get("id_").toString();
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+ String[] parts = subject.split("#");
|
|
|
+ for (String part : parts) {
|
|
|
+ if (part.contains("\"timeLimit\"")) {
|
|
|
+ try{
|
|
|
+ String timeObj = part.split(",")[0];
|
|
|
+ String timeLimit = timeObj.substring(timeObj.indexOf(":")+1).replace("\"", "");
|
|
|
+ int day = Integer.parseInt(timeLimit);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date createDate = sdf.parse(createTime);
|
|
|
+ calendar.setTime(createDate);
|
|
|
+ calendar.add(Calendar.DATE, day);
|
|
|
+ Date currentDate = new Date();
|
|
|
+ if (calendar.getTime().compareTo(currentDate) > 0) {
|
|
|
+ // 判断是否即将超时(创建时间和当前时间的间隔小于等于一天)
|
|
|
+ long timeDifference = currentDate.getTime() - createDate.getTime();
|
|
|
+ long oneDayInMillis = 24 * 60 * 60 * 1000;
|
|
|
+ if (timeDifference >= (day - 1) * oneDayInMillis) {
|
|
|
+ send = 2;
|
|
|
+ content = new StringBuilder("事务即将超时提醒");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ send = 1;
|
|
|
+ content = new StringBuilder("事务超时提醒");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ send = 0;
|
|
|
+ }
|
|
|
+ } else if (part.contains("\"loseDate\"")) {
|
|
|
+ try{
|
|
|
+ String timeObj = part.split(",")[0];
|
|
|
+ String loseDate = timeObj.substring(timeObj.indexOf(":")+1).replace("\"", "");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date deadline = sdf.parse(loseDate);
|
|
|
+ Date currentTime = new Date();
|
|
|
+ if (currentTime.after(deadline)) {
|
|
|
+ send = 1;
|
|
|
+ content = new StringBuilder("事务超时提醒");
|
|
|
+ }else if ((deadline.getTime() - currentTime.getTime()) <= (7 * 24 * 60 * 60 * 1000)) {
|
|
|
+ send = 2;
|
|
|
+ content = new StringBuilder("事务即将超时提醒");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ send = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (send !=0){
|
|
|
+ String theme = content.toString();
|
|
|
+ subject = subject.substring(0, subject.lastIndexOf("#")).trim();
|
|
|
+ if (send ==1){
|
|
|
+ subject = subject +";已超时,请及时处理!";
|
|
|
+ }else {
|
|
|
+ subject = subject +";即将超时,请及时处理!";
|
|
|
+ }
|
|
|
+ // 发送消息
|
|
|
+ Map<String, Object> vars = new HashMap<>();
|
|
|
+ vars.put("taskId",taskId);
|
|
|
+ MessageQueueProductorUtil.send(BpmConstants.CUR_USER , null , "inner" , receiver,null , theme, subject, null, null, vars);
|
|
|
+ //MessageQueueProductorUtil.send("inner" , receiver ,null , theme , subject ,null );
|
|
|
+
|
|
|
+ // 添加过期事务表数据
|
|
|
+ Map<String,Object> map = commonDao.queryOne("select shi_wu_id_ from t_gqswb where shi_wu_id_ = '"+ taskId +"'");
|
|
|
+ if (BeanUtils.isEmpty(map)) {
|
|
|
+ addGqswData(task , taskId , createTime , send);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("首页待办超时提醒消息发送异常!,异常信息:{}",e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addGqswData(Map<String, Object> task, String taskId , String createTime , int send) throws Exception {
|
|
|
+ String wanZhengMingCh = task.get("subject_").toString();
|
|
|
+ String procDefName = task.get("proc_def_name_").toString();
|
|
|
+ String name = task.get("name_").toString();
|
|
|
+ String status = task.get("status_").toString();
|
|
|
+ Map<String, Object> gqsw = new HashMap<>();
|
|
|
+ gqsw.put("id_", UniqueIdUtil.getId());
|
|
|
+ String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ gqsw.put("create_time_", currentTime);
|
|
|
+ gqsw.put("shi_wu_id_", taskId);
|
|
|
+ gqsw.put("wan_zheng_ming_ch",wanZhengMingCh);
|
|
|
+ gqsw.put("shi_wu_shuo_ming_",wanZhengMingCh.substring(0, wanZhengMingCh.lastIndexOf("#")).trim());
|
|
|
+ gqsw.put("shi_wu_ming_cheng", procDefName);
|
|
|
+ gqsw.put("shi_wu_zhuang_tai", "待"+name);
|
|
|
+ gqsw.put("shi_wu_lei_xing_", status);
|
|
|
+
|
|
|
+ String userSql = "select ex.executor_,e.name_ from ibps_bpm_task_assign ex left join ibps_party_employee e on ex.executor_ = e.id_ where task_id_='"+ taskId +"'";
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Map<String, Object>> executor = (List<Map<String, Object>>) commonDao.query(userSql);
|
|
|
+ String executorId = executor.stream().map(item -> item.get("executor_").toString()).collect(Collectors.joining(", "));
|
|
|
+ String executorName = executor.stream().map(item -> item.get("name_").toString()).collect(Collectors.joining(", "));
|
|
|
+ gqsw.put("chu_li_ren_id_", executorId);
|
|
|
+ gqsw.put("chu_li_ren_ming_", executorName);
|
|
|
+
|
|
|
+ String deptId = getDeptId(wanZhengMingCh);
|
|
|
+ gqsw.put("bu_men_id_", deptId );
|
|
|
+
|
|
|
+ Map<String,Object> manager = commonDao.queryOne("select managerId,positionName from v_user_manager where positionId='"+ deptId +"'");
|
|
|
+ if (BeanUtils.isNotEmpty(manager)){
|
|
|
+ gqsw.put("zhu_guan_id_", manager.get("managerId") );
|
|
|
+ gqsw.put("bu_men_", manager.get("positionName") );
|
|
|
+ }else {
|
|
|
+ gqsw.put("zhu_guan_id_", "" );
|
|
|
+ gqsw.put("bu_men_", "" );
|
|
|
+ }
|
|
|
+
|
|
|
+ gqsw.put("bian_zhi_shi_jian",createTime);
|
|
|
+ gqsw.put("ti_xing_ci_shu_", 1);
|
|
|
+ gqsw.put("duan_xin_ci_shu_", 0);
|
|
|
+ gqsw.put("ti_xing_shi_jian_", currentTime);
|
|
|
+
|
|
|
+ if (send == 1){
|
|
|
+ gqsw.put("guo_qi_zhuang_tai", "overtime");
|
|
|
+ }else {
|
|
|
+ gqsw.put("guo_qi_zhuang_tai", "soon");
|
|
|
+ }
|
|
|
+
|
|
|
+ commonDao.execute(this.buildInsertSql(gqsw, "t_gqswb"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDeptId(String subject) {
|
|
|
+ String[] deptStr = subject.split(",");
|
|
|
+ String deptId = "";
|
|
|
+ for (String depts : deptStr) {
|
|
|
+ if (depts.contains("\"dept\"")) {
|
|
|
+ deptId = depts.substring(depts.indexOf(":")+1).replace("\"", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return deptId;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|