将邮件事件表附加到全国火系统中

This commit is contained in:
liuchengqian 2025-01-13 09:38:02 +08:00
parent 60aae894f7
commit 3083b84c80
5 changed files with 573 additions and 0 deletions

View File

@ -38,6 +38,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/debug").permitAll() .antMatchers("/debug").permitAll()
.antMatchers("/queryFirePoint").permitAll() .antMatchers("/queryFirePoint").permitAll()
.antMatchers("/queryNotice").permitAll()//查询通知 .antMatchers("/queryNotice").permitAll()//查询通知
.antMatchers(HttpMethod.POST, "/add_email_event").permitAll()//新增邮件事件
.antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll() .antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll()

View File

@ -0,0 +1,90 @@
package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EmailEventDao;
import com.xkrs.model.entity.EmailEventEntity;
import com.xkrs.model.qo.EmailEventQo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@RestController
public class EmailEventController {
public static Logger log = LoggerFactory.getLogger(EmailEventController.class);
private final Locale locale = LocaleContextHolder.getLocale();
@Resource
private EmailEventDao emailEventDao;
@PostMapping("/add_email_event")
public String addEmailEvent(@RequestBody EmailEventQo emailEventQo) {
try {
log.info("add_email_event 添加邮件事件:" + emailEventQo.toString());
EmailEventEntity emailEventEntity = new EmailEventEntity();
emailEventEntity.setEvent(emailEventQo.getEvent());
emailEventEntity.setEmail(emailEventQo.getEmail());
emailEventEntity.setLink(emailEventQo.getLink());
emailEventEntity.setBulkId(emailEventQo.getBulkId());
emailEventEntity.setTimestamp(emailEventQo.getTimestamp());
emailEventEntity.setReason(emailEventQo.getReason());
emailEventEntity.setBounceType(emailEventQo.getBounceType());
emailEventEntity.setUsername(emailEventQo.getUsername());
emailEventEntity.setFrom(emailEventQo.getFrom());
emailEventEntity.setFromDomain(emailEventQo.getFromDomain());
emailEventEntity.setTemplateId(emailEventQo.getTemplateId());
emailEventEntity.setUseragent(emailEventQo.getUseragent());
emailEventEntity.setSubject(emailEventQo.getSubject());
emailEventEntity.setMessageId(emailEventQo.getMessageId());
emailEventEntity.setEventId(emailEventQo.getEventId());
String eventId = emailEventQo.getEventId();
if ("delivered".equals(eventId)) {
emailEventEntity.setEventDesc("递送成功,收件人邮件服务商已接收此邮件");
}
if ("dropped".equals(eventId)) {
emailEventEntity.setEventDesc("因为某种原因,这封邮件不能送达,被丢弃");
}
if ("bounce".equals(eventId)) {
emailEventEntity.setEventDesc("收件人邮件服务商拒收此邮件(一般是因为邮箱地址错误)");
}
if ("open".equals(eventId)) {
emailEventEntity.setEventDesc("收件人打开了此邮件");
}
if ("click".equals(eventId)) {
emailEventEntity.setEventDesc("收件人点击了此邮件中的链接");
}
if ("spamreport".equals(eventId)) {
emailEventEntity.setEventDesc("收件人举报了此邮件");
}
if ("unsubscribe".equals(eventId)) {
emailEventEntity.setEventDesc("收件人点击了业务方的“退订”按钮需要业务方在退订链接中包含unsubscribe关键词");
}
if ("deferred".equals(eventId)) {
emailEventEntity.setEventDesc("邮件被收件人邮件服务商延迟传递,正在重试中");
}
emailEventDao.save(emailEventEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
} catch (Exception e) {
e.printStackTrace();
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "添加失败", locale);
}
}
}

View File

@ -0,0 +1,10 @@
package com.xkrs.dao;
import com.xkrs.model.entity.EmailEventEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
@Component
public interface EmailEventDao extends JpaRepository<EmailEventEntity, Long>, JpaSpecificationExecutor<EmailEventEntity> {
}

View File

@ -0,0 +1,260 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name = "email_event")
public class EmailEventEntity implements Serializable {
/**
* 指定主键建立自增序列主键值取自序列
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "email_event_seq_gen")
@SequenceGenerator(name = "email_event_seq_gen", sequenceName = "email_event_id_seq", allocationSize = 1)
private Long id;
/**
* 事件类型详情请参见 事件类型
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String event;
/**
* 收件人地址
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String email;
/**
* 用户点击的邮件中的链接 URL仅在 event="click"时生效
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String link;
/**
* SendEmail 接囗返回的 MessageId
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String bulkId;
/**
* 事件产生的时间戳
*/
private Long timestamp;
/**
* 邮件递送失败的原因
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String reason;
/**
* 如果收件人邮件服务商拒信拒信类型取值:soft bouncelhard bounce仅在 event="bounce”的时候生效
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String bounceType;
/**
* 腾讯云账号对应的 AppID
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String username;
/**
* 发信地址(不带发件人别名)
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String from;
/**
* 发信域名
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String fromDomain;
/**
* 模板 ID
*/
private Long templateId;
/**
* 用户代理提供有关用于访问邮件的设备操作系统和浏览器的信息仅对 Open Click 事件生效
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String useragent;
/**
* 邮件主题
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String subject;
/**
* smtp 协议头中的 Message-ID用户在使用 smtp API发送时可以传自己定义的邮件唯一标识符注意这个一定
* 要能够唯一标识一封邮件目符合 RFC5322标准
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String messageId;
/**
* 事件ID
* 1:delivered 递送成功收件人邮件服务商已接收此邮件
* 2:dropped 因为某种原因这封邮件不能送达被丢弃
* 3:bounce 收件人邮件服务商拒收此邮件(一般是因为邮箱地址错误)
* 4.open 收件人打开了此邮件
* 5:click 收件人点击了此邮件中的链接
* 6:spamreport 收件人举报了此邮件
* 7:unsubscribe 收件人点击了业务方的退订按钮需要业务方在退订链接中包含"unsubscribe"关键词
* 8:deferred 邮件被收件人邮件服务商延迟传递正在重试中
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String eventId;
/**
* 事件描述
*/
@Column(length = 255, columnDefinition = "varchar(255)")
private String eventDesc;
public EmailEventEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getBulkId() {
return bulkId;
}
public void setBulkId(String bulkId) {
this.bulkId = bulkId;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getBounceType() {
return bounceType;
}
public void setBounceType(String bounceType) {
this.bounceType = bounceType;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getFromDomain() {
return fromDomain;
}
public void setFromDomain(String fromDomain) {
this.fromDomain = fromDomain;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public String getUseragent() {
return useragent;
}
public void setUseragent(String useragent) {
this.useragent = useragent;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getEventId() {
return eventId;
}
public void setEventId(String eventId) {
this.eventId = eventId;
}
public String getEventDesc() {
return eventDesc;
}
public void setEventDesc(String eventDesc) {
this.eventDesc = eventDesc;
}
}

View File

@ -0,0 +1,212 @@
package com.xkrs.model.qo;
public class EmailEventQo {
/**
* 事件类型详情请参见 事件类型
*/
private String event;
/**
* 收件人地址
*/
private String email;
/**
* 用户点击的邮件中的链接 URL仅在 event="click"时生效
*/
private String link;
/**
* SendEmail 接囗返回的 MessageId
*/
private String bulkId;
/**
* 事件产生的时间戳
*/
private Long timestamp;
/**
* 邮件递送失败的原因
*/
private String reason;
/**
* 如果收件人邮件服务商拒信拒信类型取值:soft bouncelhard bounce仅在 event="bounce”的时候生效
*/
private String bounceType;
/**
* 腾讯云账号对应的 AppID
*/
private String username;
/**
* 发信地址(不带发件人别名)
*/
private String from;
/**
* 发信域名
*/
private String fromDomain;
/**
* 模板 ID
*/
private Long templateId;
/**
* 用户代理提供有关用于访问邮件的设备操作系统和浏览器的信息仅对 Open Click 事件生效
*/
private String useragent;
/**
* 邮件主题
*/
private String subject;
/**
* smtp 协议头中的 Message-ID用户在使用 smtp API发送时可以传自己定义的邮件唯一标识符注意这个一定
* 要能够唯一标识一封邮件目符合 RFC5322标准
*/
private String messageId;
/**
* 事件ID
* 1:delivered 递送成功收件人邮件服务商已接收此邮件
* 2:dropped 因为某种原因这封邮件不能送达被丢弃
* 3:bounce 收件人邮件服务商拒收此邮件(一般是因为邮箱地址错误)
* 4.open 收件人打开了此邮件
* 5:click 收件人点击了此邮件中的链接
* 6:spamreport 收件人举报了此邮件
* 7:unsubscribe 收件人点击了业务方的退订按钮需要业务方在退订链接中包含"unsubscribe"关键词
* 8:deferred 邮件被收件人邮件服务商延迟传递正在重试中
*/
private String eventId;
public EmailEventQo() {
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getBulkId() {
return bulkId;
}
public void setBulkId(String bulkId) {
this.bulkId = bulkId;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getBounceType() {
return bounceType;
}
public void setBounceType(String bounceType) {
this.bounceType = bounceType;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getFromDomain() {
return fromDomain;
}
public void setFromDomain(String fromDomain) {
this.fromDomain = fromDomain;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public String getUseragent() {
return useragent;
}
public void setUseragent(String useragent) {
this.useragent = useragent;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getEventId() {
return eventId;
}
public void setEventId(String eventId) {
this.eventId = eventId;
}
}