|
@@ -1,5 +1,11 @@
|
|
|
package com.ruoyi.project.pssr.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.github.stuxuhai.jpinyin.PinyinFormat;
|
|
|
+import com.github.stuxuhai.jpinyin.PinyinHelper;
|
|
|
+import com.ruoyi.common.jpush.JiGuangPushService;
|
|
|
+import com.ruoyi.common.sendEmail.IMailService;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
|
@@ -11,15 +17,15 @@ import com.ruoyi.project.pssr.domain.*;
|
|
|
import com.ruoyi.project.pssr.service.*;
|
|
|
import com.ruoyi.project.reliability.domain.TSafetyvavle;
|
|
|
import com.ruoyi.project.reliability.service.ITSafetyvavleService;
|
|
|
+import com.ruoyi.project.system.domain.SysMessage;
|
|
|
import com.ruoyi.project.system.domain.SysUser;
|
|
|
+import com.ruoyi.project.system.service.ISysMessageService;
|
|
|
import com.ruoyi.project.system.service.ISysUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* PSSRController
|
|
@@ -170,6 +176,15 @@ public class TPssrAboveallController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private ITPssrProgrammeService tPssrProgrammeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JiGuangPushService jiGuangPushService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IMailService mailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysMessageService sysMessageService;
|
|
|
//endregion
|
|
|
|
|
|
//region 系统方法
|
|
@@ -262,10 +277,14 @@ public class TPssrAboveallController extends BaseController {
|
|
|
}
|
|
|
tPssrAboveallService.insertTPssrAboveall(tPssrAboveall);//新增主表数据
|
|
|
|
|
|
+ // 记录所有负责人id
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+
|
|
|
String userId = getUserId().toString();
|
|
|
//新增子表数据
|
|
|
for (TPssrSubcontent subcontent : tPssrAboveall.getSubcontents()) {
|
|
|
if (subcontent.getStatus() == 1) {
|
|
|
+ userIds.add(Long.valueOf(subcontent.getConfirm()));
|
|
|
subcontent.setAboveallId(tPssrAboveall.getId());//主表id
|
|
|
subcontent.setRegion(tPssrAboveall.getRegion());
|
|
|
subcontent.setUnit(tPssrAboveall.getUnit());
|
|
@@ -357,6 +376,10 @@ public class TPssrAboveallController extends BaseController {
|
|
|
if (model) {
|
|
|
genPssrDataByModel(aboveall, tPssrAboveall, userId);
|
|
|
}
|
|
|
+
|
|
|
+ new Thread(() -> {
|
|
|
+ sendEmail(userIds, tPssrAboveall);
|
|
|
+ },"新增pssr开始发邮件").start();
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
//endregion
|
|
@@ -1102,4 +1125,71 @@ public class TPssrAboveallController extends BaseController {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
+ // region 发邮件
|
|
|
+ private void sendEmail(Set<Long> userIds, TPssrAboveall tPssrAboveall) {
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ try {
|
|
|
+ SysUser sysUser = userService.selectUserById(userId);
|
|
|
+ String email = sysUser.getEmail();
|
|
|
+ String username = sysUser.getNickName();
|
|
|
+ String loginName = sysUser.getUserName();
|
|
|
+ String usernameEN = PinyinHelper.convertToPinyinString(username, " ", PinyinFormat.WITHOUT_TONE);
|
|
|
+ logger.info("email:" + email);
|
|
|
+ logger.info("username:" + username);
|
|
|
+ //写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); \">PSSR检查确认 </font><font face=\"微软雅黑\" size=\"3\" style=\"color: rgb(255, 255, 255); \">PSSR</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\">" +
|
|
|
+ "亲爱的 username(loginName)</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
|
+ "Dear usernameEN(loginName)</font></font></h2>" +
|
|
|
+ "<p>region区域unit的PSSR检查确认已经开始,预计开车时间为startDate:<br>" +
|
|
|
+ "You Have A New PSSR:<br>" +
|
|
|
+ "请登录<a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/pssr/subcontent/aboveallId\">PSSR清单中</a>查看。<br>" +
|
|
|
+ "Please log in the <a href=\"https://cpms.basf-ypc.net.cn/cpms/index.html#/pssr/aboveall\">PSSR</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("username", username);
|
|
|
+ String two = one.replaceFirst("usernameEN", usernameEN);
|
|
|
+ String three = two.replace("loginName", loginName);
|
|
|
+ String four = three.replace("region", tPssrAboveall.getRegion());
|
|
|
+ String five = four.replace("unit", "," + tPssrAboveall.getUnit() + "单元");
|
|
|
+ String six = five.replace("aboveallId", tPssrAboveall.getId().toString() );
|
|
|
+ String seven = six.replaceFirst("startDate", DateUtils.dateTime(tPssrAboveall.getDrivingTime()));
|
|
|
+ String result = seven.replaceFirst("date", DateUtils.dateTime());
|
|
|
+ prime = prime + result;
|
|
|
+ //写html结尾内容
|
|
|
+ String end = "</tbody></table></div></body></html>";
|
|
|
+ //拼接html
|
|
|
+ String html = start + prime + end;
|
|
|
+ logger.info("html:" + html);
|
|
|
+ mailService.sendHtmlMail(email, "PSSR:您有新的PSSR检查待处理", html);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("邮件发送失败" + JSON.toJSONString(e));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //极光推送
|
|
|
+ jiGuangPushService.send("PSSR审批", "您有一个新的待办任务,请及时处理。", String.valueOf(userId));
|
|
|
+
|
|
|
+ //系统消息推送
|
|
|
+ SysMessage sysMessage = new SysMessage();
|
|
|
+ sysMessage.setMsgTitle("PSSR审批");
|
|
|
+ sysMessage.setMsgContent("您有一个新的待办任务,请及时处理。");
|
|
|
+ sysMessage.setUserId(userId);
|
|
|
+ sysMessageService.insertSysMessage(sysMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("推送失败:{}", JSON.toJSONString(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // endregion
|
|
|
}
|