From 3083b84c803a7180351b0a98cfcd3f4899949e72 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Mon, 13 Jan 2025 09:38:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=82=AE=E4=BB=B6=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E8=A1=A8=E9=99=84=E5=8A=A0=E5=88=B0=E5=85=A8=E5=9B=BD=E7=81=AB?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../xkrs/controller/EmailEventController.java | 90 ++++++ src/main/java/com/xkrs/dao/EmailEventDao.java | 10 + .../xkrs/model/entity/EmailEventEntity.java | 260 ++++++++++++++++++ .../java/com/xkrs/model/qo/EmailEventQo.java | 212 ++++++++++++++ 5 files changed, 573 insertions(+) create mode 100644 src/main/java/com/xkrs/controller/EmailEventController.java create mode 100644 src/main/java/com/xkrs/dao/EmailEventDao.java create mode 100644 src/main/java/com/xkrs/model/entity/EmailEventEntity.java create mode 100644 src/main/java/com/xkrs/model/qo/EmailEventQo.java diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 14595df..ab0b486 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -38,6 +38,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/debug").permitAll() .antMatchers("/queryFirePoint").permitAll() .antMatchers("/queryNotice").permitAll()//查询通知 + .antMatchers(HttpMethod.POST, "/add_email_event").permitAll()//新增邮件事件 .antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll() diff --git a/src/main/java/com/xkrs/controller/EmailEventController.java b/src/main/java/com/xkrs/controller/EmailEventController.java new file mode 100644 index 0000000..ee68e11 --- /dev/null +++ b/src/main/java/com/xkrs/controller/EmailEventController.java @@ -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); + } + + } + +} diff --git a/src/main/java/com/xkrs/dao/EmailEventDao.java b/src/main/java/com/xkrs/dao/EmailEventDao.java new file mode 100644 index 0000000..244bd3c --- /dev/null +++ b/src/main/java/com/xkrs/dao/EmailEventDao.java @@ -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, JpaSpecificationExecutor { +} diff --git a/src/main/java/com/xkrs/model/entity/EmailEventEntity.java b/src/main/java/com/xkrs/model/entity/EmailEventEntity.java new file mode 100644 index 0000000..7b8b82c --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/EmailEventEntity.java @@ -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; + } + +} diff --git a/src/main/java/com/xkrs/model/qo/EmailEventQo.java b/src/main/java/com/xkrs/model/qo/EmailEventQo.java new file mode 100644 index 0000000..221da5d --- /dev/null +++ b/src/main/java/com/xkrs/model/qo/EmailEventQo.java @@ -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; + } + +}