Quellcode durchsuchen

SAI开项申请流程:邮件发送

wangggziwen vor 2 Jahren
Ursprung
Commit
ad1ce338c5

+ 93 - 0
master/src/main/java/com/ruoyi/common/thread/sai/SaiApplyMailThread.java

@@ -0,0 +1,93 @@
+package com.ruoyi.common.thread.sai;
+
+import com.github.stuxuhai.jpinyin.PinyinException;
+import com.github.stuxuhai.jpinyin.PinyinFormat;
+import com.github.stuxuhai.jpinyin.PinyinHelper;
+import com.ruoyi.common.sendEmail.IMailService;
+import com.ruoyi.project.production.domain.TSaiApply;
+import com.ruoyi.project.system.domain.SysMessage;
+import com.ruoyi.project.system.service.ISysMessageService;
+import org.activiti.engine.task.Task;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * SAI开项申请流程邮件通知线程
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2023/04/10 10:35:50
+ */
+public class SaiApplyMailThread implements Runnable {
+
+    private IMailService mailService;
+    private ISysMessageService sysMessageService;
+    private SysMessage message;
+    private String email;
+    private Task task;
+    private TSaiApply tSaiApply;
+    private String staffName;
+    private String staffNameEN;
+
+    public SaiApplyMailThread() {}
+
+    public SaiApplyMailThread(IMailService mailService, ISysMessageService sysMessageService, SysMessage message, String email, Task task, TSaiApply tSaiApply, String staffName) throws PinyinException {
+        this.mailService = mailService;
+        this.sysMessageService = sysMessageService;
+        this.email = email;
+        this.message = message;
+        this.task = task;
+        this.tSaiApply = tSaiApply;
+        this.staffName = staffName;
+        this.staffNameEN = PinyinHelper.convertToPinyinString(staffName.trim(), " ", PinyinFormat.WITHOUT_TONE);
+    }
+
+    @Override
+    public void run() {
+        this.sendMail();
+        sysMessageService.insertSysMessage(message);
+    }
+
+    private void sendMail() {
+        String jumpUrl = "/production/sai/apply";
+        //写html开始内容
+        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); \">CPMS管理系统 </font><font face=\"微软雅黑\" size=\"3\" style=\"color: rgb(255, 255, 255); \">CPMS System</font></th></tr>";
+        //表html中间内容
+        String prime = "";
+        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\">" +
+                "亲爱的staffName</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
+                "Dear staffNameEN</font></font></h2>" +
+                "<p>您有新的SAI开项申请待办任务,详情如下:<br>" +
+                "You have a new to-do task:<br>" +
+                "流程编号:<b>processId</b><br>" +
+                "任务名称:<b>taskName</b><br>" +
+                "问题描述:<b>taskDescription</b><br>" +
+                "申请时间:<b>taskApplyDate</b><br>" +
+                "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#jumpUrl\">CPMS管理系统</a>查看。<br>" +
+                "Please log in the <a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#jumpUrl\">CPMS</a> to handle it.</p>" +
+                "<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>此为系统邮件,请勿回复<br>This e-Mail is an automatic reminder sent by CPMS, please do not reply</p>" +
+                "</div></div></div></td></tr>";
+        String one = center.replaceFirst("staffName", staffName);
+        String two = one.replaceFirst("staffNameEN", staffNameEN);
+        String three = two.replaceFirst("processId", tSaiApply.getProcessId());
+        String four = three.replaceFirst("taskName", task.getName());
+        String five = four.replaceFirst("taskDescription", tSaiApply.getDescription());
+        String six = five.replaceFirst("taskApplyDate", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(tSaiApply.getApplyDate()));
+        String result = six.replaceFirst("date", String.valueOf(new Date())).replaceFirst("jumpUrl",jumpUrl).replaceFirst("jumpUrl",jumpUrl);
+        prime = prime + result;
+        //写html结尾内容
+        String end = "</tbody></table></div></body></html>";
+        //拼接html
+        String html = start + prime + end;
+        mailService.sendHtmlMail(email, "CPMS:您有新的SAI开项申请待办任务", html);
+    }
+}

+ 53 - 1
master/src/main/java/com/ruoyi/project/production/controller/TSaiApplyController.java

@@ -1,6 +1,10 @@
 package com.ruoyi.project.production.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.github.stuxuhai.jpinyin.PinyinException;
+import com.ruoyi.common.sendEmail.IMailService;
+import com.ruoyi.common.thread.Trainning.MeetingInvitationMailThread;
+import com.ruoyi.common.thread.sai.SaiApplyMailThread;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.file.ExcelUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -11,6 +15,8 @@ import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.framework.web.page.TableDataInfo;
 import com.ruoyi.project.approve.damain.DevTask;
+import com.ruoyi.project.plant.domain.TStaffmgr;
+import com.ruoyi.project.plant.service.ITStaffmgrService;
 import com.ruoyi.project.process.domain.TMoc;
 import com.ruoyi.project.production.controller.vo.SaiApplyExportVO;
 import com.ruoyi.project.production.domain.TSaiApply;
@@ -20,11 +26,13 @@ import com.ruoyi.project.production.service.ITSaiApproveFileService;
 import com.ruoyi.project.sems.domain.TApproverFile;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysDictData;
+import com.ruoyi.project.system.domain.SysMessage;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.project.system.service.ISysDeptService;
 import com.ruoyi.project.system.service.ISysDictTypeService;
+import com.ruoyi.project.system.service.ISysMessageService;
 import com.ruoyi.project.system.service.ISysUserService;
 import org.activiti.engine.ProcessEngine;
 import org.activiti.engine.ProcessEngines;
@@ -42,7 +50,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.validation.constraints.Email;
+import javax.validation.constraints.Size;
 import java.io.IOException;
+import java.sql.Array;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -77,6 +88,15 @@ public class TSaiApplyController extends BaseController
     @Autowired
     private ITSaiApproveFileService saiApproveFileService;
 
+    @Autowired
+    private ITStaffmgrService staffmgrService;
+
+    @Autowired
+    private ISysMessageService sysMessageService;
+
+    @Autowired
+    private IMailService mailService;
+
     /**
      * 查询SAI开项管理列表
      */
@@ -417,7 +437,7 @@ public class TSaiApplyController extends BaseController
     @Log(title = "SAI开项管理申请处理", businessType = BusinessType.UPDATE)
     @RepeatSubmit
     @PutMapping("/handle")
-    public AjaxResult handle(@RequestBody DevTask devTask) {
+    public AjaxResult handle(@RequestBody DevTask devTask) throws PinyinException {
         //更新数据
         TSaiApply form = devTask.getSaiApply();
         //使用任务服务完成任务(提交任务)
@@ -496,6 +516,7 @@ public class TSaiApplyController extends BaseController
                 .claim(taskId, getUserId().toString());
         taskService.addComment(taskId, processInstancesId, devTask.getComment());
         taskService.complete(taskId, param);
+        Task nextHandlerTask = null;
         // 标记taskId、TaskName
         if (nextHandler != null) {
             List<Task> list = processEngine.getTaskService()//获取任务service
@@ -505,6 +526,37 @@ public class TSaiApplyController extends BaseController
                 if (form.getProcessId().equals(t.getProcessInstanceId())) {
                     form.setTaskId(t.getId());
                     form.setTaskName(t.getName());
+                    nextHandlerTask = t;
+                }
+            }
+        }
+        if (nextHandler != null) {
+            String[] split = null;
+            if (nextHandler.indexOf(",") != -1) {
+                split = nextHandler.split(",");
+            } else {
+                split = new String[1];
+                split[0] = nextHandler;
+            }
+            for (int i = 0; i < split.length; i++) {
+                if (!split[i].equals("20276")) {    // 张力飞不发邮件
+                    SysUser sysUser = userService.selectUserById(Long.parseLong(split[i]));
+                    String staffId = sysUser.getStaffId();
+                    TStaffmgr staffmgr = staffmgrService.selectTStaffmgrByStaffId(staffId);
+                    String staffName = staffmgr.getName();
+                    String email = staffmgr.getMail();
+                    if (email != null) {
+                        // 系统通知
+                        SysMessage message = new SysMessage();
+                        message.setUserId(Long.parseLong(split[i]));
+                        message.setMsgTitle("您有一条系统消息");
+                        message.setMsgContent("您有一条SAI开项申请消息待查看");
+                        // 发送邮件
+                        SaiApplyMailThread saiApplyMailThread = new SaiApplyMailThread(
+                                mailService, sysMessageService, message, email, nextHandlerTask, form, staffName);
+                        Thread thread = new Thread(saiApplyMailThread);
+                        thread.start();
+                    }
                 }
             }
         }