SaiApplyDueMailThread.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.ruoyi.common.thread.sai;
  2. import com.github.stuxuhai.jpinyin.PinyinException;
  3. import com.github.stuxuhai.jpinyin.PinyinFormat;
  4. import com.github.stuxuhai.jpinyin.PinyinHelper;
  5. import com.ruoyi.common.sendEmail.IMailService;
  6. import com.ruoyi.project.production.domain.TSaiApply;
  7. import com.ruoyi.project.system.domain.SysUser;
  8. import javax.validation.constraints.Email;
  9. import javax.validation.constraints.NotBlank;
  10. import javax.validation.constraints.Size;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. /**
  14. * SAI开项申请到期提醒邮件通知线程
  15. *
  16. * @author Wang Zi Wen
  17. * @email wangggziwen@163.com
  18. * @date 2023/04/20 15:40:35
  19. */
  20. public class SaiApplyDueMailThread implements Runnable {
  21. private IMailService mailService;
  22. private TSaiApply saiApply;
  23. private SysUser sysUser;
  24. public SaiApplyDueMailThread() {}
  25. public SaiApplyDueMailThread(IMailService mailService, TSaiApply saiApply, SysUser sysUser) {
  26. this.mailService = mailService;
  27. this.saiApply = saiApply;
  28. this.sysUser = sysUser;
  29. }
  30. @Override
  31. public void run() {
  32. try {
  33. this.sendMail();
  34. } catch (PinyinException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38. private void sendMail() throws PinyinException {
  39. String nickName = sysUser.getNickName();
  40. String nickNameEN = PinyinHelper.convertToPinyinString(nickName.trim(), " ", PinyinFormat.WITHOUT_TONE);
  41. String userName = sysUser.getUserName();
  42. String email = sysUser.getEmail();
  43. String description = saiApply.getDescription();
  44. Date estimateFinishDate = saiApply.getEstimateFinishDate();
  45. String jumpUrl = "/production/sai/apply";
  46. //写html开始内容
  47. String start = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title></title></head><body><div style=\"background-color:#ECECEC; padding: 35px;\">" +
  48. "<table cellpadding=\"0\" align=\"center\"" +
  49. "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;\">" +
  50. "<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;\">" +
  51. "<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>";
  52. //表html中间内容
  53. String prime = "";
  54. String center = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
  55. "<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
  56. "亲爱的nickName</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
  57. "Dear nickNameEN(userName)</font></font></h2>" +
  58. "<p>您有即将到期的SAI开项申请,详情如下:<br>" +
  59. "You have a new to-do task:<br>" +
  60. "问题描述:<b>description</b><br>" +
  61. "预计完成时间:<b>estimateFinishDate</b><br>" +
  62. "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#jumpUrl\">CPMS管理系统</a>查看。<br>" +
  63. "Please log in the <a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#jumpUrl\">CPMS</a> to handle it.</p>" +
  64. "<p align=\"right\">date</p>" +
  65. "<div style=\"width:700px;margin:0 auto;\">" +
  66. "<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
  67. "<p>此为系统邮件,请勿回复<br>This e-Mail is an automatic reminder sent by CPMS, please do not reply</p>" +
  68. "</div></div></div></td></tr>";
  69. String one = center.replaceFirst("nickName", nickName);
  70. String two = one.replaceFirst("nickNameEN", nickNameEN);
  71. String three = two.replaceFirst("userName", userName);
  72. String four = three.replaceFirst("description", description);
  73. String five = four.replaceFirst("estimateFinishDate", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(estimateFinishDate));
  74. String result = five.replaceFirst("date", String.valueOf(new Date())).replaceFirst("jumpUrl",jumpUrl).replaceFirst("jumpUrl",jumpUrl);
  75. prime = prime + result;
  76. //写html结尾内容
  77. String end = "</tbody></table></div></body></html>";
  78. //拼接html
  79. String html = start + prime + end;
  80. mailService.sendHtmlMail(email, "CPMS:您有即将到期的SAI开项申请", html);
  81. }
  82. }