MailSendService.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.model.cronModel.Personnel;
  3. import cn.cslg.pas.common.utils.DateUtils2;
  4. import cn.cslg.pas.common.utils.RabbitMQUtils;
  5. import cn.cslg.pas.domain.business.ImportTask;
  6. import cn.cslg.pas.domain.business.ImportTaskCondition;
  7. import cn.cslg.pas.domain.business.Project;
  8. import cn.cslg.pas.domain.business.SystemDict;
  9. import cn.cslg.pas.service.business.ImportTaskConditionService;
  10. import cn.cslg.pas.service.business.ProjectService;
  11. import cn.cslg.pas.service.business.SystemDictService;
  12. import cn.cslg.pas.service.permissions.PermissionService;
  13. import com.alibaba.fastjson.JSON;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.stereotype.Service;
  19. import java.util.*;
  20. import java.util.regex.Matcher;
  21. import java.util.regex.Pattern;
  22. @Service
  23. public class MailSendService {
  24. @Autowired
  25. private PermissionService permissionService;
  26. @Value("${PASUrl}")
  27. private String url;
  28. @Autowired
  29. private RabbitMQUtils rabbitMQUtils;
  30. @Autowired
  31. private ImportTaskConditionService importTaskConditionService;
  32. @Autowired
  33. private ProjectService projectService;
  34. @Autowired
  35. private SystemDictService systemDictService;
  36. //发送协同邮件
  37. public String sendSynery(String personId, Boolean ifInner, Integer projectId, Integer taskId, Integer reportType, String code) {
  38. Map<String, Object> map = new LinkedHashMap<>();
  39. map.put("title", "任务通知");
  40. String name = "";
  41. //判断是否为内部人员
  42. if (ifInner) {
  43. String res = "";
  44. try {
  45. res = permissionService.getPersonnelByIdsFromPCS(Arrays.asList(personId));
  46. } catch (Exception e) {
  47. }
  48. if (!res.equals("")) {
  49. map.put("template", "mail/SyneryInside.html");
  50. JSONObject jsonObject = JSONObject.parseObject(res);
  51. List<Personnel> personnels = JSON.parseArray(jsonObject.getString("data"), Personnel.class);
  52. map.put("value1", personnels.get(0).getPersonnelName());
  53. map.put("email", personnels.get(0).getPersonnelEmail());
  54. map.put("img", "/logo.png");
  55. map.put("value2", url + "/Incomplete?taskId=" + taskId + "&reportId=" + projectId + "&type=1" + "&reportType=" + reportType);
  56. }
  57. } else {
  58. map.put("template", "mail/Synery.html");
  59. String orgin = personId;
  60. String parStr = "\\<([^}]*)\\>";
  61. Pattern pattern = Pattern.compile(parStr);
  62. Matcher matcher = pattern.matcher(orgin);
  63. if (matcher.find()) {
  64. String personName = orgin.substring(0, matcher.start());
  65. String email = matcher.group(0);
  66. email = email.replace("<", "");
  67. email = email.replace(">", "");
  68. map.put("value1", personName);
  69. map.put("email", email);
  70. map.put("img", "/logo.png");
  71. map.put("value2", code);
  72. map.put("value3", url + "/identificationCode");
  73. }
  74. }
  75. rabbitMQUtils.sendEmailMessage(map);
  76. return name;
  77. }
  78. //发送邮件给抄送人
  79. public void sentToCCMail(String personId, Boolean ifInner, String createPersonName) {
  80. Map<String, Object> map = new LinkedHashMap<>();
  81. map.put("title", "任务通知");
  82. //判断是否为内部人员
  83. if (ifInner) {
  84. String res = "";
  85. try {
  86. res = permissionService.getPersonnelByIdsFromPCS(Arrays.asList(personId));
  87. } catch (Exception e) {
  88. }
  89. if (!res.equals("")) {
  90. map.put("template", "mail/SyneryTo.html");
  91. JSONObject jsonObject = JSONObject.parseObject(res);
  92. List<Personnel> personnels = JSON.parseArray(jsonObject.getString("data"), Personnel.class);
  93. map.put("value1", personnels.get(0).getPersonnelName());
  94. map.put("email", personnels.get(0).getPersonnelEmail());
  95. map.put("img", "/logo.png");
  96. map.put("value2", createPersonName);
  97. rabbitMQUtils.sendEmailMessage(map);
  98. }
  99. } else {
  100. map.put("template", "mail/Synery.html");
  101. String orgin = personId;
  102. String parStr = "\\<([^}]*)\\>";
  103. Pattern pattern = Pattern.compile(parStr);
  104. Matcher matcher = pattern.matcher(orgin);
  105. if (matcher.find()) {
  106. String personName = orgin.substring(0, matcher.start());
  107. String email = matcher.group(0);
  108. email = email.replace("<", "");
  109. email = email.replace(">", "");
  110. map.put("value1", createPersonName);
  111. map.put("email", email);
  112. map.put("img", "/logo.png");
  113. map.put("value2", personName);
  114. }
  115. }
  116. rabbitMQUtils.sendEmailMessage(map);
  117. }
  118. //任务开始邮件
  119. public void sendAddTaskEmail(String taskName, String addPerson, String endTime, String handlePerson, String email) {
  120. Map<String, Object> map = new LinkedHashMap<>();
  121. map.put("title", "任务通知");
  122. map.put("template", "mail/eTask.html");
  123. map.put("value1", handlePerson);
  124. map.put("img", "/logo.png");
  125. map.put("email", email);
  126. map.put("value2", addPerson);
  127. map.put("value3", taskName);
  128. map.put("value4", endTime);
  129. map.put("value5", url);
  130. rabbitMQUtils.sendEmailMessage(map);
  131. }
  132. public void sendImportTaskDoneEmail(String taskTypeName, String taskName, String personId) {
  133. String res = "";
  134. try {
  135. res = permissionService.getPersonnelByIdsFromPCS(Arrays.asList(personId));
  136. } catch (Exception e) {
  137. }
  138. if (!res.equals("")) {
  139. JSONObject jsonObject = JSONObject.parseObject(res);
  140. List<Personnel> personnels = JSON.parseArray(jsonObject.getString("data"), Personnel.class);
  141. Personnel personnel = personnels.get(0);
  142. Map<String, Object> map = new LinkedHashMap<>();
  143. map.put("title", "任务通知");
  144. map.put("template", "mail/eTaskDone.html");
  145. map.put("value1", personnel.getPersonnelName());
  146. map.put("img", "/logo.png");
  147. map.put("email", personnel.getPersonnelEmail());
  148. map.put("value2", taskTypeName);
  149. map.put("value3", taskName);
  150. rabbitMQUtils.sendEmailMessage(map);
  151. }
  152. }
  153. public void sendCycleImportTaskDoneEmail(ImportTask importTask) {
  154. ImportTaskCondition importTaskCondition = importTaskConditionService.getById(importTask.getImportTaskConditionId());
  155. Integer projectId = importTaskCondition.getProjectId();
  156. Project project = projectService.getById(projectId);
  157. String personId = importTask.getCreateId();
  158. String res = "";
  159. try {
  160. res = permissionService.getPersonnelByIdsFromPCS(Arrays.asList(personId));
  161. } catch (Exception e) {
  162. }
  163. if (!res.equals("")) {
  164. JSONObject jsonObject = JSONObject.parseObject(res);
  165. List<Personnel> personnels = JSON.parseArray(jsonObject.getString("data"), Personnel.class);
  166. Personnel personnel = personnels.get(0);
  167. Map<String, Object> map = new LinkedHashMap<>();
  168. map.put("title", "监控通知");
  169. map.put("template", "mail/cycleTaskDone.html");
  170. map.put("value1", personnel.getPersonnelName());
  171. map.put("img", "/logo.png");
  172. map.put("email", personnel.getPersonnelEmail());
  173. map.put("value2", project.getName());
  174. String dateRange = "";
  175. if (importTask != null) {
  176. if (importTask.getLastUpdateToDate() != null) {
  177. if (importTask.getUpdateToDate() != null) {
  178. String toDateStr = DateUtils2.dateTimeToPatentStr(importTask.getUpdateToDate());
  179. String fromDateStr = DateUtils2.dateTimeToPatentStr(importTask.getLastUpdateToDate());
  180. dateRange = toDateStr + "~" + fromDateStr;
  181. }
  182. } else if (importTask.getUpdateToDate() != null) {
  183. String toDateStr = DateUtils2.dateTimeToPatentStr(importTask.getUpdateToDate());
  184. dateRange = "<" + toDateStr;
  185. }
  186. }
  187. map.put("value3", dateRange);
  188. map.put("value4", importTask.getAllNum());
  189. rabbitMQUtils.sendEmailMessage(map);
  190. }
  191. }
  192. public void sendSysCycleStartEmail() {
  193. LambdaQueryWrapper<SystemDict> queryWrapper = new LambdaQueryWrapper<>();
  194. queryWrapper.in(SystemDict::getType, "ADMIN");
  195. List<SystemDict> systemDictList = systemDictService.list(queryWrapper);
  196. if(systemDictList.size()==0){
  197. return;
  198. }
  199. Map<String, Object> map = new LinkedHashMap<>();
  200. map.put("title", "监控通知");
  201. map.put("template", "mail/sysCycleStart.html");
  202. map.put("img", "/logo.png");
  203. if (systemDictList != null && systemDictList.size() > 0) {
  204. SystemDict systemDict = systemDictList.remove(0);
  205. map.put("email", systemDict.getValue());
  206. if (systemDictList.size() > 0) {
  207. String[] ccs = new String[systemDictList.size()];
  208. for (int i = 0; i < systemDictList.size(); i++) {
  209. ccs[i] = systemDictList.get(i).getValue();
  210. }
  211. map.put("cc", ccs);
  212. }
  213. }
  214. rabbitMQUtils.sendEmailMessage(map);
  215. }
  216. }