|
|
@@ -1,21 +1,27 @@
|
|
|
package com.uas.platform.b2b.listener;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.message.mail.service.MailService;
|
|
|
+import com.uas.platform.b2b.core.util.DateFormatUtils;
|
|
|
import com.uas.platform.b2b.dao.*;
|
|
|
import com.uas.platform.b2b.erp.model.UserAndEnterprise;
|
|
|
import com.uas.platform.b2b.event.*;
|
|
|
import com.uas.platform.b2b.mobile.service.MobileReleaseService;
|
|
|
import com.uas.platform.b2b.model.*;
|
|
|
+import com.uas.platform.b2b.support.MessageConf;
|
|
|
+import com.uas.platform.b2b.support.SystemSession;
|
|
|
+import com.uas.platform.b2b.temporary.model.SmsMessage;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
+import com.uas.platform.core.util.HttpUtil;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 监听新增数据事件
|
|
|
@@ -45,12 +51,25 @@ public class MessageListener implements ApplicationListener<SaveReleaseEvent<?,
|
|
|
@Autowired
|
|
|
private MobileReleaseService mobileReleaseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MailService mailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageConf messageConf;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CommonDao commonDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private NoticeDao noticeDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private PurcInquiryItemDao purcInquiryItemDao;
|
|
|
|
|
|
+ private static final String emailRegex = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
|
|
|
+
|
|
|
+ private static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18|17)\\d{9}$";
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Async
|
|
|
@Override
|
|
|
@@ -119,6 +138,93 @@ public class MessageListener implements ApplicationListener<SaveReleaseEvent<?,
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 发送邮件
|
|
|
+ List<User> userEmails = commonDao.query(
|
|
|
+ "select distinct user_email userEmail from sec$users u left join sec$userrole ur on u.user_uu = ur.user_uu " +
|
|
|
+ "left join sec$roles r on r.role_id = ur.role_id " +
|
|
|
+ "where r.role_desc = '业务员' and u.user_email is not null and r.role_enuu = " + enter.getEnuu(),
|
|
|
+ User.class);
|
|
|
+ if (CollectionUtils.isEmpty(userEmails)) {
|
|
|
+ userEmails = commonDao.query(
|
|
|
+ "select distinct user_email userEmail from sec$users u left join sec$userrole ur on u.user_uu = ur.user_uu " +
|
|
|
+ "left join sec$roles r on r.role_id = ur.role_id " +
|
|
|
+ "where r.role_desc = '管理员' and u.user_email is not null and r.role_enuu = " + enter.getEnuu(),
|
|
|
+ User.class);
|
|
|
+ }
|
|
|
+ // 发邮件
|
|
|
+ Map<String, Object> model = new HashMap<String, Object>();
|
|
|
+ Enterprise vendor = enterpriseDao.findOne(enter.getEnuu());
|
|
|
+ if (null != vendor) {
|
|
|
+ model.put("vendorname", vendor.getEnName());
|
|
|
+ } else {
|
|
|
+ model.put("vendorname", "供应商");
|
|
|
+ }
|
|
|
+ if (null != item.getInquiry().getEnterprise()) {
|
|
|
+ model.put("custname", item.getInquiry().getEnterprise().getEnName());
|
|
|
+ } else {
|
|
|
+ model.put("custname", "");
|
|
|
+ }
|
|
|
+ model.put("code", item.getInquiry().getCode());
|
|
|
+ model.put("date", DateFormatUtils.DATE_FORMAT.format(new Date()));
|
|
|
+ for (User userEmail : userEmails) {
|
|
|
+ if (Pattern.matches(emailRegex, userEmail.getUserEmail())) {
|
|
|
+ try {
|
|
|
+ mailService.send(messageConf.getTplInquiryForB2B(), userEmail.getUserEmail(), model);
|
|
|
+// noticeDao.saveErpLog(detail.getPagingRelease().getEmName(), "",
|
|
|
+// detail.getPagingRelease().getEnUU(), detail.getPagingRelease().getEmUU(),
|
|
|
+// "公共询价单通知邮件", "发送成功,询价单号" + detail.getPagingRelease().getCode());
|
|
|
+ } catch (Exception e) {
|
|
|
+// noticeDao.saveErpLog(detail.getPagingRelease().getEmName(), "",
|
|
|
+// detail.getPagingRelease().getEnUU(), detail.getPagingRelease().getEmUU(),
|
|
|
+// "公共询价单通知邮件", "发送失败,询价单号" + detail.getPagingRelease().getCode());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// // 发送短信
|
|
|
+// List<User> userTels = commonDao.query(
|
|
|
+// "select distinct user_tel userTel from sec$users u left join sec$userrole ur on u.user_uu = ur.user_uu " +
|
|
|
+// "left join sec$roles r on r.role_id = ur.role_id " +
|
|
|
+// "where r.role_desc = '业务员' and u.user_tel is not null and r.role_enuu = " + enter.getEnuu(),
|
|
|
+// User.class);
|
|
|
+// if (CollectionUtils.isEmpty(userEmails)) {
|
|
|
+// userTels = commonDao.query(
|
|
|
+// "select distinct user_tel userTel from sec$users u left join sec$userrole ur on u.user_uu = ur.user_uu " +
|
|
|
+// "left join sec$roles r on r.role_id = ur.role_id " +
|
|
|
+// "where r.role_desc = '管理员' and u.user_tel is not null and r.role_enuu = " + enter.getEnuu(),
|
|
|
+// User.class);
|
|
|
+// }
|
|
|
+// // 短信设置
|
|
|
+// SmsMessage sms = new SmsMessage();
|
|
|
+// List<Object> obj = new ArrayList<Object>();
|
|
|
+// if (null != detail.getPagingRelease().getEnterprise()) {
|
|
|
+// obj.add(detail.getPagingRelease().getEnterprise().getEnName());
|
|
|
+// } else {
|
|
|
+// obj.add("客户");
|
|
|
+// }
|
|
|
+// obj.add(detail.getPagingRelease().getCode());
|
|
|
+// sms.setParams(obj);
|
|
|
+// // 发短信
|
|
|
+// for (User userTel : userTels) {
|
|
|
+// if(null != userTel.getUserTel() && userTel.getUserTel().matches(TEL_REGEXP)) {//手机号判断
|
|
|
+// try {
|
|
|
+// sms.setReceiver(userTel.getUserTel());
|
|
|
+// sms.setTemplateId(messageConf.getMsgInquiryForB2B());
|
|
|
+// HttpUtil.sendPost(messageConf.getMessageUrl(), FlexJsonUtils.toJsonDeep(sms));
|
|
|
+// noticeDao.saveErpLog(detail.getPagingRelease().getEmName(), "",
|
|
|
+// detail.getPagingRelease().getEnUU(), detail.getPagingRelease().getEmUU(),
|
|
|
+// "公共询价单通知短信", "发送成功,询价单号" + detail.getPagingRelease().getCode());
|
|
|
+// } catch (Exception e) {
|
|
|
+// noticeDao.saveErpLog(detail.getPagingRelease().getEmName(), "",
|
|
|
+// detail.getPagingRelease().getEnUU(), detail.getPagingRelease().getEmUU(),
|
|
|
+// "公共询价单通知短信", "发送失败,询价单号" + detail.getPagingRelease().getCode());
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
enUUs.add(enter.getEnuu());
|
|
|
}
|
|
|
}
|