Преглед изворни кода

SAI开项管理:到期邮件提醒

wangggziwen пре 2 година
родитељ
комит
5beb2d1a83

+ 90 - 0
master/src/main/java/com/ruoyi/common/thread/sai/SaiApplyDueMailThread.java

@@ -0,0 +1,90 @@
+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.SysUser;
+
+import javax.validation.constraints.Email;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * SAI开项申请到期提醒邮件通知线程
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2023/04/20 15:40:35
+ */
+public class SaiApplyDueMailThread implements Runnable {
+
+    private IMailService mailService;
+    private TSaiApply saiApply;
+    private SysUser sysUser;
+
+    public SaiApplyDueMailThread() {}
+
+    public SaiApplyDueMailThread(IMailService mailService, TSaiApply saiApply, SysUser sysUser) {
+        this.mailService = mailService;
+        this.saiApply = saiApply;
+        this.sysUser = sysUser;
+    }
+
+    @Override
+    public void run() {
+        try {
+            this.sendMail();
+        } catch (PinyinException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void sendMail() throws PinyinException {
+        String nickName = sysUser.getNickName();
+        String nickNameEN = PinyinHelper.convertToPinyinString(nickName.trim(), " ", PinyinFormat.WITHOUT_TONE);
+        String userName = sysUser.getUserName();
+        String email = sysUser.getEmail();
+        String description = saiApply.getDescription();
+        Date estimateFinishDate = saiApply.getEstimateFinishDate();
+        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\">" +
+                "亲爱的nickName</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
+                "Dear nickNameEN(userName)</font></font></h2>" +
+                "<p>您有即将到期的SAI开项申请,详情如下:<br>" +
+                "You have a new to-do task:<br>" +
+                "问题描述:<b>description</b><br>" +
+                "预计完成时间:<b>estimateFinishDate</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("nickName", nickName);
+        String two = one.replaceFirst("nickNameEN", nickNameEN);
+        String three = two.replaceFirst("userName", userName);
+        String four = three.replaceFirst("description", description);
+        String five = four.replaceFirst("estimateFinishDate", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(estimateFinishDate));
+        String result = five.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);
+    }
+}

+ 76 - 0
master/src/main/java/com/ruoyi/framework/task/SaiTask.java

@@ -0,0 +1,76 @@
+package com.ruoyi.framework.task;
+
+import com.ruoyi.common.sendEmail.IMailService;
+import com.ruoyi.common.thread.sai.SaiApplyDueMailThread;
+import com.ruoyi.common.thread.sai.SaiApplyMailThread;
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.project.production.controller.vo.SaiApplyQueryVO;
+import com.ruoyi.project.production.domain.TSaiApply;
+import com.ruoyi.project.production.mapper.TSaiApplyMapper;
+import com.ruoyi.project.production.service.ITSaiApplyService;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.mapper.SysUserMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 定时任务 - SAI
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2023/04/19 13:16:26
+ */
+@Component("saiTask")
+public class SaiTask extends BaseController {
+    @Autowired
+    private TSaiApplyMapper saiApplyMapper ;
+
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private IMailService mailService;
+
+    /**
+     * 检查即将到期的SAI
+     *
+     * 定义:1申请状态为“进行中”,2预计完成时间距离当前时间小于3天
+     * 处理:针对每项即将到期的SAI,分别在到期前3天和到期前1天发送邮件提醒
+     */
+    public void checkDueSai() {
+        SaiApplyQueryVO tSaiApply = new SaiApplyQueryVO();
+        tSaiApply.setApplyStatus(2L);//申请状态为“进行中”
+        List<TSaiApply> executingApplies = saiApplyMapper.selectTSaiApplyList(tSaiApply);//申请状态为“进行中”的SAI
+        if (executingApplies == null) {//SAI列表判空
+            return;
+        }
+        List<TSaiApply> dueApplies = new ArrayList<>();//申请状态为“进行中”并且即将到期的SAI
+        long now = new Date().getTime();//当前时间
+        for (TSaiApply apply : executingApplies) {//时间差小于1天
+            long estimateFinishTime = apply.getEstimateFinishDate().getTime();//预计完成时间
+            long diff = estimateFinishTime - now;//时间差(ms)
+            if (diff > 0 && diff <= 1 * 24 * 60 * 60 * 1000) {
+                dueApplies.add(apply);
+            }
+        }
+        for (TSaiApply apply : executingApplies) {//时间差小于3天
+            long estimateFinishTime = apply.getEstimateFinishDate().getTime();//预计完成时间
+            long diff = estimateFinishTime - now;//时间差(ms)
+            if (diff > 0 && diff <= 3 * 24 * 60 * 60 * 1000) {
+                dueApplies.add(apply);
+            }
+        }
+        dueApplies = dueApplies.stream().collect(Collectors.collectingAndThen(
+                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TSaiApply::getSaiApplyId))), ArrayList::new));
+        for (TSaiApply dueApply : dueApplies) {
+            String executor = dueApply.getExecutor();//整改负责人
+            SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(executor));
+            SaiApplyDueMailThread mailThread = new SaiApplyDueMailThread(mailService, dueApply, sysUser);//邮件线程
+            Thread thread = new Thread(mailThread);
+            thread.start();
+        }
+    }
+}

+ 0 - 1
master/src/main/java/com/ruoyi/project/production/mapper/TSaiApplyMapper.java

@@ -27,7 +27,6 @@ public interface TSaiApplyMapper
      * @param tSaiApply SAI开项管理
      * @return SAI开项管理集合
      */
-    @DataScope(deptAlias = "d")
     public List<TSaiApply> selectTSaiApplyList(SaiApplyQueryVO tSaiApply);
 
     /**