mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-26 19:51:56 +08:00
新增邮件发送日志
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.mail.MailMessage;
|
||||
import com.ruoyi.common.core.mail.MailSendResult;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.SysMailLog;
|
||||
import com.ruoyi.system.service.ISysMailLogService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件发送日志Controller
|
||||
*
|
||||
* @author ryas
|
||||
* created on 2024-03-01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mailLog")
|
||||
public class SysMailLogController extends BaseController {
|
||||
@Autowired
|
||||
private ISysMailLogService sysMailLogService;
|
||||
|
||||
/**
|
||||
* 查询邮件发送日志列表
|
||||
*/
|
||||
@RequiresPermissions("system:mailLog:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysMailLog sysMailLog) {
|
||||
startPage();
|
||||
List<SysMailLog> list = sysMailLogService.selectSysMailLogList(sysMailLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出邮件发送日志列表
|
||||
*/
|
||||
@RequiresPermissions("system:mailLog:export")
|
||||
@Log(title = "邮件发送日志", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysMailLog sysMailLog) {
|
||||
List<SysMailLog> list = sysMailLogService.selectSysMailLogList(sysMailLog);
|
||||
ExcelUtil<SysMailLog> util = new ExcelUtil<>(SysMailLog.class);
|
||||
util.exportExcel(response, list, "邮件发送日志数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮件发送日志详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:mailLog:query")
|
||||
@GetMapping(value = "/{mailLogId}")
|
||||
public AjaxResult getInfo(@PathVariable("mailLogId") Long mailLogId) {
|
||||
return success(sysMailLogService.selectSysMailLogByMailLogId(mailLogId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 临时邮件发送
|
||||
*/
|
||||
@RequiresPermissions("system:mailLog:send")
|
||||
@Log(title = "临时邮件发送", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/sendTemporality")
|
||||
public AjaxResult sendTemporality(@RequestBody MailMessage message) {
|
||||
MailSendResult result = sysMailLogService.sendTempMail(message);
|
||||
if (result.isSuccess()) {
|
||||
return success();
|
||||
} else {
|
||||
return error(result.getErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除邮件发送日志
|
||||
*/
|
||||
@RequiresPermissions("system:mailLog:remove")
|
||||
@Log(title = "邮件发送日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{mailLogIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] mailLogIds) {
|
||||
return toAjax(sysMailLogService.deleteSysMailLogByMailLogIds(mailLogIds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 邮件发送日志对象 sys_mail_log
|
||||
*
|
||||
* @author ryas
|
||||
* created on 2024-03-01
|
||||
*/
|
||||
public class SysMailLog extends BaseEntity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 日志主键
|
||||
*/
|
||||
private Long mailLogId;
|
||||
|
||||
/**
|
||||
* 发送状态(0未发送 1成功 2失败)
|
||||
*/
|
||||
@Excel(name = "发送状态", readConverterExp = "0=未发送,1=成功,2=失败")
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 自定业务类型
|
||||
*/
|
||||
@Excel(name = "自定业务类型")
|
||||
private String businessType;
|
||||
|
||||
/**
|
||||
* 发件人
|
||||
*/
|
||||
@Excel(name = "发件人")
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* 收件人
|
||||
*/
|
||||
@Excel(name = "收件人")
|
||||
private String to;
|
||||
|
||||
/**
|
||||
* 抄送
|
||||
*/
|
||||
@Excel(name = "抄送")
|
||||
private String cc;
|
||||
|
||||
/**
|
||||
* 邮件主题
|
||||
*/
|
||||
@Excel(name = "邮件主题")
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 日志消息
|
||||
*/
|
||||
@Excel(name = "日志消息")
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 消耗时间(ms)
|
||||
*/
|
||||
@Excel(name = "消耗时间(ms)")
|
||||
private Long costTime;
|
||||
|
||||
public void setMailLogId(Long mailLogId) {
|
||||
this.mailLogId = mailLogId;
|
||||
}
|
||||
|
||||
public Long getMailLogId() {
|
||||
return mailLogId;
|
||||
}
|
||||
|
||||
public void setStatus(Long status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setBusinessType(String businessType) {
|
||||
this.businessType = businessType;
|
||||
}
|
||||
|
||||
public String getBusinessType() {
|
||||
return businessType;
|
||||
}
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setTo(String to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public void setCc(String cc) {
|
||||
this.cc = cc;
|
||||
}
|
||||
|
||||
public String getCc() {
|
||||
return cc;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setCostTime(Long costTime) {
|
||||
this.costTime = costTime;
|
||||
}
|
||||
|
||||
public Long getCostTime() {
|
||||
return costTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("mailLogId", getMailLogId())
|
||||
.append("status", getStatus())
|
||||
.append("businessType", getBusinessType())
|
||||
.append("from", getFrom())
|
||||
.append("to", getTo())
|
||||
.append("cc", getCc())
|
||||
.append("subject", getSubject())
|
||||
.append("msg", getMsg())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("costTime", getCostTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.ruoyi.system.domain.SysMailLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件发送日志Mapper接口
|
||||
*
|
||||
* @author ryas
|
||||
* created on 2024-03-01
|
||||
*/
|
||||
public interface SysMailLogMapper {
|
||||
/**
|
||||
* 查询邮件发送日志
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 邮件发送日志
|
||||
*/
|
||||
SysMailLog selectSysMailLogByMailLogId(Long mailLogId);
|
||||
|
||||
/**
|
||||
* 查询邮件发送日志列表
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 邮件发送日志集合
|
||||
*/
|
||||
List<SysMailLog> selectSysMailLogList(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 新增邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
int insertSysMailLog(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 修改邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
int updateSysMailLog(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 删除邮件发送日志
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteSysMailLogByMailLogId(Long mailLogId);
|
||||
|
||||
/**
|
||||
* 批量删除邮件发送日志
|
||||
*
|
||||
* @param mailLogIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteSysMailLogByMailLogIds(Long[] mailLogIds);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.core.mail.MailMessage;
|
||||
import com.ruoyi.common.core.mail.MailSendResult;
|
||||
import com.ruoyi.system.domain.SysMailLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件发送日志Service接口
|
||||
*
|
||||
* @author ryas
|
||||
* created on 2024-03-01
|
||||
*/
|
||||
public interface ISysMailLogService {
|
||||
/**
|
||||
* 查询邮件发送日志
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 邮件发送日志
|
||||
*/
|
||||
SysMailLog selectSysMailLogByMailLogId(Long mailLogId);
|
||||
|
||||
/**
|
||||
* 查询邮件发送日志列表
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 邮件发送日志集合
|
||||
*/
|
||||
List<SysMailLog> selectSysMailLogList(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 新增邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
int insertSysMailLog(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 修改邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
int updateSysMailLog(SysMailLog sysMailLog);
|
||||
|
||||
/**
|
||||
* 批量删除邮件发送日志
|
||||
*
|
||||
* @param mailLogIds 需要删除的邮件发送日志主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteSysMailLogByMailLogIds(Long[] mailLogIds);
|
||||
|
||||
/**
|
||||
* 删除邮件发送日志信息
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteSysMailLogByMailLogId(Long mailLogId);
|
||||
|
||||
/**
|
||||
* 发送临时邮件
|
||||
*
|
||||
* @param message 邮件内容
|
||||
* @return 结果
|
||||
*/
|
||||
MailSendResult sendTempMail(MailMessage message);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.mail.MailMessage;
|
||||
import com.ruoyi.common.core.mail.MailSendResult;
|
||||
import com.ruoyi.common.core.mail.MailSender;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.uuid.snowflake.SnowFlakeIdGenerator;
|
||||
import com.ruoyi.system.domain.SysMailLog;
|
||||
import com.ruoyi.system.mapper.SysMailLogMapper;
|
||||
import com.ruoyi.system.service.ISysMailLogService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件发送日志Service业务层处理
|
||||
*
|
||||
* @author ryas
|
||||
* created on 2024-03-01
|
||||
*/
|
||||
@Service
|
||||
public class SysMailLogServiceImpl implements ISysMailLogService {
|
||||
|
||||
@Resource
|
||||
private SysMailLogMapper sysMailLogMapper;
|
||||
|
||||
@Resource
|
||||
private MailSender mailSender;
|
||||
|
||||
/**
|
||||
* 查询邮件发送日志
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 邮件发送日志
|
||||
*/
|
||||
@Override
|
||||
public SysMailLog selectSysMailLogByMailLogId(Long mailLogId) {
|
||||
return sysMailLogMapper.selectSysMailLogByMailLogId(mailLogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询邮件发送日志列表
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 邮件发送日志
|
||||
*/
|
||||
@Override
|
||||
public List<SysMailLog> selectSysMailLogList(SysMailLog sysMailLog) {
|
||||
return sysMailLogMapper.selectSysMailLogList(sysMailLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertSysMailLog(SysMailLog sysMailLog) {
|
||||
sysMailLog.setCreateTime(DateUtils.getNowDate());
|
||||
if (sysMailLog.getMailLogId() == null) {
|
||||
sysMailLog.setMailLogId(SnowFlakeIdGenerator.nextIdLong());
|
||||
}
|
||||
return sysMailLogMapper.insertSysMailLog(sysMailLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改邮件发送日志
|
||||
*
|
||||
* @param sysMailLog 邮件发送日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateSysMailLog(SysMailLog sysMailLog) {
|
||||
return sysMailLogMapper.updateSysMailLog(sysMailLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除邮件发送日志
|
||||
*
|
||||
* @param mailLogIds 需要删除的邮件发送日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysMailLogByMailLogIds(Long[] mailLogIds) {
|
||||
return sysMailLogMapper.deleteSysMailLogByMailLogIds(mailLogIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除邮件发送日志信息
|
||||
*
|
||||
* @param mailLogId 邮件发送日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysMailLogByMailLogId(Long mailLogId) {
|
||||
return sysMailLogMapper.deleteSysMailLogByMailLogId(mailLogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送临时邮件
|
||||
*
|
||||
* @param message 邮件内容
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public MailSendResult sendTempMail(MailMessage message) {
|
||||
//TODO 待完成
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?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.ruoyi.system.mapper.SysMailLogMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.system.domain.SysMailLog" id="SysMailLogResult">
|
||||
<result property="mailLogId" column="mail_log_id"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="businessType" column="business_type"/>
|
||||
<result property="from" column="from"/>
|
||||
<result property="to" column="to"/>
|
||||
<result property="cc" column="cc"/>
|
||||
<result property="subject" column="subject"/>
|
||||
<result property="msg" column="msg"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="costTime" column="cost_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysMailLogVo">
|
||||
select mail_log_id,
|
||||
status,
|
||||
business_type,
|
||||
sys_mail_log.from,
|
||||
sys_mail_log.to,
|
||||
cc,
|
||||
subject,
|
||||
msg,
|
||||
create_time,
|
||||
create_by,
|
||||
cost_time,
|
||||
remark
|
||||
from sys_mail_log
|
||||
</sql>
|
||||
|
||||
<select id="selectSysMailLogList" parameterType="com.ruoyi.system.domain.SysMailLog" resultMap="SysMailLogResult">
|
||||
<include refid="selectSysMailLogVo"/>
|
||||
<where>
|
||||
<if test="status != null ">and sys_mail_log.status = #{status}</if>
|
||||
<if test="to != null and to != ''">and sys_mail_log.to = #{to}</if>
|
||||
<if test="subject != null and subject != ''">and sys_mail_log.subject = #{subject}</if>
|
||||
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''">
|
||||
and create_time between #{params.beginCreateTime} and #{params.endCreateTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSysMailLogByMailLogId" parameterType="Long" resultMap="SysMailLogResult">
|
||||
<include refid="selectSysMailLogVo"/>
|
||||
where mail_log_id = #{mailLogId}
|
||||
</select>
|
||||
|
||||
<insert id="insertSysMailLog" parameterType="com.ruoyi.system.domain.SysMailLog">
|
||||
insert into sys_mail_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="mailLogId != null">mail_log_id,</if>
|
||||
<if test="status != null">sys_mail_log.status,</if>
|
||||
<if test="businessType != null">business_type,</if>
|
||||
<if test="from != null">sys_mail_log.from,</if>
|
||||
<if test="to != null">sys_mail_log.to,</if>
|
||||
<if test="cc != null">cc,</if>
|
||||
<if test="subject != null">sys_mail_log.subject,</if>
|
||||
<if test="msg != null">msg,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="costTime != null">cost_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="mailLogId != null">#{mailLogId},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="businessType != null">#{businessType},</if>
|
||||
<if test="from != null">#{from},</if>
|
||||
<if test="to != null">#{to},</if>
|
||||
<if test="cc != null">#{cc},</if>
|
||||
<if test="subject != null">#{subject},</if>
|
||||
<if test="msg != null">#{msg},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="costTime != null">#{costTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysMailLog" parameterType="com.ruoyi.system.domain.SysMailLog">
|
||||
update sys_mail_log
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="businessType != null">business_type = #{businessType},</if>
|
||||
<if test="from != null">sys_mail_log.from = #{from},</if>
|
||||
<if test="to != null">sys_mail_log.to = #{to},</if>
|
||||
<if test="cc != null">cc = #{cc},</if>
|
||||
<if test="subject != null">sys_mail_log.subject = #{subject},</if>
|
||||
<if test="msg != null">msg = #{msg},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="costTime != null">cost_time = #{costTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where mail_log_id = #{mailLogId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysMailLogByMailLogId" parameterType="Long">
|
||||
delete
|
||||
from sys_mail_log
|
||||
where mail_log_id = #{mailLogId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysMailLogByMailLogIds" parameterType="String">
|
||||
delete from sys_mail_log where mail_log_id in
|
||||
<foreach item="mailLogId" collection="array" open="(" separator="," close=")">
|
||||
#{mailLogId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user