|
@@ -1,5 +1,6 @@
|
|
|
package com.dgtly.wxportal.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
@@ -17,6 +18,7 @@ import com.dgtly.system.service.ISysConfigService;
|
|
|
import com.dgtly.system.service.ISysDictDataService;
|
|
|
import com.dgtly.system.util.MailUtils;
|
|
|
import com.dgtly.wxportal.utils.qywxutils.QyWxSendMessageUtil;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -212,51 +214,44 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
if(tucSales !=null && tucSales.size()>0){
|
|
|
OrderTucEarlyWarning warning = new OrderTucEarlyWarning();
|
|
|
List<OrderTucEarlyWarning> earlyWarnings = tucEarlyWarningMapper.selectOrderTucEarlyWarningList(warning);
|
|
|
- if(earlyWarnings !=null && earlyWarnings.size()>0){
|
|
|
+ if(earlyWarnings !=null && earlyWarnings.size()>0) {
|
|
|
//比较指标是否有误
|
|
|
-
|
|
|
- // 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
|
|
- Properties props = new Properties(); // 参数配置
|
|
|
- props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
- props.setProperty("mail.smtp.host", myEmailSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
- props.setProperty("mail.smtp.port", "25");
|
|
|
- props.setProperty("mail.smtp.auth", "true"); // 需要请求认证
|
|
|
- props.setProperty("mail.smtp.starttls.enable", "false"); // 需要请求认证
|
|
|
- props.setProperty("mail.smtp.ssl.enable", "false"); // 需要请求认证
|
|
|
- Set<String> sendEmailUser = getConfigValueSet("sendmailUnionUser");
|
|
|
- Session session = Session.getDefaultInstance(props);
|
|
|
- session.setDebug(true);
|
|
|
-
|
|
|
- for (String email : sendEmailUser
|
|
|
- ) {
|
|
|
- Mail mail = new Mail();
|
|
|
- try {
|
|
|
- mail.setFrom(myEmailAccount);
|
|
|
- mail.setTo(email);
|
|
|
- mail.setSubject("立邦随身邦业绩进度数据源预警");
|
|
|
- mail.setContent(getHtmlUserContextList(userList));
|
|
|
- //mailUtils.sendMailHtml(mailFromUsername, email, "用户账号重复通知", "您好,重复用户信息如下<br>" + userList);
|
|
|
- MimeMessage message = mailUtils.createMimeMessage(session, myEmailAccount, email, mail);
|
|
|
-
|
|
|
- // 4. 根据 Session 获取邮件传输对象
|
|
|
- Transport transport = session.getTransport();
|
|
|
-
|
|
|
- transport.connect(myEmailAccount, myEmailPassword);
|
|
|
-
|
|
|
- // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
|
|
- transport.sendMessage(message, message.getAllRecipients());
|
|
|
-
|
|
|
- // 7. 关闭连接
|
|
|
- transport.close();
|
|
|
- } catch (NoSuchProviderException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (MessagingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ for (OrderTucEarlyWarning early : tucSales
|
|
|
+ ) {
|
|
|
+ OrderTucEarlyWarning earlyWarning = tucEarlyWarningMapper.selectOrderTucEarlyWarning(early.getOrgCode());
|
|
|
+ BigDecimal tucNetValue = new BigDecimal(0);
|
|
|
+ if (StringUtils.isNotBlank(early.getOrgNetValue())) {
|
|
|
+ tucNetValue = new BigDecimal(early.getOrgNetValue());
|
|
|
+ tucNetValue = tucNetValue.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ BigDecimal earlyNetValue = new BigDecimal(0);
|
|
|
+ if (StringUtils.isNotBlank(earlyWarning.getOrgNetValue())) {
|
|
|
+ earlyNetValue = new BigDecimal(earlyWarning.getOrgNetValue());
|
|
|
+ earlyNetValue = earlyNetValue.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ if (tucNetValue.compareTo(earlyNetValue) == -1) {
|
|
|
+ sendQw(tucNetValue,earlyNetValue,1,early.getOrgCode(),early.getOrgName());
|
|
|
+ sendMail(tucNetValue,earlyNetValue,1,early.getOrgCode(),early.getOrgName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ BigDecimal tucTarget = new BigDecimal(0);
|
|
|
+ if (StringUtils.isNotBlank(early.getOrgTarget())) {
|
|
|
+ tucTarget = new BigDecimal(early.getOrgTarget());
|
|
|
+ tucTarget = tucTarget.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ BigDecimal earlyTarget = new BigDecimal(0);
|
|
|
+ if (StringUtils.isNotBlank(earlyWarning.getOrgTarget())) {
|
|
|
+ earlyTarget = new BigDecimal(earlyWarning.getOrgTarget());
|
|
|
+ earlyTarget = earlyTarget.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ if (tucTarget.compareTo(earlyTarget) == -1) {
|
|
|
+ sendQw(tucTarget,earlyTarget,2,early.getOrgCode(),early.getOrgName());
|
|
|
+ sendMail(tucTarget,earlyTarget,2,early.getOrgCode(),early.getOrgName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ tucEarlyWarningMapper.updateOrderTucEarlyWarning(early);
|
|
|
}
|
|
|
- }
|
|
|
- }else{
|
|
|
+ }else{
|
|
|
tucEarlyWarningMapper.batchInsert(tucSales);
|
|
|
}
|
|
|
}
|
|
@@ -271,26 +266,126 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- public String getHtmlUserContextList(List<UserVO> userList) {
|
|
|
+ public String getConfigValueUserAccount(String dictType){
|
|
|
+ String res = "";
|
|
|
+ List<SysDictData> dictDatas = sysDictDataService.selectSimpleDictDataByType(dictType);
|
|
|
+ if(dictDatas !=null && dictDatas.size()>0){
|
|
|
+ for(int i=0;i<dictDatas.size();i++){
|
|
|
+ if(i == 0){
|
|
|
+ res = dictDatas.get(0).getDictValue();
|
|
|
+ }else{
|
|
|
+ res = res+dictDatas.get(i).getDictValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ void sendQw(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
|
+ String sendQwUser = getConfigValueUserAccount("sendQwEarlyWarning");
|
|
|
+ if(sendQwUser !=null && !("").equals(sendQwUser) ){
|
|
|
+ if(type == 1 ){
|
|
|
+ String messageDetail="原已复核:"+oldValue+"本次已复核:"+tucValue+"已复核累计减少,请排查是否有误,该组织名称:"+orgName+"组织编码:"+orgCode;
|
|
|
+ qyWxSendMessageUtil.sendMsgSelfToCustomer(sendQwUser,messageDetail, "10086");
|
|
|
+ }
|
|
|
+ if(type == 2){
|
|
|
+ String messageDetail="原预算目标:"+oldValue+"本次预算目标:"+tucValue+"预算目标累计减少,请排查是否有误,该组织名称:"+orgName+"组织编码:"+orgCode;
|
|
|
+ qyWxSendMessageUtil.sendMsgSelfToCustomer(sendQwUser,messageDetail, "10086");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ void sendMail(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
|
+ // 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
|
|
+ Properties props = new Properties(); // 参数配置
|
|
|
+ props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
+ props.setProperty("mail.smtp.host", myEmailSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
+ props.setProperty("mail.smtp.port", "25");
|
|
|
+ props.setProperty("mail.smtp.auth", "true"); // 需要请求认证
|
|
|
+ props.setProperty("mail.smtp.starttls.enable", "false"); // 需要请求认证
|
|
|
+ props.setProperty("mail.smtp.ssl.enable", "false"); // 需要请求认证
|
|
|
+ Set<String> sendEmailUser = getConfigValueSet("sendMailEarlyWarning");
|
|
|
+ Session session = Session.getDefaultInstance(props);
|
|
|
+ session.setDebug(true);
|
|
|
+
|
|
|
+ for (String email : sendEmailUser
|
|
|
+ ) {
|
|
|
+ Mail mail = new Mail();
|
|
|
+ try {
|
|
|
+ mail.setFrom(myEmailAccount);
|
|
|
+ mail.setTo(email);
|
|
|
+ mail.setSubject("立邦随身邦业绩进度数据源预警");
|
|
|
+ mail.setContent(getHtmlUserContextList(tucValue,oldValue,type,orgCode,orgName));
|
|
|
+ //mailUtils.sendMailHtml(mailFromUsername, email, "用户账号重复通知", "您好,重复用户信息如下<br>" + userList);
|
|
|
+ MimeMessage message = mailUtils.createMimeMessage(session, myEmailAccount, email, mail);
|
|
|
+
|
|
|
+ // 4. 根据 Session 获取邮件传输对象
|
|
|
+ Transport transport = session.getTransport();
|
|
|
+
|
|
|
+ transport.connect(myEmailAccount, myEmailPassword);
|
|
|
+
|
|
|
+ // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
|
|
+ transport.sendMessage(message, message.getAllRecipients());
|
|
|
+
|
|
|
+ // 7. 关闭连接
|
|
|
+ transport.close();
|
|
|
+ } catch (NoSuchProviderException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (MessagingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+ public String getHtmlUserContextList(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName) {
|
|
|
|
|
|
String str = "";
|
|
|
- for (UserVO u : userList) {
|
|
|
+ String html ="";
|
|
|
+ if(type == 1){
|
|
|
str += "<tr>" +
|
|
|
- " <td>" + u.getUserName()
|
|
|
- + " </td><td>" + u.getLoginName()
|
|
|
- + " </td><td>" + u.getPhonenumber()
|
|
|
+ " <td>" + tucValue
|
|
|
+ + " </td><td>" + oldValue
|
|
|
+ + " </td><td>" + orgCode
|
|
|
+ + " </td><td>" + orgName
|
|
|
+ + " </td><td>" + "已复核累计减少,请排查是否有误"
|
|
|
+ " </td>" +
|
|
|
"</tr>";
|
|
|
+ html = "<table border='1' Cellspacing='0'>" +
|
|
|
+ " <tr>" +
|
|
|
+ " <th>本次已复核</th>" +
|
|
|
+ " <th>上次已复核</th>" +
|
|
|
+ " <th>组织编码</th>" +
|
|
|
+ " <th>组织名称</th>" +
|
|
|
+ " <th>检测结果</th>" +
|
|
|
+ " </tr>" +
|
|
|
+ str +
|
|
|
+ "</table>";
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- String html = "<table border='1' Cellspacing='0'>" +
|
|
|
- " <tr>" +
|
|
|
- " <th>用户昵称</th>" +
|
|
|
- " <th>用户登录名</th>" +
|
|
|
- " <th>用户手机号</th>" +
|
|
|
- " </tr>" +
|
|
|
- str +
|
|
|
- "</table>";
|
|
|
+ if(type == 2){
|
|
|
+ str += "<tr>" +
|
|
|
+ " <td>" + tucValue
|
|
|
+ + " </td><td>" + oldValue
|
|
|
+ + " </td><td>" + orgCode
|
|
|
+ + " </td><td>" + orgName
|
|
|
+ + " </td><td>" + "预算目标累计减少,请排查是否有误"
|
|
|
+ + " </td>" +
|
|
|
+ "</tr>";
|
|
|
+ html = "<table border='1' Cellspacing='0'>" +
|
|
|
+ " <tr>" +
|
|
|
+ " <th>本次预算目标</th>" +
|
|
|
+ " <th>上次预算目标</th>" +
|
|
|
+ " <th>组织编码</th>" +
|
|
|
+ " <th>组织名称</th>" +
|
|
|
+ " <th>检测结果</th>" +
|
|
|
+ " </tr>" +
|
|
|
+ str +
|
|
|
+ "</table>";
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return html;
|
|
|
}
|