Commit 0262fa5c153628e63c6c266026c7bb7a06d49f1a

Authored by YunaiV
1 parent c9c5a818

邮箱模块:完善 account 账号的增删改查功能

Showing 28 changed files with 555 additions and 272 deletions
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java
1 1 package cn.iocoder.yudao.module.system.api.mail;
2 2  
  3 +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO;
  4 +
  5 +import javax.validation.Valid;
  6 +
  7 +/**
  8 + * 邮箱发送 API 接口
  9 + *
  10 + * @author 芋道源码
  11 + */
3 12 public interface MailSendApi {
  13 +
  14 + /**
  15 + * 发送单条邮箱给 Admin 用户
  16 + *
  17 + * 在 mail 为空时,使用 userId 加载对应 Admin 的邮箱
  18 + *
  19 + * @param reqDTO 发送请求
  20 + * @return 发送日志编号
  21 + */
  22 + Long sendSingleSmsToAdmin(@Valid MailSendSingleToUserReqDTO reqDTO);
  23 +
  24 + /**
  25 + * 发送单条邮箱给 Member 用户
  26 + *
  27 + * 在 mail 为空时,使用 userId 加载对应 Member 的邮箱
  28 + *
  29 + * @param reqDTO 发送请求
  30 + * @return 发送日志编号
  31 + */
  32 + Long sendSingleSmsToMember(@Valid MailSendSingleToUserReqDTO reqDTO);
  33 +
4 34 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java deleted
1   -package cn.iocoder.yudao.module.system.api.mail.dto;
2   -
3   -import io.swagger.annotations.ApiModel;
4   -import io.swagger.annotations.ApiModelProperty;
5   -import lombok.Data;
6   -
7   -import javax.validation.constraints.Email;
8   -import javax.validation.constraints.NotNull;
9   -import java.util.List;
10   -import java.util.Map;
11   -
12   -@ApiModel("管理后台 - 邮件发送 Req VO")
13   -@Data
14   -public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的
15   -
16   - @ApiModelProperty(value = "用户编码",required = true)
17   - @NotNull(message = "用户编码不能为空")
18   - private String userId;
19   -
20   - @ApiModelProperty(value = "用户类型",required = true)
21   - @NotNull(message = "用户类型不能为空")
22   - private String userType;
23   -
24   - @ApiModelProperty(value = "邮箱模版id",example = "1024")
25   - @NotNull(message = "邮箱模版编码不能为空")
26   - private Integer templateCode;
27   -
28   - @ApiModelProperty(value = "邮箱参数")
29   - @NotNull(message = "模版参数不能为空")
30   - private Map<String,Object> templateParams;
31   -
32   - @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com")
33   - @NotNull(message = "收件人不能为空")
34   - private List<String> tos;
35   -
36   -
37   -
38   -}
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.api.mail.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.validation.constraints.Email;
  6 +import javax.validation.constraints.NotNull;
  7 +import java.util.Map;
  8 +
  9 +/**
  10 + * 邮件发送 Request DTO
  11 + *
  12 + * @author wangjingqi
  13 + */
  14 +@Data
  15 +public class MailSendSingleToUserReqDTO {
  16 +
  17 + /**
  18 + * 用户编号
  19 + */
  20 + @NotNull(message = "用户编号不能为空")
  21 + private String userId;
  22 + /**
  23 + * 邮箱
  24 + */
  25 + @Email
  26 + private String mail;
  27 +
  28 + /**
  29 + * 邮件模板编号
  30 + */
  31 + @NotNull(message = "邮件模板编号不能为空")
  32 + private String templateCode;
  33 + /**
  34 + * 邮件模板参数
  35 + */
  36 + @NotNull(message = "邮件模板参数不能为空")
  37 + private Map<String, Object> templateParams;
  38 +
  39 +}
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
... ... @@ -141,16 +141,13 @@ public interface ErrorCodeConstants {
141 141 ErrorCode OAUTH2_CODE_NOT_EXISTS = new ErrorCode(1002022000, "code 不存在");
142 142 ErrorCode OAUTH2_CODE_EXPIRE = new ErrorCode(1002022001, "code 已过期");
143 143  
144   - // TODO @芋艿:需要重新搞下 mail 错误码
145   -
146   - // ========== 邮箱账号 1002020000 ==========
147   - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在");
148   - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在");
  144 + // ========== 邮箱账号 1002023000 ==========
  145 + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002023000, "邮箱账号不存在");
  146 + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002023001, "无法删除,该邮箱账号还有邮件模板");
149 147  
150 148 // ========== 邮箱模版 1002021000 ==========
151 149 ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在");
152 150 ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在");
153   - ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版");
154 151 ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失");
155 152  
156 153 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java deleted
1   -package cn.iocoder.yudao.module.system.enums.mail;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Getter;
5   -
6   -/**
7   - * 邮件日志用户类型
8   - *
9   - * @author wangjingyi
10   - */
11   -@Getter
12   -@AllArgsConstructor
13   -public enum MailLogUserTypeEnum {
14   -
15   - COMMON (10),
16   - VIP (20);
17   -
18   - /**
19   - * 类型
20   - */
21   - private final int userType;
22   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java
1 1 package cn.iocoder.yudao.module.system.api.mail;
2 2  
  3 +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO;
3 4 import org.springframework.stereotype.Service;
4 5 import org.springframework.validation.annotation.Validated;
5 6  
... ... @@ -10,5 +11,16 @@ import org.springframework.validation.annotation.Validated;
10 11 */
11 12 @Service
12 13 @Validated
13   -public class MailSendApiImpl implements MailSendApi{
  14 +public class MailSendApiImpl implements MailSendApi {
  15 +
  16 + @Override
  17 + public Long sendSingleSmsToAdmin(MailSendSingleToUserReqDTO reqDTO) {
  18 + return null;
  19 + }
  20 +
  21 + @Override
  22 + public Long sendSingleSmsToMember(MailSendSingleToUserReqDTO reqDTO) {
  23 + return null;
  24 + }
  25 +
14 26 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java
... ... @@ -3,11 +3,7 @@ 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.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
7   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
8   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
9   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
10   -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO;
  6 +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*;
11 7 import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
12 8 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
13 9 import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
... ... @@ -36,14 +32,14 @@ public class MailAccountController {
36 32 @ApiOperation("创建邮箱账号")
37 33 @PreAuthorize("@ss.hasPermission('system:mail-account:create')")
38 34 public CommonResult<Long> createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) {
39   - return success(mailAccountService.create(createReqVO));
  35 + return success(mailAccountService.createMailAccount(createReqVO));
40 36 }
41 37  
42 38 @PutMapping("/update")
43 39 @ApiOperation("修改邮箱账号")
44 40 @PreAuthorize("@ss.hasPermission('system:mail-account:update')")
45 41 public CommonResult<Boolean> updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) {
46   - mailAccountService.update(updateReqVO);
  42 + mailAccountService.updateMailAccount(updateReqVO);
47 43 return success(true);
48 44 }
49 45  
... ... @@ -52,18 +48,15 @@ public class MailAccountController {
52 48 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
53 49 @PreAuthorize("@ss.hasPermission('system:mail-account:delete')")
54 50 public CommonResult<Boolean> deleteMailAccount(@RequestParam Long id) {
55   - mailAccountService.delete(id);
  51 + mailAccountService.deleteMailAccount(id);
56 52 return success(true);
57 53 }
58 54  
59   - // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。
60   - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE
61   -
62 55 @GetMapping("/get")
63 56 @ApiOperation("获得邮箱账号")
64 57 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
65 58 @PreAuthorize("@ss.hasPermission('system:mail-account:get')")
66   - public CommonResult<MailAccountBaseVO> getMailAccount(@RequestParam("id") Long id) {
  59 + public CommonResult<MailAccountRespVO> getMailAccount(@RequestParam("id") Long id) {
67 60 MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id);
68 61 return success(MailAccountConvert.INSTANCE.convert(mailAccountDO));
69 62 }
... ... @@ -76,14 +69,10 @@ public class MailAccountController {
76 69 return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
77 70 }
78 71  
79   - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE
80   -
81 72 @GetMapping("/list-all-simple")
82 73 @ApiOperation(value = "获得邮箱账号精简列表")
83   - public CommonResult<List<MailAccountBaseVO>> getSimpleMailAccountList() {
  74 + public CommonResult<List<MailAccountSimpleRespVO>> getSimpleMailAccountList() {
84 75 List<MailAccountDO> list = mailAccountService.getMailAccountList();
85   - // 排序后,返回给前端
86   - list.sort(Comparator.comparing(MailAccountDO::getId));
87 76 return success(MailAccountConvert.INSTANCE.convertList02(list));
88 77 }
89 78  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java
1 1 package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
2 2  
3   -import io.swagger.annotations.ApiModel;
4 3 import io.swagger.annotations.ApiModelProperty;
5 4 import lombok.Data;
6 5  
7 6 import javax.validation.constraints.Email;
8 7 import javax.validation.constraints.NotNull;
9 8  
10   -@ApiModel("管理后台 - 邮箱账号基类 Base VO")
  9 +/**
  10 + * 邮箱账号 Base VO,提供给添加、修改、详细的子 VO 使用
  11 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  12 + */
11 13 @Data
12 14 public class MailAccountBaseVO {
13 15  
14   - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com")
15   - @NotNull(message = "邮箱必填")
16   - @Email(message = "必须是Email格式")
17   - private String fromAddress;
  16 + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com")
  17 + @NotNull(message = "邮箱不能为空")
  18 + @Email(message = "必须是 Email 格式")
  19 + private String mail;
18 20  
19   - @ApiModelProperty(value = "用户名",required = true,example = "yudao")
20   - @NotNull(message = "用户名必填")
  21 + @ApiModelProperty(value = "用户名", required = true, example = "yudao")
  22 + @NotNull(message = "用户名不能为空")
21 23 private String username;
22 24  
23   - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn")
24   - @NotNull(message = "网站必填")
  25 + @ApiModelProperty(value = "密码", required = true, example = "123456")
  26 + @NotNull(message = "密码必填")
  27 + private String password;
  28 +
  29 + @ApiModelProperty(value = "网站", required = true, example = "www.iocoder.cn")
  30 + @NotNull(message = "网站不能为空")
25 31 private String host;
26 32  
27   - @ApiModelProperty(value = "端口",required = true,example = "80")
  33 + @ApiModelProperty(value = "端口", required = true, example = "80")
  34 + @NotNull(message = "端口不能为空")
28 35 private Integer port;
29 36  
30   - @ApiModelProperty(value = "是否开启ssl",required = true,example = "2")
31   - @NotNull(message = "是否开启ssl必填")
  37 + @ApiModelProperty(value = "是否开启 ssl", required = true, example = "true")
  38 + @NotNull(message = "是否开启 ssl 必填")
32 39 private Boolean sslEnable;
  40 +
33 41 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java
... ... @@ -14,7 +14,4 @@ import javax.validation.constraints.NotNull;
14 14 @ToString(callSuper = true)
15 15 public class MailAccountCreateReqVO extends MailAccountBaseVO {
16 16  
17   - @ApiModelProperty(value = "密码",required = true,example = "123456")
18   - @NotNull(message = "密码必填")
19   - private String password;
20 17 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java
... ... @@ -13,21 +13,10 @@ import lombok.ToString;
13 13 @ToString(callSuper = true)
14 14 public class MailAccountPageReqVO extends PageParam {
15 15  
16   - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com")
17   - private String fromAddress;
  16 + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com")
  17 + private String mail;
18 18  
19 19 @ApiModelProperty(value = "用户名" , required = true , example = "yudao")
20 20 private String username;
21 21  
22   - @ApiModelProperty(value = "密码" , required = true , example = "123456")
23   - private String password;
24   -
25   - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn")
26   - private String host;
27   -
28   - @ApiModelProperty(value = "端口" , required = true , example = "80")
29   - private String port;
30   -
31   - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2")
32   - private Boolean sslEnable;
33 22 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +import javax.validation.constraints.NotNull;
  10 +import java.time.LocalDateTime;
  11 +
  12 +@ApiModel("管理后台 - 邮箱账号 Response VO")
  13 +@Data
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@ToString(callSuper = true)
  16 +public class MailAccountRespVO extends MailAccountBaseVO {
  17 +
  18 + @ApiModelProperty(value = "编号", required = true, example = "1024")
  19 + @NotNull(message = "编号不能为空")
  20 + private Long id;
  21 +
  22 + @ApiModelProperty(value = "创建时间", required = true)
  23 + private LocalDateTime createTime;
  24 +
  25 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +@ApiModel("管理后台 - 邮箱账号的精简 Response VO")
  8 +@Data
  9 +public class MailAccountSimpleRespVO {
  10 +
  11 + @ApiModelProperty(value = "邮箱比那好", required = true, example = "1024")
  12 + private Long id;
  13 +
  14 + @ApiModelProperty(value = "邮箱", required = true, example = "768541388@qq.com")
  15 + private String mail;
  16 +
  17 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java
... ... @@ -18,7 +18,4 @@ public class MailAccountUpdateReqVO extends MailAccountBaseVO {
18 18 @NotNull(message = "编号不能为空")
19 19 private Long id;
20 20  
21   - @ApiModelProperty(value = "密码",required = true,example = "123456")
22   - @NotNull(message = "密码必填")
23   - private String password;
24 21 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java
... ... @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.system.convert.mail;
3 3 import cn.hutool.extra.mail.MailAccount;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
  6 +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO;
  7 +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSimpleRespVO;
6 8 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
7 9 import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage;
8 10 import org.mapstruct.Mapper;
... ... @@ -14,30 +16,33 @@ import java.util.Map;
14 16  
15 17 @Mapper
16 18 public interface MailAccountConvert {
  19 +
17 20 MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class);
18 21  
19   - MailAccountDO convert (MailAccountBaseVO mailAccountBaseVO);
  22 + MailAccountDO convert(MailAccountBaseVO bean);
20 23  
21   - MailAccountBaseVO convert (MailAccountDO mailAccountDO);
  24 + MailAccountRespVO convert(MailAccountDO bean);
22 25  
23   - PageResult<MailAccountBaseVO> convertPage(PageResult<MailAccountDO> pageResult);
  26 + PageResult<MailAccountBaseVO> convertPage(PageResult<MailAccountDO> pageResult);
24 27  
25   - List<MailAccountBaseVO> convertList02(List<MailAccountDO> list);
  28 + List<MailAccountSimpleRespVO> convertList02(List<MailAccountDO> list);
26 29  
27   - default MailAccount convertAccount(MailSendMessage mailAccountDO){
  30 + // TODO 芋艿:改下
  31 + default MailAccount convertAccount(MailSendMessage bean) {
28 32 return new MailAccount()
29   - .setHost(mailAccountDO.getHost())
30   - .setPort(mailAccountDO.getPort())
  33 + .setHost(bean.getHost())
  34 + .setPort(bean.getPort())
31 35 .setAuth(true)
32   - .setFrom(mailAccountDO.getFromAddress())
33   - .setUser(mailAccountDO.getUsername())
34   - .setPass(mailAccountDO.getPassword())
35   - .setSslEnable(mailAccountDO.getSslEnable());
  36 + .setFrom(bean.getFromAddress())
  37 + .setUser(bean.getUsername())
  38 + .setPass(bean.getPassword())
  39 + .setSslEnable(bean.getSslEnable());
36 40 }
37 41  
  42 + // TODO 芋艿:改下
38 43 default Map<String, String> convertToMap(MailAccountDO mailAccountDO , String content) {
39 44 Map<String , String> map = new HashMap<>();
40   - map.put("from_address" , mailAccountDO.getFromAddress());
  45 + map.put("from_address" , mailAccountDO.getMail());
41 46 map.put("username" , mailAccountDO.getUsername());
42 47 map.put("content" , content);
43 48 return map;
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java
1 1 package cn.iocoder.yudao.module.system.dal.dataobject.mail;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4   -import com.baomidou.mybatisplus.annotation.TableField;
5 4 import com.baomidou.mybatisplus.annotation.TableName;
6 5 import lombok.Data;
7 6 import lombok.EqualsAndHashCode;
8 7  
9 8 /**
10   - * 邮箱账号
11   - * 配置发送邮箱的账号
  9 + * 邮箱账号 DO
  10 + *
  11 + * 用途:配置发送邮箱的账号
12 12 *
13 13 * @author wangjingyi
14 14 * @since 2022-03-21
... ... @@ -25,7 +25,8 @@ public class MailAccountDO extends BaseDO {
25 25 /**
26 26 * 邮箱
27 27 */
28   - private String fromAddress;
  28 + private String mail;
  29 +
29 30 /**
30 31 * 用户名
31 32 */
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java
1 1 package cn.iocoder.yudao.module.system.dal.dataobject.mail;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
3 4 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4   -import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum;
5 5 import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum;
6 6 import com.baomidou.mybatisplus.annotation.TableField;
7 7 import com.baomidou.mybatisplus.annotation.TableName;
... ... @@ -13,7 +13,7 @@ import java.util.Date;
13 13 import java.util.Map;
14 14  
15 15 /**
16   - * 邮箱日志
  16 + * 邮箱日志 DO
17 17 * 记录每一次邮件的发送
18 18 *
19 19 * @author wangjingyi
... ... @@ -29,7 +29,7 @@ import java.util.Map;
29 29 public class MailLogDO extends BaseDO implements Serializable {
30 30  
31 31 /**
32   - * 主键
  32 + * 日志编号,自增
33 33 */
34 34 private Long id;
35 35  
... ... @@ -37,62 +37,74 @@ public class MailLogDO extends BaseDO implements Serializable {
37 37 * 用户编码
38 38 */
39 39 private Long userId;
40   -
41 40 /**
42 41 * 用户类型
43 42 *
44   - * 冗余 {@link MailLogUserTypeEnum#getUserType}
  43 + * 枚举 {@link UserTypeEnum}
45 44 */
46 45 private Integer userType;
  46 + /**
  47 + * 接收邮箱地址
  48 + */
  49 + private String toMail;
47 50  
48   - // TODO @wangjingyi:accountId
49 51 /**
50 52 * 邮箱账号编号
  53 + *
  54 + * 关联 {@link MailAccountDO#getId()}
51 55 */
52 56 private Long accountId;
53   -
54   - // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE
55 57 /**
56   - * 邮箱账号
  58 + * 发送邮箱地址
57 59 *
58   - * 冗余 {@link MailAccountDO}
  60 + * 冗余 {@link MailAccountDO#getMail()}
59 61 */
60   - private String fromAddress;
  62 + private String fromMail;
61 63  
  64 + // ========= 模板相关字段 =========
62 65 /**
63   - * 模版主键
  66 + * 模版编号
  67 + *
  68 + * 关联 {@link MailTemplateDO#getId()}
64 69 */
65 70 private Long templateId;
66   -
  71 + /**
  72 + * 末班编码
  73 + *
  74 + * 冗余 {@link MailTemplateDO#getCode()}
  75 + */
  76 + private String templateCode;
67 77 /**
68 78 * 模版内容
  79 + *
  80 + * 基于 {@link MailTemplateDO#getContent()} 格式化后的内容
69 81 */
70 82 private String templateContent;
71   -
72 83 /**
  84 + * 模版参数
  85 + *
73 86 * 基于 {@link MailTemplateDO#getParams()} 输入后的参数
74 87 */
75 88 @TableField(typeHandler = JacksonTypeHandler.class)
76 89 private Map<String,Object> templateParams;
77 90  
78   - /**
79   - * 发送时间
80   - */
81   - private Date sendTime;
82   -
83   - //=========接收相关字段=========
  91 + // ========= 发送相关字段 =========
84 92 /**
85 93 * 发送状态
86 94 *
87 95 * 枚举 {@link MailSendStatusEnum}
88 96 */
89 97 private Integer sendStatus;
  98 + /**
  99 + * 发送时间
  100 + */
  101 + private Date sendTime;
90 102  
  103 + // ========= 接收相关字段 =========
91 104 /**
92 105 * 发送结果
93 106 */
94 107 private String sendResult;
95   -
96 108 /**
97 109 * 消息ID
98 110 */
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java
... ... @@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode;
11 11 import java.util.List;
12 12  
13 13 /**
14   - * 邮箱模版
  14 + * 邮箱模版 DO
15 15 *
16 16 * @author wangjingyi
17 17 * @since 2022-03-21
... ... @@ -34,9 +34,12 @@ public class MailTemplateDO extends BaseDO {
34 34 */
35 35 private String code;
36 36 /**
37   - * 邮箱账号主键
  37 + * 发送的邮箱账号编号
  38 + *
  39 + * 关联 {@link MailAccountDO#getId()}
38 40 */
39 41 private Long accountId;
  42 +
40 43 /**
41 44 * 标题
42 45 */
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java
... ... @@ -2,37 +2,19 @@ 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.LambdaQueryWrapperX;
5 6 import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
6 7 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
7 8 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
8   -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
9 9 import org.apache.ibatis.annotations.Mapper;
10   -import org.apache.ibatis.annotations.Select;
11   -
12   -import java.util.Date;
13 10  
14 11 @Mapper
15 12 public interface MailAccountMapper extends BaseMapperX<MailAccountDO> {
16 13  
17 14 default PageResult<MailAccountDO> selectPage(MailAccountPageReqVO pageReqVO) {
18   - return selectPage(pageReqVO, new QueryWrapperX<MailAccountDO>()
19   - .likeIfPresent("from_address" , pageReqVO.getFromAddress())
20   - .likeIfPresent("host" , pageReqVO.getHost())
21   - .likeIfPresent("username" , pageReqVO.getUsername())
22   - .eqIfPresent("password" , pageReqVO.getPassword())
23   - .eqIfPresent("port" , pageReqVO.getPort())
24   - );
25   - }
26   -
27   - default MailAccountDO selectByUserName(String userName){
28   - return selectOne(new QueryWrapperX<MailAccountDO>()
29   - .eqIfPresent("username" , userName));
30   - }
31   -
32   - default MailAccountDO selectByUserNameAndId(String userName,Long id){
33   - return selectOne(new QueryWrapperX<MailAccountDO>()
34   - .eqIfPresent("username" , userName)
35   - .neIfPresent("id" , id));
  15 + return selectPage(pageReqVO, new LambdaQueryWrapperX<MailAccountDO>()
  16 + .likeIfPresent(MailAccountDO::getMail, pageReqVO.getMail())
  17 + .likeIfPresent(MailAccountDO::getUsername , pageReqVO.getUsername()));
36 18 }
37 19  
38 20 default MailAccountDO selectOneByFrom(String from){
... ... @@ -40,6 +22,4 @@ public interface MailAccountMapper extends BaseMapperX&lt;MailAccountDO&gt; {
40 22 .eqIfPresent("from_address" , from));
41 23 }
42 24  
43   - @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}")
44   - Long selectCountByUpdateTimeGt(Date maxUpdateTime);
45 25 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 5 import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
6 6 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
7 7 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
  8 +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO;
8 9 import org.apache.ibatis.annotations.Mapper;
9 10 import org.apache.ibatis.annotations.Select;
10 11  
... ... @@ -36,5 +37,10 @@ public interface MailTemplateMapper extends BaseMapperX&lt;MailTemplateDO&gt; {
36 37 default MailTemplateDO selectOneByAccountId(Long accountId){
37 38 return selectOne(new QueryWrapperX<MailTemplateDO>()
38 39 .eqIfPresent("account_id" , accountId));
39   - };
  40 + }
  41 +
  42 + default Long selectCountByAccountId(Long accountId) {
  43 + return selectCount(MailTemplateDO::getAccountId, accountId);
  44 + }
  45 +
40 46 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java
... ... @@ -55,7 +55,7 @@ public class MailProducer {
55 55 public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List<KeyValue<String, Object>> templateParams,String to) {
56 56 MailSendMessage message = new MailSendMessage();
57 57 message.setContent(content)
58   - .setFromAddress(mailAccountDO.getFromAddress())
  58 + .setFromAddress(mailAccountDO.getMail())
59 59 .setHost(mailAccountDO.getHost())
60 60 .setPort(mailAccountDO.getPort())
61 61 .setPassword(mailAccountDO.getPassword())
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java
... ... @@ -28,21 +28,21 @@ public interface MailAccountService {
28 28 * @param createReqVO 邮箱账号信息
29 29 * @return 编号
30 30 */
31   - Long create(@Valid MailAccountCreateReqVO createReqVO);
  31 + Long createMailAccount(@Valid MailAccountCreateReqVO createReqVO);
32 32  
33 33 /**
34 34 * 修改邮箱账号
35 35 *
36 36 * @param updateReqVO 邮箱账号信息
37 37 */
38   - void update(@Valid MailAccountUpdateReqVO updateReqVO);
  38 + void updateMailAccount(@Valid MailAccountUpdateReqVO updateReqVO);
39 39  
40 40 /**
41 41 * 删除邮箱账号
42 42 *
43 43 * @param id 编号
44 44 */
45   - void delete(Long id);
  45 + void deleteMailAccount(Long id);
46 46  
47 47 /**
48 48 * 获取邮箱账号信息
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java
... ... @@ -85,4 +85,12 @@ public interface MailTemplateService {
85 85 */
86 86 String formatMailTemplateContent(String content, Map<String, String> params);
87 87  
  88 + /**
  89 + * 获得指定邮箱账号下的邮件模板数量
  90 + *
  91 + * @param accountId 账号编号
  92 + * @return 数量
  93 + */
  94 + long countByAccountId(Long accountId);
  95 +
88 96 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java
1 1 package cn.iocoder.yudao.module.system.service.mail.impl;
2 2  
3   -import cn.hutool.core.collection.CollUtil;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
6 4 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
7 5 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
8 6 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
9 7 import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
10 8 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
11   -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
12   -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO;
13 9 import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
14   -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper;
15 10 import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer;
16 11 import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
  12 +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
17 13 import lombok.extern.slf4j.Slf4j;
18 14 import org.springframework.stereotype.Service;
19 15 import org.springframework.validation.annotation.Validated;
20 16  
21 17 import javax.annotation.PostConstruct;
22 18 import javax.annotation.Resource;
23   -import java.util.Date;
24 19 import java.util.List;
25 20 import java.util.Map;
26 21  
27 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
28   -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
29   -
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  24 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS;
  25 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS;
30 26  
31 27 /**
32 28 * 邮箱账号 Service 实现类
... ... @@ -43,7 +39,7 @@ public class MailAccountServiceImpl implements MailAccountService {
43 39 private MailAccountMapper mailAccountMapper;
44 40  
45 41 @Resource
46   - private MailTemplateMapper mailTemplateMapper;
  42 + private MailTemplateService mailTemplateService;
47 43  
48 44 @Resource
49 45 private MailProducer mailProducer;
... ... @@ -56,75 +52,61 @@ public class MailAccountServiceImpl implements MailAccountService {
56 52 */
57 53 private volatile Map<Long, MailAccountDO> mailAccountCache;
58 54  
59   - /**
60   - * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新
61   - */
62   - private volatile Date maxUpdateTime;
63   -
64 55 @Override
65 56 @PostConstruct
66 57 public void initLocalCache() {
67   - List<MailAccountDO> mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime);
68   - if (CollUtil.isEmpty(mailAccountDOList)) {
69   - return;
70   - }
71   -
72   - // 写入缓存
73   - mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId);
74   - maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime);
75   - log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size());
76   - }
  58 + // 第一步:查询数据
  59 + List<MailAccountDO> accounts = mailAccountMapper.selectList();
  60 + log.info("[initLocalCache][缓存邮箱账号,数量:{}]", accounts.size());
77 61  
78   - private List<MailAccountDO> loadMailAccountIfUpdate(Date maxUpdateTime) {
79   - //第一步 判断是否需要更新
80   - if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据
81   - log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]");
82   - }else{ // 判断数据库中是否有更新的账号信息
83   - if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) {
84   - return null;
85   - }
86   - log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]");
87   - }
88   - return mailAccountMapper.selectList();
  62 + // 第二步:构建缓存
  63 + mailAccountCache = convertMap(accounts, MailAccountDO::getId);
89 64 }
90 65  
91 66 @Override
92   - public Long create(MailAccountCreateReqVO createReqVO) {
93   - // username 要校验唯一
94   - this.validateMailAccountOnlyByUserName(createReqVO.getUsername());
95   - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO);
96   - mailAccountMapper.insert(mailAccountDO);
  67 + public Long createMailAccount(MailAccountCreateReqVO createReqVO) {
  68 + // 插入
  69 + MailAccountDO account = MailAccountConvert.INSTANCE.convert(createReqVO);
  70 + mailAccountMapper.insert(account);
97 71  
98   - // 更新
  72 + // 发送刷新消息
99 73 mailProducer.sendMailAccountRefreshMessage();
100   - return mailAccountDO.getId();
  74 + return account.getId();
101 75 }
102 76  
103 77 @Override
104   - public void update(MailAccountUpdateReqVO updateReqVO) {
105   - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE
106   - this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId());
107   - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
  78 + public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) {
108 79 // 校验是否存在
109   - validateMailAccountExists(mailAccountDO.getId());
  80 + validateMailAccountExists(updateReqVO.getId());
110 81  
111 82 // 更新
  83 + MailAccountDO updateObj = MailAccountConvert.INSTANCE.convert(updateReqVO);
  84 + mailAccountMapper.updateById(updateObj);
  85 + // 发送刷新消息
112 86 mailProducer.sendMailAccountRefreshMessage();
113   - mailAccountMapper.updateById(mailAccountDO);
114 87 }
115 88  
116 89 @Override
117   - public void delete(Long id) {
  90 + public void deleteMailAccount(Long id) {
118 91 // 校验是否存在账号
119 92 validateMailAccountExists(id);
120 93 // 校验是否存在关联模版
121   - validateMailTemplateByAccountId(id);
  94 + if (mailTemplateService.countByAccountId(id) > 0) {
  95 + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS);
  96 + }
  97 +
122 98 // 删除
123 99 mailAccountMapper.deleteById(id);
124   - // 更新
  100 + // 发送刷新消息
125 101 mailProducer.sendMailAccountRefreshMessage();
126 102 }
127 103  
  104 + private void validateMailAccountExists(Long id) {
  105 + if (mailAccountMapper.selectById(id) == null) {
  106 + throw exception(MAIL_ACCOUNT_NOT_EXISTS);
  107 + }
  108 + }
  109 +
128 110 @Override
129 111 public MailAccountDO getMailAccount(Long id) {
130 112 return mailAccountMapper.selectById(id);
... ... @@ -140,33 +122,4 @@ public class MailAccountServiceImpl implements MailAccountService {
140 122 return mailAccountMapper.selectList();
141 123 }
142 124  
143   - private void validateMailAccountExists(Long id) {
144   - if (mailAccountMapper.selectById(id) == null) {
145   - throw exception(MAIL_ACCOUNT_NOT_EXISTS);
146   - }
147   - }
148   -
149   - private void validateMailAccountOnlyByUserName(String userName){
150   - mailAccountCache.forEach((key,value)->{
151   - if(value.getUsername().equals(userName)){
152   - throw exception(MAIL_ACCOUNT_EXISTS);
153   - }
154   - });
155   - }
156   - private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){
157   - mailAccountCache.forEach((key , value)->{
158   - if (value.getUsername().equals(userName)){
159   - if (!key.equals(id)){
160   - throw exception(MAIL_ACCOUNT_EXISTS);
161   - }
162   - }
163   - });
164   - }
165   - private void validateMailTemplateByAccountId(Long accountId){
166   - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId);
167   - if (mailTemplateDO != null) {
168   - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE
169   - throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS);
170   - }
171   - }
172 125 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java
... ... @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
9 9 import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper;
10 10 import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum;
11 11 import cn.iocoder.yudao.module.system.service.mail.MailLogService;
12   -import org.springframework.beans.factory.annotation.Autowired;
13 12 import org.springframework.stereotype.Service;
14 13 import org.springframework.validation.annotation.Validated;
15 14  
... ... @@ -51,7 +50,7 @@ public class MailLogServiceImpl implements MailLogService {
51 50 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus()
52 51 : MailSendStatusEnum.IGNORE.getStatus())
53 52 // 设置邮箱相关字段
54   - .fromAddress(mailAccountDO.getFromAddress())
  53 + .fromMail(mailAccountDO.getMail())
55 54 .accountId(mailAccountDO.getId())
56 55 // TODO @wangjingyi:userId、userType
57 56 //用户信息
... ... @@ -60,7 +59,7 @@ public class MailLogServiceImpl implements MailLogService {
60 59 .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent);
61 60  
62 61  
63   - logDOBuilder.fromAddress(mailAccountDO.getFromAddress());
  62 + logDOBuilder.fromMail(mailAccountDO.getMail());
64 63 logDOBuilder.accountId(mailAccountDO.getId());
65 64 // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE
66 65 // 设置模板相关字段
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java
... ... @@ -53,19 +53,19 @@ public class MailTemplateServiceImpl implements MailTemplateService {
53 53 */
54 54 private volatile Map<Long, MailTemplateDO> mailTemplateCache;
55 55  
56   - private volatile Date maxUpdateTime;
57   -
58 56 @Override
59 57 @PostConstruct
60 58 public void initLocalCache() {
61   - List<MailTemplateDO> mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime);
  59 + if (true) {
  60 + return;
  61 + }
  62 + List<MailTemplateDO> mailTemplateDOList = this.loadMailTemplateIfUpdate(null);
62 63 if (CollUtil.isEmpty(mailTemplateDOList)) {
63 64 return;
64 65 }
65 66  
66 67 // 写入缓存
67 68 mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId);
68   - maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime);
69 69 log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size());
70 70 }
71 71  
... ... @@ -156,4 +156,10 @@ public class MailTemplateServiceImpl implements MailTemplateService {
156 156 // 第二步,如果有更新,则从数据库加载所有邮件模板
157 157 return mailTemplateMapper.selectList();
158 158 }
  159 +
  160 + @Override
  161 + public long countByAccountId(Long accountId) {
  162 + return mailTemplateMapper.selectCountByAccountId(accountId);
  163 + }
  164 +
159 165 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java
... ... @@ -81,7 +81,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
81 81 public void deleteSmsChannel(Long id) {
82 82 // 校验存在
83 83 this.validateSmsChannelExists(id);
84   - // 校验是否有字典数据
  84 + // 校验是否有在使用该账号的模版
85 85 if (smsTemplateService.countByChannelId(id) > 0) {
86 86 throw exception(SMS_CHANNEL_HAS_CHILDREN);
87 87 }
... ...
yudao-ui-admin/src/api/system/mail/account.js 0 → 100755
  1 +import request from '@/utils/request'
  2 +
  3 +// 创建邮箱账号
  4 +export function createMailAccount(data) {
  5 + return request({
  6 + url: '/system/mail-account/create',
  7 + method: 'post',
  8 + data: data
  9 + })
  10 +}
  11 +
  12 +// 更新邮箱账号
  13 +export function updateMailAccount(data) {
  14 + return request({
  15 + url: '/system/mail-account/update',
  16 + method: 'put',
  17 + data: data
  18 + })
  19 +}
  20 +
  21 +// 删除邮箱账号
  22 +export function deleteMailAccount(id) {
  23 + return request({
  24 + url: '/system/mail-account/delete?id=' + id,
  25 + method: 'delete'
  26 + })
  27 +}
  28 +
  29 +// 获得邮箱账号
  30 +export function getMailAccount(id) {
  31 + return request({
  32 + url: '/system/mail-account/get?id=' + id,
  33 + method: 'get'
  34 + })
  35 +}
  36 +
  37 +// 获得邮箱账号分页
  38 +export function getMailAccountPage(query) {
  39 + return request({
  40 + url: '/system/mail-account/page',
  41 + method: 'get',
  42 + params: query
  43 + })
  44 +}
... ...
yudao-ui-admin/src/views/system/mail/account/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="mail">
  7 + <el-input v-model="queryParams.mail" placeholder="请输入邮箱" clearable @keyup.enter.native="handleQuery"/>
  8 + </el-form-item>
  9 + <el-form-item label="用户名" prop="username">
  10 + <el-input v-model="queryParams.username" placeholder="请输入用户名" clearable @keyup.enter.native="handleQuery"/>
  11 + </el-form-item>
  12 + <el-form-item>
  13 + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  14 + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  15 + </el-form-item>
  16 + </el-form>
  17 +
  18 + <!-- 操作工具栏 -->
  19 + <el-row :gutter="10" class="mb8">
  20 + <el-col :span="1.5">
  21 + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  22 + v-hasPermi="['system:mail-account:create']">新增</el-button>
  23 + </el-col>
  24 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  25 + </el-row>
  26 +
  27 + <!-- 列表 -->
  28 + <el-table v-loading="loading" :data="list">
  29 + <el-table-column label="主键" align="center" prop="id" />
  30 + <el-table-column label="邮箱" align="center" prop="mail" />
  31 + <el-table-column label="用户名" align="center" prop="username" />
  32 + <el-table-column label="主机" align="center" prop="host" />
  33 + <el-table-column label="端口" align="center" prop="port" />
  34 + <el-table-column label="是否开启 SSL" align="center" prop="sslEnable">
  35 + <template v-slot="scope">
  36 + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.sslEnable" />
  37 + </template>
  38 + </el-table-column>
  39 + <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  40 + <template v-slot="scope">
  41 + <span>{{ parseTime(scope.row.createTime) }}</span>
  42 + </template>
  43 + </el-table-column>
  44 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  45 + <template v-slot="scope">
  46 + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  47 + v-hasPermi="['system:mail-account:update']">修改</el-button>
  48 + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  49 + v-hasPermi="['system:mail-account:delete']">删除</el-button>
  50 + </template>
  51 + </el-table-column>
  52 + </el-table>
  53 + <!-- 分页组件 -->
  54 + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  55 + @pagination="getList"/>
  56 +
  57 + <!-- 对话框(添加 / 修改) -->
  58 + <el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body>
  59 + <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  60 + <el-form-item label="邮箱" prop="mail">
  61 + <el-input v-model="form.mail" placeholder="请输入邮箱" />
  62 + </el-form-item>
  63 + <el-form-item label="用户名" prop="username">
  64 + <el-input v-model="form.username" placeholder="请输入用户名" />
  65 + </el-form-item>
  66 + <el-form-item label="密码" prop="password">
  67 + <el-input v-model="form.password" placeholder="请输入密码" />
  68 + </el-form-item>
  69 + <el-form-item label="主机" prop="host">
  70 + <el-input v-model="form.host" placeholder="请输入主机" />
  71 + </el-form-item>
  72 + <el-form-item label="端口" prop="port">
  73 + <el-input v-model="form.port" placeholder="请输入端口" />
  74 + </el-form-item>
  75 + <el-form-item label="是否开启 SSL" prop="sslEnable">
  76 + <el-radio-group v-model="form.sslEnable">
  77 + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  78 + :key="dict.value" :label="dict.value === 'true'">{{dict.label}}</el-radio>
  79 + </el-radio-group>
  80 + </el-form-item>
  81 + </el-form>
  82 + <div slot="footer" class="dialog-footer">
  83 + <el-button type="primary" @click="submitForm">确 定</el-button>
  84 + <el-button @click="cancel">取 消</el-button>
  85 + </div>
  86 + </el-dialog>
  87 + </div>
  88 +</template>
  89 +
  90 +<script>
  91 +import { createMailAccount, updateMailAccount, deleteMailAccount, getMailAccount, getMailAccountPage } from "@/api/system/mail/account";
  92 +
  93 +export default {
  94 + name: "MailAccount",
  95 + components: {
  96 + },
  97 + data() {
  98 + return {
  99 + // 遮罩层
  100 + loading: true,
  101 + // 导出遮罩层
  102 + exportLoading: false,
  103 + // 显示搜索条件
  104 + showSearch: true,
  105 + // 总条数
  106 + total: 0,
  107 + // 邮箱账号列表
  108 + list: [],
  109 + // 弹出层标题
  110 + title: "",
  111 + // 是否显示弹出层
  112 + open: false,
  113 + // 查询参数
  114 + queryParams: {
  115 + pageNo: 1,
  116 + pageSize: 10,
  117 + mail: null,
  118 + username: null
  119 + },
  120 + // 表单参数
  121 + form: {},
  122 + // 表单校验
  123 + rules: {
  124 + mail: [{ required: true, message: "邮箱不能为空", trigger: "blur" }],
  125 + username: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
  126 + password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
  127 + host: [{ required: true, message: "主机不能为空", trigger: "blur" }],
  128 + port: [{ required: true, message: "端口不能为空", trigger: "blur" }],
  129 + sslEnable: [{ required: true, message: "是否开启 SSL不能为空", trigger: "blur" }],
  130 + }
  131 + };
  132 + },
  133 + created() {
  134 + this.getList();
  135 + },
  136 + methods: {
  137 + /** 查询列表 */
  138 + getList() {
  139 + this.loading = true;
  140 + // 执行查询
  141 + getMailAccountPage(this.queryParams).then(response => {
  142 + this.list = response.data.list;
  143 + this.total = response.data.total;
  144 + this.loading = false;
  145 + });
  146 + },
  147 + /** 取消按钮 */
  148 + cancel() {
  149 + this.open = false;
  150 + this.reset();
  151 + },
  152 + /** 表单重置 */
  153 + reset() {
  154 + this.form = {
  155 + id: undefined,
  156 + mail: undefined,
  157 + username: undefined,
  158 + password: undefined,
  159 + host: undefined,
  160 + port: undefined,
  161 + sslEnable: true,
  162 + };
  163 + this.resetForm("form");
  164 + },
  165 + /** 搜索按钮操作 */
  166 + handleQuery() {
  167 + this.queryParams.pageNo = 1;
  168 + this.getList();
  169 + },
  170 + /** 重置按钮操作 */
  171 + resetQuery() {
  172 + this.resetForm("queryForm");
  173 + this.handleQuery();
  174 + },
  175 + /** 新增按钮操作 */
  176 + handleAdd() {
  177 + this.reset();
  178 + this.open = true;
  179 + this.title = "添加邮箱账号";
  180 + },
  181 + /** 修改按钮操作 */
  182 + handleUpdate(row) {
  183 + this.reset();
  184 + const id = row.id;
  185 + getMailAccount(id).then(response => {
  186 + this.form = response.data;
  187 + this.open = true;
  188 + this.title = "修改邮箱账号";
  189 + });
  190 + },
  191 + /** 提交按钮 */
  192 + submitForm() {
  193 + this.$refs["form"].validate(valid => {
  194 + if (!valid) {
  195 + return;
  196 + }
  197 + // 修改的提交
  198 + if (this.form.id != null) {
  199 + updateMailAccount(this.form).then(response => {
  200 + this.$modal.msgSuccess("修改成功");
  201 + this.open = false;
  202 + this.getList();
  203 + });
  204 + return;
  205 + }
  206 + // 添加的提交
  207 + createMailAccount(this.form).then(response => {
  208 + this.$modal.msgSuccess("新增成功");
  209 + this.open = false;
  210 + this.getList();
  211 + });
  212 + });
  213 + },
  214 + /** 删除按钮操作 */
  215 + handleDelete(row) {
  216 + const id = row.id;
  217 + this.$modal.confirm('是否确认删除邮箱账号编号为"' + id + '"的数据项?').then(function() {
  218 + return deleteMailAccount(id);
  219 + }).then(() => {
  220 + this.getList();
  221 + this.$modal.msgSuccess("删除成功");
  222 + }).catch(() => {});
  223 + }
  224 + }
  225 +};
  226 +</script>
... ...