SendEmailThead.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.ruoyi.common.thread;
  2. import com.ruoyi.common.sendEmail.IMailService;
  3. import com.ruoyi.project.sems.domain.TApprove;
  4. import java.util.Date;
  5. public class SendEmailThead implements Runnable {
  6. private IMailService mailService;
  7. private String email;
  8. private String apNo;
  9. private String username;
  10. private String usernameEN;
  11. private TApprove tApprove;
  12. private String sendType;
  13. public SendEmailThead(String email, String apNo, String username, String usernameEN, IMailService mailService, TApprove tApprove, String sendType) {
  14. this.email = email;
  15. this.apNo = apNo;
  16. this.username = username;
  17. this.usernameEN = usernameEN;
  18. this.mailService = mailService;
  19. this.tApprove = tApprove;
  20. this.sendType = sendType;
  21. }
  22. /*
  23. * 发送邮件
  24. */
  25. @Override
  26. public void run() {
  27. if (sendType.equals("year")) {
  28. year();
  29. }else if (sendType.equals("month")) {
  30. month();
  31. }
  32. }
  33. /*
  34. * 发送年度邮件
  35. */
  36. public void year() {
  37. String devType = null;
  38. String devTypeEN = null;
  39. switch (tApprove.getDevType().toString()) {
  40. case "1":
  41. devType = "压力容器";
  42. devTypeEN = "Pressure Vessel";
  43. break;
  44. case "2":
  45. devType = "压力管道";
  46. devTypeEN = "Pressure Pipeline";
  47. break;
  48. }
  49. String approveType = "生成" + devType + "年度检查报告";
  50. String approveTypeEN = "Generate annual inspection report of " + devTypeEN;
  51. //写html开始内容
  52. String start = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title></title></head><body><div style=\"background-color:#ECECEC; padding: 35px;\">" +
  53. "<table cellpadding=\"0\" align=\"center\"" +
  54. "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;\">" +
  55. "<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;\">" +
  56. "<font face=\"微软雅黑\" size=\"5\" style=\"color: rgb(255, 255, 255); \">特种设备信息管理系统 </font><font face=\"微软雅黑\" size=\"3\" style=\"color: rgb(255, 255, 255); \">Special Equipment Management System (SEMS)</font></th></tr>";
  57. //表html中间内容
  58. String prime = "";
  59. String center = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
  60. "<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
  61. "亲爱的 username</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
  62. "Dear usernameEN</font></font></h2>" +
  63. "<p>您有一个新的待办任务:<br>" +
  64. "You have a new to-do task:<br>" +
  65. "任务编号:<b>apNo</b><br>" +
  66. "Task Number: <b>apNoEN</b><br>" +
  67. "申请设备类型:<b>devType</b><br>" +
  68. "Equipment Type: <b>devTypeEN</b><br>" +
  69. "审批类型:<b>approveType</b><br>" +
  70. "Application Category: <b>approveTypeEN</b><br>" +
  71. "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/approve/pending\">特种设备信息管理系统</a>查看。<br>" +
  72. "Please log in the <a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/approve/pending\">SEMS</a> to handle it.</p>" +
  73. "<p align=\"right\">date</p>" +
  74. "<div style=\"width:700px;margin:0 auto;\">" +
  75. "<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
  76. "<p>此为系统邮件,请勿回复<br>This e-Mail is an automatic reminder sent by SEMS, please do not reply</p>" +
  77. "</div></div></div></td></tr>";
  78. String one = center.replaceFirst("username", username);
  79. String two = one.replaceFirst("usernameEN", usernameEN);
  80. String three = two.replaceFirst("devType", devType);
  81. String four = three.replaceFirst("apNo", apNo);
  82. String five = four.replaceFirst("apNoEN", apNo);
  83. String six = five.replaceFirst("devTypeEN", devTypeEN);
  84. String seven = six.replaceFirst("approveType", approveType);
  85. String eight = seven.replaceFirst("approveTypeEN", approveTypeEN);
  86. String result = eight.replaceFirst("date", String.valueOf(new Date()));
  87. prime = prime + result;
  88. //写html结尾内容
  89. String end = "</tbody></table></div></body></html>";
  90. //拼接html
  91. String html = start + prime + end;
  92. mailService.sendHtmlMail(email, "特种设备:您有一个新的待办任务 SEMS:You have a new to-do task (" + apNo + ")", html);
  93. }
  94. /*
  95. * 发送月度邮件
  96. */
  97. public void month() {
  98. String approveType = "生成月度检查报告";
  99. String approveTypeEN = "Generate monthly inspection report";
  100. //写html开始内容
  101. String start = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title></title></head><body><div style=\"background-color:#ECECEC; padding: 35px;\">" +
  102. "<table cellpadding=\"0\" align=\"center\"" +
  103. "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;\">" +
  104. "<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;\">" +
  105. "<font face=\"微软雅黑\" size=\"5\" style=\"color: rgb(255, 255, 255); \">特种设备信息管理系统 </font><font face=\"微软雅黑\" size=\"3\" style=\"color: rgb(255, 255, 255); \">Special Equipment Management System (SEMS)</font></th></tr>";
  106. //表html中间内容
  107. String prime = "";
  108. String center = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
  109. "<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
  110. "亲爱的 username</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
  111. "Dear usernameEN</font></font></h2>" +
  112. "<p>您有一个新的待办任务:<br>" +
  113. "You have a new to-do task:<br>" +
  114. "任务编号:<b>apNo</b><br>" +
  115. "Task Number: <b>apNoEN</b><br>" +
  116. "审批类型:<b>approveType</b><br>" +
  117. "Application Category: <b>approveTypeEN</b><br>" +
  118. "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/approve/pending\">特种设备信息管理系统</a>查看。<br>" +
  119. "Please log in the <a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/approve/pending\">SEMS</a> to handle it.</p>" +
  120. "<p align=\"right\">date</p>" +
  121. "<div style=\"width:700px;margin:0 auto;\">" +
  122. "<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
  123. "<p>此为系统邮件,请勿回复<br>This e-Mail is an automatic reminder sent by SEMS, please do not reply</p>" +
  124. "</div></div></div></td></tr>";
  125. String one = center.replaceFirst("username", username);
  126. String two = one.replaceFirst("usernameEN", usernameEN);
  127. String three = two.replaceFirst("apNo", apNo);
  128. String four = three.replaceFirst("apNoEN", apNo);
  129. String five = four.replaceFirst("approveType", approveType);
  130. String six = five.replaceFirst("approveTypeEN", approveTypeEN);
  131. String result = six.replaceFirst("date", String.valueOf(new Date()));
  132. prime = prime + result;
  133. //写html结尾内容
  134. String end = "</tbody></table></div></body></html>";
  135. //拼接html
  136. String html = start + prime + end;
  137. mailService.sendHtmlMail(email, "特种设备:您有一个新的待办任务 SEMS:You have a new to-do task (" + apNo + ")", html);
  138. }
  139. }