|
@@ -3,17 +3,14 @@ package com.dgtly.wxportal.service.impl;
|
|
|
import java.math.BigDecimal;
|
|
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 com.dgtly.common.utils.DateUtils;
|
|
import com.dgtly.common.utils.DateUtils;
|
|
|
import com.dgtly.system.domain.Mail;
|
|
import com.dgtly.system.domain.Mail;
|
|
|
import com.dgtly.system.domain.OrderTucEarlyWarning;
|
|
import com.dgtly.system.domain.OrderTucEarlyWarning;
|
|
|
import com.dgtly.system.domain.SysDictData;
|
|
import com.dgtly.system.domain.SysDictData;
|
|
|
-import com.dgtly.system.domain.UserVO;
|
|
|
|
|
import com.dgtly.system.mapper.OrderTucEarlyWarningMapper;
|
|
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.service.ISysDictDataService;
|
|
|
import com.dgtly.system.util.MailUtils;
|
|
import com.dgtly.system.util.MailUtils;
|
|
@@ -64,6 +61,7 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
public String myEmailPassword;
|
|
public String myEmailPassword;
|
|
|
@Value(value = "${spring.mail.host}")
|
|
@Value(value = "${spring.mail.host}")
|
|
|
public String myEmailSMTPHost;
|
|
public String myEmailSMTPHost;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询企业微信发送消息历史记录
|
|
* 查询企业微信发送消息历史记录
|
|
|
*
|
|
*
|
|
@@ -155,7 +153,6 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
) {
|
|
) {
|
|
|
String user =null;
|
|
String user =null;
|
|
|
String deliverNumber =null;
|
|
String deliverNumber =null;
|
|
|
- String orderFormat =null;
|
|
|
|
|
String customerName = userMapper.getCustomNameByCode(customerId);
|
|
String customerName = userMapper.getCustomNameByCode(customerId);
|
|
|
Map<String, Map<String,Object>> maps = userMapper.selectLoginNamesByOrgCodeSelf(customerId);
|
|
Map<String, Map<String,Object>> maps = userMapper.selectLoginNamesByOrgCodeSelf(customerId);
|
|
|
Iterator<Map.Entry<String, Object>> iterator = tmsMap.get(customerId).entrySet().iterator();
|
|
Iterator<Map.Entry<String, Object>> iterator = tmsMap.get(customerId).entrySet().iterator();
|
|
@@ -261,6 +258,90 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 交货冻结取消要货企微消息通知
|
|
|
|
|
+ * 取消后按经销商分组,向经销商侧负责人/要货人 + 对应销售推送通知。
|
|
|
|
|
+ * 消息内容:
|
|
|
|
|
+ * "因经销商交货冻结,已取消以下订单的要货,如需重新要货,请解冻后再操作:[订单号列表]"
|
|
|
|
|
+ * @param canceledOrderList 已取消的要货记录详情列表(含 customerCode/orderNumber/confirmBy)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void sendFreezeCustomerCancelOrderMessage(List<Map<String, Object>> canceledOrderList) {
|
|
|
|
|
+ if (canceledOrderList == null || canceledOrderList.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 按经销商编码分组,收集订单号和要货人
|
|
|
|
|
+ Map<String, List<String>> customerOrderMap = new LinkedHashMap<>();
|
|
|
|
|
+ Map<String, Set<String>> customerConfirmByMap = new LinkedHashMap<>();
|
|
|
|
|
+ for (Map<String, Object> detail : canceledOrderList) {
|
|
|
|
|
+ String customerCode = String.valueOf(detail.get("customerCode"));
|
|
|
|
|
+ String orderNumber = String.valueOf(detail.get("orderNumber"));
|
|
|
|
|
+ String confirmBy = detail.get("confirmBy") != null ? String.valueOf(detail.get("confirmBy")) : "";
|
|
|
|
|
+ customerOrderMap.computeIfAbsent(customerCode, k -> new ArrayList<>()).add(orderNumber);
|
|
|
|
|
+ customerConfirmByMap.computeIfAbsent(customerCode, k -> new LinkedHashSet<>()).add(confirmBy);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (Map.Entry<String, List<String>> entry : customerOrderMap.entrySet()) {
|
|
|
|
|
+ String customerCode = entry.getKey();
|
|
|
|
|
+ List<String> orderNumbers = entry.getValue();
|
|
|
|
|
+ Set<String> confirmBys = customerConfirmByMap.get(customerCode);
|
|
|
|
|
+
|
|
|
|
|
+ // 拼装通知内容
|
|
|
|
|
+ String orderList = String.join("、", orderNumbers);
|
|
|
|
|
+ String msgContent = "因经销商交货冻结,已取消以下订单的要货,如需重新要货,请解冻后再操作:" + orderList;
|
|
|
|
|
+
|
|
|
|
|
+ // 收集收件人(用 | 分隔,企微支持多人合并)
|
|
|
|
|
+ Set<String> toUserSet = new LinkedHashSet<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 经销商侧负责人
|
|
|
|
|
+ Map<String, Map<String, Object>> cusUserMap =
|
|
|
|
|
+ userMapper.selectLoginNamesByOrgCodeSelf(customerCode);
|
|
|
|
|
+ if (cusUserMap != null && cusUserMap.containsKey(customerCode)) {
|
|
|
|
|
+ Object touser = cusUserMap.get(customerCode).get("touser");
|
|
|
|
|
+ if (touser != null && StringUtils.isNotBlank(touser.toString())) {
|
|
|
|
|
+ Arrays.stream(touser.toString().split("\\|"))
|
|
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
|
+ .forEach(toUserSet::add);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 要货人(confirm_by 即 sys_user.login_name)
|
|
|
|
|
+ for (String confirmBy : confirmBys) {
|
|
|
|
|
+ if (StringUtils.isNotBlank(confirmBy)) {
|
|
|
|
|
+ toUserSet.add(confirmBy);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 对应销售
|
|
|
|
|
+ String salesLoginName = userMapper.selectLoginNameByCustomerCode(customerCode);
|
|
|
|
|
+ if (StringUtils.isNotBlank(salesLoginName)) {
|
|
|
|
|
+ Arrays.stream(salesLoginName.split("\\|"))
|
|
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
|
+ .forEach(toUserSet::add);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 查询收件人失败不阻断主流程
|
|
|
|
|
+ org.slf4j.LoggerFactory.getLogger(WxSendMessageServiceImpl.class)
|
|
|
|
|
+ .error("【交货冻结取货】查询企微通知收件人失败,经销商编码={}", customerCode, e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (toUserSet.isEmpty()) {
|
|
|
|
|
+ org.slf4j.LoggerFactory.getLogger(WxSendMessageServiceImpl.class)
|
|
|
|
|
+ .warn("【交货冻结取货】经销商 {} 未找到任何企微收件人,跳过通知", customerCode);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 发送(|分隔多人)
|
|
|
|
|
+ String toUserStr = String.join("|", toUserSet);
|
|
|
|
|
+ qyWxSendMessageUtil.sendMsgSelfToCustomer(toUserStr, msgContent, "50");
|
|
|
|
|
+
|
|
|
|
|
+ org.slf4j.LoggerFactory.getLogger(WxSendMessageServiceImpl.class)
|
|
|
|
|
+ .info("【交货冻结取货】已向经销商 {} 相关人员 [{}] 发送企微通知,订单:{}",
|
|
|
|
|
+ customerCode, toUserStr, orderList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Set<String> getConfigValueSet(String dictType){
|
|
public Set<String> getConfigValueSet(String dictType){
|
|
|
Set<String> res = new HashSet<>();
|
|
Set<String> res = new HashSet<>();
|
|
|
List<SysDictData> dictDatas = sysDictDataService.selectSimpleDictDataByType(dictType);
|
|
List<SysDictData> dictDatas = sysDictDataService.selectSimpleDictDataByType(dictType);
|
|
@@ -284,6 +365,7 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
}
|
|
}
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
void sendQw(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
void sendQw(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
|
String sendQwUser = getConfigValueUserAccount("sendQwEarlyWarning");
|
|
String sendQwUser = getConfigValueUserAccount("sendQwEarlyWarning");
|
|
|
if(sendQwUser !=null && !("").equals(sendQwUser) ){
|
|
if(sendQwUser !=null && !("").equals(sendQwUser) ){
|
|
@@ -296,41 +378,32 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
qyWxSendMessageUtil.sendMsgSelfToCustomer(sendQwUser,messageDetail, "66");
|
|
qyWxSendMessageUtil.sendMsgSelfToCustomer(sendQwUser,messageDetail, "66");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
void sendMail(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
void sendMail(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName){
|
|
|
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
|
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
|
|
- Properties props = new Properties(); // 参数配置
|
|
|
|
|
- props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
|
|
- props.setProperty("mail.smtp.host", myEmailSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
|
|
|
|
+ Properties props = new Properties();
|
|
|
|
|
+ props.setProperty("mail.transport.protocol", "smtp");
|
|
|
|
|
+ props.setProperty("mail.smtp.host", myEmailSMTPHost);
|
|
|
props.setProperty("mail.smtp.port", "25");
|
|
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"); // 需要请求认证
|
|
|
|
|
|
|
+ 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");
|
|
Set<String> sendEmailUser = getConfigValueSet("sendMailEarlyWarning");
|
|
|
Session session = Session.getDefaultInstance(props);
|
|
Session session = Session.getDefaultInstance(props);
|
|
|
session.setDebug(true);
|
|
session.setDebug(true);
|
|
|
|
|
|
|
|
- for (String email : sendEmailUser
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ for (String email : sendEmailUser) {
|
|
|
Mail mail = new Mail();
|
|
Mail mail = new Mail();
|
|
|
try {
|
|
try {
|
|
|
mail.setFrom(myEmailAccount);
|
|
mail.setFrom(myEmailAccount);
|
|
|
mail.setTo(email);
|
|
mail.setTo(email);
|
|
|
mail.setSubject("立邦随身邦业绩进度数据源预警");
|
|
mail.setSubject("立邦随身邦业绩进度数据源预警");
|
|
|
mail.setContent(getHtmlUserContextList(tucValue,oldValue,type,orgCode,orgName));
|
|
mail.setContent(getHtmlUserContextList(tucValue,oldValue,type,orgCode,orgName));
|
|
|
- //mailUtils.sendMailHtml(mailFromUsername, email, "用户账号重复通知", "您好,重复用户信息如下<br>" + userList);
|
|
|
|
|
MimeMessage message = mailUtils.createMimeMessage(session, myEmailAccount, email, mail);
|
|
MimeMessage message = mailUtils.createMimeMessage(session, myEmailAccount, email, mail);
|
|
|
-
|
|
|
|
|
- // 4. 根据 Session 获取邮件传输对象
|
|
|
|
|
Transport transport = session.getTransport();
|
|
Transport transport = session.getTransport();
|
|
|
-
|
|
|
|
|
transport.connect(myEmailAccount, myEmailPassword);
|
|
transport.connect(myEmailAccount, myEmailPassword);
|
|
|
-
|
|
|
|
|
- // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
|
|
|
|
transport.sendMessage(message, message.getAllRecipients());
|
|
transport.sendMessage(message, message.getAllRecipients());
|
|
|
-
|
|
|
|
|
- // 7. 关闭连接
|
|
|
|
|
transport.close();
|
|
transport.close();
|
|
|
} catch (NoSuchProviderException e) {
|
|
} catch (NoSuchProviderException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -340,11 +413,9 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public String getHtmlUserContextList(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName) {
|
|
public String getHtmlUserContextList(BigDecimal tucValue,BigDecimal oldValue,int type,String orgCode,String orgName) {
|
|
|
-
|
|
|
|
|
String str = "";
|
|
String str = "";
|
|
|
String html ="";
|
|
String html ="";
|
|
|
if(type == 1){
|
|
if(type == 1){
|
|
@@ -366,7 +437,6 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
" </tr>" +
|
|
" </tr>" +
|
|
|
str +
|
|
str +
|
|
|
"</table>";
|
|
"</table>";
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(type == 2){
|
|
if(type == 2){
|
|
@@ -388,7 +458,6 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
|
|
|
" </tr>" +
|
|
" </tr>" +
|
|
|
str +
|
|
str +
|
|
|
"</table>";
|
|
"</table>";
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
return html;
|