|
|
|
@@ -1,10 +1,15 @@ |
|
|
|
package com.iformall.service.msg.impl; |
|
|
|
|
|
|
|
import com.iformall.domain.po.WxMsgValidationcode; |
|
|
|
import com.iformall.domain.po.WxMsgValidationcodeModel; |
|
|
|
import com.iformall.domain.po.msg.BaseMsg; |
|
|
|
import com.iformall.domain.po.msg.MailMsg; |
|
|
|
import com.iformall.domain.po.WxMsgModel; |
|
|
|
import com.iformall.mapper.WxMsgModelMapper; |
|
|
|
import com.iformall.mapper.WxMsgValidationcodeMapper; |
|
|
|
import com.iformall.mapper.WxMsgValidationcodeModelMapper; |
|
|
|
import com.iformall.service.msg.MsgSendService; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@@ -15,8 +20,11 @@ import org.springframework.mail.SimpleMailMessage; |
|
|
|
import org.springframework.mail.javamail.JavaMailSender; |
|
|
|
import org.springframework.mail.javamail.MimeMessageHelper; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.w3c.dom.stylesheets.LinkStyle; |
|
|
|
|
|
|
|
import javax.mail.internet.MimeMessage; |
|
|
|
import java.io.File; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -30,25 +38,26 @@ public class SendEmailServiceImpl implements MsgSendService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private JavaMailSender sender; |
|
|
|
|
|
|
|
@Value("${spring.mail.username}") |
|
|
|
private String from; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMsgModelMapper wxMsgModelMapper; |
|
|
|
@Autowired |
|
|
|
private WxMsgValidationcodeModelMapper wxMsgValidationcodeModelMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void send(BaseMsg baseMsg) throws Exception{ |
|
|
|
MailMsg mailMsg = (MailMsg)baseMsg; |
|
|
|
//根据模板替换动态内容 |
|
|
|
if(mailMsg.getModelId() != null){ |
|
|
|
WxMsgModel msgModel = new WxMsgModel(); |
|
|
|
WxMsgValidationcodeModel msgModel = new WxMsgValidationcodeModel(); |
|
|
|
msgModel.setTenantId(mailMsg.getTenantId()); |
|
|
|
msgModel.setModelId(mailMsg.getModelId()); |
|
|
|
WxMsgModel wxMsgModel = wxMsgModelMapper.findOneByModelId(msgModel); |
|
|
|
if(wxMsgModel == null){ |
|
|
|
msgModel.setType(mailMsg.getModelId()); |
|
|
|
List<WxMsgValidationcodeModel> modelList = wxMsgValidationcodeModelMapper.findList(msgModel); |
|
|
|
if(CollectionUtils.isEmpty(modelList)){ |
|
|
|
throw new Exception("模板id:"+mailMsg.getModelId()+"不存在"); |
|
|
|
} |
|
|
|
WxMsgValidationcodeModel wxMsgModel = modelList.get(0); |
|
|
|
|
|
|
|
String msg = wxMsgModel.getContent(); |
|
|
|
for (Map.Entry<String, String> entry : mailMsg.getDynamicContentMap().entrySet()) { |
|
|
|
|