邮件model层
This commit is contained in:
parent
7eda1393db
commit
566c745bfd
|
@ -79,12 +79,6 @@
|
|||
<version>2.3.4.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package cn.org.gitlink.notification.model.dao.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class EmailJob {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private Integer sender;
|
||||
|
||||
private String emails;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String content;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date createdAt;
|
||||
|
||||
@JsonProperty("dispatched_at")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date dispatchedAt;
|
||||
|
||||
private Integer dispatchedStatus;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(Integer sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public void setEmails(String emails) {
|
||||
this.emails = emails == null ? null : emails.trim();
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject == null ? null : subject.trim();
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content == null ? null : content.trim();
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getDispatchedAt() {
|
||||
return dispatchedAt;
|
||||
}
|
||||
|
||||
public void setDispatchedAt(Date dispatchedAt) {
|
||||
this.dispatchedAt = dispatchedAt;
|
||||
}
|
||||
|
||||
public Integer getDispatchedStatus() {
|
||||
return dispatchedStatus;
|
||||
}
|
||||
|
||||
public void setDispatchedStatus(Integer dispatchedStatus) {
|
||||
this.dispatchedStatus = dispatchedStatus;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package cn.org.gitlink.notification.model.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class EmailSendRecord {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String email;
|
||||
|
||||
private Integer jobId;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date createdAt;
|
||||
|
||||
@JsonProperty("sent_at")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date sentAt;
|
||||
|
||||
private Integer status;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email == null ? null : email.trim();
|
||||
}
|
||||
|
||||
public Integer getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
public void setJobId(Integer jobId) {
|
||||
this.jobId = jobId;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getSentAt() {
|
||||
return sentAt;
|
||||
}
|
||||
|
||||
public void setSentAt(Date sentAt) {
|
||||
this.sentAt = sentAt;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package cn.org.gitlink.notification.model.dao.entity.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public class NewEmailJobParamsVo {
|
||||
|
||||
@ApiModelProperty(value = "邮件发送者", required = true)
|
||||
@NotNull(message = "邮件发送者不能为空")
|
||||
@Range(min = Integer.MIN_VALUE, max = Integer.MAX_VALUE)
|
||||
private Integer sender;
|
||||
|
||||
@ApiModelProperty(value = "邮件地址,eg: w@163.com,j@163.com", required = true)
|
||||
@Pattern(regexp = "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*(,\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)*$", message = "邮件地址串非法")
|
||||
@NotBlank(message = "邮件地址不能为空")
|
||||
private String emails;
|
||||
|
||||
@ApiModelProperty(value = "邮件主题", required = true)
|
||||
@NotBlank(message = "邮件主题不能为空")
|
||||
@Size(max = 255, message = "邮件主题长度在0~255")
|
||||
private String subject;
|
||||
|
||||
@ApiModelProperty(value = "邮件内容", required = true)
|
||||
@NotBlank(message = "邮件内容不能为空")
|
||||
private String content;
|
||||
|
||||
public Integer getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(Integer sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public void setEmails(String emails) {
|
||||
this.emails = emails;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package cn.org.gitlink.notification.model.dao.entity.vo;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public class NewEmailJobVo {
|
||||
//平台编码
|
||||
private String platform;
|
||||
|
||||
@ApiModelProperty(value = "邮件发送者", required = true)
|
||||
@NotNull(message = "邮件发送者不能为空")
|
||||
@Range(min = Integer.MIN_VALUE, max = Integer.MAX_VALUE)
|
||||
private Integer sender;
|
||||
|
||||
@ApiModelProperty(value = "邮件地址,eg: w@163.com,j@163.com", required = true)
|
||||
@Pattern(regexp = "^(\\-|\\+?)\\d+(,\\d+)*$", message = "邮件地址串非法")
|
||||
@NotBlank(message = "邮件地址不能为空")
|
||||
private String emails;
|
||||
|
||||
@ApiModelProperty(value = "邮件主题", required = true)
|
||||
@NotBlank(message = "邮件主题不能为空")
|
||||
@Size(max = 255, message = "邮件主题长度在0~255")
|
||||
private String subject;
|
||||
|
||||
@ApiModelProperty(value = "邮件内容", required = true)
|
||||
@NotBlank(message = "邮件内容不能为空")
|
||||
private String content;
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public Integer getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(Integer sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public void setEmails(String emails) {
|
||||
this.emails = emails;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package cn.org.gitlink.notification.model.dao.mapper;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailJob;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailJobsMapper extends BaseMapper<EmailJob> {
|
||||
int deleteByPrimaryKey(@Param("platform") String platform, Integer id);
|
||||
|
||||
int insert(@Param("platform") String platform, @Param("record") EmailJob record);
|
||||
|
||||
int insertSelective(@Param("platform") String platform, @Param("record") EmailJob record);
|
||||
|
||||
EmailJob selectByPrimaryKey(@Param("platform") String platform, Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(@Param("platform") String platform, @Param("record") EmailJob record);
|
||||
|
||||
int updateByPrimaryKey(@Param("platform") String platform, @Param("record") EmailJob record);
|
||||
|
||||
List<EmailJob> getNotDispatchedEmailJobs(@Param("platform") String platform);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.org.gitlink.notification.model.dao.mapper;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailSendRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailSendRecordsMapper extends BaseMapper<EmailSendRecord> {
|
||||
int deleteByPrimaryKey(@Param("platform") String platform, Integer id);
|
||||
|
||||
int insert(@Param("platform") String platform, @Param("record") EmailSendRecord record);
|
||||
|
||||
int insertSelective(@Param("platform") String platform, @Param("record") EmailSendRecord record);
|
||||
|
||||
EmailSendRecord selectByPrimaryKey(@Param("platform") String platform, Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(@Param("platform") String platform, @Param("record") EmailSendRecord record);
|
||||
|
||||
int updateByPrimaryKey(@Param("platform") String platform, @Param("record") EmailSendRecord record);
|
||||
|
||||
//批量插入邮件发送任务记录
|
||||
int insertEmailSendRecordBatch(@Param("platform") String platform,@Param("list") List<EmailSendRecord> emailSendRecordList);
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package cn.org.gitlink.notification.model.service.notification;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailJob;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewEmailJobVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailJobsService extends IService<EmailJob> {
|
||||
|
||||
/**
|
||||
* @Description: 添加发送邮件任务
|
||||
*
|
||||
* @Param newEmailJobVo
|
||||
* @return: boolean
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
boolean sendEmail(NewEmailJobVo newEmailJobVo) throws Exception;
|
||||
|
||||
/**
|
||||
* @Description: 获取所有未处理邮件任务列表
|
||||
*
|
||||
* @Param platform 平台编码
|
||||
* @return: List<EmailJob>
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
List<EmailJob> getNotDispatchedEmailJobs(String platform) throws Exception;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
*
|
||||
* @Param platform 平台编码
|
||||
* @Param emailJobId 邮件任务id
|
||||
* @Param dispatchedAt 处理时间
|
||||
* @Param dispatchedStatus 处理状态 -1 未处理,1 处理成功,2 处理失败
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.org.gitlink.notification.model.service.notification;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailSendRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public interface EmailSendRecordsService extends IService<EmailSendRecord> {
|
||||
/**
|
||||
* @Description: 新增邮件任务到邮件发送记录表中
|
||||
* @Param platform 平台编码
|
||||
* @Param emails 邮件地址,eg: w@163.com,j@163.com
|
||||
* @Param jobId 邮件任务id
|
||||
* @return: boolean
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
boolean newEmailSendRecords(String platform, String emails, Integer jobId) throws Exception;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
*
|
||||
* @Param platform 平台编码
|
||||
* @Param emailSendRecordId 邮件发送记录id
|
||||
* @Param sentAt 发送时间
|
||||
* @Param status 发送状态 -1 未发送,1 发送成功,2 发送失败
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
int markEmailSendRecordAs(String platform, Integer emailSendRecordId, Date sentAt, Integer status) throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.org.gitlink.notification.model.service.notification.impl;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailJob;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewEmailJobVo;
|
||||
import cn.org.gitlink.notification.model.dao.mapper.EmailJobsMapper;
|
||||
import cn.org.gitlink.notification.model.service.notification.EmailJobsService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EmailJobsServiceImpl extends ServiceImpl<EmailJobsMapper, EmailJob> implements EmailJobsService {
|
||||
|
||||
@Override
|
||||
public boolean sendEmail(NewEmailJobVo newEmailJobVo) {
|
||||
String platform = newEmailJobVo.getPlatform();
|
||||
EmailJob emailJob = new EmailJob();
|
||||
BeanUtils.copyProperties(newEmailJobVo, emailJob);
|
||||
return baseMapper.insertSelective(platform, emailJob) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmailJob> getNotDispatchedEmailJobs(String platform) {
|
||||
return baseMapper.getNotDispatchedEmailJobs(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception {
|
||||
EmailJob emailJob = new EmailJob();
|
||||
emailJob.setId(emailJobId);
|
||||
emailJob.setDispatchedAt(dispatchedAt);
|
||||
emailJob.setDispatchedStatus(dispatchedStatus);
|
||||
return baseMapper.updateByPrimaryKeySelective(platform, emailJob);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.org.gitlink.notification.model.service.notification.impl;
|
||||
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailSendRecord;
|
||||
import cn.org.gitlink.notification.model.dao.mapper.EmailSendRecordsMapper;
|
||||
import cn.org.gitlink.notification.model.service.notification.EmailSendRecordsService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EmailSendRecordsServiceImpl extends ServiceImpl<EmailSendRecordsMapper, EmailSendRecord> implements EmailSendRecordsService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean newEmailSendRecords(String platform, String emails, Integer jobId) {
|
||||
EmailSendRecord emailSendRecord = new EmailSendRecord();
|
||||
emailSendRecord.setJobId(jobId);
|
||||
List<String> list = Arrays.asList(emails.split(","));
|
||||
List<EmailSendRecord> emailSendRecordList = new ArrayList<EmailSendRecord>();
|
||||
for (String email : list){
|
||||
emailSendRecord.setEmail(email);
|
||||
emailSendRecordList.add(emailSendRecord);
|
||||
}
|
||||
int i = baseMapper.insertEmailSendRecordBatch(platform, emailSendRecordList);
|
||||
return i > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int markEmailSendRecordAs(String platform, Integer emailSendRecordId, Date sentAt, Integer status) throws Exception {
|
||||
EmailSendRecord emailSendRecord = new EmailSendRecord();
|
||||
emailSendRecord.setId(emailSendRecordId);
|
||||
emailSendRecord.setSentAt(sentAt);
|
||||
emailSendRecord.setStatus(status);
|
||||
return baseMapper.updateByPrimaryKeySelective(platform, emailSendRecord);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?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="cn.org.gitlink.notification.model.dao.mapper.EmailJobsMapper" >
|
||||
<resultMap id="BaseResultMap" type="cn.org.gitlink.notification.model.dao.entity.EmailJob" >
|
||||
<id column="id" property="id" jdbcType="INTEGER" />
|
||||
<result column="sender" property="sender" jdbcType="INTEGER" />
|
||||
<result column="emails" property="emails" jdbcType="VARCHAR" />
|
||||
<result column="subject" property="subject" jdbcType="VARCHAR" />
|
||||
<result column="content" property="content" jdbcType="VARCHAR" />
|
||||
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
|
||||
<result column="dispatched_at" property="dispatchedAt" jdbcType="TIMESTAMP" />
|
||||
<result column="dispatched_status" property="dispatchedStatus" jdbcType="INTEGER" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List" >
|
||||
id, sender, emails, subject, content, created_at, dispatched_at, dispatched_status
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from ${platform}_email_jobs
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
delete from ${platform}_email_jobs
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailJob" >
|
||||
insert into ${platform}_email_jobs (id, sender, emails,
|
||||
subject, content, created_at,
|
||||
dispatched_at, dispatched_status)
|
||||
values (#{record.id,jdbcType=INTEGER}, #{record.sender,jdbcType=INTEGER}, #{record.emails,jdbcType=VARCHAR},
|
||||
#{record.subject,jdbcType=VARCHAR}, #{record.content,jdbcType=VARCHAR}, #{record.createdAt,jdbcType=TIMESTAMP},
|
||||
#{record.dispatchedAt,jdbcType=TIMESTAMP}, #{record.dispatchedStatus,jdbcType=INTEGER})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailJob" >
|
||||
insert into ${platform}_email_jobs
|
||||
<trim prefix="(" suffix=")" suffixOverrides="," >
|
||||
<if test="record.id != null" >
|
||||
id,
|
||||
</if>
|
||||
<if test="record.sender != null" >
|
||||
sender,
|
||||
</if>
|
||||
<if test="record.emails != null" >
|
||||
emails,
|
||||
</if>
|
||||
<if test="record.subject != null" >
|
||||
subject,
|
||||
</if>
|
||||
<if test="record.content != null" >
|
||||
content,
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
created_at,
|
||||
</if>
|
||||
<if test="record.dispatchedAt != null" >
|
||||
dispatched_at,
|
||||
</if>
|
||||
<if test="record.dispatchedStatus != null" >
|
||||
dispatched_status,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
||||
<if test="record.id != null" >
|
||||
#{record.id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.sender != null" >
|
||||
#{record.sender,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.emails != null" >
|
||||
#{record.emails,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.subject != null" >
|
||||
#{record.subject,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.content != null" >
|
||||
#{record.content,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
#{record.createdAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.dispatchedAt != null" >
|
||||
#{record.dispatchedAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.dispatchedStatus != null" >
|
||||
#{record.dispatchedStatus,jdbcType=INTEGER},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailJob" >
|
||||
update ${platform}_email_jobs
|
||||
<set >
|
||||
<if test="record.sender != null" >
|
||||
sender = #{record.sender,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.emails != null" >
|
||||
emails = #{record.emails,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.subject != null" >
|
||||
subject = #{record.subject,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.content != null" >
|
||||
content = #{record.content,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.dispatchedAt != null" >
|
||||
dispatched_at = #{record.dispatchedAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.dispatchedStatus != null" >
|
||||
dispatched_status = #{record.dispatchedStatus,jdbcType=INTEGER},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{record.id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailJob" >
|
||||
update ${platform}_email_jobs
|
||||
set sender = #{record.sender,jdbcType=INTEGER},
|
||||
emails = #{record.emails,jdbcType=VARCHAR},
|
||||
subject = #{record.subject,jdbcType=VARCHAR},
|
||||
content = #{record.content,jdbcType=VARCHAR},
|
||||
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
|
||||
dispatched_at = #{record.dispatchedAt,jdbcType=TIMESTAMP},
|
||||
dispatched_status = #{record.dispatchedStatus,jdbcType=INTEGER}
|
||||
where id = #{record.id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<select id="getNotDispatchedEmailJobs" resultMap="BaseResultMap">
|
||||
select * from ${platform}_email_jobs
|
||||
where dispatched_status = -1
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,120 @@
|
|||
<?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="cn.org.gitlink.notification.model.dao.mapper.EmailSendRecordsMapper" >
|
||||
<resultMap id="BaseResultMap" type="cn.org.gitlink.notification.model.dao.entity.EmailSendRecord" >
|
||||
<id column="id" property="id" jdbcType="INTEGER" />
|
||||
<result column="email" property="email" jdbcType="VARCHAR" />
|
||||
<result column="job_id" property="jobId" jdbcType="INTEGER" />
|
||||
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
|
||||
<result column="sent_at" property="sentAt" jdbcType="TIMESTAMP" />
|
||||
<result column="status" property="status" jdbcType="INTEGER" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List" >
|
||||
id, email, job_id, created_at, sent_at, status
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from ${platform}_email_send_records
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
delete from ${platform}_email_send_records
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailSendRecord" >
|
||||
insert into ${platform}_email_send_records (id, email, job_id,
|
||||
created_at, sent_at, status
|
||||
)
|
||||
values (#{record.id,jdbcType=INTEGER}, #{record.email,jdbcType=VARCHAR}, #{record.jobId,jdbcType=INTEGER},
|
||||
#{record.createdAt,jdbcType=TIMESTAMP}, #{record.sentAt,jdbcType=TIMESTAMP}, #{record.status,jdbcType=INTEGER}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailSendRecord" >
|
||||
insert into ${platform}_email_send_records
|
||||
<trim prefix="(" suffix=")" suffixOverrides="," >
|
||||
<if test="record.id != null" >
|
||||
id,
|
||||
</if>
|
||||
<if test="record.email != null" >
|
||||
email,
|
||||
</if>
|
||||
<if test="record.jobId != null" >
|
||||
job_id,
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
created_at,
|
||||
</if>
|
||||
<if test="record.sentAt != null" >
|
||||
sent_at,
|
||||
</if>
|
||||
<if test="record.status != null" >
|
||||
status,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
||||
<if test="record.id != null" >
|
||||
#{record.id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.email != null" >
|
||||
#{record.email,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.jobId != null" >
|
||||
#{record.jobId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
#{record.createdAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.sentAt != null" >
|
||||
#{record.sentAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.status != null" >
|
||||
#{record.status,jdbcType=INTEGER},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailSendRecord" >
|
||||
update ${platform}_email_send_records
|
||||
<set >
|
||||
<if test="record.email != null" >
|
||||
email = #{record.email,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.jobId != null" >
|
||||
job_id = #{record.jobId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.createdAt != null" >
|
||||
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.sentAt != null" >
|
||||
sent_at = #{record.sentAt,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="record.status != null" >
|
||||
status = #{record.status,jdbcType=INTEGER},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{record.id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="cn.org.gitlink.notification.model.dao.entity.EmailSendRecord" >
|
||||
update ${platform}_email_send_records
|
||||
set email = #{record.email,jdbcType=VARCHAR},
|
||||
job_id = #{record.jobId,jdbcType=INTEGER},
|
||||
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
|
||||
sent_at = #{record.sentAt,jdbcType=TIMESTAMP},
|
||||
status = #{record.status,jdbcType=INTEGER}
|
||||
where id = #{record.id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<insert id ="insertEmailSendRecordBatch" parameterType="java.util.List" >
|
||||
<selectKey resultType ="java.lang.Integer" keyProperty= "id"
|
||||
order= "AFTER">
|
||||
SELECT LAST_INSERT_ID()
|
||||
</selectKey >
|
||||
insert into ${platform}_email_send_records
|
||||
(id, email, job_id)
|
||||
values
|
||||
<foreach collection ="list" item="record" index= "index" separator =",">
|
||||
(
|
||||
#{record.id,jdbcType=INTEGER}, #{record.email,jdbcType=VARCHAR}, #{record.jobId,jdbcType=INTEGER}
|
||||
)
|
||||
</foreach >
|
||||
</insert >
|
||||
</mapper>
|
|
@ -0,0 +1,98 @@
|
|||
package cn.org.gitlink.notification.writer.controller;
|
||||
|
||||
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
||||
import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
||||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
import cn.org.gitlink.notification.common.utils.KafkaUtil;
|
||||
import cn.org.gitlink.notification.common.utils.ValidatorUtils;
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailJob;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewEmailJobParamsVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewEmailJobVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewSysNotificationVo;
|
||||
import cn.org.gitlink.notification.model.service.notification.EmailJobsService;
|
||||
import cn.org.gitlink.notification.model.service.notification.EmailSendRecordsService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/gns/email")
|
||||
@Configuration
|
||||
public class EmailJobsController {
|
||||
|
||||
//todo yml文件中配置topic后替换
|
||||
private static final String GITLINK_EMAIL_TOPIC = "topic_gitlink_email";
|
||||
|
||||
private Logger logger = LogManager.getLogger(EmailJobsController.class);
|
||||
|
||||
@Autowired
|
||||
private KafkaUtil kafkaUtil;
|
||||
|
||||
@ApiOperation("发送邮件任务")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public ResponseData sendNotification(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
||||
@Validated @RequestBody NewEmailJobParamsVo newEmailJobParamsVo,
|
||||
|
||||
BindingResult bindingResult){
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和NewEmailJobParamsVo拼装
|
||||
NewEmailJobVo newEmailJobVo = new NewEmailJobVo();
|
||||
try {
|
||||
BeanUtils.copyProperties(newEmailJobParamsVo, newEmailJobVo);
|
||||
} catch (BeansException e) {
|
||||
logger.error(e);
|
||||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
newEmailJobVo.setPlatform(platform);
|
||||
|
||||
try {
|
||||
//todo creatTopic
|
||||
|
||||
kafkaUtil.sendMessage(GITLINK_EMAIL_TOPIC, JSONObject.toJSONString(newEmailJobVo));
|
||||
return DataPacketUtil.jsonSuccessResult();
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证 platform合法性
|
||||
*
|
||||
* @param platform
|
||||
* @return
|
||||
*/
|
||||
private ResponseData validatePlatformCode(String platform) {
|
||||
|
||||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!NotificationSystemConstant.PLATFORM_CODE_MAP.containsKey(platform)) {
|
||||
logger.debug("\t 输入参数 {platform} 的值 {" + platform + "} 无效");
|
||||
return DataPacketUtil.jsonFailResult("{platform} 参数非法");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue