|
|
@@ -0,0 +1,114 @@
|
|
|
+package com.ruoyi.framework.task;
|
|
|
+
|
|
|
+import com.github.stuxuhai.jpinyin.PinyinFormat;
|
|
|
+import com.github.stuxuhai.jpinyin.PinyinHelper;
|
|
|
+import com.ruoyi.common.sendEmail.IMailService;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.SpringContextUtils;
|
|
|
+import com.ruoyi.framework.web.controller.BaseController;
|
|
|
+import com.ruoyi.project.pssr.domain.TPssrAboveall;
|
|
|
+import com.ruoyi.project.pssr.domain.TPssrApprove;
|
|
|
+import com.ruoyi.project.pssr.domain.TPssrSubcontent;
|
|
|
+import com.ruoyi.project.pssr.service.ITPssrAboveallService;
|
|
|
+import com.ruoyi.project.pssr.service.ITPssrApproveService;
|
|
|
+import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
|
|
|
+import com.ruoyi.project.system.domain.SysUser;
|
|
|
+import com.ruoyi.project.system.service.ISysUserService;
|
|
|
+import org.activiti.engine.ProcessEngine;
|
|
|
+import org.activiti.engine.ProcessEngines;
|
|
|
+import org.activiti.engine.task.Task;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@Component("pssrTodoTask")
|
|
|
+public class PssrTodoTask extends BaseController {
|
|
|
+ @Autowired
|
|
|
+ private ITPssrAboveallService tPssrAboveallService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITPssrSubcontentService tPssrSubcontentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITPssrApproveService tPssrApproveService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ public void execute() {
|
|
|
+
|
|
|
+ IMailService mailService = (IMailService) SpringContextUtils.getBean("mailService");
|
|
|
+ try {
|
|
|
+ String[] processDefinitionKeys = new String[]{"pssr1confirm", "pssr2confirm", "pssr3confirm", "pssrMgrConfirm"};
|
|
|
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
|
|
+ List<Task> taskList = processEngine.getTaskService() // 获取任务Service
|
|
|
+ .createTaskQuery() // 创建查询对象
|
|
|
+ .processDefinitionKeyIn(Arrays.asList(processDefinitionKeys)) // 根据流程定义Key列表查询
|
|
|
+ .orderByTaskCreateTime()
|
|
|
+ .desc()
|
|
|
+ .list(); // 返回结果列表
|
|
|
+ Set<String> userIds = new HashSet<>();
|
|
|
+ for (Task task : taskList) {
|
|
|
+ String processId = task.getProcessInstanceId();
|
|
|
+ TPssrApprove tPssrApprove = new TPssrApprove();
|
|
|
+ tPssrApprove.setProcessId(processId);
|
|
|
+ for (TPssrApprove approve : tPssrApproveService.selectTPssrApproveList(tPssrApprove)) {
|
|
|
+ TPssrAboveall aboveall;
|
|
|
+ if (approve.getAboveallId() != null) {
|
|
|
+ aboveall = tPssrAboveallService.selectTPssrAboveallById(approve.getAboveallId());
|
|
|
+ } else {
|
|
|
+ TPssrSubcontent subcontent = tPssrSubcontentService.selectTPssrSubcontentById(approve.getSubId());
|
|
|
+ aboveall = tPssrAboveallService.selectTPssrAboveallById(subcontent.getAboveallId());
|
|
|
+ }
|
|
|
+ if (aboveall.getDrivingTime() != null) {
|
|
|
+ String datePoor = DateUtils.getDatePoor(aboveall.getDrivingTime(), DateUtils.getNowDate());
|
|
|
+ int day = Integer.parseInt(datePoor.substring(0,datePoor.indexOf("天")));
|
|
|
+ logger.info("==========================日期差:{}",day);
|
|
|
+ if (day <= 7) {
|
|
|
+ String userId = task.getAssignee();
|
|
|
+ userIds.add(userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String userId : userIds) {
|
|
|
+ SysUser user = sysUserService.selectUserById(Long.valueOf(userId));
|
|
|
+ //logger.info("==========================任务列表:{}",taskList);
|
|
|
+ String username = user.getNickName();
|
|
|
+ String loginName = user.getUserName();
|
|
|
+ String usernameEN = PinyinHelper.convertToPinyinString(username, " ", PinyinFormat.WITHOUT_TONE);
|
|
|
+ String email = user.getEmail();
|
|
|
+ String start = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title></title></head><body><div style=\"background-color:#ECECEC; padding: 35px;\">" +
|
|
|
+ "<table cellpadding=\"0\" align=\"center\"" +
|
|
|
+ "style=\"width: 600px; margin: 0px auto; text-align: left; position: relative; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; font-size: 14px; font-family:微软雅黑, 黑体; line-height: 1.5; box-shadow: rgb(153, 153, 153) 0px 0px 5px; border-collapse: collapse; background-position: initial initial; background-repeat: initial initial;background:#fff;\">" +
|
|
|
+ "<tbody><tr><th valign=\"middle\" style=\"height: 25px; line-height: 25px; padding: 15px 35px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #42a3d3; background-color: #49bcff; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px;\">" +
|
|
|
+ "<font face=\"微软雅黑\" size=\"5\" style=\"color: rgb(255, 255, 255); \">PSSR任务到期提醒</font><font face=\"微软雅黑\" size=\"3\" style=\"color: rgb(255, 255, 255); \"></font></th></tr>";
|
|
|
+ //表html中间内容
|
|
|
+ String center = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
|
|
|
+ "<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
|
+ "亲爱的 username(loginName)</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
|
+ "<p>您的PSSR检查有未完成的任务,请在预计开车日期前处理。<br>" +
|
|
|
+ "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/#/approve/pending\">我的待办</a>查看。<br>" +
|
|
|
+ "<p align=\"right\">date</p>" +
|
|
|
+ "<div style=\"width:700px;margin:0 auto;\">" +
|
|
|
+ "<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
|
|
|
+ "<p>此为系统邮件,请勿回复</p>" +
|
|
|
+ "</div></div></div></td></tr>";
|
|
|
+ String one = center.replaceFirst("username", username);
|
|
|
+ String three = one.replace("loginName", loginName);
|
|
|
+ String result = three.replaceFirst("date", DateUtils.getDate());
|
|
|
+ String end = "</tbody></table></div></body></html>";
|
|
|
+ //拼接html
|
|
|
+ String html = start + result + end;
|
|
|
+ logger.info("html:" + html);
|
|
|
+ mailService.sendHtmlMail(email, " PSSR任务到期提醒", html);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|