Commit 525078abd36c091b33462aa22ac31006855ce0a0

Authored by YunaiV
1 parent f9ab45df

邮箱模块:完善 log 相关的逻辑

Showing 19 changed files with 388 additions and 266 deletions
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java
... ... @@ -7,7 +7,7 @@ import lombok.Getter;
7 7 * 邮件的发送状态枚举
8 8 *
9 9 * @author wangjingyi
10   - * @date 2022/4/10 13:39
  10 + * @since 2022/4/10 13:39
11 11 */
12 12 @Getter
13 13 @AllArgsConstructor
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java
... ... @@ -3,23 +3,20 @@ package cn.iocoder.yudao.module.system.controller.admin.mail;
3 3  
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
7   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.*;
  6 +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
  7 +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO;
8 8 import cn.iocoder.yudao.module.system.convert.mail.MailLogConvert;
9 9 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
10 10 import cn.iocoder.yudao.module.system.service.mail.MailLogService;
11 11 import io.swagger.annotations.Api;
12 12 import io.swagger.annotations.ApiOperation;
13   -import org.springframework.beans.factory.annotation.Autowired;
14 13 import org.springframework.security.access.prepost.PreAuthorize;
15 14 import org.springframework.web.bind.annotation.GetMapping;
16 15 import org.springframework.web.bind.annotation.RequestMapping;
17 16 import org.springframework.web.bind.annotation.RestController;
18   -import javax.servlet.http.HttpServletResponse;
19   -import javax.validation.Valid;
20 17  
21   -import java.io.IOException;
22   -import java.util.List;
  18 +import javax.annotation.Resource;
  19 +import javax.validation.Valid;
23 20  
24 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 22  
... ... @@ -29,7 +26,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
29 26 @RequestMapping("/system/mail-log")
30 27 public class MailLogController {
31 28  
32   - @Autowired
  29 + @Resource
33 30 private MailLogService mailLogService;
34 31  
35 32 @GetMapping("/page")
... ... @@ -40,14 +37,4 @@ public class MailLogController {
40 37 return success(MailLogConvert.INSTANCE.convertPage(pageResult));
41 38 }
42 39  
43   - @GetMapping("/export-excel")
44   - @ApiOperation("导出邮箱日志Excel")
45   - @PreAuthorize("@ss.hasPermission('system:mail-log:export')")
46   - public void exportMailLogExcel(@Valid MailLogExportReqVO exportReqVO ,
47   - HttpServletResponse response) throws IOException {
48   - List<MailLogDO> list = mailLogService.getMailLogList(exportReqVO);
49   - // 导出 Excel
50   - List<MailLogExcelVO> datas = MailLogConvert.INSTANCE.convertList(list);
51   - ExcelUtils.write(response, "邮箱日志.xls", "数据", MailLogExcelVO.class, datas);
52   - }
53 40 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java 100644 → 100755
1 1 package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
2 2  
3   -import com.baomidou.mybatisplus.annotation.TableField;
4   -import com.baomidou.mybatisplus.annotation.TableId;
5   -import io.swagger.annotations.ApiModel;
6   -import io.swagger.annotations.ApiModelProperty;
7   -import lombok.Data;
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import java.time.LocalDateTime;
  8 +import io.swagger.annotations.*;
  9 +import javax.validation.constraints.*;
8 10 import org.springframework.format.annotation.DateTimeFormat;
9 11  
10   -import java.sql.Timestamp;
11   -
12 12 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
13 13  
14   -@ApiModel("管理后台 - 邮箱日志基类 Base VO")
  14 +/**
  15 +* 邮件日志 Base VO,提供给添加、修改、详细的子 VO 使用
  16 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  17 +*/
15 18 @Data
16 19 public class MailLogBaseVO {
17 20  
18   - @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com")
19   - private String from;
  21 + @ApiModelProperty(value = "用户编号", example = "30883")
  22 + private Long userId;
  23 +
  24 + @ApiModelProperty(value = "用户类型", example = "2", notes = "参见 UserTypeEnum 枚举")
  25 + private Byte userType;
  26 +
  27 + @ApiModelProperty(value = "接收邮箱地址", required = true, example = "76854@qq.com")
  28 + @NotNull(message = "接收邮箱地址不能为空")
  29 + private String toMail;
  30 +
  31 + @ApiModelProperty(value = "邮箱账号编号", required = true, example = "18107")
  32 + @NotNull(message = "邮箱账号编号不能为空")
  33 + private Long accountId;
20 34  
21   - @ApiModelProperty(value = "模版编号" , required = false , example = "templeId")
22   - private String templateId;
  35 + @ApiModelProperty(value = "发送邮箱地址", required = true, example = "85757@qq.com")
  36 + @NotNull(message = "发送邮箱地址不能为空")
  37 + private String fromMail;
23 38  
24   - @ApiModelProperty(value = "模版code" , required = false , example = "templeCode")
  39 + @ApiModelProperty(value = "模板编号", required = true, example = "5678")
  40 + @NotNull(message = "模板编号不能为空")
  41 + private Long templateId;
  42 +
  43 + @ApiModelProperty(value = "模板编码", required = true, example = "test_01")
  44 + @NotNull(message = "模板编码不能为空")
25 45 private String templateCode;
26 46  
27   - @ApiModelProperty(value = "标题" , required = false , example = "芋道源码")
28   - private String title;
  47 + @ApiModelProperty(value = "模版发送人名称", example = "李四")
  48 + private String templateNickname;
  49 +
  50 + @ApiModelProperty(value = "邮件标题", required = true, example = "测试标题")
  51 + @NotNull(message = "邮件标题不能为空")
  52 + private String templateTitle;
  53 +
  54 + @ApiModelProperty(value = "邮件内容", required = true, example = "测试内容")
  55 + @NotNull(message = "邮件内容不能为空")
  56 + private String templateContent;
29 57  
30   - @ApiModelProperty(value = "内容" , required = false , example = "遇到源码")
31   - private String content;
  58 + @ApiModelProperty(value = "邮件参数", required = true)
  59 + @NotNull(message = "邮件参数不能为空")
  60 + private Map<String, Object> templateParams;
32 61  
33   - @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com")
34   - private String to;
  62 + @ApiModelProperty(value = "发送状态", required = true, example = "1", notes = "参见 MailSendStatusEnum 枚举")
  63 + @NotNull(message = "发送状态不能为空")
  64 + private Byte sendStatus;
35 65  
  66 + @ApiModelProperty(value = "发送时间")
36 67 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
37   - @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20")
38   - private Timestamp sendTime;
  68 + private LocalDateTime sendTime;
39 69  
40   - @ApiModelProperty(value = "发送状态" , required = false , example = "1")
41   - private Boolean sendStatus;
  70 + @ApiModelProperty(value = "发送返回的消息 ID", example = "28568")
  71 + private String sendMessageId;
42 72  
43   - @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com")
44   - private String sendResult;
  73 + @ApiModelProperty(value = "发送异常")
  74 + private String sendException;
45 75  
46 76 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
2   -
3   -import com.alibaba.excel.annotation.ExcelProperty;
4   -import io.swagger.annotations.ApiModel;
5   -import lombok.Data;
6   -import org.springframework.format.annotation.DateTimeFormat;
7   -
8   -import java.sql.Timestamp;
9   -import java.util.Date;
10   -
11   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
12   -
13   -@ApiModel("管理后台 - 邮箱日志导出 Request VO")
14   -@Data
15   -public class MailLogExcelVO {
16   -
17   - @ExcelProperty(value = "邮箱" )
18   - private String from;
19   -
20   - @ExcelProperty(value = "模版编号" )
21   - private String templeCode;
22   -
23   - @ExcelProperty(value = "标题")
24   - private String title;
25   -
26   - @ExcelProperty(value = "内容")
27   - private String content;
28   -
29   - @ExcelProperty(value = "收件人" )
30   - private String to;
31   -
32   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
33   - @ExcelProperty(value = "发送时间" )
34   - private Date sendTime;
35   -
36   - @ExcelProperty(value = "发送状态")
37   - private Integer sendStatus;
38   -
39   - @ExcelProperty(value = "发送结果")
40   - private String sendResult;
41   -
42   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
2   -
3   -import io.swagger.annotations.ApiModel;
4   -import lombok.Data;
5   -
6   -@ApiModel("管理后台 - 邮箱日志导出 Request VO")
7   -@Data
8   -public class MailLogExportReqVO extends MailLogPageReqVO {
9   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java
... ... @@ -9,6 +9,7 @@ import lombok.ToString;
9 9 import org.springframework.format.annotation.DateTimeFormat;
10 10  
11 11 import java.sql.Timestamp;
  12 +import java.time.LocalDateTime;
12 13  
13 14 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
14 15  
... ... @@ -18,33 +19,26 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
18 19 @ToString(callSuper = true)
19 20 public class MailLogPageReqVO extends PageParam {
20 21  
21   - // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 DONE
  22 + @ApiModelProperty(value = "用户编号", example = "30883")
  23 + private Long userId;
22 24  
23   - @ApiModelProperty(value = "邮箱" , example = "yudaoyuanma@123.com")
24   - private String from;
  25 + @ApiModelProperty(value = "用户类型", example = "2", notes = "参见 UserTypeEnum 枚举")
  26 + private Byte userType;
25 27  
26   - @ApiModelProperty(value = "模版编号" , required = false , example = "templeId")
27   - private String templateId;
  28 + @ApiModelProperty(value = "接收邮箱地址", example = "76854@qq.com", notes = "模糊匹配")
  29 + private String toMail;
28 30  
29   - @ApiModelProperty(value = "模版code" , required = false , example = "templeCode")
30   - private String templateCode;
  31 + @ApiModelProperty(value = "邮箱账号编号", example = "18107")
  32 + private Long accountId;
31 33  
32   - @ApiModelProperty(value = "标题" , required = false , example = "芋道源码")
33   - private String title;
  34 + @ApiModelProperty(value = "模板编号", example = "5678")
  35 + private Long templateId;
34 36  
35   - @ApiModelProperty(value = "内容" , required = false , example = "遇到源码")
36   - private String content;
37   -
38   - @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com")
39   - private String to;
  37 + @ApiModelProperty(value = "发送状态", example = "1", notes = "参见 MailSendStatusEnum 枚举")
  38 + private Integer sendStatus;
40 39  
  40 + @ApiModelProperty(value = "发送时间")
41 41 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
42   - @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20")
43   - private Timestamp sendTime;
44   -
45   - @ApiModelProperty(value = "发送状态" , required = false , example = "1")
46   - private Boolean sendStatus;
  42 + private LocalDateTime[] sendTime;
47 43  
48   - @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com")
49   - private String sendResult;
50 44 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java 100644 → 100755
1 1 package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
2 2  
3   -import io.swagger.annotations.ApiModel;
4   -import io.swagger.annotations.ApiModelProperty;
5   -import lombok.Data;
6   -import org.springframework.format.annotation.DateTimeFormat;
  3 +import lombok.*;
  4 +import java.time.LocalDateTime;
  5 +import io.swagger.annotations.*;
7 6  
8   -import java.sql.Timestamp;
9   -
10   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
11   -
12   -@ApiModel("管理后台 - 邮箱日志返回 Request VO")
  7 +@ApiModel("管理后台 - 邮件日志 Response VO")
13 8 @Data
14   -public class MailLogRespVO {
15   -
16   - @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com")
17   - private String from;
18   -
19   - @ApiModelProperty(value = "模版编号" , required = false , example = "templeId")
20   - private String templateId;
21   -
22   - @ApiModelProperty(value = "模版code" , required = false , example = "templeCode")
23   - private String templateCode;
24   -
25   - @ApiModelProperty(value = "标题" , required = false , example = "芋道源码")
26   - private String title;
27   -
28   - @ApiModelProperty(value = "内容" , required = false , example = "遇到源码")
29   - private String content;
30   -
31   - @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com")
32   - private String to;
33   -
34   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
35   - @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20")
36   - private Timestamp sendTime;
  9 +@EqualsAndHashCode(callSuper = true)
  10 +@ToString(callSuper = true)
  11 +public class MailLogRespVO extends MailLogBaseVO {
37 12  
38   - @ApiModelProperty(value = "发送状态" , required = false , example = "1")
39   - private Integer sendStatus;
  13 + @ApiModelProperty(value = "编号", required = true, example = "31020")
  14 + private Long id;
40 15  
41   - @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com")
42   - private String sendResult;
  16 + @ApiModelProperty(value = "创建时间", required = true)
  17 + private LocalDateTime createTime;
43 18  
44 19 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java
1 1 package cn.iocoder.yudao.module.system.convert.mail;
2 2  
  3 +import cn.hutool.core.util.StrUtil;
3 4 import cn.hutool.extra.mail.MailAccount;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
6 7 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO;
7 8 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSimpleRespVO;
8 9 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
9   -import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage;
10 10 import org.mapstruct.Mapper;
11 11 import org.mapstruct.factory.Mappers;
12 12  
13   -import java.util.HashMap;
14 13 import java.util.List;
15   -import java.util.Map;
16 14  
17 15 @Mapper
18 16 public interface MailAccountConvert {
... ... @@ -27,25 +25,11 @@ public interface MailAccountConvert {
27 25  
28 26 List<MailAccountSimpleRespVO> convertList02(List<MailAccountDO> list);
29 27  
30   - // TODO 芋艿:改下
31   - default MailAccount convertAccount(MailSendMessage bean) {
32   - return new MailAccount()
33   - .setHost(bean.getHost())
34   - .setPort(bean.getPort())
35   - .setAuth(true)
36   - .setFrom(bean.getMail())
37   - .setUser(bean.getUsername())
38   - .setPass(bean.getPassword())
39   - .setSslEnable(bean.getSslEnable());
40   - }
41   -
42   - // TODO 芋艿:改下
43   - default Map<String, String> convertToMap(MailAccountDO mailAccountDO , String content) {
44   - Map<String , String> map = new HashMap<>();
45   - map.put("from_address" , mailAccountDO.getMail());
46   - map.put("username" , mailAccountDO.getUsername());
47   - map.put("content" , content);
48   - return map;
  28 + default MailAccount convert(MailAccountDO account, String nickname) {
  29 + String from = StrUtil.isNotEmpty(nickname) ? nickname + " <" + account.getMail() + ">" : account.getMail();
  30 + return new MailAccount().setFrom(from).setAuth(true)
  31 + .setUser(account.getUsername()).setPass(account.getPassword())
  32 + .setHost(account.getHost()).setPort(account.getPort()).setSslEnable(account.getSslEnable());
49 33 }
50 34  
51 35 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java
1 1 package cn.iocoder.yudao.module.system.convert.mail;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExcelVO;
5 4 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO;
6 5 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
7 6 import org.mapstruct.Mapper;
8 7 import org.mapstruct.factory.Mappers;
9 8  
10   -import java.util.List;
11   -
12 9 @Mapper
13 10 public interface MailLogConvert {
  11 +
14 12 MailLogConvert INSTANCE = Mappers.getMapper(MailLogConvert.class);
15 13  
16 14 PageResult<MailLogRespVO> convertPage(PageResult<MailLogDO> pageResult);
17 15  
18   - List<MailLogExcelVO> convertList(List<MailLogDO> list);
19 16 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java
... ... @@ -114,8 +114,8 @@ public class MailLogDO extends BaseDO implements Serializable {
114 114 */
115 115 private String sendMessageId;
116 116 /**
117   - * 发送结果
  117 + * 发送异常
118 118 */
119   - private String sendResult;
  119 + private String sendException;
120 120  
121 121 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java
... ... @@ -2,41 +2,25 @@ package cn.iocoder.yudao.module.system.dal.mysql.mail;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5   -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
6   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7 6 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
8 7 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
9 8 import org.apache.ibatis.annotations.Mapper;
10 9  
11   -import java.util.List;
12 10 @Mapper
13 11 public interface MailLogMapper extends BaseMapperX<MailLogDO> {
14 12  
15   - default PageResult<MailLogDO> selectPage(MailLogPageReqVO pageVO){
16   - return selectPage(pageVO , new QueryWrapperX<MailLogDO>()
17   - .eqIfPresent("from", pageVO.getFrom())
18   - .eqIfPresent("templeCode", pageVO.getTemplateCode())
19   - .likeIfPresent("title" , pageVO.getTitle())
20   - .likeIfPresent("content" , pageVO.getContent())
21   - .eqIfPresent("to", pageVO.getTo())
22   - .eqIfPresent("sendTime" , pageVO.getSendTime())
23   - .eqIfPresent("sendStatus" , pageVO.getSendStatus())
24   - .eqIfPresent("sendResult" , pageVO.getSendResult())
25   - .orderByDesc("sendTime")
26   - );
27   - };
  13 + default PageResult<MailLogDO> selectPage(MailLogPageReqVO reqVO) {
  14 + return selectPage(reqVO, new LambdaQueryWrapperX<MailLogDO>()
  15 + .eqIfPresent(MailLogDO::getUserId, reqVO.getUserId())
  16 + .eqIfPresent(MailLogDO::getUserType, reqVO.getUserType())
  17 + .likeIfPresent(MailLogDO::getToMail, reqVO.getToMail())
  18 + .eqIfPresent(MailLogDO::getAccountId, reqVO.getAccountId())
  19 + .likeIfPresent(MailLogDO::getFromMail, reqVO.getFromMail())
  20 + .eqIfPresent(MailLogDO::getTemplateId, reqVO.getTemplateId())
  21 + .eqIfPresent(MailLogDO::getSendStatus, reqVO.getSendStatus())
  22 + .betweenIfPresent(MailLogDO::getSendTime, reqVO.getSendTime())
  23 + .orderByDesc(MailLogDO::getId));
  24 + }
28 25  
29   - default List<MailLogDO> selectList(MailLogExportReqVO exportReqVO){
30   - return selectList(new QueryWrapperX<MailLogDO>()
31   - .eqIfPresent("from", exportReqVO.getFrom())
32   - .eqIfPresent("templeCode", exportReqVO.getTemplateCode())
33   - .likeIfPresent("title" , exportReqVO.getTitle())
34   - .likeIfPresent("content" , exportReqVO.getContent())
35   - .eqIfPresent("to", exportReqVO.getTo())
36   - .eqIfPresent("sendTime" , exportReqVO.getSendTime())
37   - .eqIfPresent("sendStatus" , exportReqVO.getSendStatus())
38   - .eqIfPresent("sendResult" , exportReqVO.getSendResult())
39   - .orderByDesc("sendTime")
40   - );
41   - };
42 26 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java
1 1 package cn.iocoder.yudao.module.system.service.mail;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO;
5 4 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
6 5 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
7 6 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
8 7 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
9 8  
10   -import java.util.List;
11 9 import java.util.Map;
12 10  
13 11 /**
... ... @@ -27,41 +25,29 @@ public interface MailLogService {
27 25 PageResult<MailLogDO> getMailLogPage(MailLogPageReqVO pageVO);
28 26  
29 27 /**
30   - * 邮件日志数组信息
31   - *
32   - * @param exportReqVO 导出筛选请求
33   - * @return 导出的日志数据
34   - */
35   - List<MailLogDO> getMailLogList(MailLogExportReqVO exportReqVO);
36   -
37   - /**
38 28 * 创建邮件日志
39 29 *
40 30 * @param userId 用户编码
41 31 * @param userType 用户类型
42   - * @param to 收件人
43   - * @param mailAccountDO 邮件账号信息
  32 + * @param toMail 收件人邮件
  33 + * @param account 邮件账号信息
44 34 * @param template 模版信息
45 35 * @param templateContent 模版内容
46 36 * @param templateParams 模版参数
47 37 * @param isSend 是否发送成功
  38 + * @return 日志编号
48 39 */
49   - Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map<String, Object> templateParams, Boolean isSend);
50   -
51   - /**
52   - * 更新邮件发送结果
53   - *
54   - * @param logId 发送日志Id
55   - * @param result 发送结果 默认返回messageId
56   - */
57   - void updateMailSendResult(Long logId, String result);
  40 + Long createMailLog(Long userId,Integer userType, String toMail,
  41 + MailAccountDO account, MailTemplateDO template ,
  42 + String templateContent, Map<String, Object> templateParams, Boolean isSend);
58 43  
59 44 /**
60 45 * 更新邮件发送结果
61 46 *
62   - * @param logId 发送日志Id
63   - * @param exception 发送结果
  47 + * @param logId 日志编号
  48 + * @param messageId 发送后的消息编号
  49 + * @param exception 发送异常
64 50 */
65   - void updateFailMailSendResult(Long logId, String exception);
  51 + void updateMailSendResult(Long logId, String messageId, Exception exception);
66 52  
67 53 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImpl.java
1 1 package cn.iocoder.yudao.module.system.service.mail;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO;
5 4 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
6 5 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
7 6 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
... ... @@ -13,10 +12,11 @@ import org.springframework.validation.annotation.Validated;
13 12  
14 13 import javax.annotation.Resource;
15 14 import java.util.Date;
16   -import java.util.List;
17 15 import java.util.Map;
18 16 import java.util.Objects;
19 17  
  18 +import static cn.hutool.core.exceptions.ExceptionUtil.getRootCauseMessage;
  19 +
20 20 /**
21 21 * 邮件日志 Service 实现类
22 22 *
... ... @@ -36,11 +36,6 @@ public class MailLogServiceImpl implements MailLogService {
36 36 }
37 37  
38 38 @Override
39   - public List<MailLogDO> getMailLogList(MailLogExportReqVO exportReqVO) {
40   - return mailLogMapper.selectList(exportReqVO);
41   - }
42   -
43   - @Override
44 39 public Long createMailLog(Long userId, Integer userType, String toMail,
45 40 MailAccountDO account, MailTemplateDO template,
46 41 String templateContent, Map<String, Object> templateParams, Boolean isSend) {
... ... @@ -61,20 +56,18 @@ public class MailLogServiceImpl implements MailLogService {
61 56 return logDO.getId();
62 57 }
63 58  
64   - // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。DONE
65 59 @Override
66   - public void updateMailSendResult(Long logId, String result) {
67   - MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
68   - logDOBuilder.id(logId).sendTime(new Date()).sendResult(result).sendMessageId(result).sendStatus(MailSendStatusEnum.SUCCESS.getStatus());
69   - MailLogDO mailLogDO = logDOBuilder.build();
70   - mailLogMapper.updateById(mailLogDO);
71   - }
  60 + public void updateMailSendResult(Long logId, String messageId, Exception exception) {
  61 + // 1. 成功
  62 + if (exception == null) {
  63 + mailLogMapper.updateById(new MailLogDO().setId(logId).setSendTime(new Date())
  64 + .setSendStatus(MailSendStatusEnum.SUCCESS.getStatus()).setSendMessageId(messageId));
  65 + return;
  66 + }
  67 + // 2. 失败
  68 + mailLogMapper.updateById(new MailLogDO().setId(logId).setSendTime(new Date())
  69 + .setSendStatus(MailSendStatusEnum.FAILURE.getStatus()).setSendException(getRootCauseMessage(exception)));
72 70  
73   - @Override
74   - public void updateFailMailSendResult(Long logId, String exception) {
75   - MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
76   - logDOBuilder.id(logId).sendTime(new Date()).sendResult(exception).sendStatus(MailSendStatusEnum.FAILURE.getStatus());
77   - MailLogDO mailLogDO = logDOBuilder.build();
78   - mailLogMapper.updateById(mailLogDO);
79 71 }
  72 +
80 73 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java
... ... @@ -9,14 +9,9 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
9 9 import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
10 10 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
11 11 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
12   -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
13 12 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
14   -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
15 13 import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage;
16 14 import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer;
17   -import cn.iocoder.yudao.module.system.service.mail.MailLogService;
18   -import cn.iocoder.yudao.module.system.service.mail.MailSendService;
19   -import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
20 15 import cn.iocoder.yudao.module.system.service.member.MemberService;
21 16 import cn.iocoder.yudao.module.system.service.user.AdminUserService;
22 17 import com.google.common.annotations.VisibleForTesting;
... ... @@ -111,15 +106,18 @@ public class MailSendServiceImpl implements MailSendService {
111 106  
112 107 @Override
113 108 public void doSendMail(MailSendMessage message) {
114   - // 装载账号信息
115   - MailAccount mailAccount = MailAccountConvert.INSTANCE.convertAccount(message);
116   - // 发送邮件
  109 + // 1. 创建发送账号
  110 + MailAccountDO account = checkMailAccountValid(message.getAccountId());
  111 + MailAccount mailAccount = MailAccountConvert.INSTANCE.convert(account, message.getNickname());
  112 + // 2. 发送邮件
117 113 try {
118 114 String messageId = MailUtil.send(mailAccount, message.getMail(),
119 115 message.getTitle(), message.getContent(),true);
120   - mailLogService.updateMailSendResult(message.getLogId() , messageId);
121   - } catch (Exception e){
122   - mailLogService.updateFailMailSendResult(message.getLogId() , e.getMessage());
  116 + // 3. 更新结果(成功)
  117 + mailLogService.updateMailSendResult(message.getLogId(), messageId, null);
  118 + } catch (Exception e) {
  119 + // 3. 更新结果(异常)
  120 + mailLogService.updateMailSendResult(message.getLogId(), null, e);
123 121 }
124 122 }
125 123  
... ... @@ -170,4 +168,5 @@ public class MailSendServiceImpl implements MailSendService {
170 168 return new KeyValue<>(key, value);
171 169 }).collect(Collectors.toList());
172 170 }
  171 +
173 172 }
... ...
yudao-ui-admin/src/api/system/mail/log.js 0 → 100755
  1 +import request from '@/utils/request'
  2 +
  3 +// 获得邮件日志
  4 +export function getMailLog(id) {
  5 + return request({
  6 + url: '/system/mail-log/get?id=' + id,
  7 + method: 'get'
  8 + })
  9 +}
  10 +
  11 +// 获得邮件日志分页
  12 +export function getMailLogPage(query) {
  13 + return request({
  14 + url: '/system/mail-log/page',
  15 + method: 'get',
  16 + params: query
  17 + })
  18 +}
... ...
yudao-ui-admin/src/utils/dict.js
... ... @@ -25,6 +25,7 @@ export const DICT_TYPE = {
25 25 SYSTEM_SMS_RECEIVE_STATUS: 'system_sms_receive_status',
26 26 SYSTEM_ERROR_CODE_TYPE: 'system_error_code_type',
27 27 SYSTEM_OAUTH2_GRANT_TYPE: 'system_oauth2_grant_type',
  28 + SYSTEM_MAIL_SEND_STATUS: 'system_mail_send_status',
28 29  
29 30 // ========== INFRA 模块 ==========
30 31 INFRA_BOOLEAN_STRING: 'infra_boolean_string',
... ...
yudao-ui-admin/src/views/system/mail/log/index.vue 0 → 100755
  1 +<template>
  2 + <div class="app-container">
  3 +
  4 + <!-- 搜索工作栏 -->
  5 + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  6 + <el-form-item label="接收邮箱" prop="toMail">
  7 + <el-input v-model="queryParams.toMail" placeholder="请输入接收邮箱" clearable @keyup.enter.native="handleQuery"/>
  8 + </el-form-item>
  9 + <el-form-item label="邮箱账号" prop="accountId">
  10 + <el-select v-model="queryParams.accountId" placeholder="请输入邮箱账号" clearable>
  11 + <el-option v-for="account in accountOptions" :key="account.id" :value="account.id" :label="account.mail" />
  12 + </el-select>
  13 + </el-form-item>
  14 + <el-form-item label="模板编号" prop="templateId">
  15 + <el-input v-model="queryParams.templateId" placeholder="请输入模板编号" clearable @keyup.enter.native="handleQuery"/>
  16 + </el-form-item>
  17 + <el-form-item label="发送状态" prop="sendStatus">
  18 + <el-select v-model="queryParams.sendStatus" placeholder="请选择发送状态" clearable size="small">
  19 + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_MAIL_SEND_STATUS)"
  20 + :key="dict.value" :label="dict.label" :value="dict.value"/>
  21 + </el-select>
  22 + </el-form-item>
  23 + <el-form-item label="发送时间" prop="sendTime">
  24 + <el-date-picker v-model="queryParams.sendTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  25 + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  26 + </el-form-item>
  27 + <el-form-item label="用户编号" prop="userId">
  28 + <el-input v-model="queryParams.userId" placeholder="请输入用户编号" clearable @keyup.enter.native="handleQuery"/>
  29 + </el-form-item>
  30 + <el-form-item label="用户类型" prop="userType">
  31 + <el-select v-model="queryParams.userType" placeholder="请选择用户类型" clearable>
  32 + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.USER_TYPE)"
  33 + :key="dict.value" :label="dict.label" :value="dict.value"/>
  34 + </el-select>
  35 + </el-form-item>
  36 + <el-form-item>
  37 + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  38 + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  39 + </el-form-item>
  40 + </el-form>
  41 +
  42 + <!-- 操作工具栏 -->
  43 + <el-row :gutter="10" class="mb8">
  44 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  45 + </el-row>
  46 +
  47 + <!-- 列表 -->
  48 + <el-table v-loading="loading" :data="list">
  49 + <el-table-column label="编号" align="center" prop="id" />
  50 + <el-table-column label="发送时间" align="center" prop="sendTime" width="180">
  51 + <template v-slot="scope">
  52 + <span>{{ parseTime(scope.row.sendTime) }}</span>
  53 + </template>
  54 + </el-table-column>
  55 + <el-table-column label="接收邮箱" align="center" prop="toMail" width="200">
  56 + <template v-slot="scope">
  57 + <div>{{ scope.row.toMail }}</div>
  58 + <div v-if="scope.row.userType && scope.row.userId">
  59 + <dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType"/>{{ '(' + scope.row.userId + ')' }}
  60 + </div>
  61 + </template>
  62 + </el-table-column>
  63 + <el-table-column label="邮件标题" align="center" prop="templateTitle" />
  64 + <el-table-column label="发送状态" align="center" prop="sendStatus">
  65 + <template v-slot="scope">
  66 + <dict-tag :type="DICT_TYPE.SYSTEM_MAIL_SEND_STATUS" :value="scope.row.sendStatus" />
  67 + </template>
  68 + </el-table-column>
  69 + <el-table-column label="邮箱账号" align="center" prop="fromMail" />
  70 + <el-table-column label="模板编号" align="center" prop="templateId" />
  71 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  72 + <template v-slot="scope">
  73 + <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
  74 + v-hasPermi="['system:mail-log:query']">详细</el-button>
  75 + </template>
  76 + </el-table-column>
  77 + </el-table>
  78 + <!-- 分页组件 -->
  79 + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  80 + @pagination="getList"/>
  81 +
  82 + <!-- 邮件日志详细-->
  83 + <el-dialog :title="title" :visible.sync="open" width="700px" v-dialogDrag append-to-body>
  84 + <el-form ref="form" :model="form" label-width="160px">
  85 + <el-row>
  86 + <el-col :span="24">
  87 + <el-form-item label="日志主键:">{{ form.id }}</el-form-item>
  88 + <el-form-item label="用户编号:">{{ form.userId }}</el-form-item>
  89 + <el-form-item label="用户类型:">
  90 + <dict-tag :type="DICT_TYPE.USER_TYPE" :value="form.userType"/>
  91 + </el-form-item>
  92 + <el-form-item label="接收邮箱地址:">{{ form.toMail }}</el-form-item>
  93 + <el-form-item label="邮箱账号编号:">{{ form.accountId }}</el-form-item>
  94 + <el-form-item label="发送邮箱地址:">{{ form.fromMail }}</el-form-item>
  95 + <el-form-item label="模板编号:">{{ form.templateId }}</el-form-item>
  96 + <el-form-item label="模板编码:">{{ form.templateCode }}</el-form-item>
  97 + <el-form-item label="模版发送人名称:">{{ form.templateNickname }}</el-form-item>
  98 + <el-form-item label="邮件标题:">{{ form.templateTitle }}</el-form-item>
  99 + <el-form-item label="邮件内容:">
  100 + <editor v-model="form.templateContent" :min-height="192" read-only />
  101 + </el-form-item>
  102 + <el-form-item label="邮件参数:">{{ form.templateParams }}</el-form-item>
  103 + <el-form-item label="发送状态:">
  104 + <dict-tag :type="DICT_TYPE.SYSTEM_MAIL_SEND_STATUS" :value="form.sendStatus" />
  105 + </el-form-item>
  106 + <el-form-item label="发送时间:">{{ parseTime(form.sendTime) }}</el-form-item>
  107 + <el-form-item label="发送返回的消息编号:">{{ form.sendMessageId }}</el-form-item>
  108 + <el-form-item label="发送异常:">{{ form.sendException }}</el-form-item>
  109 + </el-col>
  110 + </el-row>
  111 + </el-form>
  112 + <div slot="footer" class="dialog-footer">
  113 + <el-button @click="open = false">关 闭</el-button>
  114 + </div>
  115 + </el-dialog>
  116 + </div>
  117 +</template>
  118 +
  119 +<script>
  120 +import { getMailLog, getMailLogPage } from "@/api/system/mail/log";
  121 +import Editor from '@/components/Editor';
  122 +import { getSimpleMailAccountList } from "@/api/system/mail/account";
  123 +
  124 +export default {
  125 + name: "MailLog",
  126 + components: {
  127 + Editor,
  128 + },
  129 + data() {
  130 + return {
  131 + // 遮罩层
  132 + loading: true,
  133 + // 导出遮罩层
  134 + exportLoading: false,
  135 + // 显示搜索条件
  136 + showSearch: true,
  137 + // 总条数
  138 + total: 0,
  139 + // 邮件日志列表
  140 + list: [],
  141 + // 弹出层标题
  142 + title: "",
  143 + // 是否显示弹出层
  144 + open: false,
  145 + // 查询参数
  146 + queryParams: {
  147 + pageNo: 1,
  148 + pageSize: 10,
  149 + userId: null,
  150 + userType: null,
  151 + toMail: null,
  152 + accountId: null,
  153 + templateId: null,
  154 + sendStatus: null,
  155 + sendTime: [],
  156 + },
  157 + // 表单参数
  158 + form: {},
  159 + // 邮箱账号
  160 + accountOptions: []
  161 + };
  162 + },
  163 + created() {
  164 + this.getList();
  165 + // 获得邮箱账号列表
  166 + getSimpleMailAccountList().then(response => {
  167 + this.accountOptions = response.data
  168 + })
  169 + },
  170 + methods: {
  171 + /** 查询列表 */
  172 + getList() {
  173 + this.loading = true;
  174 + // 执行查询
  175 + getMailLogPage(this.queryParams).then(response => {
  176 + this.list = response.data.list;
  177 + this.total = response.data.total;
  178 + this.loading = false;
  179 + });
  180 + },
  181 + /** 取消按钮 */
  182 + cancel() {
  183 + this.open = false;
  184 + this.reset();
  185 + },
  186 + /** 表单重置 */
  187 + reset() {
  188 + this.form = {
  189 + id: undefined,
  190 + userId: undefined,
  191 + userType: undefined,
  192 + toMail: undefined,
  193 + accountId: undefined,
  194 + fromMail: undefined,
  195 + templateId: undefined,
  196 + templateCode: undefined,
  197 + templateNickname: undefined,
  198 + templateTitle: undefined,
  199 + templateContent: undefined,
  200 + templateParams: undefined,
  201 + sendStatus: undefined,
  202 + sendTime: undefined,
  203 + sendMessageId: undefined,
  204 + sendException: undefined,
  205 + };
  206 + this.resetForm("form");
  207 + },
  208 + /** 搜索按钮操作 */
  209 + handleQuery() {
  210 + this.queryParams.pageNo = 1;
  211 + this.getList();
  212 + },
  213 + /** 重置按钮操作 */
  214 + resetQuery() {
  215 + this.resetForm("queryForm");
  216 + this.handleQuery();
  217 + },
  218 + /** 详细按钮操作 */
  219 + handleView(row) {
  220 + this.open = true;
  221 + this.form = row;
  222 + }
  223 + }
  224 +};
  225 +</script>
... ...
yudao-ui-admin/src/views/system/mail/template/index.vue
... ... @@ -44,7 +44,7 @@
44 44 <el-table-column label="模板编码" align="center" prop="code" />
45 45 <el-table-column label="模板名称" align="center" prop="name" />
46 46 <el-table-column label="模板标题" align="center" prop="title" />
47   - <el-table-column label="邮箱账号" align="center" prop="accountId">
  47 + <el-table-column label="邮箱账号" align="center" prop="accountId" width="200">
48 48 <template v-slot="scope">
49 49 {{ accountOptions.find(account => account.id === scope.row.accountId)?.mail }}
50 50 </template>
... ...
yudao-ui-admin/src/views/system/sms/smsLog.vue
... ... @@ -94,7 +94,7 @@
94 94 </el-table-column>
95 95 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
96 96 <template v-slot="scope">
97   - <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row,scope.index)"
  97 + <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
98 98 v-hasPermi="['system:sms-log:query']">详细</el-button>
99 99 </template>
100 100 </el-table-column>
... ...