邮件发送
This commit is contained in:
parent
c2e3ca063c
commit
9d1f0f5852
|
@ -0,0 +1,10 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.dao;
|
||||||
|
|
||||||
|
import com.hzya.frame.basedao.dao.IBaseDao;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.entity.SendEmailEntity;
|
||||||
|
|
||||||
|
public interface ISendEmailDao extends IBaseDao<SendEmailEntity, String> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.dao.impl;
|
||||||
|
|
||||||
|
import com.hzya.frame.basedao.dao.MybatisGenericDao;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.dao.ISendEmailDao;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.entity.SendEmailEntity;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class SendEmailDaoImpl extends MybatisGenericDao<SendEmailEntity, String> implements ISendEmailDao {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.entity;
|
||||||
|
|
||||||
|
import com.hzya.frame.web.entity.BaseEntity;
|
||||||
|
|
||||||
|
public class SendEmailEntity extends BaseEntity {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.hzya.frame.plugin.sendEmail.dao.impl.SendEmailDaoImpl">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.plugin;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hzya.frame.base.PluginBaseEntity;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.service.ISendEmailService;
|
||||||
|
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件发送
|
||||||
|
*
|
||||||
|
* @author makejava
|
||||||
|
* @since 2024-06-21 13:52:35
|
||||||
|
*/
|
||||||
|
public class SendEmailPluginInitializer extends PluginBaseEntity{
|
||||||
|
Logger logger = LoggerFactory.getLogger(SendEmailPluginInitializer.class);
|
||||||
|
@Autowired
|
||||||
|
private ISendEmailService sendEmailService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
logger.info(getPluginLabel() + "执行初始化方法initialize()");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
logger.info(getPluginLabel() + "执行销毁方法destroy()");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginId() {
|
||||||
|
return "SendEmailPlugin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginName() {
|
||||||
|
return "SendEmailPlugin插件";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginLabel() {
|
||||||
|
return "SendEmailPlugin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginType() {
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public JsonResultEntity executeBusiness(JSONObject requestJson) {
|
||||||
|
try {
|
||||||
|
logger.info("======开始执行邮件发送同步========");
|
||||||
|
return sendEmailService.sendEmail(requestJson);
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.info("======执行邮件发送同步失败:{}========",e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hzya.frame.basedao.service.IBaseService;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.entity.SendEmailEntity;
|
||||||
|
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||||
|
|
||||||
|
public interface ISendEmailService extends IBaseService<SendEmailEntity, String>{
|
||||||
|
/**
|
||||||
|
* @Author lvleigang
|
||||||
|
* @Description 发送邮件
|
||||||
|
* @Date 5:31 下午 2025/6/26
|
||||||
|
* @param requestJson
|
||||||
|
* @return com.hzya.frame.web.entity.JsonResultEntity
|
||||||
|
**/
|
||||||
|
JsonResultEntity sendEmail(JSONObject requestJson);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.hzya.frame.plugin.sendEmail.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hzya.frame.basedao.service.impl.BaseService;
|
||||||
|
import com.hzya.frame.email.EmailUtil;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.dao.ISendEmailDao;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.entity.SendEmailEntity;
|
||||||
|
import com.hzya.frame.plugin.sendEmail.service.ISendEmailService;
|
||||||
|
import com.hzya.frame.web.entity.BaseResult;
|
||||||
|
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SendEmailServiceImpl extends BaseService<SendEmailEntity, String> implements ISendEmailService {
|
||||||
|
@Value("${zt.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private ISendEmailDao sendEmailDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EmailUtil emailUtil;
|
||||||
|
@Autowired
|
||||||
|
public void setSendEmailDao(ISendEmailDao dao) {
|
||||||
|
this.sendEmailDao = dao;
|
||||||
|
this.dao = dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param requestJson
|
||||||
|
* @return com.hzya.frame.web.entity.JsonResultEntity
|
||||||
|
* @Author lvleigang
|
||||||
|
* @Description 发送邮件
|
||||||
|
* @Date 1:44 下午 2025/7/9
|
||||||
|
**/
|
||||||
|
public JsonResultEntity sendEmail(JSONObject requestJson) {
|
||||||
|
logger.error("发送邮件入参:" + requestJson.toJSONString());
|
||||||
|
JSONObject jsonStr = requestJson.getJSONObject("jsonStr");
|
||||||
|
if (jsonStr == null) {
|
||||||
|
return BaseResult.getFailureMessageEntity("系统错误");
|
||||||
|
}
|
||||||
|
JSONObject businessDataStr = jsonStr.getJSONObject("businessDataStr");
|
||||||
|
if (businessDataStr == null) {
|
||||||
|
return BaseResult.getFailureMessageEntity("系统错误");
|
||||||
|
}
|
||||||
|
JSONObject mainData = businessDataStr.getJSONObject("formmain_1233");
|
||||||
|
if (mainData == null) {
|
||||||
|
return BaseResult.getFailureMessageEntity("系统错误");
|
||||||
|
}
|
||||||
|
String sendEmail = mainData.getString("field0034");//供应商邮箱
|
||||||
|
if(sendEmail == null || "".equals(sendEmail)){
|
||||||
|
return BaseResult.getFailureMessageEntity("供应商邮箱为空,请检查");
|
||||||
|
}
|
||||||
|
String subject = null;
|
||||||
|
//subject = mainData.getString("field0034");//todo
|
||||||
|
if(sendEmail == null || "".equals(sendEmail)){
|
||||||
|
subject = "采购";
|
||||||
|
}
|
||||||
|
JSONArray detailArray = businessDataStr.getJSONArray("formson_1234");
|
||||||
|
//组装发送数据
|
||||||
|
String htmls = null;
|
||||||
|
try {
|
||||||
|
htmls = getSendData(mainData, detailArray);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return BaseResult.getFailureMessageEntity("发送邮件失败:组装数据失败");
|
||||||
|
}
|
||||||
|
//发送数据
|
||||||
|
logger.error("发送邮件发送数据:" + htmls);
|
||||||
|
try {
|
||||||
|
String filePath = "/Users/apple/Desktop/【C4协同费控产品】(报表相关)字典说明zm@2025.pdf";
|
||||||
|
File file = new File(filePath);
|
||||||
|
List<MultipartFile> attachments = new ArrayList<>();
|
||||||
|
try (FileInputStream input = new FileInputStream(file)) {
|
||||||
|
MultipartFile multipartFile = new MockMultipartFile(
|
||||||
|
file.getName(), // 对应表单中的文件字段名
|
||||||
|
file.getName(), // 原始文件名
|
||||||
|
"application/pdf", // 或根据文件类型指定 MIME 类型
|
||||||
|
input
|
||||||
|
);
|
||||||
|
attachments.add(multipartFile);
|
||||||
|
}
|
||||||
|
emailUtil.sendHtmlAndFileMessage(sendEmail,subject, htmls,attachments);
|
||||||
|
return BaseResult.getSuccessMessageEntity("发送邮件成功");
|
||||||
|
}catch (Exception e){
|
||||||
|
return BaseResult.getFailureMessageEntity("发送邮件失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mainData
|
||||||
|
* @param detailArray
|
||||||
|
* @return com.alibaba.fastjson.JSONObject
|
||||||
|
* @Author lvleigang
|
||||||
|
* @Description 组装数据
|
||||||
|
* @Date 6:12 下午 2025/6/27
|
||||||
|
**/
|
||||||
|
private String getSendData(JSONObject mainData, JSONArray detailArray) throws ParseException {
|
||||||
|
JSONObject sendData = new JSONObject();
|
||||||
|
sendData.put("buyerName", mainData.getString("field0092"));//购方名称
|
||||||
|
|
||||||
|
if (detailArray != null && detailArray.size() > 0) {
|
||||||
|
for (int i = 0; i < detailArray.size(); i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sendData.toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<plugin>
|
||||||
|
<id>SendEmailPlugin</id>
|
||||||
|
<name>SendEmailPlugin插件</name>
|
||||||
|
<category>20250731001</category>
|
||||||
|
</plugin>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||||
|
<beans default-autowire="byName">
|
||||||
|
<bean name="sendEmailDao" class="com.hzya.frame.plugin.sendEmail.dao.impl.SendEmailDaoImpl" />
|
||||||
|
</beans>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||||
|
<beans default-autowire="byName">
|
||||||
|
<bean name="sendEmailPluginInitializer" class="com.hzya.frame.plugin.sendEmail.plugin.SendEmailPluginInitializer" />
|
||||||
|
</beans>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||||
|
<beans default-autowire="byName">
|
||||||
|
<bean name="sendEmailService" class="com.hzya.frame.plugin.sendEmail.service.impl.SendEmailServiceImpl" />
|
||||||
|
</beans>
|
Loading…
Reference in New Issue