|
@@ -1,21 +1,38 @@
|
|
|
package com.dgtly.wxportal.service.impl;
|
|
package com.dgtly.wxportal.service.impl;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import com.dgtly.common.utils.DateUtils;
|
|
import com.dgtly.common.utils.DateUtils;
|
|
|
|
|
+import com.dgtly.system.domain.Mail;
|
|
|
|
|
+import com.dgtly.system.domain.OrderTucEarlyWarning;
|
|
|
|
|
+import com.dgtly.system.domain.SysDictData;
|
|
|
|
|
+import com.dgtly.system.domain.UserVO;
|
|
|
|
|
+import com.dgtly.system.mapper.OrderTucEarlyWarningMapper;
|
|
|
import com.dgtly.system.mapper.SysBatchSignForMapper;
|
|
import com.dgtly.system.mapper.SysBatchSignForMapper;
|
|
|
import com.dgtly.system.mapper.SysUserMapper;
|
|
import com.dgtly.system.mapper.SysUserMapper;
|
|
|
|
|
+import com.dgtly.system.service.IOrderTucEarlyWarningService;
|
|
|
import com.dgtly.system.service.ISysConfigService;
|
|
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 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.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.dgtly.wxportal.mapper.WxSendMessageMapper;
|
|
import com.dgtly.wxportal.mapper.WxSendMessageMapper;
|
|
|
import com.dgtly.wxportal.domain.WxSendMessage;
|
|
import com.dgtly.wxportal.domain.WxSendMessage;
|
|
|
import com.dgtly.wxportal.service.IWxSendMessageService;
|
|
import com.dgtly.wxportal.service.IWxSendMessageService;
|
|
|
import com.dgtly.common.core.text.Convert;
|
|
import com.dgtly.common.core.text.Convert;
|
|
|
|
|
|
|
|
|
|
+import javax.mail.MessagingException;
|
|
|
|
|
+import javax.mail.NoSuchProviderException;
|
|
|
|
|
+import javax.mail.Session;
|
|
|
|
|
+import javax.mail.Transport;
|
|
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 企业微信发送消息历史记录Service业务层处理
|
|
* 企业微信发送消息历史记录Service业务层处理
|
|
|
*
|
|
*
|
|
@@ -35,6 +52,18 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
private ISysConfigService configService;
|
|
private ISysConfigService configService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SysBatchSignForMapper batchSignForMapper;
|
|
private SysBatchSignForMapper batchSignForMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysDictDataService sysDictDataService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OrderTucEarlyWarningMapper tucEarlyWarningMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MailUtils mailUtils;
|
|
|
|
|
+ @Value(value = "${spring.mail.username}")
|
|
|
|
|
+ private String myEmailAccount;
|
|
|
|
|
+ @Value(value = "${spring.mail.password}")
|
|
|
|
|
+ public String myEmailPassword;
|
|
|
|
|
+ @Value(value = "${spring.mail.host}")
|
|
|
|
|
+ public String myEmailSMTPHost;
|
|
|
/**
|
|
/**
|
|
|
* 查询企业微信发送消息历史记录
|
|
* 查询企业微信发送消息历史记录
|
|
|
*
|
|
*
|
|
@@ -161,4 +190,207 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 业绩进度指标预警邮件/企微消息通知
|
|
|
|
|
+ * @param:
|
|
|
|
|
+ * @return:
|
|
|
|
|
+ * @author: njs
|
|
|
|
|
+ * @date: 2024/2/4 9:21
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void sendMailAndWxEarlyTucMessage() {
|
|
|
|
|
+ int year = Calendar.getInstance().get(Calendar.YEAR);
|
|
|
|
|
+ int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
|
|
|
|
|
+ String MonthStr = "";
|
|
|
|
|
+ if(month < 10){
|
|
|
|
|
+ MonthStr = "0"+month;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ MonthStr = String.valueOf(month);
|
|
|
|
|
+ }
|
|
|
|
|
+ String startTime = String.valueOf(year)+"01";
|
|
|
|
|
+ String endTime = String.valueOf(year)+ MonthStr;
|
|
|
|
|
+ List<OrderTucEarlyWarning> tucSales = tucEarlyWarningMapper.selectTucGroupSales(startTime,endTime);
|
|
|
|
|
+ if(tucSales !=null && tucSales.size()>0){
|
|
|
|
|
+ OrderTucEarlyWarning warning = new OrderTucEarlyWarning();
|
|
|
|
|
+ List<OrderTucEarlyWarning> earlyWarnings = tucEarlyWarningMapper.selectOrderTucEarlyWarningList(warning);
|
|
|
|
|
+ if(earlyWarnings !=null && earlyWarnings.size()>0) {
|
|
|
|
|
+ //比较指标是否有误
|
|
|
|
|
+ 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());
|
|
|
|
|
+ tucEarlyWarningMapper.deleteOrderTucEarlyWarning();
|
|
|
|
|
+ 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());
|
|
|
|
|
+ tucEarlyWarningMapper.deleteOrderTucEarlyWarning();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ early.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
+ tucEarlyWarningMapper.updateOrderTucEarlyWarning(early);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ tucEarlyWarningMapper.batchInsert(tucSales);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Set<String> getConfigValueSet(String dictType){
|
|
|
|
|
+ Set<String> res = new HashSet<>();
|
|
|
|
|
+ List<SysDictData> dictDatas = sysDictDataService.selectSimpleDictDataByType(dictType);
|
|
|
|
|
+ for(SysDictData d: dictDatas){
|
|
|
|
|
+ res.add(d.getDictValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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, "66");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(type == 2){
|
|
|
|
|
+ String messageDetail="数据源业绩指标预警:原预算目标:"+oldValue+" 本次预算目标:"+tucValue+" 预算目标累计减少,请排查是否有误,该组织名称:"+orgName+" 组织编码:"+orgCode;
|
|
|
|
|
+ qyWxSendMessageUtil.sendMsgSelfToCustomer(sendQwUser,messageDetail, "66");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ 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 = "";
|
|
|
|
|
+ String html ="";
|
|
|
|
|
+ if(type == 1){
|
|
|
|
|
+ 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>";
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|