🔧 简化 mail 模块的 VO

pull/79/head
YunaiV 2023-12-02 19:55:10 +08:00
parent 80afe88dad
commit ce42bf7826
24 changed files with 168 additions and 303 deletions

View File

@ -62,7 +62,7 @@ public class DictDataController {
return success(true);
}
@GetMapping("/list-all-simple")
@GetMapping(value = {"/list-all-simple", "simple-list"})
@Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
// 无需添加权限认证,因为前端全局都需要
public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {

View File

@ -3,13 +3,16 @@ package cn.iocoder.yudao.module.system.controller.admin.mail;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*;
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSimpleRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -30,14 +33,14 @@ public class MailAccountController {
@PostMapping("/create")
@Operation(summary = "创建邮箱账号")
@PreAuthorize("@ss.hasPermission('system:mail-account:create')")
public CommonResult<Long> createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) {
public CommonResult<Long> createMailAccount(@Valid @RequestBody MailAccountSaveReqVO createReqVO) {
return success(mailAccountService.createMailAccount(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "修改邮箱账号")
@PreAuthorize("@ss.hasPermission('system:mail-account:update')")
public CommonResult<Boolean> updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateMailAccount(@Valid @RequestBody MailAccountSaveReqVO updateReqVO) {
mailAccountService.updateMailAccount(updateReqVO);
return success(true);
}
@ -56,23 +59,23 @@ public class MailAccountController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:mail-account:get')")
public CommonResult<MailAccountRespVO> getMailAccount(@RequestParam("id") Long id) {
MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id);
return success(MailAccountConvert.INSTANCE.convert(mailAccountDO));
MailAccountDO account = mailAccountService.getMailAccount(id);
return success(BeanUtils.toBean(account, MailAccountRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得邮箱账号分页")
@PreAuthorize("@ss.hasPermission('system:mail-account:query')")
public CommonResult<PageResult<MailAccountBaseVO>> getMailAccountPage(@Valid MailAccountPageReqVO pageReqVO) {
public CommonResult<PageResult<MailAccountRespVO>> getMailAccountPage(@Valid MailAccountPageReqVO pageReqVO) {
PageResult<MailAccountDO> pageResult = mailAccountService.getMailAccountPage(pageReqVO);
return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
return success(BeanUtils.toBean(pageResult, MailAccountRespVO.class));
}
@GetMapping("/list-all-simple")
@GetMapping({"/list-all-simple", "simple-list"})
@Operation(summary = "获得邮箱账号精简列表")
public CommonResult<List<MailAccountSimpleRespVO>> getSimpleMailAccountList() {
List<MailAccountDO> list = mailAccountService.getMailAccountList();
return success(MailAccountConvert.INSTANCE.convertList02(list));
return success(BeanUtils.toBean(list, MailAccountSimpleRespVO.class));
}
}

View File

@ -1,16 +1,15 @@
package cn.iocoder.yudao.module.system.controller.admin.mail;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO;
import cn.iocoder.yudao.module.system.convert.mail.MailLogConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
import cn.iocoder.yudao.module.system.service.mail.MailLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -22,7 +21,6 @@ import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 邮件日志")
@RestController
@RequestMapping("/system/mail-log")
@ -36,7 +34,7 @@ public class MailLogController {
@PreAuthorize("@ss.hasPermission('system:mail-log:query')")
public CommonResult<PageResult<MailLogRespVO>> getMailLogPage(@Valid MailLogPageReqVO pageVO) {
PageResult<MailLogDO> pageResult = mailLogService.getMailLogPage(pageVO);
return success(MailLogConvert.INSTANCE.convertPage(pageResult));
return success(BeanUtils.toBean(pageResult, MailLogRespVO.class));
}
@GetMapping("/get")
@ -44,8 +42,8 @@ public class MailLogController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:mail-log:query')")
public CommonResult<MailLogRespVO> getMailTemplate(@RequestParam("id") Long id) {
MailLogDO mailLogDO = mailLogService.getMailLog(id);
return success(MailLogConvert.INSTANCE.convert(mailLogDO));
MailLogDO log = mailLogService.getMailLog(id);
return success(BeanUtils.toBean(log, MailLogRespVO.class));
}
}

View File

@ -2,14 +2,14 @@ package cn.iocoder.yudao.module.system.controller.admin.mail;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*;
import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import cn.iocoder.yudao.module.system.service.mail.MailSendService;
import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -33,14 +33,14 @@ public class MailTemplateController {
@PostMapping("/create")
@Operation(summary = "创建邮件模版")
@PreAuthorize("@ss.hasPermission('system:mail-template:create')")
public CommonResult<Long> createMailTemplate(@Valid @RequestBody MailTemplateCreateReqVO createReqVO){
public CommonResult<Long> createMailTemplate(@Valid @RequestBody MailTemplateSaveReqVO createReqVO){
return success(mailTempleService.createMailTemplate(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "修改邮件模版")
@PreAuthorize("@ss.hasPermission('system:mail-template:update')")
public CommonResult<Boolean> updateMailTemplate(@Valid @RequestBody MailTemplateUpdateReqVO updateReqVO){
public CommonResult<Boolean> updateMailTemplate(@Valid @RequestBody MailTemplateSaveReqVO updateReqVO){
mailTempleService.updateMailTemplate(updateReqVO);
return success(true);
}
@ -59,8 +59,8 @@ public class MailTemplateController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:mail-template:get')")
public CommonResult<MailTemplateRespVO> getMailTemplate(@RequestParam("id") Long id) {
MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id);
return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO));
MailTemplateDO template = mailTempleService.getMailTemplate(id);
return success(BeanUtils.toBean(template, MailTemplateRespVO.class));
}
@GetMapping("/page")
@ -68,14 +68,14 @@ public class MailTemplateController {
@PreAuthorize("@ss.hasPermission('system:mail-template:query')")
public CommonResult<PageResult<MailTemplateRespVO>> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) {
PageResult<MailTemplateDO> pageResult = mailTempleService.getMailTemplatePage(pageReqVO);
return success(MailTemplateConvert.INSTANCE.convertPage(pageResult));
return success(BeanUtils.toBean(pageResult, MailTemplateRespVO.class));
}
@GetMapping("/list-all-simple")
@GetMapping({"/list-all-simple", "simple-list"})
@Operation(summary = "获得邮件模版精简列表")
public CommonResult<List<MailTemplateSimpleRespVO>> getSimpleTemplateList() {
List<MailTemplateDO> list = mailTempleService.getMailTemplateList();
return success(MailTemplateConvert.INSTANCE.convertList02(list));
return success(BeanUtils.toBean(list, MailTemplateSimpleRespVO.class));
}
@PostMapping("/send-mail")

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 邮箱账号创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailAccountCreateReqVO extends MailAccountBaseVO {
}

View File

@ -2,22 +2,34 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 邮箱账号 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailAccountRespVO extends MailAccountBaseVO {
public class MailAccountRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "编号不能为空")
private Long id;
@Schema(description = "邮箱", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma@123.com")
private String mail;
@Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
private String username;
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
private String password;
@Schema(description = "SMTP 服务器域名", requiredMode = Schema.RequiredMode.REQUIRED, example = "www.iocoder.cn")
private String host;
@Schema(description = "SMTP 服务器端口", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
private Integer port;
@Schema(description = "是否开启 ssl", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean sslEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -6,12 +6,12 @@ import lombok.Data;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
/**
* Base VO VO 使
* VO Swagger
*/
@Schema(description = "管理后台 - 邮箱账号创建/修改 Request VO")
@Data
public class MailAccountBaseVO {
public class MailAccountSaveReqVO {
@Schema(description = "编号", example = "1024")
private Long id;
@Schema(description = "邮箱", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma@123.com")
@NotNull(message = "邮箱不能为空")

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 邮箱账号修改 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailAccountUpdateReqVO extends MailAccountBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -1,75 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class MailLogBaseVO {
@Schema(description = "用户编号", example = "30883")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2")
private Byte userType;
@Schema(description = "接收邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "76854@qq.com")
@NotNull(message = "接收邮箱地址不能为空")
private String toMail;
@Schema(description = "邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18107")
@NotNull(message = "邮箱账号编号不能为空")
private Long accountId;
@Schema(description = "发送邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "85757@qq.com")
@NotNull(message = "发送邮箱地址不能为空")
private String fromMail;
@Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5678")
@NotNull(message = "模板编号不能为空")
private Long templateId;
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
@NotNull(message = "模板编码不能为空")
private String templateCode;
@Schema(description = "模版发送人名称", example = "李四")
private String templateNickname;
@Schema(description = "邮件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试标题")
@NotNull(message = "邮件标题不能为空")
private String templateTitle;
@Schema(description = "邮件内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
@NotNull(message = "邮件内容不能为空")
private String templateContent;
@Schema(description = "邮件参数", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "邮件参数不能为空")
private Map<String, Object> templateParams;
@Schema(description = "发送状态,参见 MailSendStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "发送状态不能为空")
private Byte sendStatus;
@Schema(description = "发送时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime sendTime;
@Schema(description = "发送返回的消息 ID", example = "28568")
private String sendMessageId;
@Schema(description = "发送异常")
private String sendException;
}

View File

@ -2,20 +2,62 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.Map;
@Schema(description = "管理后台 - 邮件日志 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailLogRespVO extends MailLogBaseVO {
public class MailLogRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31020")
private Long id;
@Schema(description = "用户编号", example = "30883")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2")
private Byte userType;
@Schema(description = "接收邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "76854@qq.com")
private String toMail;
@Schema(description = "邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18107")
private Long accountId;
@Schema(description = "发送邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "85757@qq.com")
private String fromMail;
@Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5678")
private Long templateId;
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
private String templateCode;
@Schema(description = "模版发送人名称", example = "李四")
private String templateNickname;
@Schema(description = "邮件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试标题")
private String templateTitle;
@Schema(description = "邮件内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
private String templateContent;
@Schema(description = "邮件参数", requiredMode = Schema.RequiredMode.REQUIRED)
private Map<String, Object> templateParams;
@Schema(description = "发送状态,参见 MailSendStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Byte sendStatus;
@Schema(description = "发送时间")
private LocalDateTime sendTime;
@Schema(description = "发送返回的消息 ID", example = "28568")
private String sendMessageId;
@Schema(description = "发送异常")
private String sendException;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 邮件模版创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailTemplateCreateReqVO extends MailTemplateBaseVO {
}

View File

@ -2,24 +2,44 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 邮件末班 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailTemplateRespVO extends MailTemplateBaseVO {
public class MailTemplateRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试名字")
private String name;
@Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
private String code;
@Schema(description = "发送的邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long accountId;
@Schema(description = "发送人名称", example = "芋头")
private String nickname;
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
private String title;
@Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,注册成功啦")
private String content;
@Schema(description = "参数数组", example = "name,code")
private List<String> params;
@Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "备注", example = "奥特曼")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -6,12 +6,12 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Base VO VO 使
* VO Swagger
*/
@Schema(description = "管理后台 - 邮件模版创建/修改 Request VO")
@Data
public class MailTemplateBaseVO {
public class MailTemplateSaveReqVO {
@Schema(description = "编号", example = "1024")
private Long id;
@Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试名字")
@NotNull(message = "名称不能为空")

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 邮件模版修改 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailTemplateUpdateReqVO extends MailTemplateBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -2,29 +2,15 @@ package cn.iocoder.yudao.module.system.convert.mail;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface MailAccountConvert {
MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class);
MailAccountDO convert(MailAccountCreateReqVO bean);
MailAccountDO convert(MailAccountUpdateReqVO bean);
MailAccountRespVO convert(MailAccountDO bean);
PageResult<MailAccountBaseVO> convertPage(PageResult<MailAccountDO> pageResult);
List<MailAccountSimpleRespVO> convertList02(List<MailAccountDO> list);
default MailAccount convert(MailAccountDO account, String nickname) {
String from = StrUtil.isNotEmpty(nickname) ? nickname + " <" + account.getMail() + ">" : account.getMail();
return new MailAccount().setFrom(from).setAuth(true)

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.system.convert.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface MailLogConvert {
MailLogConvert INSTANCE = Mappers.getMapper(MailLogConvert.class);
PageResult<MailLogRespVO> convertPage(PageResult<MailLogDO> pageResult);
MailLogRespVO convert(MailLogDO bean);
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.yudao.module.system.convert.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSimpleRespVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface MailTemplateConvert {
MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class);
MailTemplateDO convert(MailTemplateUpdateReqVO bean);
MailTemplateDO convert(MailTemplateCreateReqVO bean);
MailTemplateRespVO convert(MailTemplateDO bean);
PageResult<MailTemplateRespVO> convertPage(PageResult<MailTemplateDO> pageResult);
List<MailTemplateSimpleRespVO> convertList02(List<MailTemplateDO> list);
}

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import javax.validation.Valid;
@ -23,14 +22,14 @@ public interface MailAccountService {
* @param createReqVO
* @return
*/
Long createMailAccount(@Valid MailAccountCreateReqVO createReqVO);
Long createMailAccount(@Valid MailAccountSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateMailAccount(@Valid MailAccountUpdateReqVO updateReqVO);
void updateMailAccount(@Valid MailAccountSaveReqVO updateReqVO);
/**
*

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
@ -39,21 +38,20 @@ public class MailAccountServiceImpl implements MailAccountService {
private MailTemplateService mailTemplateService;
@Override
public Long createMailAccount(MailAccountCreateReqVO createReqVO) {
// 插入
MailAccountDO account = MailAccountConvert.INSTANCE.convert(createReqVO);
public Long createMailAccount(MailAccountSaveReqVO createReqVO) {
MailAccountDO account = BeanUtils.toBean(createReqVO, MailAccountDO.class);
mailAccountMapper.insert(account);
return account.getId();
}
@Override
@CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#updateReqVO.id")
public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) {
public void updateMailAccount(MailAccountSaveReqVO updateReqVO) {
// 校验是否存在
validateMailAccountExists(updateReqVO.getId());
// 更新
MailAccountDO updateObj = MailAccountConvert.INSTANCE.convert(updateReqVO);
MailAccountDO updateObj = BeanUtils.toBean(updateReqVO, MailAccountDO.class);
mailAccountMapper.updateById(updateObj);
}
@ -63,7 +61,7 @@ public class MailAccountServiceImpl implements MailAccountService {
// 校验是否存在账号
validateMailAccountExists(id);
// 校验是否存在关联模版
if (mailTemplateService.countByAccountId(id) > 0) {
if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) {
throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS);
}

View File

@ -12,7 +12,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.Objects;

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import javax.validation.Valid;
@ -24,14 +23,14 @@ public interface MailTemplateService {
* @param createReqVO
* @return
*/
Long createMailTemplate(@Valid MailTemplateCreateReqVO createReqVO);
Long createMailTemplate(@Valid MailTemplateSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO);
void updateMailTemplate(@Valid MailTemplateSaveReqVO updateReqVO);
/**
*
@ -86,6 +85,6 @@ public interface MailTemplateService {
* @param accountId
* @return
*/
long countByAccountId(Long accountId);
long getMailTemplateCountByAccountId(Long accountId);
}

View File

@ -4,10 +4,9 @@ import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper;
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
@ -48,12 +47,12 @@ public class MailTemplateServiceImpl implements MailTemplateService {
private MailTemplateMapper mailTemplateMapper;
@Override
public Long createMailTemplate(MailTemplateCreateReqVO createReqVO) {
public Long createMailTemplate(MailTemplateSaveReqVO createReqVO) {
// 校验 code 是否唯一
validateCodeUnique(null, createReqVO.getCode());
// 插入
MailTemplateDO template = MailTemplateConvert.INSTANCE.convert(createReqVO)
MailTemplateDO template = BeanUtils.toBean(createReqVO, MailTemplateDO.class)
.setParams(parseTemplateContentParams(createReqVO.getContent()));
mailTemplateMapper.insert(template);
return template.getId();
@ -62,14 +61,14 @@ public class MailTemplateServiceImpl implements MailTemplateService {
@Override
@CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE,
allEntries = true) // allEntries 清空所有缓存,因为可能修改到 code 字段,不好清理
public void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO) {
public void updateMailTemplate(@Valid MailTemplateSaveReqVO updateReqVO) {
// 校验是否存在
validateMailTemplateExists(updateReqVO.getId());
// 校验 code 是否唯一
validateCodeUnique(updateReqVO.getId(),updateReqVO.getCode());
// 更新
MailTemplateDO updateObj = MailTemplateConvert.INSTANCE.convert(updateReqVO)
MailTemplateDO updateObj = BeanUtils.toBean(updateReqVO, MailTemplateDO.class)
.setParams(parseTemplateContentParams(updateReqVO.getContent()));
mailTemplateMapper.updateById(updateObj);
}
@ -132,7 +131,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
}
@Override
public long countByAccountId(Long accountId) {
public long getMailTemplateCountByAccountId(Long accountId) {
return mailTemplateMapper.selectCountByAccountId(accountId);
}

View File

@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
import org.junit.jupiter.api.Test;
@ -43,7 +42,8 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateMailAccount_success() {
// 准备参数
MailAccountCreateReqVO reqVO = randomPojo(MailAccountCreateReqVO.class, o -> o.setMail(randomEmail()));
MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class, o -> o.setMail(randomEmail()))
.setId(null); // 防止 id 被赋值
// 调用
Long mailAccountId = mailAccountService.createMailAccount(reqVO);
@ -51,7 +51,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest {
assertNotNull(mailAccountId);
// 校验记录的属性是否正确
MailAccountDO mailAccount = mailAccountMapper.selectById(mailAccountId);
assertPojoEquals(reqVO, mailAccount);
assertPojoEquals(reqVO, mailAccount, "id");
}
@Test
@ -60,7 +60,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest {
MailAccountDO dbMailAccount = randomPojo(MailAccountDO.class);
mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据
// 准备参数
MailAccountUpdateReqVO reqVO = randomPojo(MailAccountUpdateReqVO.class, o -> {
MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class, o -> {
o.setId(dbMailAccount.getId()); // 设置更新的 ID
o.setMail(randomEmail());
});
@ -75,7 +75,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest {
@Test
public void testUpdateMailAccount_notExists() {
// 准备参数
MailAccountUpdateReqVO reqVO = randomPojo(MailAccountUpdateReqVO.class);
MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> mailAccountService.updateMailAccount(reqVO), MAIL_ACCOUNT_NOT_EXISTS);
@ -89,7 +89,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest {
// 准备参数
Long id = dbMailAccount.getId();
// mock 方法(无关联模版)
when(mailTemplateService.countByAccountId(eq(id))).thenReturn(0L);
when(mailTemplateService.getMailTemplateCountByAccountId(eq(id))).thenReturn(0L);
// 调用
mailAccountService.deleteMailAccount(id);

View File

@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper;
import org.junit.jupiter.api.Test;
@ -43,7 +42,8 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateMailTemplate_success() {
// 准备参数
MailTemplateCreateReqVO reqVO = randomPojo(MailTemplateCreateReqVO.class);
MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class)
.setId(null); // 防止 id 被赋值
// 调用
Long mailTemplateId = mailTemplateService.createMailTemplate(reqVO);
@ -51,7 +51,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest {
assertNotNull(mailTemplateId);
// 校验记录的属性是否正确
MailTemplateDO mailTemplate = mailTemplateMapper.selectById(mailTemplateId);
assertPojoEquals(reqVO, mailTemplate);
assertPojoEquals(reqVO, mailTemplate, "id");
}
@Test
@ -60,7 +60,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest {
MailTemplateDO dbMailTemplate = randomPojo(MailTemplateDO.class);
mailTemplateMapper.insert(dbMailTemplate);// @Sql: 先插入出一条存在的数据
// 准备参数
MailTemplateUpdateReqVO reqVO = randomPojo(MailTemplateUpdateReqVO.class, o -> {
MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class, o -> {
o.setId(dbMailTemplate.getId()); // 设置更新的 ID
});
@ -74,7 +74,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest {
@Test
public void testUpdateMailTemplate_notExists() {
// 准备参数
MailTemplateUpdateReqVO reqVO = randomPojo(MailTemplateUpdateReqVO.class);
MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> mailTemplateService.updateMailTemplate(reqVO), MAIL_TEMPLATE_NOT_EXISTS);
@ -207,7 +207,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest {
Long accountId = dbMailTemplate.getAccountId();
// 调用
long count = mailTemplateService.countByAccountId(accountId);
long count = mailTemplateService.getMailTemplateCountByAccountId(accountId);
// 断言
assertEquals(1, count);
}