From 3b42b7061000c66eea944bdc22b9f8ca2ec50fa0 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 23 Mar 2022 20:59:46 +0800 Subject: [PATCH 01/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mail/SystemMailAccountController.java | 95 +++++++++++++++++++ .../admin/mail/SystemMailLogController.java | 20 ++++ .../mail/SystemMailTempleController.java | 20 ++++ .../vo/account/SystemMailAccountBaseVO.java | 26 +++++ .../mail/SystemMailAccountConvert.java | 25 +++++ .../dataobject/mail/SystemMailAccountDO.java | 54 +++++++++++ .../dal/dataobject/mail/SystemMailLogDO.java | 61 ++++++++++++ .../dataobject/mail/SystemMailTempleDO.java | 54 +++++++++++ .../mysql/mail/SystemMailAccountMapper.java | 28 ++++++ .../dal/mysql/mail/SystemMailLogMapper.java | 16 ++++ .../mysql/mail/SystemMailTempleMapper.java | 16 ++++ .../mail/SystemMailAccountService.java | 31 ++++++ .../service/mail/SystemMailLogService.java | 14 +++ .../service/mail/SystemMailTempleService.java | 13 +++ .../impl/SystemMailAccountServiceImpl.java | 63 ++++++++++++ .../mail/impl/SystemMailLogServiceImpl.java | 18 ++++ .../impl/SystemMailTempleServiceImpl.java | 18 ++++ 17 files changed, 572 insertions(+) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java new file mode 100644 index 000000000..d6ba85dcd --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail; + + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; +import cn.iocoder.yudao.module.system.convert.mail.SystemMailAccountConvert; +import cn.iocoder.yudao.module.system.convert.sms.SmsChannelConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; +import cn.iocoder.yudao.module.system.service.mail.SystemMailAccountService; +import cn.iocoder.yudao.module.system.service.sms.SmsChannelService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import java.util.Comparator; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + *

+ * 前端控制器 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Api(tags = "管理后台 - 邮件模板") +@RestController +@RequestMapping("/system-mail-account") +public class SystemMailAccountController { + @Resource + private SystemMailAccountService systemMailAccountService; + + @PostMapping("/create") + @ApiOperation("创建邮箱账号") + @PreAuthorize("@ss.hasPermission('system:system-mail-account:create')") + public CommonResult createMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { + return success(systemMailAccountService.create(baseVO)); + } + + @PutMapping("/update") + @ApiOperation("修改邮箱账号") + @PreAuthorize("@ss.hasPermission('system:system-mail-account:update')") + public CommonResult updateMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { + systemMailAccountService.update(baseVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除邮箱账号") + @PreAuthorize("@ss.hasPermission('system:system-mail-account:delete')") + public CommonResult deleteMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { + systemMailAccountService.delete(baseVO); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得邮箱账号") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:system-mail-account:get')") + public CommonResult getMailAccount(@RequestParam("id") Long id) { + SystemMailAccountDO systemMailAccountDO = systemMailAccountService.getMailAccount(id); + return success(SystemMailAccountConvert.INSTANCE.convert(systemMailAccountDO)); + } + + @GetMapping("/page") + @ApiOperation("获得邮箱账号分页") + @PreAuthorize("@ss.hasPermission('system:system-mail-account:query')") + public CommonResult> getSmsChannelPage(@Valid PageParam pageParam) { + PageResult pageResult = systemMailAccountService.getMailAccountPage(pageParam); + return success(SystemMailAccountConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/list-all-simple") + @ApiOperation(value = "获得邮箱账号精简列表") + public CommonResult> getSimpleSmsChannels() { + List list = systemMailAccountService.getMailAccountList(); + // 排序后,返回给前端 + list.sort(Comparator.comparing(SystemMailAccountDO::getId)); + return success(SystemMailAccountConvert.INSTANCE.convertList02(list)); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java new file mode 100644 index 000000000..710e3f4d3 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 前端控制器 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@RestController +@RequestMapping("/system-mail-log") +public class SystemMailLogController { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java new file mode 100644 index 000000000..7b76958d1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 前端控制器 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@RestController +@RequestMapping("/system-mail-temple") +public class SystemMailTempleController { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java new file mode 100644 index 000000000..4f74da0c8 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class SystemMailAccountBaseVO { + @ApiModelProperty(value = "来源" , required = true , example = "yudaoyuanma") + private String from; + + @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + private String username; + + @ApiModelProperty(value = "密码" , required = true , example = "123456") + private String password; + + @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") + private String host; + + @ApiModelProperty(value = "端口" , required = true , example = "80") + private String port; + + @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") + private Integer sslEnable; +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java new file mode 100644 index 000000000..465bff31f --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java @@ -0,0 +1,25 @@ +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.account.SystemMailAccountBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface SystemMailAccountConvert { + SystemMailAccountConvert INSTANCE = Mappers.getMapper(SystemMailAccountConvert.class); + + SystemMailAccountDO convert (SystemMailAccountBaseVO systemMailAccountBaseVO); + + SystemMailAccountBaseVO convert (SystemMailAccountDO systemMailAccountDO); + + PageResult convertPage(PageResult pageResult); + + List convertList02(List list); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java new file mode 100644 index 000000000..c5d90dfd1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value="SystemMailAccount对象", description="") +@TableName(value = "system_mail_account", autoResultMap = true) +public class SystemMailAccountDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("from") + private String from; + + @TableField("username") + private String username; + + @TableField("password") + private String password; + + @TableField("host") + private String host; + + @TableField("port") + private String port; + + @TableField("sslEnable") + private Integer sslEnable; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java new file mode 100644 index 000000000..b909e0c37 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java @@ -0,0 +1,61 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import java.sql.Timestamp; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value="SystemMailLog对象", description="") +public class SystemMailLogDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("account_code") + private String accountCode; + + @TableField("from") + private String from; + + @TableField("temple_code") + private String templeCode; + + @TableField("title") + private String title; + + @TableField("content") + private String content; + + @TableField("to") + private String to; + + @TableField("sendTime") + private Timestamp sendTime; + + @TableField("sendStatus") + private String sendStatus; + + @TableField("sendResult") + private String sendResult; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java new file mode 100644 index 000000000..3a13d1b4b --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value="SystemMailTemple对象", description="") +public class SystemMailTempleDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("name") + private String name; + + @TableField("code") + private String code; + + @TableField("username") + private String username; + + @TableField("title") + private String title; + + @TableField("content") + private String content; + + @TableField("status") + private String status; + + @TableField("remark") + private String remark; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java new file mode 100644 index 000000000..576c23bdd --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; +import org.apache.ibatis.annotations.Mapper; + + +/** + *

+ * Mapper 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Mapper +public interface SystemMailAccountMapper extends BaseMapperX { + + default PageResult selectPage(PageParam pageParam) { + return selectPage(pageParam, new QueryWrapperX()); + } + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java new file mode 100644 index 000000000..7432fdde3 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailLogDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface SystemMailLogMapper extends BaseMapper { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java new file mode 100644 index 000000000..0460cc7b2 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailTempleDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface SystemMailTempleMapper extends BaseMapper { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java new file mode 100644 index 000000000..38f787131 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.system.service.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface SystemMailAccountService { + + Long create(SystemMailAccountBaseVO baseVO); + + String update(SystemMailAccountBaseVO baseVO); + + String delete(SystemMailAccountBaseVO baseVO); + + SystemMailAccountDO getMailAccount(Long id); + + PageResult getMailAccountPage(PageParam pageParam); + + List getMailAccountList(); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java new file mode 100644 index 000000000..ff5043878 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.system.service.mail; + + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface SystemMailLogService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java new file mode 100644 index 000000000..507b64b9a --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.module.system.service.mail; + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface SystemMailTempleService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java new file mode 100644 index 000000000..b50ca35b5 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; +import cn.iocoder.yudao.module.system.convert.mail.SystemMailAccountConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.SystemMailAccountMapper; +import cn.iocoder.yudao.module.system.service.mail.SystemMailAccountService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class SystemMailAccountServiceImpl implements SystemMailAccountService { + @Resource + SystemMailAccountMapper systemMailAccountMapper; + @Override + public Long create(SystemMailAccountBaseVO baseVO) { + SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); + systemMailAccountMapper.insert(systemMailAccountDO); + return systemMailAccountDO.getId(); + } + + @Override + public String update(SystemMailAccountBaseVO baseVO) { + SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); + systemMailAccountMapper.updateById(systemMailAccountDO); + return null; + } + + @Override + public String delete(SystemMailAccountBaseVO baseVO) { + SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); + systemMailAccountMapper.deleteById(systemMailAccountDO); + return null; + } + + @Override + public SystemMailAccountDO getMailAccount(Long id) { + return systemMailAccountMapper.selectById(id); + } + + @Override + public PageResult getMailAccountPage(PageParam pageParam) { + return systemMailAccountMapper.selectPage(pageParam); + } + + @Override + public List getMailAccountList() { + return systemMailAccountMapper.selectList(); + } + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java new file mode 100644 index 000000000..4b17a3e21 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.iocoder.yudao.module.system.service.mail.SystemMailLogService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class SystemMailLogServiceImpl implements SystemMailLogService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java new file mode 100644 index 000000000..e59cb01ba --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.iocoder.yudao.module.system.service.mail.SystemMailTempleService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class SystemMailTempleServiceImpl implements SystemMailTempleService { + +} From 50f7af00e9249108f8113e4ffd3e480c9651dfa9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 23 Mar 2022 21:17:31 +0800 Subject: [PATCH 02/41] =?UTF-8?q?code=20review=20=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/SystemMailAccountController.java | 17 ++++++++--------- .../vo/account/SystemMailAccountBaseVO.java | 5 ++++- .../dal/mysql/mail/SystemMailAccountMapper.java | 4 +--- .../service/mail/SystemMailAccountService.java | 2 ++ .../mail/impl/SystemMailAccountServiceImpl.java | 12 +++++++++++- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java index d6ba85dcd..c625b7cda 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java @@ -5,16 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; import cn.iocoder.yudao.module.system.convert.mail.SystemMailAccountConvert; -import cn.iocoder.yudao.module.system.convert.sms.SmsChannelConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.service.mail.SystemMailAccountService; -import cn.iocoder.yudao.module.system.service.sms.SmsChannelService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -23,12 +16,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; - import java.util.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +// TODO @ジョイイ:使用 Swagger 注解,不用写这个注释啦 /** *

* 前端控制器 @@ -39,11 +32,13 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; */ @Api(tags = "管理后台 - 邮件模板") @RestController -@RequestMapping("/system-mail-account") +@RequestMapping("/system-mail-account") // TODO @ジョイイ:/system/mail-account public class SystemMailAccountController { @Resource private SystemMailAccountService systemMailAccountService; + // TODO @ジョイイ:最好,VO 分拆下,参考下别的模块 + @PostMapping("/create") @ApiOperation("创建邮箱账号") @PreAuthorize("@ss.hasPermission('system:system-mail-account:create')") @@ -59,6 +54,8 @@ public class SystemMailAccountController { return success(true); } + // TODO @ジョイイ:删除,编号即可 + @DeleteMapping("/delete") @ApiOperation("删除邮箱账号") @PreAuthorize("@ss.hasPermission('system:system-mail-account:delete')") @@ -76,6 +73,8 @@ public class SystemMailAccountController { return success(SystemMailAccountConvert.INSTANCE.convert(systemMailAccountDO)); } + // TODO @ジョイイ:分页的查询条件 + @GetMapping("/page") @ApiOperation("获得邮箱账号分页") @PreAuthorize("@ss.hasPermission('system:system-mail-account:query')") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java index 4f74da0c8..07352140c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; -import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +// TODO @ジョイイ:System 去掉哈 @Data public class SystemMailAccountBaseVO { + + // TODO @ジョイイ:example 写的不太对,这个应该是邮箱; @ApiModelProperty(value = "来源" , required = true , example = "yudaoyuanma") private String from; @@ -21,6 +23,7 @@ public class SystemMailAccountBaseVO { @ApiModelProperty(value = "端口" , required = true , example = "80") private String port; + // TODO @ジョイイ:Boolean @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") private Integer sslEnable; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java index 576c23bdd..d4855c1b2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java @@ -4,12 +4,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import org.apache.ibatis.annotations.Mapper; - +// TODO @ジョイイ: Mapper 一般不用注释,因为用途不大 /** *

* Mapper 接口 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java index 38f787131..b7ffbfa41 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; import java.util.List; +// TODO @ジョイイ:类注释,应该是 邮箱账号 Service 接口 + /** *

* 服务类 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java index b50ca35b5..e1ef51267 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +// TODO @ジョイイ:类注释,应该是 邮箱账号 Service 实现类 + /** *

* 服务实现类 @@ -22,24 +24,32 @@ import java.util.List; */ @Service public class SystemMailAccountServiceImpl implements SystemMailAccountService { + // TODO @ジョイイ: private @Resource - SystemMailAccountMapper systemMailAccountMapper; + SystemMailAccountMapper systemMailAccountMapper; // TODO @ジョイイ: 变量,和方法要空一行 @Override public Long create(SystemMailAccountBaseVO baseVO) { + // TODO @ジョイイ: username 要校验唯一 SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); systemMailAccountMapper.insert(systemMailAccountDO); return systemMailAccountDO.getId(); } + // TODO @ジョイイ: 不用返回值,void 即可 @Override public String update(SystemMailAccountBaseVO baseVO) { + // TODO @ジョイイ: username 要校验唯一 + // TODO @ジョイイ: 校验是否存在 SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); systemMailAccountMapper.updateById(systemMailAccountDO); return null; } + // TODO @ジョイイ: 不用返回值,void 即可 + @Override public String delete(SystemMailAccountBaseVO baseVO) { + // TODO @ジョイイ: 校验是否存在 SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); systemMailAccountMapper.deleteById(systemMailAccountDO); return null; From 54ad304514ee4944be688dab7aa814167e1aa2aa Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Fri, 25 Mar 2022 02:59:51 +0800 Subject: [PATCH 03/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=20TODO=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 5 + .../admin/mail/MailAccountController.java | 85 ++++++++++++ ...Controller.java => MailLogController.java} | 40 +++--- ...troller.java => MailTempleController.java} | 40 +++--- .../mail/SystemMailAccountController.java | 94 -------------- ...ountBaseVO.java => MailAccountBaseVO.java} | 9 +- .../vo/account/MailAccountCreateReqVO.java | 8 ++ .../mail/vo/account/MailAccountPageReqVO.java | 26 ++++ .../vo/account/MailAccountUpdateReqVO.java | 8 ++ .../convert/mail/MailAccountConvert.java | 22 ++++ .../mail/SystemMailAccountConvert.java | 25 ---- ...mMailAccountDO.java => MailAccountDO.java} | 100 +++++++------- .../{SystemMailLogDO.java => MailLogDO.java} | 122 +++++++++--------- ...temMailTempleDO.java => MailTempleDO.java} | 108 ++++++++-------- .../dal/mysql/mail/MailAccountMapper.java | 23 ++++ ...mMailLogMapper.java => MailLogMapper.java} | 32 ++--- ...empleMapper.java => MailTempleMapper.java} | 32 ++--- .../mysql/mail/SystemMailAccountMapper.java | 26 ---- .../service/mail/MailAccountService.java | 33 +++++ ...ailLogService.java => MailLogService.java} | 28 ++-- ...pleService.java => MailTempleService.java} | 26 ++-- .../mail/SystemMailAccountService.java | 33 ----- .../mail/impl/MailAccountServiceImpl.java | 99 ++++++++++++++ ...rviceImpl.java => MailLogServiceImpl.java} | 36 +++--- ...ceImpl.java => MailTempleServiceImpl.java} | 36 +++--- .../impl/SystemMailAccountServiceImpl.java | 73 ----------- 26 files changed, 608 insertions(+), 561 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/{SystemMailLogController.java => MailLogController.java} (85%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/{SystemMailTempleController.java => MailTempleController.java} (84%) delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/{SystemMailAccountBaseVO.java => MailAccountBaseVO.java} (69%) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/{SystemMailAccountDO.java => MailAccountDO.java} (75%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/{SystemMailLogDO.java => MailLogDO.java} (88%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/{SystemMailTempleDO.java => MailTempleDO.java} (86%) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/{SystemMailLogMapper.java => MailLogMapper.java} (55%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/{SystemMailTempleMapper.java => MailTempleMapper.java} (53%) delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/{SystemMailLogService.java => MailLogService.java} (71%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/{SystemMailTempleService.java => MailTempleService.java} (71%) delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/{SystemMailLogServiceImpl.java => MailLogServiceImpl.java} (56%) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/{SystemMailTempleServiceImpl.java => MailTempleServiceImpl.java} (54%) delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 6b44615ce..0cdab761c 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -119,4 +119,9 @@ public interface ErrorCodeConstants { ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002018001, "社交解绑失败,非当前用户绑定"); ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002018002, "社交授权失败,找不到对应的用户"); + // ========== 邮箱账号 1002019000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019000, "邮箱账号存在"); + + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java new file mode 100644 index 000000000..5cace6378 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -0,0 +1,85 @@ +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.MailAccountBaseVO; +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.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.Comparator; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + + +@Api(tags = "管理后台 - 邮件模板") +@RestController +@RequestMapping("/system/mail-account") +public class MailAccountController { + @Resource + private MailAccountService mailAccountService; + + + @PostMapping("/create") + @ApiOperation("创建邮箱账号") + @PreAuthorize("@ss.hasPermission('system:mail-account:create')") + public CommonResult createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) { + return success(mailAccountService.create(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("修改邮箱账号") + @PreAuthorize("@ss.hasPermission('system:mail-account:update')") + public CommonResult updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) { + mailAccountService.update(updateReqVO); + return success(true); + } + + + @DeleteMapping("/delete") + @ApiOperation("删除邮箱账号") + @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") + public CommonResult deleteMailAccount(@Valid @RequestBody Long id) { + mailAccountService.delete(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得邮箱账号") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:mail-account:get')") + public CommonResult getMailAccount(@RequestParam("id") Long id) { + MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); + return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); + } + + + @GetMapping("/page") + @ApiOperation("获得邮箱账号分页") + @PreAuthorize("@ss.hasPermission('system:mail-account:query')") + public CommonResult> getSmsChannelPage(@Valid MailAccountPageReqVO pageReqVO) { + PageResult pageResult = mailAccountService.getMailAccountPage(pageReqVO); + return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/list-all-simple") + @ApiOperation(value = "获得邮箱账号精简列表") + public CommonResult> getSimpleSmsChannels() { + List list = mailAccountService.getMailAccountList(); + // 排序后,返回给前端 + list.sort(Comparator.comparing(MailAccountDO::getId)); + return success(MailAccountConvert.INSTANCE.convertList02(list)); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java similarity index 85% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java index 710e3f4d3..2bc87c6ac 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailLogController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java @@ -1,20 +1,20 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * 前端控制器 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@RestController -@RequestMapping("/system-mail-log") -public class SystemMailLogController { - -} +package cn.iocoder.yudao.module.system.controller.admin.mail; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 前端控制器 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@RestController +@RequestMapping("/system-mail-log") +public class MailLogController { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java similarity index 84% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java index 7b76958d1..7a4151fbe 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailTempleController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java @@ -1,20 +1,20 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * 前端控制器 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@RestController -@RequestMapping("/system-mail-temple") -public class SystemMailTempleController { - -} +package cn.iocoder.yudao.module.system.controller.admin.mail; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 前端控制器 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@RestController +@RequestMapping("/system-mail-temple") +public class MailTempleController { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java deleted file mode 100644 index c625b7cda..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/SystemMailAccountController.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail; - - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; -import cn.iocoder.yudao.module.system.convert.mail.SystemMailAccountConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import cn.iocoder.yudao.module.system.service.mail.SystemMailAccountService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.validation.Valid; -import java.util.Comparator; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -// TODO @ジョイイ:使用 Swagger 注解,不用写这个注释啦 -/** - *

- * 前端控制器 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Api(tags = "管理后台 - 邮件模板") -@RestController -@RequestMapping("/system-mail-account") // TODO @ジョイイ:/system/mail-account -public class SystemMailAccountController { - @Resource - private SystemMailAccountService systemMailAccountService; - - // TODO @ジョイイ:最好,VO 分拆下,参考下别的模块 - - @PostMapping("/create") - @ApiOperation("创建邮箱账号") - @PreAuthorize("@ss.hasPermission('system:system-mail-account:create')") - public CommonResult createMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { - return success(systemMailAccountService.create(baseVO)); - } - - @PutMapping("/update") - @ApiOperation("修改邮箱账号") - @PreAuthorize("@ss.hasPermission('system:system-mail-account:update')") - public CommonResult updateMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { - systemMailAccountService.update(baseVO); - return success(true); - } - - // TODO @ジョイイ:删除,编号即可 - - @DeleteMapping("/delete") - @ApiOperation("删除邮箱账号") - @PreAuthorize("@ss.hasPermission('system:system-mail-account:delete')") - public CommonResult deleteMailAccount(@Valid @RequestBody SystemMailAccountBaseVO baseVO) { - systemMailAccountService.delete(baseVO); - return success(true); - } - - @GetMapping("/get") - @ApiOperation("获得邮箱账号") - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('system:system-mail-account:get')") - public CommonResult getMailAccount(@RequestParam("id") Long id) { - SystemMailAccountDO systemMailAccountDO = systemMailAccountService.getMailAccount(id); - return success(SystemMailAccountConvert.INSTANCE.convert(systemMailAccountDO)); - } - - // TODO @ジョイイ:分页的查询条件 - - @GetMapping("/page") - @ApiOperation("获得邮箱账号分页") - @PreAuthorize("@ss.hasPermission('system:system-mail-account:query')") - public CommonResult> getSmsChannelPage(@Valid PageParam pageParam) { - PageResult pageResult = systemMailAccountService.getMailAccountPage(pageParam); - return success(SystemMailAccountConvert.INSTANCE.convertPage(pageResult)); - } - - @GetMapping("/list-all-simple") - @ApiOperation(value = "获得邮箱账号精简列表") - public CommonResult> getSimpleSmsChannels() { - List list = systemMailAccountService.getMailAccountList(); - // 排序后,返回给前端 - list.sort(Comparator.comparing(SystemMailAccountDO::getId)); - return success(SystemMailAccountConvert.INSTANCE.convertList02(list)); - } -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java similarity index 69% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 07352140c..7b65a0876 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -3,12 +3,10 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -// TODO @ジョイイ:System 去掉哈 @Data -public class SystemMailAccountBaseVO { +public class MailAccountBaseVO { - // TODO @ジョイイ:example 写的不太对,这个应该是邮箱; - @ApiModelProperty(value = "来源" , required = true , example = "yudaoyuanma") + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") @@ -23,7 +21,6 @@ public class SystemMailAccountBaseVO { @ApiModelProperty(value = "端口" , required = true , example = "80") private String port; - // TODO @ジョイイ:Boolean @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") - private Integer sslEnable; + private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java new file mode 100644 index 000000000..b07801cee --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -0,0 +1,8 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import lombok.Data; + +@Data +public class MailAccountCreateReqVO extends MailAccountBaseVO{ + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java new file mode 100644 index 000000000..6ddbc2ae6 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MailAccountPageReqVO extends PageParam { + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + private String username; + + @ApiModelProperty(value = "密码" , required = true , example = "123456") + private String password; + + @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") + private String host; + + @ApiModelProperty(value = "端口" , required = true , example = "80") + private String port; + + @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") + private Boolean sslEnable; +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java new file mode 100644 index 000000000..9482ce474 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -0,0 +1,8 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import lombok.Data; + +@Data +public class MailAccountUpdateReqVO extends MailAccountBaseVO{ + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java new file mode 100644 index 000000000..a288dd84a --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -0,0 +1,22 @@ +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.account.MailAccountBaseVO; +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 (MailAccountBaseVO mailAccountBaseVO); + + MailAccountBaseVO convert (MailAccountDO mailAccountDO); + + PageResult convertPage(PageResult pageResult); + + List convertList02(List list); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java deleted file mode 100644 index 465bff31f..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/SystemMailAccountConvert.java +++ /dev/null @@ -1,25 +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.account.SystemMailAccountBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface SystemMailAccountConvert { - SystemMailAccountConvert INSTANCE = Mappers.getMapper(SystemMailAccountConvert.class); - - SystemMailAccountDO convert (SystemMailAccountBaseVO systemMailAccountBaseVO); - - SystemMailAccountBaseVO convert (SystemMailAccountDO systemMailAccountDO); - - PageResult convertPage(PageResult pageResult); - - List convertList02(List list); -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java similarity index 75% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index c5d90dfd1..195bc0bb0 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,54 +1,46 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.mail; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; - -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - *

- * - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Accessors(chain = true) -@ApiModel(value="SystemMailAccount对象", description="") -@TableName(value = "system_mail_account", autoResultMap = true) -public class SystemMailAccountDO extends BaseDO implements Serializable { - - private static final long serialVersionUID = 1L; - @TableId - private Long id; - - @TableField("from") - private String from; - - @TableField("username") - private String username; - - @TableField("password") - private String password; - - @TableField("host") - private String host; - - @TableField("port") - private String port; - - @TableField("sslEnable") - private Integer sslEnable; - - -} +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@ApiModel(value="MailAccount对象", description="") +@TableName(value = "system_mail_account", autoResultMap = true) +public class MailAccountDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("from") + private String from; + + @TableField("username") + private String username; + + @TableField("password") + private String password; + + @TableField("host") + private String host; + + @TableField("port") + private String port; + + @TableField("sslEnable") + private Boolean sslEnable; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java similarity index 88% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index b909e0c37..0d435a8c3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,61 +1,61 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.mail; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import java.sql.Timestamp; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - *

- * - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Accessors(chain = true) -@ApiModel(value="SystemMailLog对象", description="") -public class SystemMailLogDO extends BaseDO implements Serializable { - - private static final long serialVersionUID = 1L; - @TableId - private Long id; - - @TableField("account_code") - private String accountCode; - - @TableField("from") - private String from; - - @TableField("temple_code") - private String templeCode; - - @TableField("title") - private String title; - - @TableField("content") - private String content; - - @TableField("to") - private String to; - - @TableField("sendTime") - private Timestamp sendTime; - - @TableField("sendStatus") - private String sendStatus; - - @TableField("sendResult") - private String sendResult; - - -} +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import java.sql.Timestamp; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@ApiModel(value="SystemMailLog对象", description="") +public class MailLogDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("account_code") + private String accountCode; + + @TableField("from") + private String from; + + @TableField("temple_code") + private String templeCode; + + @TableField("title") + private String title; + + @TableField("content") + private String content; + + @TableField("to") + private String to; + + @TableField("sendTime") + private Timestamp sendTime; + + @TableField("sendStatus") + private String sendStatus; + + @TableField("sendResult") + private String sendResult; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java similarity index 86% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java index 3a13d1b4b..c48de644d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/SystemMailTempleDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java @@ -1,54 +1,54 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.mail; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - *

- * - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Accessors(chain = true) -@ApiModel(value="SystemMailTemple对象", description="") -public class SystemMailTempleDO extends BaseDO implements Serializable { - - private static final long serialVersionUID = 1L; - @TableId - private Long id; - - @TableField("name") - private String name; - - @TableField("code") - private String code; - - @TableField("username") - private String username; - - @TableField("title") - private String title; - - @TableField("content") - private String content; - - @TableField("status") - private String status; - - @TableField("remark") - private String remark; - - -} +package cn.iocoder.yudao.module.system.dal.dataobject.mail; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * 邮箱账号 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@ApiModel(value="SystemMailTemple对象", description="") +public class MailTempleDO extends BaseDO implements Serializable { + + private static final long serialVersionUID = 1L; + @TableId + private Long id; + + @TableField("name") + private String name; + + @TableField("code") + private String code; + + @TableField("username") + private String username; + + @TableField("title") + private String title; + + @TableField("content") + private String content; + + @TableField("status") + private String status; + + @TableField("remark") + private String remark; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java new file mode 100644 index 000000000..f7e06862f --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MailAccountMapper extends BaseMapperX { + + default PageResult selectPage(MailAccountPageReqVO pageReqVO) { + return selectPage(pageReqVO, new QueryWrapperX() + .likeIfPresent("form" , pageReqVO.getFrom()) + .likeIfPresent("host" , pageReqVO.getHost()) + .likeIfPresent("username" , pageReqVO.getUsername()) + .eqIfPresent("password" , pageReqVO.getPassword()) + .eqIfPresent("port" , pageReqVO.getPort()) + ); + } + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java similarity index 55% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java index 7432fdde3..2f6912812 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailLogMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java @@ -1,16 +1,16 @@ -package cn.iocoder.yudao.module.system.dal.mysql.mail; - -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailLogDO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface SystemMailLogMapper extends BaseMapper { - -} +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailLogMapper extends BaseMapper { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java similarity index 53% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java index 0460cc7b2..0264ca301 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailTempleMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java @@ -1,16 +1,16 @@ -package cn.iocoder.yudao.module.system.dal.mysql.mail; - -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailTempleDO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface SystemMailTempleMapper extends BaseMapper { - -} +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTempleDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailTempleMapper extends BaseMapper { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java deleted file mode 100644 index d4855c1b2..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/SystemMailAccountMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.mail; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import org.apache.ibatis.annotations.Mapper; - -// TODO @ジョイイ: Mapper 一般不用注释,因为用途不大 -/** - *

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Mapper -public interface SystemMailAccountMapper extends BaseMapperX { - - default PageResult selectPage(PageParam pageParam) { - return selectPage(pageParam, new QueryWrapperX()); - } - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java new file mode 100644 index 000000000..759263a40 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -0,0 +1,33 @@ +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.dal.dataobject.mail.MailAccountDO; + +import java.util.List; + + +/** + *

+ * 邮箱账号 Service 接口 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailAccountService { + + Long create(MailAccountCreateReqVO createReqVO); + + void update(MailAccountUpdateReqVO updateReqVO); + + void delete(Long id); + + MailAccountDO getMailAccount(Long id); + + PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO); + + List getMailAccountList(); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java similarity index 71% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index ff5043878..d5442936f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.system.service.mail; - - -/** - *

- * 服务类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface SystemMailLogService { - -} +package cn.iocoder.yudao.module.system.service.mail; + + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailLogService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java similarity index 71% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java index 507b64b9a..3c14626f9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailTempleService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java @@ -1,13 +1,13 @@ -package cn.iocoder.yudao.module.system.service.mail; - -/** - *

- * 服务类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface SystemMailTempleService { - -} +package cn.iocoder.yudao.module.system.service.mail; + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailTempleService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java deleted file mode 100644 index b7ffbfa41..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/SystemMailAccountService.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.system.service.mail; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; - -import java.util.List; - -// TODO @ジョイイ:类注释,应该是 邮箱账号 Service 接口 - -/** - *

- * 服务类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface SystemMailAccountService { - - Long create(SystemMailAccountBaseVO baseVO); - - String update(SystemMailAccountBaseVO baseVO); - - String delete(SystemMailAccountBaseVO baseVO); - - SystemMailAccountDO getMailAccount(Long id); - - PageResult getMailAccountPage(PageParam pageParam); - - List getMailAccountList(); -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java new file mode 100644 index 000000000..11625a7bc --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -0,0 +1,99 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + +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.convert.mail.MailAccountConvert; +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.service.mail.MailAccountService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; + + +/** + *

+ * 邮箱账号 Service 实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class MailAccountServiceImpl implements MailAccountService { + + @Resource + private MailAccountMapper mailAccountMapper; + + @Override + public Long create(MailAccountCreateReqVO createReqVO) { + // username 要校验唯一 + Map map = new HashMap<>(); + map.put("username" , createReqVO.getUsername()); + this.validateMailAccountOnly(map); + MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); + mailAccountMapper.insert(mailAccountDO); + return mailAccountDO.getId(); + } + + @Override + public void update(MailAccountUpdateReqVO updateReqVO) { + // username 要校验唯一 + Map map = new HashMap<>(); + map.put("username" , updateReqVO.getUsername()); + this.validateMailAccountOnly(map); + MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); + // 校验是否存在 + this.validateMailAccountExists(mailAccountDO.getId()); + mailAccountMapper.updateById(mailAccountDO); + } + + + @Override + public void delete(Long id) { + // 校验是否存在 + this.validateMailAccountExists(id); + mailAccountMapper.deleteById(id); + } + + @Override + public MailAccountDO getMailAccount(Long id) { + return mailAccountMapper.selectById(id); + } + + @Override + public PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO) { + return mailAccountMapper.selectPage(pageReqVO); + } + + @Override + public List getMailAccountList() { + return mailAccountMapper.selectList(); + } + + private void validateMailAccountExists(Long id) { + if (mailAccountMapper.selectById(id) == null) { + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + } + + private void validateMailAccountOnly(Map params){ + QueryWrapper queryWrapper = new QueryWrapper(); + params.forEach((k , v)->{ + queryWrapper.like(k , v); + }); + if (mailAccountMapper.selectOne(queryWrapper) != null) { + throw exception(MAIL_ACCOUNT_EXISTS); + } + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java similarity index 56% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 4b17a3e21..af2ff6694 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -1,18 +1,18 @@ -package cn.iocoder.yudao.module.system.service.mail.impl; - - -import cn.iocoder.yudao.module.system.service.mail.SystemMailLogService; -import org.springframework.stereotype.Service; - -/** - *

- * 服务实现类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Service -public class SystemMailLogServiceImpl implements SystemMailLogService { - -} +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.iocoder.yudao.module.system.service.mail.MailLogService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class MailLogServiceImpl implements MailLogService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java similarity index 54% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java index e59cb01ba..be83bccc8 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailTempleServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java @@ -1,18 +1,18 @@ -package cn.iocoder.yudao.module.system.service.mail.impl; - - -import cn.iocoder.yudao.module.system.service.mail.SystemMailTempleService; -import org.springframework.stereotype.Service; - -/** - *

- * 服务实现类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Service -public class SystemMailTempleServiceImpl implements SystemMailTempleService { - -} +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.iocoder.yudao.module.system.service.mail.MailTempleService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class MailTempleServiceImpl implements MailTempleService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java deleted file mode 100644 index e1ef51267..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/SystemMailAccountServiceImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -package cn.iocoder.yudao.module.system.service.mail.impl; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO; -import cn.iocoder.yudao.module.system.convert.mail.SystemMailAccountConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO; -import cn.iocoder.yudao.module.system.dal.mysql.mail.SystemMailAccountMapper; -import cn.iocoder.yudao.module.system.service.mail.SystemMailAccountService; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.List; - -// TODO @ジョイイ:类注释,应该是 邮箱账号 Service 实现类 - -/** - *

- * 服务实现类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Service -public class SystemMailAccountServiceImpl implements SystemMailAccountService { - // TODO @ジョイイ: private - @Resource - SystemMailAccountMapper systemMailAccountMapper; // TODO @ジョイイ: 变量,和方法要空一行 - @Override - public Long create(SystemMailAccountBaseVO baseVO) { - // TODO @ジョイイ: username 要校验唯一 - SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); - systemMailAccountMapper.insert(systemMailAccountDO); - return systemMailAccountDO.getId(); - } - - // TODO @ジョイイ: 不用返回值,void 即可 - @Override - public String update(SystemMailAccountBaseVO baseVO) { - // TODO @ジョイイ: username 要校验唯一 - // TODO @ジョイイ: 校验是否存在 - SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); - systemMailAccountMapper.updateById(systemMailAccountDO); - return null; - } - - // TODO @ジョイイ: 不用返回值,void 即可 - - @Override - public String delete(SystemMailAccountBaseVO baseVO) { - // TODO @ジョイイ: 校验是否存在 - SystemMailAccountDO systemMailAccountDO = SystemMailAccountConvert.INSTANCE.convert(baseVO); - systemMailAccountMapper.deleteById(systemMailAccountDO); - return null; - } - - @Override - public SystemMailAccountDO getMailAccount(Long id) { - return systemMailAccountMapper.selectById(id); - } - - @Override - public PageResult getMailAccountPage(PageParam pageParam) { - return systemMailAccountMapper.selectPage(pageParam); - } - - @Override - public List getMailAccountList() { - return systemMailAccountMapper.selectList(); - } - -} From de10aa6ab2b43e7b26e2390320d5f076ec602973 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 26 Mar 2022 04:34:11 +0800 Subject: [PATCH 04/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailLogController.java | 43 +++++++++++++++++- .../admin/mail/vo/log/MailLogBaseVO.java | 42 +++++++++++++++++ .../admin/mail/vo/log/MailLogExcelVO.java | 37 +++++++++++++++ .../admin/mail/vo/log/MailLogExportReqVO.java | 4 ++ .../admin/mail/vo/log/MailLogPageReqVO.java | 40 +++++++++++++++++ .../admin/mail/vo/log/MailLogRespVO.java | 4 ++ .../system/convert/mail/MailLogConvert.java | 19 ++++++++ .../system/dal/dataobject/mail/MailLogDO.java | 5 ++- .../system/dal/mysql/mail/MailLogMapper.java | 45 ++++++++++++++----- .../system/service/mail/MailLogService.java | 10 +++++ .../service/mail/impl/MailLogServiceImpl.java | 21 ++++++++- 11 files changed, 256 insertions(+), 14 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java index 2bc87c6ac..6615448d3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java @@ -1,20 +1,59 @@ 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.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.*; +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.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + /** *

- * 前端控制器 + * 邮箱日志功能 *

* * @author wangjingyi * @since 2022-03-21 */ @RestController -@RequestMapping("/system-mail-log") +@RequestMapping("/system/mail-log") public class MailLogController { + @Autowired + private MailLogService mailLogService; + @GetMapping("/page") + @ApiOperation("获得邮箱日志分页") + @PreAuthorize("@ss.hasPermission('system:mail-log:query')") + public CommonResult> getMailLogPage(@Valid MailLogPageReqVO pageVO) { + PageResult pageResult = mailLogService.getMailLogPage(pageVO); + return success(MailLogConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出邮箱日志Excel") + @PreAuthorize("@ss.hasPermission('system:mail-log:export')") + public void exportMailLogExcel(@Valid MailLogExportReqVO exportReqVO , + HttpServletResponse response) throws IOException { + List list = mailLogService.getMailLogList(exportReqVO); + // 导出 Excel + List datas = MailLogConvert.INSTANCE.convertList(list); + ExcelUtils.write(response, "邮箱日志.xls", "数据", MailLogExcelVO.class, datas); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java new file mode 100644 index 000000000..80b6e8828 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.format.annotation.DateTimeFormat; + +import java.sql.Timestamp; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +public class MailLogBaseVO { + + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") + private String templeId; + + @ApiModelProperty(value = "模版code" , required = false , example = "templeCode") + private String templeCode; + + @ApiModelProperty(value = "标题" , required = false , example = "芋道源码") + private String title; + + @ApiModelProperty(value = "内容" , required = false , example = "遇到源码") + private String content; + + @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com") + private String to; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20") + private Timestamp sendTime; + + @ApiModelProperty(value = "发送状态" , required = false , example = "1") + private Boolean sendStatus; + + @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") + private String sendResult; + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java new file mode 100644 index 000000000..e6eee9f19 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; + +import com.alibaba.excel.annotation.ExcelProperty; +import org.springframework.format.annotation.DateTimeFormat; + +import java.sql.Timestamp; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +public class MailLogExcelVO { + + @ExcelProperty(value = "邮箱" ) + private String from; + + @ExcelProperty(value = "模版编号" ) + private String templeCode; + + @ExcelProperty(value = "标题") + private String title; + + @ExcelProperty(value = "内容") + private String content; + + @ExcelProperty(value = "收件人" ) + private String to; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ExcelProperty(value = "发送时间" ) + private Timestamp sendTime; + + @ExcelProperty(value = "发送状态") + private Boolean sendStatus; + + @ExcelProperty(value = "发送结果") + private String sendResult; + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java new file mode 100644 index 000000000..0c8696980 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; + +public class MailLogExportReqVO extends MailLogPageReqVO{ +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java new file mode 100644 index 000000000..a12953af4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.sql.Timestamp; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@Data +public class MailLogPageReqVO extends PageParam { + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") + private String templeId; + + @ApiModelProperty(value = "模版code" , required = false , example = "templeCode") + private String templeCode; + + @ApiModelProperty(value = "标题" , required = false , example = "芋道源码") + private String title; + + @ApiModelProperty(value = "内容" , required = false , example = "遇到源码") + private String content; + + @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com") + private String to; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20") + private Timestamp sendTime; + + @ApiModelProperty(value = "发送状态" , required = false , example = "1") + private Boolean sendStatus; + + @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") + private String sendResult; +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java new file mode 100644 index 000000000..9bbf35179 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; + +public class MailLogRespVO extends MailLogBaseVO { +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java new file mode 100644 index 000000000..417550886 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java @@ -0,0 +1,19 @@ +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.MailLogExcelVO; +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; + +import java.util.List; + +@Mapper +public interface MailLogConvert { + MailLogConvert INSTANCE = Mappers.getMapper(MailLogConvert.class); + + PageResult convertPage(PageResult pageResult); + + List convertList(List list); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 0d435a8c3..ae3d603da 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -36,6 +36,9 @@ public class MailLogDO extends BaseDO implements Serializable { @TableField("from") private String from; + @TableField("temple_id") + private String templeId; + @TableField("temple_code") private String templeCode; @@ -52,7 +55,7 @@ public class MailLogDO extends BaseDO implements Serializable { private Timestamp sendTime; @TableField("sendStatus") - private String sendStatus; + private Boolean sendStatus; @TableField("sendResult") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java index 2f6912812..51be49019 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java @@ -1,16 +1,41 @@ package cn.iocoder.yudao.module.system.dal.mysql.mail; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -/** - *

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface MailLogMapper extends BaseMapper { +import java.util.List; +public interface MailLogMapper extends BaseMapperX { + + default PageResult selectPage(MailLogPageReqVO pageVO){ + return selectPage(pageVO , new QueryWrapperX() + .eqIfPresent("from", pageVO.getFrom()) + .eqIfPresent("templeCode", pageVO.getTempleCode()) + .likeIfPresent("title" , pageVO.getTitle()) + .likeIfPresent("content" , pageVO.getContent()) + .eqIfPresent("to", pageVO.getTo()) + .eqIfPresent("sendTime" , pageVO.getSendTime()) + .eqIfPresent("sendStatus" , pageVO.getSendStatus()) + .eqIfPresent("sendResult" , pageVO.getSendResult()) + .orderByDesc("sendTime") + ); + }; + + default List selectList(MailLogExportReqVO exportReqVO){ + return selectList(new QueryWrapperX() + .eqIfPresent("from", exportReqVO.getFrom()) + .eqIfPresent("templeCode", exportReqVO.getTempleCode()) + .likeIfPresent("title" , exportReqVO.getTitle()) + .likeIfPresent("content" , exportReqVO.getContent()) + .eqIfPresent("to", exportReqVO.getTo()) + .eqIfPresent("sendTime" , exportReqVO.getSendTime()) + .eqIfPresent("sendStatus" , exportReqVO.getSendStatus()) + .eqIfPresent("sendResult" , exportReqVO.getSendResult()) + .orderByDesc("sendTime") + ); + }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index d5442936f..79d38730d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -1,6 +1,13 @@ 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.log.MailLogExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; + +import java.util.List; + /** *

* 服务类 @@ -11,4 +18,7 @@ package cn.iocoder.yudao.module.system.service.mail; */ public interface MailLogService { + PageResult getMailLogPage(MailLogPageReqVO pageVO); + + List getMailLogList(MailLogExportReqVO exportReqVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index af2ff6694..2daeeab3e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -1,12 +1,20 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.service.mail.MailLogService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + /** *

- * 服务实现类 + * 邮箱日志实现类 *

* * @author wangjingyi @@ -14,5 +22,16 @@ import org.springframework.stereotype.Service; */ @Service public class MailLogServiceImpl implements MailLogService { + @Autowired + MailLogMapper mailLogMapper; + @Override + public PageResult getMailLogPage(MailLogPageReqVO pageVO) { + return mailLogMapper.selectPage(pageVO); + } + + @Override + public List getMailLogList(MailLogExportReqVO exportReqVO) { + return mailLogMapper.selectList(exportReqVO); + } } From 132c8b0e84d7741d3990f10cdc012cb1a490b9b7 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 26 Mar 2022 06:26:36 +0800 Subject: [PATCH 05/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9mapstruct=20=E7=9B=B8=E5=85=B3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 5 +- .../admin/mail/MailAccountController.java | 7 +- .../admin/mail/MailLogController.java | 13 +-- .../admin/mail/MailTemplateController.java | 82 +++++++++++++++++ .../admin/mail/MailTempleController.java | 20 ---- .../admin/mail/vo/log/MailLogBaseVO.java | 4 +- .../admin/mail/vo/log/MailLogExcelVO.java | 2 + .../admin/mail/vo/log/MailLogPageReqVO.java | 5 +- .../admin/mail/vo/log/MailLogRespVO.java | 39 +++++++- .../mail/vo/template/MailTemplateBaseVO.java | 31 +++++++ .../vo/template/MailTemplateCreateReqVO.java | 10 ++ .../vo/template/MailTemplatePageReqVO.java | 32 +++++++ .../vo/template/MailTemplateUpdateReqVO.java | 7 ++ .../convert/mail/MailTemplateConvert.java | 26 ++++++ .../system/dal/dataobject/mail/MailLogDO.java | 12 +-- ...{MailTempleDO.java => MailTemplateDO.java} | 6 +- .../system/dal/mysql/mail/MailLogMapper.java | 7 +- .../dal/mysql/mail/MailTemplateMapper.java | 25 +++++ .../dal/mysql/mail/MailTempleMapper.java | 16 ---- .../service/mail/MailTemplateService.java | 33 +++++++ .../service/mail/MailTempleService.java | 13 --- .../mail/impl/MailTemplateServiceImpl.java | 92 +++++++++++++++++++ .../mail/impl/MailTempleServiceImpl.java | 18 ---- 23 files changed, 405 insertions(+), 100 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/{MailTempleDO.java => MailTemplateDO.java} (88%) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 0cdab761c..7def30042 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -121,7 +121,10 @@ public interface ErrorCodeConstants { // ========== 邮箱账号 1002019000 ========== ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019000, "邮箱账号存在"); + ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019001, "邮箱账号存在"); + // ========== 邮箱账号 1002020000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 5cace6378..9b62bf233 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -24,14 +24,13 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -@Api(tags = "管理后台 - 邮件模板") +@Api(tags = "管理后台 - 邮件账号") @RestController @RequestMapping("/system/mail-account") public class MailAccountController { @Resource private MailAccountService mailAccountService; - @PostMapping("/create") @ApiOperation("创建邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:create')") @@ -69,14 +68,14 @@ public class MailAccountController { @GetMapping("/page") @ApiOperation("获得邮箱账号分页") @PreAuthorize("@ss.hasPermission('system:mail-account:query')") - public CommonResult> getSmsChannelPage(@Valid MailAccountPageReqVO pageReqVO) { + public CommonResult> getMailAccountPage(@Valid MailAccountPageReqVO pageReqVO) { PageResult pageResult = mailAccountService.getMailAccountPage(pageReqVO); return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") - public CommonResult> getSimpleSmsChannels() { + public CommonResult> getSimpleMailAccountList() { List list = mailAccountService.getMailAccountList(); // 排序后,返回给前端 list.sort(Comparator.comparing(MailAccountDO::getId)); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java index 6615448d3..f6375f290 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java @@ -8,14 +8,13 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.*; 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.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; - import org.springframework.web.bind.annotation.RestController; - import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -24,14 +23,8 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -/** - *

- * 邮箱日志功能 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ + +@Api(tags = "管理后台 - 邮件日志") @RestController @RequestMapping("/system/mail-log") public class MailLogController { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java new file mode 100644 index 000000000..988882d83 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -0,0 +1,82 @@ +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.template.MailTemplateBaseVO; +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.convert.mail.MailTemplateConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import java.util.Comparator; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Api(tags = "管理后台 - 邮件模版") +@RestController +@RequestMapping("/system/mail-template") +public class MailTemplateController { + @Autowired + MailTemplateService mailTempleService; + + @PostMapping("/create") + @ApiOperation("创建邮箱模版") + @PreAuthorize("@ss.hasPermission('system:mail-template:create')") + public CommonResult createMailTemplate(@Valid @RequestBody MailTemplateCreateReqVO createReqVO){ + return success(mailTempleService.create(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("修改邮箱模版") + @PreAuthorize("@ss.hasPermission('system:mail-template:update')") + public CommonResult updateMailTemplate(@Valid @RequestBody MailTemplateUpdateReqVO updateReqVO){ + mailTempleService.update(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除邮箱模版") + @PreAuthorize("@ss.hasPermission('system:mail-template:delete')") + public CommonResult deleteMailTemplate(@Valid @RequestBody Long id) { + mailTempleService.delete(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得邮箱模版") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:mail-template:get')") + public CommonResult getMailTemplate(@RequestParam("id") Long id) { + MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id); + return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); + } + + + @GetMapping("/page") + @ApiOperation("获得邮箱模版分页") + @PreAuthorize("@ss.hasPermission('system:mail-account:query')") + public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { + PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); + return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/list-all-simple") + @ApiOperation(value = "获得邮箱模版精简列表") + public CommonResult> getSimpleTemplateList() { + List list = mailTempleService.getMailTemplateList(); + // 排序后,返回给前端 + list.sort(Comparator.comparing(MailTemplateDO::getId)); + return success(MailTemplateConvert.INSTANCE.convertList02(list)); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java deleted file mode 100644 index 7a4151fbe..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTempleController.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * 前端控制器 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@RestController -@RequestMapping("/system-mail-temple") -public class MailTempleController { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java index 80b6e8828..eec39193c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java @@ -15,10 +15,10 @@ public class MailLogBaseVO { private String from; @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") - private String templeId; + private String templateId; @ApiModelProperty(value = "模版code" , required = false , example = "templeCode") - private String templeCode; + private String templateCode; @ApiModelProperty(value = "标题" , required = false , example = "芋道源码") private String title; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java index e6eee9f19..03d439f33 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@Data public class MailLogExcelVO { @ExcelProperty(value = "邮箱" ) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index a12953af4..7ed4419b7 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -8,16 +8,17 @@ import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + @Data public class MailLogPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") private String from; @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") - private String templeId; + private String templateId; @ApiModelProperty(value = "模版code" , required = false , example = "templeCode") - private String templeCode; + private String templateCode; @ApiModelProperty(value = "标题" , required = false , example = "芋道源码") private String title; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index 9bbf35179..c3c5a2fdd 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -1,4 +1,41 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; -public class MailLogRespVO extends MailLogBaseVO { +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.sql.Timestamp; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@Data +public class MailLogRespVO { + + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") + private String templateId; + + @ApiModelProperty(value = "模版code" , required = false , example = "templeCode") + private String templateCode; + + @ApiModelProperty(value = "标题" , required = false , example = "芋道源码") + private String title; + + @ApiModelProperty(value = "内容" , required = false , example = "遇到源码") + private String content; + + @ApiModelProperty(value = "收件人" , required = false , example = "yudaoyuanma@456.com") + private String to; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "发送时间" , required = false , example = "2022-03-26 03:45:20") + private Timestamp sendTime; + + @ApiModelProperty(value = "发送状态" , required = false , example = "1") + private Boolean sendStatus; + + @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") + private String sendResult; + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java new file mode 100644 index 000000000..b0577b44e --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MailTemplateBaseVO { + @ApiModelProperty("主键") + private Long id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("标识") + private String code; + + @ApiModelProperty("发件人") + private String username; + + @ApiModelProperty("标题") + private String title; + + @ApiModelProperty("内容") + private String content; + + @ApiModelProperty("状态") + private String status; + + @ApiModelProperty("备注") + private String remark; +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java new file mode 100644 index 000000000..e18c39026 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MailTemplateCreateReqVO extends MailTemplateBaseVO{ + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java new file mode 100644 index 000000000..5725febd0 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MailTemplatePageReqVO extends PageParam { + @ApiModelProperty("主键") + private Long id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("标识") + private String code; + + @ApiModelProperty("发件人") + private String username; + + @ApiModelProperty("标题") + private String title; + + @ApiModelProperty("内容") + private String content; + + @ApiModelProperty("状态") + private String status; + + @ApiModelProperty("备注") + private String remark; +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java new file mode 100644 index 000000000..ed0d882bb --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java @@ -0,0 +1,7 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import lombok.Data; + +@Data +public class MailTemplateUpdateReqVO extends MailTemplateBaseVO{ +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java new file mode 100644 index 000000000..3f4693bcb --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -0,0 +1,26 @@ +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.account.MailAccountBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvertImpl; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +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(MailTemplateBaseVO baseVO); + + MailTemplateBaseVO convert(MailTemplateDO mailTemplateDO); + + PageResult convertPage(PageResult pageResult); + + List convertList02(List list); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index ae3d603da..8183174a1 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,20 +1,18 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; import java.sql.Timestamp; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableField; import java.io.Serializable; import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** *

- * + * 邮箱日志 *

* * @author wangjingyi @@ -36,11 +34,11 @@ public class MailLogDO extends BaseDO implements Serializable { @TableField("from") private String from; - @TableField("temple_id") - private String templeId; + @TableField("template_id") + private String templateId; - @TableField("temple_code") - private String templeCode; + @TableField("template_code") + private String templateCode; @TableField("title") private String title; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java similarity index 88% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index c48de644d..e2d5a6d8c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTempleDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -13,7 +13,7 @@ import lombok.experimental.Accessors; /** *

- * 邮箱账号 + * 邮箱模版 *

* * @author wangjingyi @@ -22,8 +22,8 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="SystemMailTemple对象", description="") -public class MailTempleDO extends BaseDO implements Serializable { +@ApiModel(value="SystemMailTemplate对象", description="") +public class MailTemplateDO extends BaseDO implements Serializable { private static final long serialVersionUID = 1L; @TableId diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java index 51be49019..a8b8ccf61 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailLogMapper.java @@ -6,15 +6,16 @@ import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import org.apache.ibatis.annotations.Mapper; import java.util.List; - +@Mapper public interface MailLogMapper extends BaseMapperX { default PageResult selectPage(MailLogPageReqVO pageVO){ return selectPage(pageVO , new QueryWrapperX() .eqIfPresent("from", pageVO.getFrom()) - .eqIfPresent("templeCode", pageVO.getTempleCode()) + .eqIfPresent("templeCode", pageVO.getTemplateCode()) .likeIfPresent("title" , pageVO.getTitle()) .likeIfPresent("content" , pageVO.getContent()) .eqIfPresent("to", pageVO.getTo()) @@ -28,7 +29,7 @@ public interface MailLogMapper extends BaseMapperX { default List selectList(MailLogExportReqVO exportReqVO){ return selectList(new QueryWrapperX() .eqIfPresent("from", exportReqVO.getFrom()) - .eqIfPresent("templeCode", exportReqVO.getTempleCode()) + .eqIfPresent("templeCode", exportReqVO.getTemplateCode()) .likeIfPresent("title" , exportReqVO.getTitle()) .likeIfPresent("content" , exportReqVO.getContent()) .eqIfPresent("to", exportReqVO.getTo()) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java new file mode 100644 index 000000000..06e76d9ab --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.system.dal.mysql.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import org.apache.ibatis.annotations.Mapper; + + +@Mapper +public interface MailTemplateMapper extends BaseMapperX { + + default PageResult selectPage(MailTemplatePageReqVO pageReqVO){ + return selectPage(pageReqVO , new QueryWrapperX() + .likeIfPresent("name" , pageReqVO.getName()) + .likeIfPresent("username" , pageReqVO.getUsername()) + .likeIfPresent("title" , pageReqVO.getTitle()) + .likeIfPresent("content" , pageReqVO.getContent()) + .eqIfPresent("status" , pageReqVO.getStatus()) + .likeIfPresent("remark" , pageReqVO.getRemark()) + ); + } + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java deleted file mode 100644 index 0264ca301..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTempleMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.mail; - -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTempleDO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface MailTempleMapper extends BaseMapper { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java new file mode 100644 index 000000000..3aaf72a48 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -0,0 +1,33 @@ +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.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailTemplateService { + + Long create(MailTemplateCreateReqVO createReqVO); + + void update(MailTemplateUpdateReqVO updateReqVO); + + void delete(Long id); + + MailTemplateDO getMailTemplate(Long id); + + PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO); + + List getMailTemplateList(); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java deleted file mode 100644 index 3c14626f9..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTempleService.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.yudao.module.system.service.mail; - -/** - *

- * 服务类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface MailTempleService { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java new file mode 100644 index 000000000..377bbd658 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -0,0 +1,92 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +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.convert.mail.MailTemplateConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +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.service.mail.MailTemplateService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; + +/** + *

+ * 邮箱模版 服务实现类 + *

+ * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +public class MailTemplateServiceImpl implements MailTemplateService { + @Resource + private MailTemplateMapper mailTemplateMapper; + + @Override + public Long create(MailTemplateCreateReqVO createReqVO) { + // name 要校验唯一 + Map map = new HashMap<>(); + map.put("name" , createReqVO.getName()); + this.validateMailTemplateOnly(map); + MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); + mailTemplateMapper.insert(mailTemplateDO); + return mailTemplateDO.getId(); + } + + @Override + public void update(MailTemplateUpdateReqVO updateReqVO) { + // username 要校验唯一 + Map map = new HashMap<>(); + map.put("username" , updateReqVO.getUsername()); + this.validateMailTemplateOnly(map); + MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); + // 校验是否存在 + this.validateMailTemplateExists(mailTemplateDO.getId()); + mailTemplateMapper.updateById(mailTemplateDO); + } + @Override + public void delete(Long id) { + // 校验是否存在 + this.validateMailTemplateExists(id); + mailTemplateMapper.deleteById(id); + } + + @Override + public MailTemplateDO getMailTemplate(Long id) {return mailTemplateMapper.selectById(id);} + + @Override + public PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO) { + return mailTemplateMapper.selectPage(pageReqVO); + } + + @Override + public List getMailTemplateList() {return mailTemplateMapper.selectList();} + + private void validateMailTemplateExists(Long id) { + if (mailTemplateMapper.selectById(id) == null) { + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + } + + private void validateMailTemplateOnly(Map params){ + QueryWrapper queryWrapper = new QueryWrapper(); + params.forEach((k , v)->{ + queryWrapper.like(k , v); + }); + if (mailTemplateMapper.selectOne(queryWrapper) != null) { + throw exception(MAIL_TEMPLATE_EXISTS); + } + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java deleted file mode 100644 index be83bccc8..000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTempleServiceImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.service.mail.impl; - - -import cn.iocoder.yudao.module.system.service.mail.MailTempleService; -import org.springframework.stereotype.Service; - -/** - *

- * 服务实现类 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Service -public class MailTempleServiceImpl implements MailTempleService { - -} From bd86b89ea53226071a07a0e821d2ad00bea8e028 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 26 Mar 2022 07:50:58 +0800 Subject: [PATCH 06/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=20FI?= =?UTF-8?q?XME=E9=83=A8=E5=88=86=E9=9C=80=E8=A6=81=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 8 ++++ .../admin/mail/vo/send/MailSendVO.java | 26 +++++++++++++ .../dal/dataobject/mail/MailAccountDO.java | 4 +- .../service/mail/MailAccountService.java | 3 ++ .../mail/impl/MailAccountServiceImpl.java | 37 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 9b62bf233..33469e3c2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou 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.send.MailSendVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -81,4 +82,11 @@ public class MailAccountController { list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } + @PostMapping("/send") + @ApiOperation("发送邮件") + @PreAuthorize("@ss.hasPermission('system:mail-account:send')") + public CommonResult sendMail(MailSendVO mailSendVO){ + mailAccountService.sendMail(mailSendVO); + return success(true); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java new file mode 100644 index 000000000..41d9d03b4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.send; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; +@Data +public class MailSendVO { + + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "标题" , example = "标题") + private String title; + + @ApiModelProperty(value = "内容" , example = "内容") + private String content; + + @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + private List tos; + + @ApiModelProperty(value = "附件" , example = "附件编码") + private List fileIds; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 195bc0bb0..2147af7fe 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -16,7 +16,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="MailAccount对象", description="") +@ApiModel(value="MailAccount对象", description="邮箱账号") @TableName(value = "system_mail_account", autoResultMap = true) public class MailAccountDO extends BaseDO implements Serializable { @@ -37,7 +37,7 @@ public class MailAccountDO extends BaseDO implements Serializable { private String host; @TableField("port") - private String port; + private Integer port; @TableField("sslEnable") private Boolean sslEnable; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 759263a40..3cc0acb02 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,6 +4,7 @@ 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.send.MailSendVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import java.util.List; @@ -30,4 +31,6 @@ public interface MailAccountService { PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO); List getMailAccountList(); + + void sendMail(MailSendVO mailSendVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 11625a7bc..98aa646c7 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,12 +1,17 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; 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.send.MailSendVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; @@ -35,6 +40,9 @@ public class MailAccountServiceImpl implements MailAccountService { @Resource private MailAccountMapper mailAccountMapper; + @Resource + private MailTemplateMapper mailTemplateMapper; + @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 @@ -81,6 +89,35 @@ public class MailAccountServiceImpl implements MailAccountService { return mailAccountMapper.selectList(); } + @Override + public void sendMail(MailSendVO mailSendVO) { + // FIXME 查询模版信息 查询模版多条时 使用规则是什么 + List mailTemplateDOList = mailTemplateMapper.selectList( + "username",mailSendVO.getFrom() + ); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from",mailSendVO.getFrom() + ); + // FIXME 模版和邮件内容合成方式未知 + String content = mailSendVO.getContent(); + String templateContent = ""; + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = new MailAccount(); + account.setHost(mailAccountDO.getHost()); + account.setPort(mailAccountDO.getPort()); + account.setAuth(true); + account.setFrom(mailAccountDO.getFrom()); + account.setUser(mailAccountDO.getUsername()); + account.setPass(mailAccountDO.getPassword()); + account.setSslEnable(mailAccountDO.getSslEnable()); + //发送 + MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false); + } + private void validateMailAccountExists(Long id) { if (mailAccountMapper.selectById(id) == null) { throw exception(MAIL_ACCOUNT_NOT_EXISTS); From e4326036f86657685bc357eefa1de3525c4a4def Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 26 Mar 2022 08:06:32 +0800 Subject: [PATCH 07/41] =?UTF-8?q?fix=20=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=20=E8=B4=A6=E5=8F=B7=E4=BF=A1=E6=81=AF=E8=A3=85?= =?UTF-8?q?=E8=BD=BD=20=E5=9C=A8convert=E4=B8=AD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/convert/mail/MailAccountConvert.java | 12 ++++++++++++ .../service/mail/impl/MailAccountServiceImpl.java | 10 ++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index a288dd84a..fe768efbd 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.convert.mail; +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.MailAccountBaseVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; @@ -19,4 +20,15 @@ public interface MailAccountConvert { PageResult convertPage(PageResult pageResult); List convertList02(List list); + + default MailAccount convertAccount(MailAccountDO mailAccountDO){ + return new MailAccount() + .setHost(mailAccountDO.getHost()) + .setPort(mailAccountDO.getPort()) + .setAuth(true) + .setFrom(mailAccountDO.getFrom()) + .setUser(mailAccountDO.getUsername()) + .setPass(mailAccountDO.getPassword()) + .setSslEnable(mailAccountDO.getSslEnable()); + }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 98aa646c7..0c0d86eba 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -106,14 +106,8 @@ public class MailAccountServiceImpl implements MailAccountService { //List fileIds = mailSendVO.getFileIds(); //装载账号信息 - MailAccount account = new MailAccount(); - account.setHost(mailAccountDO.getHost()); - account.setPort(mailAccountDO.getPort()); - account.setAuth(true); - account.setFrom(mailAccountDO.getFrom()); - account.setUser(mailAccountDO.getUsername()); - account.setPass(mailAccountDO.getPassword()); - account.setSslEnable(mailAccountDO.getSslEnable()); + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); + //发送 MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false); } From 017d6e5e4e62779488e8307500f5b8fdf6fce8a3 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 26 Mar 2022 08:19:36 +0800 Subject: [PATCH 08/41] =?UTF-8?q?fix=20=E9=82=AE=E4=BB=B6=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E6=A8=A1=E5=9D=97=20=E9=94=99=E8=AF=AF=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=20=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7=20->=20?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iocoder/yudao/module/system/enums/ErrorCodeConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 7def30042..8520cb115 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -123,8 +123,8 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019001, "邮箱账号存在"); - // ========== 邮箱账号 1002020000 ========== + // ========== 邮箱模版 1002020000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); } From 082c209c87feb9e193fa3811e7d1757b1428717b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 27 Mar 2022 12:01:20 +0800 Subject: [PATCH 09/41] =?UTF-8?q?code=20review=20=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E7=9A=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/mail/MailAccountController.java | 8 ++++---- .../admin/mail/vo/account/MailAccountCreateReqVO.java | 4 ++-- .../admin/mail/vo/account/MailAccountUpdateReqVO.java | 2 ++ .../system/controller/admin/mail/vo/send/MailSendVO.java | 2 +- .../module/system/service/mail/MailAccountService.java | 4 ++-- .../system/service/mail/impl/MailAccountServiceImpl.java | 7 +++++-- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 33469e3c2..0fb95087a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -30,7 +30,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-account") public class MailAccountController { @Resource - private MailAccountService mailAccountService; + private MailAccountService mailAccountService; // TODO @wangjingyi:属性和类名,中间要空一行 @PostMapping("/create") @ApiOperation("创建邮箱账号") @@ -50,7 +50,7 @@ public class MailAccountController { @DeleteMapping("/delete") @ApiOperation("删除邮箱账号") - @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") + @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") // TODO @wangjingyi:id 应该是 @RequestParam。另外,id 的 swagger 注解,要写下 public CommonResult deleteMailAccount(@Valid @RequestBody Long id) { mailAccountService.delete(id); return success(true); @@ -63,7 +63,7 @@ public class MailAccountController { public CommonResult getMailAccount(@RequestParam("id") Long id) { MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); - } + } // TODO wangjingyi:方法与方法之间,只空一行 @GetMapping("/page") @@ -82,7 +82,7 @@ public class MailAccountController { list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } - @PostMapping("/send") + @PostMapping("/send") // TODO wangjingyi:方法与方法之间,空一行 @ApiOperation("发送邮件") @PreAuthorize("@ss.hasPermission('system:mail-account:send')") public CommonResult sendMail(MailSendVO mailSendVO){ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index b07801cee..9dc681962 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import lombok.Data; -@Data -public class MailAccountCreateReqVO extends MailAccountBaseVO{ +@Data // TODO @wangjingyi:swagger 注解 +public class MailAccountCreateReqVO extends MailAccountBaseVO{ // TODO @wangjingyi:要空格再 { } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 9482ce474..925e7cd44 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -5,4 +5,6 @@ import lombok.Data; @Data public class MailAccountUpdateReqVO extends MailAccountBaseVO{ + // TODO @wangjingyi:更新的话,是不是要有个 id??? + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java index 41d9d03b4..4d1bd9a5f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java @@ -5,7 +5,7 @@ import lombok.Data; import java.util.List; @Data -public class MailSendVO { +public class MailSendVO { // TODO @wangjingyi:1)参数校验;2)ReqVO @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 3cc0acb02..464c43205 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -13,12 +13,12 @@ import java.util.List; /** *

* 邮箱账号 Service 接口 - *

+ *

// TODO wangjingyi:不用

标签; * * @author wangjingyi * @since 2022-03-21 */ -public interface MailAccountService { +public interface MailAccountService { // TODO wangjingyi:方法的注释 Long create(MailAccountCreateReqVO createReqVO); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 0c0d86eba..c4610222a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -62,7 +62,7 @@ public class MailAccountServiceImpl implements MailAccountService { this.validateMailAccountOnly(map); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); + this.validateMailAccountExists(mailAccountDO.getId()); // TODO wangjingyi:没有传递 id 噢 mailAccountMapper.updateById(mailAccountDO); } @@ -92,6 +92,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void sendMail(MailSendVO mailSendVO) { // FIXME 查询模版信息 查询模版多条时 使用规则是什么 + // 回复:选择某一条模板,进行发送邮件。 List mailTemplateDOList = mailTemplateMapper.selectList( "username",mailSendVO.getFrom() ); @@ -100,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService { "from",mailSendVO.getFrom() ); // FIXME 模版和邮件内容合成方式未知 + // 回复:参考短信的方式,通过 {name} {mobile} 这样的占位符。搜 formatSmsTemplateContent 方法 String content = mailSendVO.getContent(); String templateContent = ""; // 后续功能 TODO :附件查询 @@ -119,9 +121,10 @@ public class MailAccountServiceImpl implements MailAccountService { } private void validateMailAccountOnly(Map params){ + // TODO wangjingyi:Service 里,不允许出现 MyBatis 操作。而是 Mapper 提供对应查询方法 QueryWrapper queryWrapper = new QueryWrapper(); params.forEach((k , v)->{ - queryWrapper.like(k , v); + queryWrapper.like(k , v); // TODO wangjingyi:账号,应该是 equlas,不能是 like }); if (mailAccountMapper.selectOne(queryWrapper) != null) { throw exception(MAIL_ACCOUNT_EXISTS); From 1a120cd07c8cb1bfa71c6cce6c9dc27c2c6b8b4d Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 30 Mar 2022 14:17:53 +0800 Subject: [PATCH 10/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mail/vo/send/{MailSendVO.java => MailReqVO.java} | 12 +++++++++++- .../system/convert/mail/MailAccountConvert.java | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) rename yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/{MailSendVO.java => MailReqVO.java} (60%) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java similarity index 60% rename from yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java rename to yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 4d1bd9a5f..0bd9d5d22 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -1,13 +1,18 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.send; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.NotNull; import java.util.List; + +@ApiModel("管理后台 - 邮件发送 Req VO") @Data -public class MailSendVO { // TODO @wangjingyi:1)参数校验;2)ReqVO +public class MailReqVO { // TODO @wangjingyi:1)参数校验;2)ReqVO @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱账号不能为空") private String from; @ApiModelProperty(value = "标题" , example = "标题") @@ -16,7 +21,12 @@ public class MailSendVO { // TODO @wangjingyi:1)参数校验;2)ReqVO @ApiModelProperty(value = "内容" , example = "内容") private String content; + @ApiModelProperty(value = "邮箱模版id" , example = "1024") + @NotNull(message = "邮箱模版id不能为空") + private Integer templateId; + @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + @NotNull(message = "收件人不能为空") private List tos; @ApiModelProperty(value = "附件" , example = "附件编码") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index fe768efbd..8dbfbc58d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -7,7 +7,9 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Mapper public interface MailAccountConvert { @@ -31,4 +33,13 @@ public interface MailAccountConvert { .setPass(mailAccountDO.getPassword()) .setSslEnable(mailAccountDO.getSslEnable()); }; + + default Map convertToMap(MailAccountDO mailAccountDO , String content) { + Map map = new HashMap<>(); + map.put("from" , mailAccountDO.getFrom()); + map.put("username" , mailAccountDO.getUsername()); + map.put("content" , content); + return map; + }; + } From f349fbf84a03c5926e9bd9ebeafef5699377836c Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 30 Mar 2022 14:20:32 +0800 Subject: [PATCH 11/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97swagg?= =?UTF-8?q?er=E6=B3=A8=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 20 +++++----- .../mail/vo/account/MailAccountBaseVO.java | 3 +- .../vo/account/MailAccountCreateReqVO.java | 10 ++++- .../mail/vo/account/MailAccountPageReqVO.java | 6 +++ .../vo/account/MailAccountUpdateReqVO.java | 15 ++++++- .../admin/mail/vo/log/MailLogBaseVO.java | 4 ++ .../admin/mail/vo/log/MailLogExcelVO.java | 2 + .../admin/mail/vo/log/MailLogExportReqVO.java | 7 +++- .../admin/mail/vo/log/MailLogPageReqVO.java | 6 +++ .../admin/mail/vo/log/MailLogRespVO.java | 3 ++ .../mail/vo/template/MailTemplateBaseVO.java | 2 + .../vo/template/MailTemplateCreateReqVO.java | 9 ++++- .../vo/template/MailTemplatePageReqVO.java | 6 +++ .../vo/template/MailTemplateUpdateReqVO.java | 15 ++++++- .../service/mail/MailAccountService.java | 40 ++++++++++++++++--- .../system/service/mail/MailLogService.java | 15 +++++-- .../service/mail/MailTemplateService.java | 33 ++++++++++++--- .../service/mail/impl/MailLogServiceImpl.java | 3 +- .../mail/impl/MailTemplateServiceImpl.java | 4 +- 19 files changed, 166 insertions(+), 37 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 0fb95087a..2d2eb959b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou 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.send.MailSendVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -29,8 +29,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/system/mail-account") public class MailAccountController { + @Resource - private MailAccountService mailAccountService; // TODO @wangjingyi:属性和类名,中间要空一行 + private MailAccountService mailAccountService; @PostMapping("/create") @ApiOperation("创建邮箱账号") @@ -50,8 +51,9 @@ public class MailAccountController { @DeleteMapping("/delete") @ApiOperation("删除邮箱账号") - @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") // TODO @wangjingyi:id 应该是 @RequestParam。另外,id 的 swagger 注解,要写下 - public CommonResult deleteMailAccount(@Valid @RequestBody Long id) { + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") + public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { mailAccountService.delete(id); return success(true); } @@ -63,8 +65,7 @@ public class MailAccountController { public CommonResult getMailAccount(@RequestParam("id") Long id) { MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); - } // TODO wangjingyi:方法与方法之间,只空一行 - + } @GetMapping("/page") @ApiOperation("获得邮箱账号分页") @@ -82,11 +83,12 @@ public class MailAccountController { list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } - @PostMapping("/send") // TODO wangjingyi:方法与方法之间,空一行 + + @PostMapping("/send") @ApiOperation("发送邮件") @PreAuthorize("@ss.hasPermission('system:mail-account:send')") - public CommonResult sendMail(MailSendVO mailSendVO){ - mailAccountService.sendMail(mailSendVO); + public CommonResult sendMail(MailReqVO mailReqVO){ + mailAccountService.sendMail(mailReqVO); return success(true); } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 7b65a0876..49400316b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; - +@ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data public class MailAccountBaseVO { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 9dc681962..8585e9d75 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -1,8 +1,14 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; +import io.swagger.annotations.ApiModel; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; -@Data // TODO @wangjingyi:swagger 注解 -public class MailAccountCreateReqVO extends MailAccountBaseVO{ // TODO @wangjingyi:要空格再 { +@ApiModel("管理后台 - 邮箱账号创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailAccountCreateReqVO extends MailAccountBaseVO { } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 6ddbc2ae6..520f31998 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -1,10 +1,16 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +@ApiModel("管理后台 - 邮箱账号分页 Request VO") @Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 925e7cd44..43a13ad18 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -1,10 +1,21 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import javax.validation.constraints.NotNull; + +@ApiModel("管理后台 - 邮箱账号修改 Request VO") @Data -public class MailAccountUpdateReqVO extends MailAccountBaseVO{ +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailAccountUpdateReqVO extends MailAccountBaseVO { - // TODO @wangjingyi:更新的话,是不是要有个 id??? + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java index eec39193c..04679c7f0 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java @@ -2,13 +2,17 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@ApiModel("管理后台 - 邮箱日志基类 Base VO") +@Data public class MailLogBaseVO { @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java index 03d439f33..442a101a3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -8,6 +9,7 @@ import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@ApiModel("管理后台 - 邮箱日志导出 Request VO") @Data public class MailLogExcelVO { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java index 0c8696980..7f737ae4b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExportReqVO.java @@ -1,4 +1,9 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; -public class MailLogExportReqVO extends MailLogPageReqVO{ +import io.swagger.annotations.ApiModel; +import lombok.Data; + +@ApiModel("管理后台 - 邮箱日志导出 Request VO") +@Data +public class MailLogExportReqVO extends MailLogPageReqVO { } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 7ed4419b7..9928a7746 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -1,15 +1,21 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +@ApiModel("管理后台 - 邮箱日志分页 Request VO") @Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index c3c5a2fdd..af8e81698 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -7,6 +8,8 @@ import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 邮箱日志返回 Request VO") @Data public class MailLogRespVO { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index b0577b44e..b718e2918 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +@ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data public class MailTemplateBaseVO { @ApiModelProperty("主键") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java index e18c39026..2311cb087 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; -import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiModel; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +@ApiModel("管理后台 - 邮箱模版创建 Request VO") @Data -public class MailTemplateCreateReqVO extends MailTemplateBaseVO{ +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailTemplateCreateReqVO extends MailTemplateBaseVO { } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index 5725febd0..398e6ac03 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -1,10 +1,16 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +@ApiModel("管理后台 - 邮箱模版分页 Request VO") @Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class MailTemplatePageReqVO extends PageParam { @ApiModelProperty("主键") private Long id; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java index ed0d882bb..82d9997be 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java @@ -1,7 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import javax.validation.constraints.NotNull; + +@ApiModel("管理后台 - 邮箱模版修改 Request VO") @Data -public class MailTemplateUpdateReqVO extends MailTemplateBaseVO{ +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailTemplateUpdateReqVO extends MailTemplateBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 464c43205..5b8a07b34 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,33 +4,61 @@ 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.send.MailSendVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import java.util.List; /** - *

* 邮箱账号 Service 接口 - *

// TODO wangjingyi:不用

标签; * * @author wangjingyi * @since 2022-03-21 */ -public interface MailAccountService { // TODO wangjingyi:方法的注释 - +public interface MailAccountService { + /** + * 创建邮箱账号 + * @param createReqVO + * @return + */ Long create(MailAccountCreateReqVO createReqVO); + /** + * 修改邮箱账号 + * @param updateReqVO + */ void update(MailAccountUpdateReqVO updateReqVO); + /** + * 删除邮箱账号 + * @param id + */ void delete(Long id); + /** + * 获取邮箱账号信息 + * @param id + * @return + */ MailAccountDO getMailAccount(Long id); + /** + * 获取邮箱账号分页信息 + * @param pageReqVO + * @return + */ PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO); + /** + * 获取邮箱数组信息 + * @return + */ List getMailAccountList(); - void sendMail(MailSendVO mailSendVO); + /** + * 发送邮件 + * @param mailReqVO + */ + void sendMail(MailReqVO mailReqVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 79d38730d..fa195259b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -9,16 +9,23 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import java.util.List; /** - *

- * 服务类 - *

+ * 邮箱日志服务类 * * @author wangjingyi * @since 2022-03-21 */ public interface MailLogService { - + /** + * 邮箱日志分页 + * @param pageVO + * @return + */ PageResult getMailLogPage(MailLogPageReqVO pageVO); + /** + * 邮箱日志数组信息 + * @param exportReqVO + * @return + */ List getMailLogList(MailLogExportReqVO exportReqVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 3aaf72a48..da68a43d0 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -4,30 +4,53 @@ 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.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; /** - *

- * 服务类 - *

+ * 邮箱模版服务类 * * @author wangjingyi * @since 2022-03-21 */ public interface MailTemplateService { - + /** + * 邮箱模版创建 + * @param createReqVO + * @return + */ Long create(MailTemplateCreateReqVO createReqVO); + /** + * 邮箱模版修改 + * @param updateReqVO + */ void update(MailTemplateUpdateReqVO updateReqVO); + /** + * 邮箱模版删除 + * @param id + */ void delete(Long id); + /** + * 获取邮箱模版 + * @param id + * @return + */ MailTemplateDO getMailTemplate(Long id); + /** + * 获取邮箱模版分页 + * @param pageReqVO + * @return + */ PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO); + /** + * 获取邮箱模板数组 + * @return + */ List getMailTemplateList(); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 2daeeab3e..7e4950f6d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -13,15 +13,14 @@ import org.springframework.stereotype.Service; import java.util.List; /** - *

* 邮箱日志实现类 - *

* * @author wangjingyi * @since 2022-03-21 */ @Service public class MailLogServiceImpl implements MailLogService { + @Autowired MailLogMapper mailLogMapper; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 377bbd658..92db1d83c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -22,15 +22,14 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** - *

* 邮箱模版 服务实现类 - *

* * @author wangjingyi * @since 2022-03-21 */ @Service public class MailTemplateServiceImpl implements MailTemplateService { + @Resource private MailTemplateMapper mailTemplateMapper; @@ -56,6 +55,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { this.validateMailTemplateExists(mailTemplateDO.getId()); mailTemplateMapper.updateById(mailTemplateDO); } + @Override public void delete(Long id) { // 校验是否存在 From 1bf1d3ee6a4125d7efd23be8ce1e6513fcae9ef5 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 30 Mar 2022 14:21:03 +0800 Subject: [PATCH 12/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/mail/MailAccountMapper.java | 13 +++++++ .../mail/impl/MailAccountServiceImpl.java | 35 +++++++------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index f7e06862f..effeed1b9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -5,8 +5,14 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; + @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -20,4 +26,11 @@ public interface MailAccountMapper extends BaseMapperX { ); } + default MailAccountDO selectByParams(Map params){ + QueryWrapperX queryWrapperX = new QueryWrapperX(); + params.forEach((k , v)->{ + queryWrapperX.eqIfPresent((String) k, v); + }); + return this.selectOne(queryWrapperX); + }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index c4610222a..8c8900dcf 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,19 +1,19 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; 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.send.MailSendVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -27,9 +27,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU /** - *

* 邮箱账号 Service 实现类 - *

* * @author wangjingyi * @since 2022-03-21 @@ -66,7 +64,6 @@ public class MailAccountServiceImpl implements MailAccountService { mailAccountMapper.updateById(mailAccountDO); } - @Override public void delete(Long id) { // 校验是否存在 @@ -90,20 +87,16 @@ public class MailAccountServiceImpl implements MailAccountService { } @Override - public void sendMail(MailSendVO mailSendVO) { - // FIXME 查询模版信息 查询模版多条时 使用规则是什么 - // 回复:选择某一条模板,进行发送邮件。 - List mailTemplateDOList = mailTemplateMapper.selectList( - "username",mailSendVO.getFrom() - ); + public void sendMail(MailReqVO mailReqVO) { + MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); //查询账号信息 MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from",mailSendVO.getFrom() + "from", mailReqVO.getFrom() ); - // FIXME 模版和邮件内容合成方式未知 - // 回复:参考短信的方式,通过 {name} {mobile} 这样的占位符。搜 formatSmsTemplateContent 方法 - String content = mailSendVO.getContent(); - String templateContent = ""; + String content = mailReqVO.getContent(); + Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); + content = StrUtil.format(mailTemplateDO.getContent(), params); + // 后续功能 TODO :附件查询 //List fileIds = mailSendVO.getFileIds(); @@ -111,7 +104,7 @@ public class MailAccountServiceImpl implements MailAccountService { MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); //发送 - MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false); + MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } private void validateMailAccountExists(Long id) { @@ -121,12 +114,8 @@ public class MailAccountServiceImpl implements MailAccountService { } private void validateMailAccountOnly(Map params){ - // TODO wangjingyi:Service 里,不允许出现 MyBatis 操作。而是 Mapper 提供对应查询方法 - QueryWrapper queryWrapper = new QueryWrapper(); - params.forEach((k , v)->{ - queryWrapper.like(k , v); // TODO wangjingyi:账号,应该是 equlas,不能是 like - }); - if (mailAccountMapper.selectOne(queryWrapper) != null) { + MailAccountDO mailAccountDO = mailAccountMapper.selectByParams(params); + if (mailAccountDO != null) { throw exception(MAIL_ACCOUNT_EXISTS); } } From 7d9a6cb2ef1c49afdff4166782be4174d8137053 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 30 Mar 2022 21:46:54 +0800 Subject: [PATCH 13/41] =?UTF-8?q?code=20review=20=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 5 ++--- .../admin/mail/MailTemplateController.java | 3 +-- .../system/dal/dataobject/mail/MailAccountDO.java | 15 +++++++-------- .../system/dal/mysql/mail/MailAccountMapper.java | 7 ++----- .../system/service/mail/MailAccountService.java | 7 +++++-- .../system/service/mail/MailTemplateService.java | 3 +++ .../service/mail/impl/MailAccountServiceImpl.java | 7 ++++--- .../mail/impl/MailTemplateServiceImpl.java | 11 ++++++----- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 2d2eb959b..660ea4ab4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -48,12 +48,11 @@ public class MailAccountController { return success(true); } - @DeleteMapping("/delete") @ApiOperation("删除邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") - public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { + public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { // TODO @wangjingyi:不需要 @Valid 这里。了解下 Validator mailAccountService.delete(id); return success(true); } @@ -87,7 +86,7 @@ public class MailAccountController { @PostMapping("/send") @ApiOperation("发送邮件") @PreAuthorize("@ss.hasPermission('system:mail-account:send')") - public CommonResult sendMail(MailReqVO mailReqVO){ + public CommonResult sendMail(MailReqVO mailReqVO){ // TODO @wangjingyi:应该是测试短信模板,做到 MailTemplateController 里。参考下短信那的做法哈 mailAccountService.sendMail(mailReqVO); return success(true); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index 988882d83..258dc3856 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -28,7 +28,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { @Autowired - MailTemplateService mailTempleService; + MailTemplateService mailTempleService; // TODO @wangjingyi:private;和上面要空一行; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -62,7 +62,6 @@ public class MailTemplateController { return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); } - @GetMapping("/page") @ApiOperation("获得邮箱模版分页") @PreAuthorize("@ss.hasPermission('system:mail-account:query')") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 2147af7fe..a7db81860 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,26 +1,25 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; - +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.io.Serializable; + @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="MailAccount对象", description="邮箱账号") -@TableName(value = "system_mail_account", autoResultMap = true) +@ApiModel(value="MailAccount对象", description="邮箱账号") // TODO @wangjingyi:不需要 swagger 注解 +@TableName(value = "system_mail_account", autoResultMap = true) // TODO @wangjingyi:这个放在最上面,关键字段 public class MailAccountDO extends BaseDO implements Serializable { - private static final long serialVersionUID = 1L; + // TODO @wangjingyi:每个字段的注释;字段名,如果一直,不用 @TableField + @TableId private Long id; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index effeed1b9..6785e33ec 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -5,14 +5,10 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Map; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; - @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -26,11 +22,12 @@ public interface MailAccountMapper extends BaseMapperX { ); } + // TODO @wangjingyi:不要提供这样的泛的方法,而是明确的查询方法 default MailAccountDO selectByParams(Map params){ QueryWrapperX queryWrapperX = new QueryWrapperX(); params.forEach((k , v)->{ queryWrapperX.eqIfPresent((String) k, v); }); - return this.selectOne(queryWrapperX); + return this.selecOne(queryWrapperX); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 5b8a07b34..572aa3ffb 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -11,14 +11,17 @@ import java.util.List; /** - * 邮箱账号 Service 接口 + * 邮箱账号 Service 接口 * * @author wangjingyi * @since 2022-03-21 */ public interface MailAccountService { + + // TODO @wangjingyi:注释,完整;参数校验还是要做的; + /** - * 创建邮箱账号 + * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 * @param createReqVO * @return */ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index da68a43d0..98fe87ef9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -15,6 +15,9 @@ import java.util.List; * @since 2022-03-21 */ public interface MailTemplateService { + + // TODO @wangjingyi:注释,完整;参数校验还是要做的; + /** * 邮箱模版创建 * @param createReqVO diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 8c8900dcf..4cb5ed0e2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -33,6 +33,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU * @since 2022-03-21 */ @Service +// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -54,13 +55,13 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 + // username 要校验唯一 TODO @wangjingyi:不要用 map 参数 Map map = new HashMap<>(); map.put("username" , updateReqVO.getUsername()); - this.validateMailAccountOnly(map); + this.validateMailAccountOnly(map); // TODO @wangjingyi:如果 username 是自己用呢,要排除下自己呀 MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); // TODO wangjingyi:没有传递 id 噢 + this.validateMailAccountExists(mailAccountDO.getId()); mailAccountMapper.updateById(mailAccountDO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 92db1d83c..9fd80bdfe 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemp 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.dal.dataobject.mail.MailAccountDO; 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.service.mail.MailTemplateService; @@ -19,15 +18,17 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; /** - * 邮箱模版 服务实现类 + * 邮箱模版 服务实现类 * * @author wangjingyi * @since 2022-03-21 */ @Service +// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 public class MailTemplateServiceImpl implements MailTemplateService { @Resource @@ -37,7 +38,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { public Long create(MailTemplateCreateReqVO createReqVO) { // name 要校验唯一 Map map = new HashMap<>(); - map.put("name" , createReqVO.getName()); + map.put("name" , createReqVO.getName()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 this.validateMailTemplateOnly(map); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); @@ -48,7 +49,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { public void update(MailTemplateUpdateReqVO updateReqVO) { // username 要校验唯一 Map map = new HashMap<>(); - map.put("username" , updateReqVO.getUsername()); + map.put("username" , updateReqVO.getUsername()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 this.validateMailTemplateOnly(map); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 From e1d79b5ea948afe1d8c5b7524061824fe0996f84 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 31 Mar 2022 18:00:03 +0800 Subject: [PATCH 14/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A=E3=80=81=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=94=B9=E6=B3=9B=E5=9E=8B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 9 +-- .../admin/mail/MailLogController.java | 1 + .../admin/mail/MailTemplateController.java | 14 ++++- .../mail/vo/account/MailAccountBaseVO.java | 4 ++ .../admin/mail/vo/send/MailReqVO.java | 2 +- .../mail/vo/template/MailTemplateBaseVO.java | 3 + .../dal/dataobject/mail/MailAccountDO.java | 33 +++++++---- .../system/dal/dataobject/mail/MailLogDO.java | 49 +++++++++++----- .../dal/dataobject/mail/MailTemplateDO.java | 37 ++++++++---- .../dal/mysql/mail/MailAccountMapper.java | 9 +-- .../dal/mysql/mail/MailTemplateMapper.java | 3 + .../service/mail/MailAccountService.java | 34 +++++------ .../service/mail/MailTemplateService.java | 36 +++++++----- .../mail/impl/MailAccountServiceImpl.java | 38 +++---------- .../service/mail/impl/MailLogServiceImpl.java | 2 + .../mail/impl/MailTemplateServiceImpl.java | 57 +++++++++++++------ 16 files changed, 204 insertions(+), 127 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 660ea4ab4..c16c7a60b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -52,7 +52,7 @@ public class MailAccountController { @ApiOperation("删除邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") - public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { // TODO @wangjingyi:不需要 @Valid 这里。了解下 Validator + public CommonResult deleteMailAccount(@RequestParam Long id) { mailAccountService.delete(id); return success(true); } @@ -83,11 +83,4 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertList02(list)); } - @PostMapping("/send") - @ApiOperation("发送邮件") - @PreAuthorize("@ss.hasPermission('system:mail-account:send')") - public CommonResult sendMail(MailReqVO mailReqVO){ // TODO @wangjingyi:应该是测试短信模板,做到 MailTemplateController 里。参考下短信那的做法哈 - mailAccountService.sendMail(mailReqVO); - return success(true); - } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java index f6375f290..1cad6a02a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java @@ -28,6 +28,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/system/mail-log") public class MailLogController { + @Autowired private MailLogService mailLogService; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index 258dc3856..cffd7f980 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -2,6 +2,7 @@ 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.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; @@ -27,8 +28,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/system/mail-template") public class MailTemplateController { + @Autowired - MailTemplateService mailTempleService; // TODO @wangjingyi:private;和上面要空一行; + MailTemplateService mailTempleService; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -64,7 +66,7 @@ public class MailTemplateController { @GetMapping("/page") @ApiOperation("获得邮箱模版分页") - @PreAuthorize("@ss.hasPermission('system:mail-account:query')") + @PreAuthorize("@ss.hasPermission('system:mail-template:query')") public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); @@ -78,4 +80,12 @@ public class MailTemplateController { list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } + + @PostMapping("/send") + @ApiOperation("发送邮件") + @PreAuthorize("@ss.hasPermission('system:mail-template:send')") + public CommonResult sendMail(@Valid @RequestBody MailReqVO mailReqVO){ + mailTempleService.sendMail(mailReqVO); + return success(true); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 49400316b..870d06e48 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -3,6 +3,9 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; + +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data public class MailAccountBaseVO { @@ -11,6 +14,7 @@ public class MailAccountBaseVO { private String from; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + @NotNull(message = "用户名必填") private String username; @ApiModelProperty(value = "密码" , required = true , example = "123456") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 0bd9d5d22..de75cddc9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -9,7 +9,7 @@ import java.util.List; @ApiModel("管理后台 - 邮件发送 Req VO") @Data -public class MailReqVO { // TODO @wangjingyi:1)参数校验;2)ReqVO +public class MailReqVO { @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") @NotNull(message = "邮箱账号不能为空") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index b718e2918..074ed69d2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data public class MailTemplateBaseVO { @@ -14,6 +16,7 @@ public class MailTemplateBaseVO { private String name; @ApiModelProperty("标识") + @NotNull(message = "邮箱模版code不能为空") private String code; @ApiModelProperty("发件人") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index a7db81860..0d603cb99 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -11,34 +11,45 @@ import lombok.experimental.Accessors; import java.io.Serializable; +@TableName(value = "system_mail_account", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="MailAccount对象", description="邮箱账号") // TODO @wangjingyi:不需要 swagger 注解 -@TableName(value = "system_mail_account", autoResultMap = true) // TODO @wangjingyi:这个放在最上面,关键字段 public class MailAccountDO extends BaseDO implements Serializable { - // TODO @wangjingyi:每个字段的注释;字段名,如果一直,不用 @TableField - - @TableId + /** + * 主键 + */ private Long id; - @TableField("from") + /** + * 邮箱 + */ private String from; - @TableField("username") + /** + * 用户名 + */ private String username; - @TableField("password") + /** + * 密码 + */ private String password; - @TableField("host") + /** + * 主机 + */ private String host; - @TableField("port") + /** + * 端口 + */ private Integer port; - @TableField("sslEnable") + /** + * 是否开启ssl + */ private Boolean sslEnable; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 8183174a1..4fc0c0a5c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -5,6 +5,8 @@ import java.sql.Timestamp; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableField; import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; @@ -18,44 +20,65 @@ import lombok.experimental.Accessors; * @author wangjingyi * @since 2022-03-21 */ +@TableName(value = "system_mail_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="SystemMailLog对象", description="") public class MailLogDO extends BaseDO implements Serializable { - private static final long serialVersionUID = 1L; - @TableId + /** + * 主键 + */ private Long id; - @TableField("account_code") + /** + * 邮箱账号编号 + */ private String accountCode; - @TableField("from") + /** + * 邮箱账号 + */ private String from; - @TableField("template_id") + /** + * 模版主键 + */ private String templateId; - @TableField("template_code") + /** + * 模版编号 + */ private String templateCode; - @TableField("title") + /** + * 标题 + */ private String title; - @TableField("content") + /** + * 内容 + */ private String content; - @TableField("to") + /** + * 收件人 + */ private String to; - @TableField("sendTime") + /** + * 发送时间 + */ private Timestamp sendTime; - @TableField("sendStatus") + /** + * 发送状态 + */ private Boolean sendStatus; - @TableField("sendResult") + /** + * 发送结果 + */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index e2d5a6d8c..83ebb533d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableField; import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -19,35 +21,50 @@ import lombok.experimental.Accessors; * @author wangjingyi * @since 2022-03-21 */ +@TableName(value = "system_mail_template", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="SystemMailTemplate对象", description="") public class MailTemplateDO extends BaseDO implements Serializable { - private static final long serialVersionUID = 1L; - @TableId + /** + * 主键 + */ private Long id; - @TableField("name") + /** + * 模版名称 + */ private String name; - @TableField("code") + /** + * 模版编号 + */ private String code; - @TableField("username") + /** + * 用户名 + */ private String username; - @TableField("title") + /** + * 标题 + */ private String title; - @TableField("content") + /** + * 内容 + */ private String content; - @TableField("status") + /** + * 状态 + */ private String status; - @TableField("remark") + /** + * 备注 + */ private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 6785e33ec..d0a43e679 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -22,12 +22,9 @@ public interface MailAccountMapper extends BaseMapperX { ); } - // TODO @wangjingyi:不要提供这样的泛的方法,而是明确的查询方法 - default MailAccountDO selectByParams(Map params){ + default MailAccountDO selectByUserName(String userName){ QueryWrapperX queryWrapperX = new QueryWrapperX(); - params.forEach((k , v)->{ - queryWrapperX.eqIfPresent((String) k, v); - }); - return this.selecOne(queryWrapperX); + queryWrapperX.eqIfPresent("username", userName); + return this.selectOne(queryWrapperX); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 06e76d9ab..635a2bf90 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -22,4 +22,7 @@ public interface MailTemplateMapper extends BaseMapperX { ); } + default MailTemplateDO selectOneByCode(String code){ + return selectOne("code" , code); + }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 572aa3ffb..9792c6cc5 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import javax.validation.Valid; import java.util.List; @@ -22,46 +23,47 @@ public interface MailAccountService { /** * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 - * @param createReqVO - * @return + * + * @param createReqVO 邮箱账号信息 + * @return 编号 */ - Long create(MailAccountCreateReqVO createReqVO); + Long create(@Valid MailAccountCreateReqVO createReqVO); /** * 修改邮箱账号 - * @param updateReqVO + * + * @param updateReqVO 邮箱账号信息 */ - void update(MailAccountUpdateReqVO updateReqVO); + void update(@Valid MailAccountUpdateReqVO updateReqVO); /** * 删除邮箱账号 - * @param id + * + * @param id 编号 */ void delete(Long id); /** * 获取邮箱账号信息 - * @param id - * @return + * + * @param id 编号 + * @return 邮箱账号信息 */ MailAccountDO getMailAccount(Long id); /** * 获取邮箱账号分页信息 - * @param pageReqVO - * @return + * + * @param pageReqVO 邮箱账号分页参数 + * @return 邮箱账号分页信息 */ PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO); /** * 获取邮箱数组信息 - * @return + * + * @return 邮箱账号信息数组 */ List getMailAccountList(); - /** - * 发送邮件 - * @param mailReqVO - */ - void sendMail(MailReqVO mailReqVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 98fe87ef9..1511309eb 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -1,11 +1,13 @@ 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.send.MailReqVO; 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.dal.dataobject.mail.MailTemplateDO; +import javax.validation.Valid; import java.util.List; /** @@ -16,44 +18,52 @@ import java.util.List; */ public interface MailTemplateService { - // TODO @wangjingyi:注释,完整;参数校验还是要做的; - /** * 邮箱模版创建 - * @param createReqVO - * @return + * @param createReqVO 邮箱信息 + * @return 编号 */ - Long create(MailTemplateCreateReqVO createReqVO); + Long create(@Valid MailTemplateCreateReqVO createReqVO); /** * 邮箱模版修改 - * @param updateReqVO + * @param updateReqVO 邮箱信息 */ - void update(MailTemplateUpdateReqVO updateReqVO); + void update(@Valid MailTemplateUpdateReqVO updateReqVO); /** * 邮箱模版删除 - * @param id + * @param id 编号 */ void delete(Long id); /** * 获取邮箱模版 - * @param id - * @return + * + * @param id 编号 + * @return 邮件模版 */ MailTemplateDO getMailTemplate(Long id); /** * 获取邮箱模版分页 - * @param pageReqVO - * @return + * + * @param pageReqVO 模版信息 + * @return 邮箱模版分页信息 */ PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO); /** * 获取邮箱模板数组 - * @return + * + * @return 模版数组 */ List getMailTemplateList(); + + /** + * 发送邮件 + * + * @param mailReqVO 邮件发送信息 + */ + void sendMail(MailReqVO mailReqVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 4cb5ed0e2..fa2f8879e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.HashMap; @@ -33,7 +34,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU * @since 2022-03-21 */ @Service -// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 +@Validated public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -45,9 +46,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - Map map = new HashMap<>(); - map.put("username" , createReqVO.getUsername()); - this.validateMailAccountOnly(map); + this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); return mailAccountDO.getId(); @@ -55,10 +54,8 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:不要用 map 参数 - Map map = new HashMap<>(); - map.put("username" , updateReqVO.getUsername()); - this.validateMailAccountOnly(map); // TODO @wangjingyi:如果 username 是自己用呢,要排除下自己呀 + // username 要校验唯一 + this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailAccountExists(mailAccountDO.getId()); @@ -87,35 +84,14 @@ public class MailAccountServiceImpl implements MailAccountService { return mailAccountMapper.selectList(); } - @Override - public void sendMail(MailReqVO mailReqVO) { - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", mailReqVO.getFrom() - ); - String content = mailReqVO.getContent(); - Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = StrUtil.format(mailTemplateDO.getContent(), params); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - - //发送 - MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); - } - private void validateMailAccountExists(Long id) { if (mailAccountMapper.selectById(id) == null) { throw exception(MAIL_ACCOUNT_NOT_EXISTS); } } - private void validateMailAccountOnly(Map params){ - MailAccountDO mailAccountDO = mailAccountMapper.selectByParams(params); + private void validateMailAccountOnlyByUserName(String userName){ + MailAccountDO mailAccountDO = mailAccountMapper.selectByUserName(userName); if (mailAccountDO != null) { throw exception(MAIL_ACCOUNT_EXISTS); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 7e4950f6d..c6b492498 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import java.util.List; @@ -19,6 +20,7 @@ import java.util.List; * @since 2022-03-21 */ @Service +@Validated public class MailLogServiceImpl implements MailLogService { @Autowired diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9fd80bdfe..7ce118303 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -1,18 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; 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.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,29 +38,27 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL * @since 2022-03-21 */ @Service -// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 +@Validated public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource + private MailAccountMapper mailAccountMapper; @Override public Long create(MailTemplateCreateReqVO createReqVO) { - // name 要校验唯一 - Map map = new HashMap<>(); - map.put("name" , createReqVO.getName()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 - this.validateMailTemplateOnly(map); + // code 要校验唯一 + this.validateMailTemplateOnlyByCode(createReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); return mailTemplateDO.getId(); } @Override - public void update(MailTemplateUpdateReqVO updateReqVO) { - // username 要校验唯一 - Map map = new HashMap<>(); - map.put("username" , updateReqVO.getUsername()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 - this.validateMailTemplateOnly(map); + public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { + // code 要校验唯一 + this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailTemplateExists(mailTemplateDO.getId()); @@ -75,18 +83,35 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public List getMailTemplateList() {return mailTemplateMapper.selectList();} + @Override + public void sendMail(MailReqVO mailReqVO) { + MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from", mailReqVO.getFrom() + ); + String content = mailReqVO.getContent(); + Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); + content = StrUtil.format(mailTemplateDO.getContent(), params); + + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); + + //发送 + MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); + } + private void validateMailTemplateExists(Long id) { if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnly(Map params){ - QueryWrapper queryWrapper = new QueryWrapper(); - params.forEach((k , v)->{ - queryWrapper.like(k , v); - }); - if (mailTemplateMapper.selectOne(queryWrapper) != null) { + private void validateMailTemplateOnlyByCode(String code){ + if (mailTemplateMapper.selectOneByCode(code) != null) { throw exception(MAIL_TEMPLATE_EXISTS); } } From d1812761db1e7a485c32f1bc6be051a6f3ca1d02 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 31 Mar 2022 21:40:10 +0800 Subject: [PATCH 15/41] =?UTF-8?q?code=20review=20=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20second?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mail/vo/account/MailAccountBaseVO.java | 2 +- .../admin/mail/vo/send/MailReqVO.java | 2 +- .../mail/vo/template/MailTemplateBaseVO.java | 2 +- .../dal/dataobject/mail/MailAccountDO.java | 25 +++++++---------- .../system/dal/dataobject/mail/MailLogDO.java | 17 +++++------- .../dal/dataobject/mail/MailTemplateDO.java | 27 +++++-------------- .../dal/mysql/mail/MailAccountMapper.java | 5 ++-- .../dal/mysql/mail/MailTemplateMapper.java | 1 + .../service/mail/MailAccountService.java | 5 +--- .../service/mail/MailTemplateService.java | 3 +++ .../mail/impl/MailAccountServiceImpl.java | 10 ++----- .../mail/impl/MailTemplateServiceImpl.java | 6 ++--- 12 files changed, 36 insertions(+), 69 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 870d06e48..67cf9ba3a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data -public class MailAccountBaseVO { +public class MailAccountBaseVO { // TODO @wangjingqi:1), 不用空格;2)from、username、password、host、sslEnable 都要参数校验,非空;3)username 要 Email 格式;port Integer; @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index de75cddc9..4ce06a718 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -9,7 +9,7 @@ import java.util.List; @ApiModel("管理后台 - 邮件发送 Req VO") @Data -public class MailReqVO { +public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") @NotNull(message = "邮箱账号不能为空") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index 074ed69d2..e3c9797ab 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data -public class MailTemplateBaseVO { +public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不完善;2)id、name、code、username、title、content、status 是不是要参数校验呀 @ApiModelProperty("主键") private Long id; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 0d603cb99..d285adec5 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,56 +1,49 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import java.io.Serializable; +/** + * 邮箱账号 + * 配置发送邮箱的账号 + * + * @author wangjingyi + * @since 2022-03-21 + */ @TableName(value = "system_mail_account", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class MailAccountDO extends BaseDO implements Serializable { +public class MailAccountDO extends BaseDO { /** * 主键 */ private Long id; - /** * 邮箱 */ private String from; - /** * 用户名 */ private String username; - /** * 密码 */ private String password; - /** * 主机 */ private String host; - /** * 端口 */ private Integer port; - /** - * 是否开启ssl + * 是否开启 SSL */ private Boolean sslEnable; - } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 4fc0c0a5c..f6b9e689c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,21 +1,16 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import java.sql.Timestamp; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; - import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.sql.Timestamp; /** - *

* 邮箱日志 - *

+ * 记录每一次邮件的发送 * * @author wangjingyi * @since 2022-03-21 @@ -23,7 +18,6 @@ import lombok.experimental.Accessors; @TableName(value = "system_mail_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) public class MailLogDO extends BaseDO implements Serializable { /** @@ -31,11 +25,13 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long id; + // TODO @wangjingyi:accountId /** * 邮箱账号编号 */ private String accountCode; + // TODO @wangjingyi:如果是冗余字段,记得 @ 下; /** * 邮箱账号 */ @@ -74,6 +70,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送状态 */ + // TODO @wangjingyi:四个状态,参考短信模块 private Boolean sendStatus; /** diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index 83ebb533d..b86e39e95 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -1,22 +1,13 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; -import java.io.Serializable; - import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; /** - *

* 邮箱模版 - *

* * @author wangjingyi * @since 2022-03-21 @@ -24,48 +15,42 @@ import lombok.experimental.Accessors; @TableName(value = "system_mail_template", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class MailTemplateDO extends BaseDO implements Serializable { +public class MailTemplateDO extends BaseDO { /** * 主键 */ private Long id; - /** * 模版名称 */ private String name; - /** * 模版编号 */ private String code; - + // TODO @wangjingyi:应该使用 accountId 呀 /** * 用户名 */ private String username; - /** * 标题 */ private String title; - /** * 内容 */ private String content; - /** * 状态 + * + * 枚举 {@link CommonStatusEnum} */ - private String status; - + private String status; // TODO @wangjingyi:Integer /** * 备注 */ private String remark; - } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index d0a43e679..8697b2151 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,8 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import org.apache.ibatis.annotations.Mapper; -import java.util.Map; - @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -23,7 +21,8 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - QueryWrapperX queryWrapperX = new QueryWrapperX(); + // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); + QueryWrapperX queryWrapperX = new QueryWrapperX<>(); queryWrapperX.eqIfPresent("username", userName); return this.selectOne(queryWrapperX); }; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 635a2bf90..d65887e54 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -23,6 +23,7 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ + // TODO @wangjingyi:优先使用 lambada 查询 return selectOne("code" , code); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 9792c6cc5..c1289154f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,7 +4,6 @@ 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.send.MailReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; @@ -19,10 +18,8 @@ import java.util.List; */ public interface MailAccountService { - // TODO @wangjingyi:注释,完整;参数校验还是要做的; - /** - * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 + * 创建邮箱账号 * * @param createReqVO 邮箱账号信息 * @return 编号 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1511309eb..1071eae5d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ public interface MailTemplateService { /** * 邮箱模版创建 + * * @param createReqVO 邮箱信息 * @return 编号 */ @@ -27,12 +28,14 @@ public interface MailTemplateService { /** * 邮箱模版修改 + * * @param updateReqVO 邮箱信息 */ void update(@Valid MailTemplateUpdateReqVO updateReqVO); /** * 邮箱模版删除 + * * @param id 编号 */ void delete(Long id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index fa2f8879e..aa1fb1d46 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.module.system.service.mail.impl; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; 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.send.MailReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -18,9 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; @@ -54,7 +47,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 + // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 @@ -64,6 +57,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { + // TODO @wangjingyi:删除时,要判断是否有使用的模板 // 校验是否存在 this.validateMailAccountExists(id); mailAccountMapper.deleteById(id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 7ce118303..2bd74ac4c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -15,15 +15,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; -import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +55,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); + this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailTemplateExists(mailTemplateDO.getId()); @@ -85,6 +82,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void sendMail(MailReqVO mailReqVO) { + // TODO @@wangjingyi:发送的时候,参考下短信; MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); //查询账号信息 MailAccountDO mailAccountDO = mailAccountMapper.selectOne( From d7305739d3fcef6efe25c12d33c02b903c181308 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 30 Apr 2022 21:31:55 +0800 Subject: [PATCH 16/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 + .../pom.xml | 65 +++++++++++ .../config/YudaoMailAutoConfiguration.java | 21 ++++ .../mail/core/client/MailClient.java | 23 ++++ .../mail/core/client/MailClientFactory.java | 5 + .../mail/core/client/MailCodeMapping.java | 17 +++ .../mail/core/client/MailCommonResult.java | 68 +++++++++++ .../core/client/dto/MailReceiveRespDTO.java | 48 ++++++++ .../mail/core/client/dto/MailSendRespDTO.java | 18 +++ .../core/client/dto/MailTemplateRespDTO.java | 31 +++++ .../core/client/impl/AbstractMailClient.java | 14 +++ .../client/impl/MailClientFactoryImpl.java | 39 +++++++ .../client/impl/hutool/HutoolMailClient.java | 29 +++++ .../impl/hutool/HutoolMailCodeMapping.java | 20 ++++ .../mail/core/enums/MailChannelEnum.java | 32 ++++++ .../MailFrameworkErrorCodeConstants.java | 47 ++++++++ .../enums/MailTemplateAuditStatusEnum.java | 21 ++++ .../core/property/MailChannelProperties.java | 52 +++++++++ .../module/system/api/mail/MailSendApi.java | 4 + .../system/api/mail/dto/MailSendReqDTO.java | 38 +++++++ .../system/enums/ErrorCodeConstants.java | 1 + .../system/enums/mail/MailSendStatusEnum.java | 24 ++++ .../yudao-module-system-impl/pom.xml | 5 + .../system/api/mail/MailSendApiImpl.java | 14 +++ .../mail/vo/account/MailAccountBaseVO.java | 22 ++-- .../admin/mail/vo/log/MailLogExcelVO.java | 5 +- .../admin/mail/vo/log/MailLogRespVO.java | 2 +- .../admin/mail/vo/send/MailReqVO.java | 14 ++- .../mail/vo/template/MailTemplateBaseVO.java | 12 +- .../vo/template/MailTemplatePageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailLogDO.java | 22 ++-- .../dal/dataobject/mail/MailTemplateDO.java | 9 +- .../dal/mysql/mail/MailAccountMapper.java | 7 +- .../dal/mysql/mail/MailTemplateMapper.java | 15 ++- .../mq/consumer/mail/MailSendConsumer.java | 8 +- .../mq/message/mail/MailSendMessage.java | 26 +++-- .../system/mq/producer/mail/MailProducer.java | 65 +++++++++++ .../system/service/mail/MailLogService.java | 16 +++ .../system/service/mail/MailSendService.java | 41 +++++++ .../service/mail/MailTemplateService.java | 17 +++ .../mail/impl/MailAccountServiceImpl.java | 20 +++- .../service/mail/impl/MailLogServiceImpl.java | 42 +++++++ .../mail/impl/MailSendServiceImpl.java | 107 ++++++++++++++++++ .../mail/impl/MailTemplateServiceImpl.java | 55 ++++++++- 44 files changed, 1085 insertions(+), 59 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 73bb614cd..42c887c56 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,6 +30,7 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms + yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml new file mode 100644 index 000000000..8cca21778 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml @@ -0,0 +1,65 @@ + + + + cn.iocoder.boot + yudao-framework + ${revision} + + 4.0.0 + yudao-spring-boot-starter-biz-mail + jar + + + + cn.iocoder.boot + yudao-common + + + + + org.springframework.boot + spring-boot-starter + + + + + io.opentracing + opentracing-util + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + + + + + com.google.guava + guava + true + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + + jakarta.validation + jakarta.validation-api + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java new file mode 100644 index 000000000..c83b1e5f1 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.config; + +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 邮箱配置类 + * + * @author 芋道源码 + */ +@Configuration +public class YudaoMailAutoConfiguration { + + @Bean + public MailClientFactory mailClientFactory() { + return new MailClientFactoryImpl(); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java new file mode 100644 index 000000000..a17260410 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import java.util.List; + +/** + * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 + * + * @author wangjingyi + * @date 2021/4/19 19:21 + */ +public interface MailClient { + + /** + * 发送邮件 + * + * @param from 邮箱账号 + * @param content 内容 + * @param title 标题 + * @param tos 收件人 + * @return 邮件发送结果 + */ + String sendMail(String from, String content, String title, List tos); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java new file mode 100644 index 000000000..3244dfe76 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java @@ -0,0 +1,5 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +public interface MailClientFactory { + MailClient getMailClient(); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java new file mode 100644 index 000000000..c33b4be3e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +import java.util.function.Function; + +/** + * 将 API 的错误码,转换为通用的错误码 + * + * @see MailCommonResult + * @see MailFrameworkErrorCodeConstants + * + * @author 芋道源码 + */ +public interface MailCodeMapping extends Function { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java new file mode 100644 index 000000000..a53a3b989 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.hutool.core.exceptions.ExceptionUtil; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +/** + * 短信的 CommonResult 拓展类 + * + * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 + * + * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 + * + * @author 芋道源码 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailCommonResult extends CommonResult { + + /** + * API 返回错误码 + * + * 由于第三方的错误码可能是字符串,所以使用 String 类型 + */ + private String apiCode; + /** + * API 返回提示 + */ + private String apiMsg; + + /** + * API 请求编号 + */ + private String apiRequestId; + + private MailCommonResult() { + } + + public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, + T data, MailCodeMapping codeMapping) { + Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); + MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); + result.setData(data); + // 翻译错误码 + if (codeMapping != null) { + ErrorCode errorCode = codeMapping.apply(apiCode); + if (errorCode == null) { + errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; + } + result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); + } + return result; + } + + public static MailCommonResult error(Throwable ex) { + MailCommonResult result = new MailCommonResult<>(); + result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); + result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); + return result; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java new file mode 100644 index 000000000..11f27f58a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * 消息接收 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailReceiveRespDTO { + + /** + * 是否接收成功 + */ + private Boolean success; + /** + * API 接收结果的编码 + */ + private String errorCode; + /** + * API 接收结果的说明 + */ + private String errorMsg; + + /** + * 手机号 + */ + private String mobile; + /** + * 用户接收时间 + */ + private Date receiveTime; + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + /** + * 短信日志编号 + * + * 对应 SysSmsLogDO 的编号 + */ + private Long logId; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java new file mode 100644 index 000000000..b4a94a634 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信发送 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailSendRespDTO { + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java new file mode 100644 index 000000000..14bdeacd8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信模板 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailTemplateRespDTO { + + /** + * 模板编号 + */ + private String id; + /** + * 短信内容 + */ + private String content; + /** + * 审核状态 + * + */ + private Integer auditStatus; + /** + * 审核未通过的理由 + */ + private String auditReason; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java new file mode 100644 index 000000000..097c8e095 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +/** + * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 + * + * @author zzf + * @date 2021/2/1 9:28 + */ +@Slf4j +public abstract class AbstractMailClient implements MailClient { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java new file mode 100644 index 000000000..9923bd3df --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import cn.iocoder.yudao.framework.mail.core.client.MailClient; +import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +@Validated +@Slf4j +public class MailClientFactoryImpl implements MailClientFactory { + + private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); + + public MailClientFactoryImpl (){ + Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { + AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); + channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); + }); + } + + private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { + switch (mailChannelEnum){ + case HUTOOL: return new HutoolMailClient(); + } + // 创建失败,错误日志 + 抛出异常 + log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); + throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); + } + + @Override + public MailClient getMailClient() { + return channelCodeClients.get("HUTOOL"); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java new file mode 100644 index 000000000..457ad7e37 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + + +/** + * 邮件客户端实现 + * + * @author wangjingyi + * @date 2021/4/25 14:25 + */ +@Slf4j +public class HutoolMailClient extends AbstractMailClient { + + @Override + public String sendMail(String from, String content, String title, List tos) { + try{ + return MailUtil.send(from , title , content , false , null); + }catch (Exception e){ + log.error(e.getMessage()); + } + return ""; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java new file mode 100644 index 000000000..711d36950 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; + +/** + * 阿里云的 SmsCodeMapping 实现类 + * + * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 + * + * @author 芋道源码 + */ +public class HutoolMailCodeMapping implements MailCodeMapping { + + @Override + public ErrorCode apply(String apiCode) { + return null; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java new file mode 100644 index 000000000..51d2f1fca --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.hutool.core.util.ArrayUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信渠道枚举 + * + * @author zzf + * @date 2021/1/25 10:56 + */ +@Getter +@AllArgsConstructor +public enum MailChannelEnum { + HUTOOL("HUTOOL" , "HUTOOL"), + ; + + /** + * 编码 + */ + private final String code; + /** + * 名字 + */ + private final String name; + + public static MailChannelEnum getByCode(String code) { + return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java new file mode 100644 index 000000000..e5ef74cf3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * 短信框架的错误码枚举 + * + * 短信框架,使用 2-001-000-000 段 + * + * @author 芋道源码 + */ +public interface MailFrameworkErrorCodeConstants { + + ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); + + // ========== 权限 / 限流等相关 2001000100 ========== + + ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); + // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 + ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); + + // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 + ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); + // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 + ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); + + ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); + + // ========== 模板相关 2001000200 ========== + ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 + ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); + + // ========== 签名相关 2001000300 ========== + ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); + + // ========== 账户相关 2001000400 ========== + ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); + ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); + + // ========== 其它相关 2001000900 开头 ========== + ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); + ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); + ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); + + ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java new file mode 100644 index 000000000..95c3c31a3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信模板的审核状态枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum MailTemplateAuditStatusEnum { + + CHECKING(1), + SUCCESS(2), + FAIL(3); + + private final Integer status; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java new file mode 100644 index 000000000..1f19ac12b --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.framework.mail.core.property; + +import lombok.Data; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 短信渠道配置类 + * + * @author zzf + * @date 2021/1/25 17:01 + */ +@Data +@Validated +public class MailChannelProperties { + + /** + * 渠道编号 + */ + @NotNull(message = "短信渠道 ID 不能为空") + private Long id; + /** + * 短信签名 + */ + @NotEmpty(message = "短信签名不能为空") + private String signature; + /** + * 渠道编码 + * + * 枚举 {@link MailChannelEnum} + */ + @NotEmpty(message = "渠道编码不能为空") + private String code; + /** + * 短信 API 的账号 + */ + @NotEmpty(message = "短信 API 的账号不能为空") + private String apiKey; + /** + * 短信 API 的秘钥 + */ + @NotEmpty(message = "短信 API 的秘钥不能为空") + private String apiSecret; + /** + * 短信发送回调 URL + */ + private String callbackUrl; + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java new file mode 100644 index 000000000..2ffe0d7cb --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.api.mail; + +public interface MailSendApi { +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java new file mode 100644 index 000000000..a3b0f2e35 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.system.api.mail.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel("管理后台 - 邮件发送 Req VO") +@Data +public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 + + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") + private String from; + + @ApiModelProperty(value = "标题",example = "标题") + private String title; + + @ApiModelProperty(value = "内容",example = "内容") + private String content; + + @ApiModelProperty(value = "邮箱模版id",example = "1024") + @NotNull(message = "邮箱模版id不能为空") + private Integer templateId; + + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "收件人不能为空") + private List tos; + + @ApiModelProperty(value = "附件",example = "附件编码") + private List fileIds; + + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 8520cb115..07322ccd7 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -126,5 +126,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002020000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java new file mode 100644 index 000000000..8936ea9c7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件的发送状态枚举 + * + * @author wangjingyi + * @date 2022/4/10 13:39 + */ +@Getter +@AllArgsConstructor +public enum MailSendStatusEnum { + + INIT(0), // 初始化 + SUCCESS(10), // 发送成功 + FAILURE(20), // 发送失败 + IGNORE(30), // 忽略,即不发送 + ; + + private final int status; + +} diff --git a/yudao-module-system/yudao-module-system-impl/pom.xml b/yudao-module-system/yudao-module-system-impl/pom.xml index b297830b5..65dc74d03 100644 --- a/yudao-module-system/yudao-module-system-impl/pom.xml +++ b/yudao-module-system/yudao-module-system-impl/pom.xml @@ -47,6 +47,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict + + cn.iocoder.boot + yudao-spring-boot-starter-biz-mail + cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission @@ -102,6 +106,7 @@ yudao-spring-boot-starter-excel + diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java new file mode 100644 index 000000000..cce0ed388 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.system.api.mail; + +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +/** + * 邮件发送 API 接口 + * + * @author wangjingyi + */ +@Service +@Validated +public class MailSendApiImpl implements MailSendApi{ +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 67cf9ba3a..d8650b52e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -4,28 +4,34 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data -public class MailAccountBaseVO { // TODO @wangjingqi:1), 不用空格;2)from、username、password、host、sslEnable 都要参数校验,非空;3)username 要 Email 格式;port Integer; +public class MailAccountBaseVO { - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱必填") private String from; - @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") + @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码" , required = true , example = "123456") + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") private String password; - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") + @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") + @NotNull(message = "网站必填") private String host; - @ApiModelProperty(value = "端口" , required = true , example = "80") - private String port; + @ApiModelProperty(value = "端口",required = true,example = "80") + private Integer port; - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") + @ApiModelProperty(value = "是否开启ssl",required = true,example = "2") + @NotNull(message = "是否开启ssl必填") private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java index 442a101a3..d341ce678 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -6,6 +6,7 @@ import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; +import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -30,10 +31,10 @@ public class MailLogExcelVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @ExcelProperty(value = "发送时间" ) - private Timestamp sendTime; + private Date sendTime; @ExcelProperty(value = "发送状态") - private Boolean sendStatus; + private Integer sendStatus; @ExcelProperty(value = "发送结果") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index af8e81698..024e075f4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -36,7 +36,7 @@ public class MailLogRespVO { private Timestamp sendTime; @ApiModelProperty(value = "发送状态" , required = false , example = "1") - private Boolean sendStatus; + private Integer sendStatus; @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 4ce06a718..65142ee3f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; @@ -11,25 +12,26 @@ import java.util.List; @Data public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") private String from; - @ApiModelProperty(value = "标题" , example = "标题") + @ApiModelProperty(value = "标题",example = "标题") private String title; - @ApiModelProperty(value = "内容" , example = "内容") + @ApiModelProperty(value = "内容",example = "内容") private String content; - @ApiModelProperty(value = "邮箱模版id" , example = "1024") + @ApiModelProperty(value = "邮箱模版id",example = "1024") @NotNull(message = "邮箱模版id不能为空") private Integer templateId; - @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件" , example = "附件编码") + @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index e3c9797ab..1e44336aa 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -4,15 +4,18 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data -public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不完善;2)id、name、code、username、title、content、status 是不是要参数校验呀 +public class MailTemplateBaseVO { @ApiModelProperty("主键") + @NotNull(message = "主键不能为空") private Long id; @ApiModelProperty("名称") + @NotNull(message = "名称不能为空") private String name; @ApiModelProperty("标识") @@ -20,16 +23,21 @@ public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不 private String code; @ApiModelProperty("发件人") + @NotNull(message = "发件人不能为空") + @Email(message = "发件人格式有误") private String username; @ApiModelProperty("标题") + @NotNull(message = "标题不能为空") private String title; @ApiModelProperty("内容") + @NotNull(message = "内容不能为空") private String content; @ApiModelProperty("状态") - private String status; + @NotNull(message = "状态不能为空") + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index 398e6ac03..a48c5a91a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -31,7 +31,7 @@ public class MailTemplatePageReqVO extends PageParam { private String content; @ApiModelProperty("状态") - private String status; + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index f6b9e689c..7454d2acb 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import java.io.Serializable; -import java.sql.Timestamp; +import java.util.Date; /** * 邮箱日志 @@ -18,6 +18,10 @@ import java.sql.Timestamp; @TableName(value = "system_mail_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@AllArgsConstructor +@NoArgsConstructor public class MailLogDO extends BaseDO implements Serializable { /** @@ -29,7 +33,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号编号 */ - private String accountCode; + private Long accountId; // TODO @wangjingyi:如果是冗余字段,记得 @ 下; /** @@ -40,7 +44,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 模版主键 */ - private String templateId; + private Long templateId; /** * 模版编号 @@ -65,16 +69,18 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送时间 */ - private Timestamp sendTime; + private Date sendTime; /** * 发送状态 + * + * 枚举 {@link MailSendStatusEnum} */ - // TODO @wangjingyi:四个状态,参考短信模块 - private Boolean sendStatus; + private Integer sendStatus; /** * 发送结果 + * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index b86e39e95..96f9ba4ab 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Date; + /** * 邮箱模版 * @@ -29,11 +31,10 @@ public class MailTemplateDO extends BaseDO { * 模版编号 */ private String code; - // TODO @wangjingyi:应该使用 accountId 呀 /** - * 用户名 + * 邮箱账号主键 */ - private String username; + private Long accountId; /** * 标题 */ @@ -47,7 +48,7 @@ public class MailTemplateDO extends BaseDO { * * 枚举 {@link CommonStatusEnum} */ - private String status; // TODO @wangjingyi:Integer + private Integer status; /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 8697b2151..651f5c75f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -21,9 +22,7 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - queryWrapperX.eqIfPresent("username", userName); - return this.selectOne(queryWrapperX); + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index d65887e54..a5cbf0b2a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -6,6 +6,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper @@ -23,7 +26,15 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ - // TODO @wangjingyi:优先使用 lambada 查询 - return selectOne("code" , code); + return selectOne(new QueryWrapperX() + .eqIfPresent("code" , code)); + }; + + @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectByMaxUpdateTime(Date maxUpdateTime); + + default MailTemplateDO selectOneByAccountId(Long accountId){ + return selectOne(new QueryWrapperX() + .eqIfPresent("account_id" , accountId)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java index 4b02f760e..978ea5997 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java @@ -2,17 +2,23 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -// TODO 芋艿:这个暂未实现 +import javax.annotation.Resource; + + @Component @Slf4j public class MailSendConsumer extends AbstractStreamMessageListener { + @Resource + private MailSendService mailSendService; @Override public void onMessage(MailSendMessage message) { log.info("[onMessage][消息内容({})]", message); + mailSendService.doSendMail(message); } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index aee02c76e..275a45825 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; +import java.util.List; import java.util.Map; /** @@ -16,29 +17,34 @@ import java.util.Map; @EqualsAndHashCode(callSuper = true) public class MailSendMessage extends AbstractStreamMessage { + /** + * 日志id + */ + @NotNull(message = "邮箱日志id不能为空") + private Long logId; /** * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String address; + private String from; /** - * 短信模板编号 + * 邮箱模板编号 */ - @NotNull(message = "短信模板编号不能为空") + @NotNull(message = "邮箱模板编号不能为空") private String templateCode; /** - * 短信模板参数 + * 收件人 */ - private Map templateParams; - + @NotNull(message = "收件人不能为空") + private List tos; /** - * 用户编号,允许空 + * 标题 */ - private Integer userId; + private String title; /** - * 用户类型,允许空 + * 内容 */ - private Integer userType; + private String content; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java new file mode 100644 index 000000000..ed82c24a4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.system.mq.producer.mail; + +import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Mail 邮件相关消息的 Producer + * + * @author wangjingyi + * @date 2021/4/19 13:33 + */ +@Slf4j +@Component +public class MailProducer { + + @Resource + private RedisMQTemplate redisMQTemplate; + + /** + * 发送 {@link SmsChannelRefreshMessage} 消息 + */ + public void sendMailChannelRefreshMessage() { + SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link SmsTemplateRefreshMessage} 消息 + */ + public void sendMailTemplateRefreshMessage() { + SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link MailSendMessage} 消息 + * + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 邮箱模版信息 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + MailSendMessage message = new MailSendMessage(); + message.setContent(content); + message.setFrom(mailAccountDO.getFrom()); + message.setTemplateCode(mailTemplateDO.getCode()); + message.setTitle(title); + message.setTos(tos); + message.setLogId(sendLogId); + redisMQTemplate.send(message); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index fa195259b..0a5d25ba2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -4,7 +4,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.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; @@ -28,4 +30,18 @@ public interface MailLogService { * @return */ List getMailLogList(MailLogExportReqVO exportReqVO); + + /** + * 创建邮箱日志 + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 + */ + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + + Long updateSmsSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java new file mode 100644 index 000000000..31f6a3f3e --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -0,0 +1,41 @@ +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.send.MailReqVO; +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.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * 邮箱模版服务类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailSendService { + + /** + * 发送邮件 + * + * @param templateCode 邮件模版编码 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + void sendMail(String templateCode, String from , String content , List tos , String title); + + /** + * 执行真正的邮件发送 + * 注意,该方法仅仅提供给 MQ Consumer 使用 + * + * @param message 邮件 + */ + void doSendMail(MailSendMessage message); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1071eae5d..b8101f0af 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import javax.validation.Valid; import java.util.List; +import java.util.Map; /** * 邮箱模版服务类 @@ -18,6 +19,7 @@ import java.util.List; */ public interface MailTemplateService { + void initLocalCache(); /** * 邮箱模版创建 * @@ -62,6 +64,13 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** + *从缓存中获取邮箱模版 + * + * @param code 模板编码 + * @return 邮箱模板 + */ + MailTemplateDO getMailTemplateByCodeFromCache(String code); /** * 发送邮件 @@ -69,4 +78,12 @@ public interface MailTemplateService { * @param mailReqVO 邮件发送信息 */ void sendMail(MailReqVO mailReqVO); + + /** + * 邮件模版内容合成 + * @param content 邮箱模版 + * @param params 合成参数 + * @return + */ + String formateMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index aa1fb1d46..36ca05213 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou 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.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -16,8 +17,7 @@ import javax.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -47,8 +47,8 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 - this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); + // username 要校验唯一 + this.validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailAccountExists(mailAccountDO.getId()); @@ -57,9 +57,10 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { - // TODO @wangjingyi:删除时,要判断是否有使用的模板 - // 校验是否存在 + // 校验是否存在账号 this.validateMailAccountExists(id); + // 校验是否存在关联模版 + this.validateMailTemplateByAccountId(id); mailAccountMapper.deleteById(id); } @@ -90,4 +91,11 @@ public class MailAccountServiceImpl implements MailAccountService { throw exception(MAIL_ACCOUNT_EXISTS); } } + + private void validateMailTemplateByAccountId(Long accountId){ + MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); + if (mailTemplateDO != null) { + throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + } + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index c6b492498..bdceb0d72 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -4,14 +4,21 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.sql.Timestamp; +import java.util.Date; import java.util.List; +import java.util.Objects; /** * 邮箱日志实现类 @@ -35,4 +42,39 @@ public class MailLogServiceImpl implements MailLogService { public List getMailLogList(MailLogExportReqVO exportReqVO) { return mailLogMapper.selectList(exportReqVO); } + + @Override + public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.accountId(mailAccountDO.getId()); + logDOBuilder.content(content); + logDOBuilder.title(title); + logDOBuilder.templateCode(mailTemplateDO.getCode()); + logDOBuilder.templateId(mailTemplateDO.getId()); + logDOBuilder.to(tos.toString()); + logDOBuilder.sendTime(new Date()); + logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() + : MailSendStatusEnum.IGNORE.getStatus()); + + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } + + @Override + public Long updateSmsSendResult(Long logId, String result) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId); + logDOBuilder.sendResult(result); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + return logId; + } + + public Long create(){ + MailLogDO mailLogDO = new MailLogDO(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java new file mode 100644 index 000000000..61e428048 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -0,0 +1,107 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.hutool.extra.mail.MailAccount; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; +import cn.iocoder.yudao.module.system.service.mail.MailLogService; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; + +/** + * 邮箱模版 服务实现类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +@Validated +@Slf4j +public class MailSendServiceImpl implements MailSendService { + + @Resource + private MailTemplateMapper mailTemplateMapper; + @Resource + private MailAccountMapper mailAccountMapper; + @Resource + private MailTemplateService mailTemplateService; + @Resource + private MailLogService mailLogService; + @Resource + private MailClientFactory mailClientFactory; + @Resource + private MailProducer mailProducer; + + + @Override + public void sendMail(String templateCode, String from , String content , List tos , String title) { + // TODO @@wangjingyi:发送的时候,参考下短信; + MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); + // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 + Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from", from + ); + Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); + content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); + + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); + + // 发送 MQ 消息,异步执行发送短信 + if (isSend) { + mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + } + } + + @Override + public void doSendMail(MailSendMessage message) { + MailClient mailClient = mailClientFactory.getMailClient(); + String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + mailLogService.updateSmsSendResult(message.getLogId() , result); + } + + private MailTemplateDO checkMailTemplateValid(String templateCode) { + MailTemplateDO mailTemplateDO = mailTemplateService.getMailTemplateByCodeFromCache(templateCode); + if (mailTemplateDO == null){ + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + return mailTemplateDO; + } + + private void validateMailTemplateExists(Long id) { + if (mailTemplateMapper.selectById(id) == null) { + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + } + + private void validateMailTemplateOnlyByCode(String code){ + if (mailTemplateMapper.selectOneByCode(code) != null) { + throw exception(MAIL_TEMPLATE_EXISTS); + } + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 2bd74ac4c..e1d212186 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; @@ -13,14 +15,18 @@ import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Date; import java.util.List; import java.util.Map; @@ -36,6 +42,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL */ @Service @Validated +@Slf4j public class MailTemplateServiceImpl implements MailTemplateService { @Resource @@ -43,6 +50,38 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailAccountMapper mailAccountMapper; + private volatile List mailTemplateDOList; + + /** + * 邮件模板缓存 + * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailTemplateCache; + + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + if(maxUpdateTime == null){ + mailTemplateDOList = mailTemplateMapper.selectList(); + }else{ + if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ + return; + } + } + if (CollUtil.isEmpty(mailTemplateDOList)) { + return; + } + + // 写入缓存 + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); + log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); + } + @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 @@ -54,11 +93,9 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailTemplateExists(mailTemplateDO.getId()); + this.validateMailTemplateExists(updateReqVO.getId()); + MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); } @@ -80,6 +117,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public List getMailTemplateList() {return mailTemplateMapper.selectList();} + @Override + public MailTemplateDO getMailTemplateByCodeFromCache(String code) { + return mailTemplateCache.get(code); + } + @Override public void sendMail(MailReqVO mailReqVO) { // TODO @@wangjingyi:发送的时候,参考下短信; @@ -102,6 +144,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + @Override + public String formateMailTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + private void validateMailTemplateExists(Long id) { if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); From 0b0e37a3d50f05b6518acdaed2f761a81f9bfd17 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 2 May 2022 23:21:45 +0800 Subject: [PATCH 17/41] =?UTF-8?q?code=20review=20=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 6 +++++- .../admin/mail/MailTemplateController.java | 3 +++ .../mail/vo/account/MailAccountPageReqVO.java | 1 + .../service/mail/MailAccountService.java | 1 - .../system/service/mail/MailLogService.java | 19 ++++++++++------- .../service/mail/MailTemplateService.java | 1 + .../mail/impl/MailAccountServiceImpl.java | 21 ++++++++++++------- .../service/mail/impl/MailLogServiceImpl.java | 3 ++- .../mail/impl/MailSendServiceImpl.java | 2 +- .../mail/impl/MailTemplateServiceImpl.java | 6 ++++++ 10 files changed, 44 insertions(+), 19 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index c16c7a60b..864c106d6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -24,7 +24,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - @Api(tags = "管理后台 - 邮件账号") @RestController @RequestMapping("/system/mail-account") @@ -57,6 +56,9 @@ public class MailAccountController { return success(true); } + // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + @GetMapping("/get") @ApiOperation("获得邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -74,6 +76,8 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") public CommonResult> getSimpleMailAccountList() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index cffd7f980..f75c8daad 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -29,6 +29,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { + // TODO @wangjingyi:private @Autowired MailTemplateService mailTempleService; @@ -55,6 +56,8 @@ public class MailTemplateController { return success(true); } + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 520f31998..2ae2ad162 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -12,6 +12,7 @@ import lombok.ToString; @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index c1289154f..e8937d973 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; import java.util.List; - /** * 邮箱账号 Service 接口 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 0a5d25ba2..f5d417411 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -1,6 +1,5 @@ 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.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -11,14 +10,16 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; /** - * 邮箱日志服务类 + * 邮箱日志服务类 * * @author wangjingyi * @since 2022-03-21 */ public interface MailLogService { + /** * 邮箱日志分页 + * * @param pageVO * @return */ @@ -26,6 +27,7 @@ public interface MailLogService { /** * 邮箱日志数组信息 + * * @param exportReqVO * @return */ @@ -33,13 +35,14 @@ public interface MailLogService { /** * 创建邮箱日志 - * @param mailAccountDO 邮箱账号信息 + * + * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index b8101f0af..99b8fafef 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ import java.util.Map; public interface MailTemplateService { void initLocalCache(); + /** * 邮箱模版创建 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 36ca05213..06945127c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** - * 邮箱账号 Service 实现类 + * 邮箱账号 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -39,28 +39,34 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); + validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); + + // 更新 return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 - this.validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 + validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); + validateMailAccountExists(mailAccountDO.getId()); + + // 更新 mailAccountMapper.updateById(mailAccountDO); } @Override public void delete(Long id) { // 校验是否存在账号 - this.validateMailAccountExists(id); + validateMailAccountExists(id); // 校验是否存在关联模版 - this.validateMailTemplateByAccountId(id); + validateMailTemplateByAccountId(id); + + // 删除 mailAccountMapper.deleteById(id); } @@ -95,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService { private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS throw exception(MAIL_RELATE_TEMPLATE_EXISTS); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index bdceb0d72..7c1b277da 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -62,6 +61,7 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } + // TODO @wangjingyi:不需要返回 id 呀 @Override public Long updateSmsSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); @@ -72,6 +72,7 @@ public class MailLogServiceImpl implements MailLogService { return logId; } + // TODO @wangjingyi:无用的方法,需要进行删除 public Long create(){ MailLogDO mailLogDO = new MailLogDO(); mailLogMapper.insert(mailLogDO); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 61e428048..f2146f027 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; @@ -80,6 +79,7 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 MailClient mailClient = mailClientFactory.getMailClient(); String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); mailLogService.updateSmsSendResult(message.getLogId() , result); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index e1d212186..f3d85841e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -62,6 +62,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 @Override @PostConstruct public void initLocalCache() { @@ -85,9 +86,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 this.validateMailTemplateOnlyByCode(createReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); + // TODO @wangjingyi:mq 更新 return mailTemplateDO.getId(); } @@ -97,6 +100,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { this.validateMailTemplateExists(updateReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); + // TODO @wangjingyi:mq 更新 } @Override @@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); + // TODO @wangjingyi:mq 更新 } @Override @@ -144,6 +149,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + // TODO @@wangjingyi:单词拼写错误 @Override public String formateMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From ea92b8412173b0ef0c65e30e9cbebcd56e029ed6 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 4 May 2022 22:31:12 +0800 Subject: [PATCH 18/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4mail-module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 - .../pom.xml | 65 ------------------ .../config/YudaoMailAutoConfiguration.java | 21 ------ .../mail/core/client/MailClient.java | 23 ------- .../mail/core/client/MailClientFactory.java | 5 -- .../mail/core/client/MailCodeMapping.java | 17 ----- .../mail/core/client/MailCommonResult.java | 68 ------------------- .../core/client/dto/MailReceiveRespDTO.java | 48 ------------- .../mail/core/client/dto/MailSendRespDTO.java | 18 ----- .../core/client/dto/MailTemplateRespDTO.java | 31 --------- .../core/client/impl/AbstractMailClient.java | 14 ---- .../client/impl/MailClientFactoryImpl.java | 39 ----------- .../client/impl/hutool/HutoolMailClient.java | 29 -------- .../impl/hutool/HutoolMailCodeMapping.java | 20 ------ .../mail/core/enums/MailChannelEnum.java | 32 --------- .../MailFrameworkErrorCodeConstants.java | 47 ------------- .../enums/MailTemplateAuditStatusEnum.java | 21 ------ .../core/property/MailChannelProperties.java | 52 -------------- .../system/enums/ErrorCodeConstants.java | 18 +++-- .../yudao-module-system-biz/pom.xml | 4 -- .../convert/mail/MailTemplateConvert.java | 4 -- .../mail/impl/MailSendServiceImpl.java | 10 +-- 22 files changed, 14 insertions(+), 573 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 42c887c56..73bb614cd 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,7 +30,6 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms - yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml deleted file mode 100644 index 8cca21778..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - cn.iocoder.boot - yudao-framework - ${revision} - - 4.0.0 - yudao-spring-boot-starter-biz-mail - jar - - - - cn.iocoder.boot - yudao-common - - - - - org.springframework.boot - spring-boot-starter - - - - - io.opentracing - opentracing-util - - - - - cn.iocoder.boot - yudao-spring-boot-starter-test - test - - - - - com.google.guava - guava - true - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - - - - jakarta.validation - jakarta.validation-api - - - org.projectlombok - lombok - - - - \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java deleted file mode 100644 index c83b1e5f1..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.config; - -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * 邮箱配置类 - * - * @author 芋道源码 - */ -@Configuration -public class YudaoMailAutoConfiguration { - - @Bean - public MailClientFactory mailClientFactory() { - return new MailClientFactoryImpl(); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java deleted file mode 100644 index a17260410..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import java.util.List; - -/** - * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 - * - * @author wangjingyi - * @date 2021/4/19 19:21 - */ -public interface MailClient { - - /** - * 发送邮件 - * - * @param from 邮箱账号 - * @param content 内容 - * @param title 标题 - * @param tos 收件人 - * @return 邮件发送结果 - */ - String sendMail(String from, String content, String title, List tos); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java deleted file mode 100644 index 3244dfe76..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -public interface MailClientFactory { - MailClient getMailClient(); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java deleted file mode 100644 index c33b4be3e..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -import java.util.function.Function; - -/** - * 将 API 的错误码,转换为通用的错误码 - * - * @see MailCommonResult - * @see MailFrameworkErrorCodeConstants - * - * @author 芋道源码 - */ -public interface MailCodeMapping extends Function { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java deleted file mode 100644 index a53a3b989..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -/** - * 短信的 CommonResult 拓展类 - * - * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 - * - * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 - * - * @author 芋道源码 - */ -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailCommonResult extends CommonResult { - - /** - * API 返回错误码 - * - * 由于第三方的错误码可能是字符串,所以使用 String 类型 - */ - private String apiCode; - /** - * API 返回提示 - */ - private String apiMsg; - - /** - * API 请求编号 - */ - private String apiRequestId; - - private MailCommonResult() { - } - - public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, - T data, MailCodeMapping codeMapping) { - Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); - MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); - result.setData(data); - // 翻译错误码 - if (codeMapping != null) { - ErrorCode errorCode = codeMapping.apply(apiCode); - if (errorCode == null) { - errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; - } - result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); - } - return result; - } - - public static MailCommonResult error(Throwable ex) { - MailCommonResult result = new MailCommonResult<>(); - result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); - result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); - return result; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java deleted file mode 100644 index 11f27f58a..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -import java.util.Date; - -/** - * 消息接收 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailReceiveRespDTO { - - /** - * 是否接收成功 - */ - private Boolean success; - /** - * API 接收结果的编码 - */ - private String errorCode; - /** - * API 接收结果的说明 - */ - private String errorMsg; - - /** - * 手机号 - */ - private String mobile; - /** - * 用户接收时间 - */ - private Date receiveTime; - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - /** - * 短信日志编号 - * - * 对应 SysSmsLogDO 的编号 - */ - private Long logId; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java deleted file mode 100644 index b4a94a634..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信发送 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailSendRespDTO { - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java deleted file mode 100644 index 14bdeacd8..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信模板 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailTemplateRespDTO { - - /** - * 模板编号 - */ - private String id; - /** - * 短信内容 - */ - private String content; - /** - * 审核状态 - * - */ - private Integer auditStatus; - /** - * 审核未通过的理由 - */ - private String auditReason; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java deleted file mode 100644 index 097c8e095..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; - -/** - * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 - * - * @author zzf - * @date 2021/2/1 9:28 - */ -@Slf4j -public abstract class AbstractMailClient implements MailClient { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java deleted file mode 100644 index 9923bd3df..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import cn.iocoder.yudao.framework.mail.core.client.MailClient; -import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -@Validated -@Slf4j -public class MailClientFactoryImpl implements MailClientFactory { - - private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); - - public MailClientFactoryImpl (){ - Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { - AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); - channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); - }); - } - - private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { - switch (mailChannelEnum){ - case HUTOOL: return new HutoolMailClient(); - } - // 创建失败,错误日志 + 抛出异常 - log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); - } - - @Override - public MailClient getMailClient() { - return channelCodeClients.get("HUTOOL"); - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java deleted file mode 100644 index 457ad7e37..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.hutool.extra.mail.MailUtil; -import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; - - -/** - * 邮件客户端实现 - * - * @author wangjingyi - * @date 2021/4/25 14:25 - */ -@Slf4j -public class HutoolMailClient extends AbstractMailClient { - - @Override - public String sendMail(String from, String content, String title, List tos) { - try{ - return MailUtil.send(from , title , content , false , null); - }catch (Exception e){ - log.error(e.getMessage()); - } - return ""; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java deleted file mode 100644 index 711d36950..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; - -/** - * 阿里云的 SmsCodeMapping 实现类 - * - * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 - * - * @author 芋道源码 - */ -public class HutoolMailCodeMapping implements MailCodeMapping { - - @Override - public ErrorCode apply(String apiCode) { - return null; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java deleted file mode 100644 index 51d2f1fca..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.hutool.core.util.ArrayUtil; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信渠道枚举 - * - * @author zzf - * @date 2021/1/25 10:56 - */ -@Getter -@AllArgsConstructor -public enum MailChannelEnum { - HUTOOL("HUTOOL" , "HUTOOL"), - ; - - /** - * 编码 - */ - private final String code; - /** - * 名字 - */ - private final String name; - - public static MailChannelEnum getByCode(String code) { - return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java deleted file mode 100644 index e5ef74cf3..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; - -/** - * 短信框架的错误码枚举 - * - * 短信框架,使用 2-001-000-000 段 - * - * @author 芋道源码 - */ -public interface MailFrameworkErrorCodeConstants { - - ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); - - // ========== 权限 / 限流等相关 2001000100 ========== - - ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); - // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 - ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); - - // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 - ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); - // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 - ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); - - ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); - - // ========== 模板相关 2001000200 ========== - ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 - ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); - - // ========== 签名相关 2001000300 ========== - ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); - - // ========== 账户相关 2001000400 ========== - ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); - ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); - - // ========== 其它相关 2001000900 开头 ========== - ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); - ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); - ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); - - ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java deleted file mode 100644 index 95c3c31a3..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信模板的审核状态枚举 - * - * @author 芋道源码 - */ -@AllArgsConstructor -@Getter -public enum MailTemplateAuditStatusEnum { - - CHECKING(1), - SUCCESS(2), - FAIL(3); - - private final Integer status; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java deleted file mode 100644 index 1f19ac12b..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.property; - -import lombok.Data; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 短信渠道配置类 - * - * @author zzf - * @date 2021/1/25 17:01 - */ -@Data -@Validated -public class MailChannelProperties { - - /** - * 渠道编号 - */ - @NotNull(message = "短信渠道 ID 不能为空") - private Long id; - /** - * 短信签名 - */ - @NotEmpty(message = "短信签名不能为空") - private String signature; - /** - * 渠道编码 - * - * 枚举 {@link MailChannelEnum} - */ - @NotEmpty(message = "渠道编码不能为空") - private String code; - /** - * 短信 API 的账号 - */ - @NotEmpty(message = "短信 API 的账号不能为空") - private String apiKey; - /** - * 短信 API 的秘钥 - */ - @NotEmpty(message = "短信 API 的秘钥不能为空") - private String apiSecret; - /** - * 短信发送回调 URL - */ - private String callbackUrl; - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 07322ccd7..d514345da 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -119,13 +119,17 @@ public interface ErrorCodeConstants { ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002018001, "社交解绑失败,非当前用户绑定"); ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002018002, "社交授权失败,找不到对应的用户"); - // ========== 邮箱账号 1002019000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019001, "邮箱账号存在"); + // ========== 系统铭感词 1002019000 ========= + ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1002019000, "系统敏感词在所有标签中都不存在"); + ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1002019001, "系统敏感词已在标签中存在"); - // ========== 邮箱模版 1002020000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); + // ========== 邮箱账号 1002020000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + + // ========== 邮箱模版 1002021000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml index 2240f3b95..e23ba8ab8 100644 --- a/yudao-module-system/yudao-module-system-biz/pom.xml +++ b/yudao-module-system/yudao-module-system-biz/pom.xml @@ -42,10 +42,6 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict - - cn.iocoder.boot - yudao-spring-boot-starter-biz-mail - cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 3f4693bcb..35c6c0a9b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -1,11 +1,7 @@ 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.account.MailAccountBaseVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvertImpl; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index f2146f027..bc4b496f1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -13,10 +13,8 @@ import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; import javax.annotation.Resource; import java.util.List; @@ -46,8 +44,6 @@ public class MailSendServiceImpl implements MailSendService { @Resource private MailLogService mailLogService; @Resource - private MailClientFactory mailClientFactory; - @Resource private MailProducer mailProducer; @@ -80,9 +76,9 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - MailClient mailClient = mailClientFactory.getMailClient(); - String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - mailLogService.updateSmsSendResult(message.getLogId() , result); + //MailClient mailClient = mailClientFactory.getMailClient(); + //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + //mailLogService.updateSmsSendResult(message.getLogId() , result); } private MailTemplateDO checkMailTemplateValid(String templateCode) { From 8bc5254e308ab0d774635f0629bc508f58c8041a Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 03:06:00 +0800 Subject: [PATCH 19/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=20=E4=BF=AE=E6=94=B9=E6=A0=A1=E9=AA=8C=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/MailAccountController.java | 4 +- .../admin/mail/MailTemplateController.java | 25 ++--- .../mail/vo/account/MailAccountBaseVO.java | 4 - .../vo/account/MailAccountCreateReqVO.java | 6 ++ .../vo/account/MailAccountUpdateReqVO.java | 3 + .../mail/vo/template/MailTemplateRespVO.java | 4 + .../convert/mail/MailAccountConvert.java | 3 +- .../convert/mail/MailTemplateConvert.java | 7 +- .../dal/mysql/mail/MailAccountMapper.java | 17 ++++ .../dal/mysql/mail/MailTemplateMapper.java | 2 +- .../mail/MailTemplateRefreshConsumer.java | 29 ++++++ .../mail/MailAccountRefreshMessage.java | 19 ++++ .../mq/message/mail/MailSendMessage.java | 24 +++++ .../mail/MailTemplateRefreshMessage.java | 19 ++++ .../system/mq/producer/mail/MailProducer.java | 19 ++-- .../service/mail/MailAccountService.java | 5 + .../system/service/mail/MailLogService.java | 8 +- .../service/mail/MailTemplateService.java | 12 +-- .../mail/impl/MailAccountServiceImpl.java | 86 +++++++++++++--- .../service/mail/impl/MailLogServiceImpl.java | 13 +-- .../mail/impl/MailSendServiceImpl.java | 41 +++++--- .../mail/impl/MailTemplateServiceImpl.java | 98 +++++++++---------- 23 files changed, 318 insertions(+), 132 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index d514345da..32ba7181e 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -130,6 +130,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002021000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 864c106d6..17a305c48 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -57,7 +57,7 @@ public class MailAccountController { } // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE @GetMapping("/get") @ApiOperation("获得邮箱账号") @@ -76,7 +76,7 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index f75c8daad..2fae6164b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -3,10 +3,7 @@ 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.send.MailReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -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.*; 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.MailTemplateService; @@ -29,9 +26,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { - // TODO @wangjingyi:private + // TODO @wangjingyi:private DONE @Autowired - MailTemplateService mailTempleService; + private MailTemplateService mailTempleService; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -56,13 +53,13 @@ public class MailTemplateController { return success(true); } - // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 DONE RespVO中需要BaseVO 中哪些字段 @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:get')") - public CommonResult getMailTemplate(@RequestParam("id") Long id) { + public CommonResult getMailTemplate(@RequestParam("id") Long id) { MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id); return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); } @@ -70,25 +67,17 @@ public class MailTemplateController { @GetMapping("/page") @ApiOperation("获得邮箱模版分页") @PreAuthorize("@ss.hasPermission('system:mail-template:query')") - public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { + public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); } @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱模版精简列表") - public CommonResult> getSimpleTemplateList() { + public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); // 排序后,返回给前端 list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } - - @PostMapping("/send") - @ApiOperation("发送邮件") - @PreAuthorize("@ss.hasPermission('system:mail-template:send')") - public CommonResult sendMail(@Valid @RequestBody MailReqVO mailReqVO){ - mailTempleService.sendMail(mailReqVO); - return success(true); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index d8650b52e..b785b74cc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -20,10 +20,6 @@ public class MailAccountBaseVO { @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") @NotNull(message = "网站必填") private String host; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 8585e9d75..476a3077a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -1,14 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 邮箱账号创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountCreateReqVO extends MailAccountBaseVO { + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 43a13ad18..4544e95b5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -18,4 +18,7 @@ public class MailAccountUpdateReqVO extends MailAccountBaseVO { @NotNull(message = "编号不能为空") private Long id; + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java new file mode 100644 index 000000000..33683b1c5 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +public class MailTemplateRespVO extends MailTemplateBaseVO{ +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index 8dbfbc58d..f2228e170 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -4,6 +4,7 @@ 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.MailAccountBaseVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,7 +24,7 @@ public interface MailAccountConvert { List convertList02(List list); - default MailAccount convertAccount(MailAccountDO mailAccountDO){ + default MailAccount convertAccount(MailSendMessage mailAccountDO){ return new MailAccount() .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 35c6c0a9b..87fd8efe7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -2,6 +2,7 @@ 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.MailTemplateBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,9 +15,9 @@ public interface MailTemplateConvert { MailTemplateDO convert(MailTemplateBaseVO baseVO); - MailTemplateBaseVO convert(MailTemplateDO mailTemplateDO); + MailTemplateRespVO convert(MailTemplateDO mailTemplateDO); - PageResult convertPage(PageResult pageResult); + PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 651f5c75f..420b24eeb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,6 +7,9 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -25,4 +28,18 @@ public interface MailAccountMapper extends BaseMapperX { return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); }; + + default MailAccountDO selectByUserNameAndId(String userName,Long id){ + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName) + .neIfPresent("id" , id)); + }; + + default MailAccountDO selectOneByFrom(String from){ + return selectOne(new QueryWrapperX() + .eqIfPresent("from" , from)); + }; + + @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") + Long selectCountByUpdateTimeGt(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index a5cbf0b2a..d7d1cd73c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -30,7 +30,7 @@ public interface MailTemplateMapper extends BaseMapperX { .eqIfPresent("code" , code)); }; - @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + @Select("SELECT COUNT(*) FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") Long selectByMaxUpdateTime(Date maxUpdateTime); default MailTemplateDO selectOneByAccountId(Long accountId){ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java new file mode 100644 index 000000000..b4eac0165 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.system.mq.consumer.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 针对 {@link MailTemplateRefreshMessage} 的消费者 + * + * @author wangjingyi + */ +@Component +@Slf4j +public class MailTemplateRefreshConsumer extends AbstractChannelMessageListener { + + @Resource + private MailTemplateService mailTemplateService; + + @Override + public void onMessage(MailTemplateRefreshMessage message) { + log.info("[onMessage][收到 MailTemplate 刷新信息]"); + mailTemplateService.initLocalCache(); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java new file mode 100644 index 000000000..d5eafb04d --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱账号的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailAccountRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-account.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 275a45825..3df7c6dcf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -27,6 +27,16 @@ public class MailSendMessage extends AbstractStreamMessage { */ @NotNull(message = "邮箱地址不能为空") private String from; + /** + * 用户名 + */ + @NotNull(message = "用户名不能为空") + private String username; + /** + * 密码 + */ + @NotNull(message = "密码不能为空") + private String password; /** * 邮箱模板编号 */ @@ -45,6 +55,20 @@ public class MailSendMessage extends AbstractStreamMessage { * 内容 */ private String content; + /** + * 主机 + */ + @NotNull(message = "host不能为空") + private String host; + /** + * 端口 + */ + @NotNull(message = "端口号不能为空") + private Integer port; + /** + * 是否开启 SSL + */ + private Boolean sslEnable; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java new file mode 100644 index 000000000..476411ca1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱模板的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailTemplateRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-template.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index ed82c24a4..db8bbebf6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -4,7 +4,9 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; @@ -28,18 +30,18 @@ public class MailProducer { private RedisMQTemplate redisMQTemplate; /** - * 发送 {@link SmsChannelRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailChannelRefreshMessage() { - SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + public void sendMailTemplateRefreshMessage() { + MailTemplateRefreshMessage message = new MailTemplateRefreshMessage(); redisMQTemplate.send(message); } /** - * 发送 {@link SmsTemplateRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailTemplateRefreshMessage() { - SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + public void sendMailAccountRefreshMessage() { + MailAccountRefreshMessage message = new MailAccountRefreshMessage(); redisMQTemplate.send(message); } @@ -56,6 +58,11 @@ public class MailProducer { MailSendMessage message = new MailSendMessage(); message.setContent(content); message.setFrom(mailAccountDO.getFrom()); + message.setHost(mailAccountDO.getHost()); + message.setPort(mailAccountDO.getPort()); + message.setPassword(mailAccountDO.getPassword()); + message.setUsername(mailAccountDO.getUsername()); + message.setSslEnable(mailAccountDO.getSslEnable()); message.setTemplateCode(mailTemplateDO.getCode()); message.setTitle(title); message.setTos(tos); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index e8937d973..fe0615f4f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -17,6 +17,11 @@ import java.util.List; */ public interface MailAccountService { + /** + * 初始化邮箱账号的本地缓存 + */ + void initLocalCache(); + /** * 创建邮箱账号 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index f5d417411..da35012e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -46,5 +46,11 @@ public interface MailLogService { */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); - Long updateSmsSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId + */ + void updateMailSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 99b8fafef..873d337f4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -19,6 +19,9 @@ import java.util.Map; */ public interface MailTemplateService { + /** + * 初始化邮箱模版的本地缓存 + */ void initLocalCache(); /** @@ -73,18 +76,11 @@ public interface MailTemplateService { */ MailTemplateDO getMailTemplateByCodeFromCache(String code); - /** - * 发送邮件 - * - * @param mailReqVO 邮件发送信息 - */ - void sendMail(MailReqVO mailReqVO); - /** * 邮件模版内容合成 * @param content 邮箱模版 * @param params 合成参数 * @return */ - String formateMailTemplateContent(String content, Map params); + String formatMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 06945127c..3ae44693b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,20 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.util.Date; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -28,6 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; */ @Service @Validated +@Slf4j public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -36,26 +45,71 @@ public class MailAccountServiceImpl implements MailAccountService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource + private MailProducer mailProducer; + + /** + * 邮箱账号缓存 + * key:邮箱账号编码 {@link MailAccountDO#getId()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailAccountCache; + + /** + * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 + */ + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + List mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime); + if (CollUtil.isEmpty(mailAccountDOList)) { + return; + } + + // 写入缓存 + mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId); + maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime); + log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size()); + } + + private List loadMailAccountIfUpdate(Date maxUpdateTime) { + //第一步 判断是否需要更新 + if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]"); + }else{ // 判断数据库中是否有更新的账号信息 + if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { + return null; + } + log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]"); + } + return mailAccountMapper.selectList(); + } + @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - validateMailAccountOnlyByUserName(createReqVO.getUsername()); + this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); // 更新 + mailProducer.sendMailAccountRefreshMessage(); return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 - validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE + this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 validateMailAccountExists(mailAccountDO.getId()); // 更新 + mailProducer.sendMailAccountRefreshMessage(); mailAccountMapper.updateById(mailAccountDO); } @@ -65,9 +119,10 @@ public class MailAccountServiceImpl implements MailAccountService { validateMailAccountExists(id); // 校验是否存在关联模版 validateMailTemplateByAccountId(id); - // 删除 mailAccountMapper.deleteById(id); + // 更新 + mailProducer.sendMailAccountRefreshMessage(); } @Override @@ -92,17 +147,26 @@ public class MailAccountServiceImpl implements MailAccountService { } private void validateMailAccountOnlyByUserName(String userName){ - MailAccountDO mailAccountDO = mailAccountMapper.selectByUserName(userName); - if (mailAccountDO != null) { - throw exception(MAIL_ACCOUNT_EXISTS); - } + mailAccountCache.forEach((key,value)->{ + if(value.getUsername().equals(userName)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + }); + } + private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){ + mailAccountCache.forEach((key , value)->{ + if (value.getUsername().equals(userName)){ + if (!key.equals(id)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + } + }); } - private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS - throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); } } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 7c1b277da..76a7198ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -8,13 +8,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; -import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.Objects; @@ -61,21 +59,14 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 + // TODO @wangjingyi:不需要返回 id 呀 DONE @Override - public Long updateSmsSendResult(Long logId, String result) { + public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); logDOBuilder.id(logId); logDOBuilder.sendResult(result); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); - return logId; } - // TODO @wangjingyi:无用的方法,需要进行删除 - public Long create(){ - MailLogDO mailLogDO = new MailLogDO(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index bc4b496f1..6b0cccd83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; @@ -21,8 +22,7 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 邮箱模版 服务实现类 @@ -49,36 +49,47 @@ public class MailSendServiceImpl implements MailSendService { @Override public void sendMail(String templateCode, String from , String content , List tos , String title) { - // TODO @@wangjingyi:发送的时候,参考下短信; + // TODO @@wangjingyi:发送的时候,参考下短信;DONE + //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", from - ); + //校验账号信息是否合法 + MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); // 后续功能 TODO :附件查询 //List fileIds = mailSendVO.getFileIds(); - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - // 发送 MQ 消息,异步执行发送短信 if (isSend) { mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); } } + private MailAccountDO checkMailAccountValid(String from) { + MailAccountDO mailAccountDO = mailAccountMapper.selectOneByFrom(from); + if(null == mailAccountDO){ + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + return mailAccountDO; + } + @Override public void doSendMail(MailSendMessage message) { - // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - //MailClient mailClient = mailClientFactory.getMailClient(); - //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - //mailLogService.updateSmsSendResult(message.getLogId() , result); + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 DONE + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); + //发送邮件 + try{ + String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + mailLogService.updateMailSendResult(message.getLogId() , messageId); + }catch (Exception e){ + mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + } + } private MailTemplateDO checkMailTemplateValid(String templateCode) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index f3d85841e..89a0b43ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -48,59 +49,53 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; @Resource - private MailAccountMapper mailAccountMapper; - - private volatile List mailTemplateDOList; + private MailProducer mailProducer; /** * 邮件模板缓存 - * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * key:邮箱模板编码 {@link MailTemplateDO#getId()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - private volatile Map mailTemplateCache; + private volatile Map mailTemplateCache; private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { - if(maxUpdateTime == null){ - mailTemplateDOList = mailTemplateMapper.selectList(); - }else{ - if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ - return; - } - } + List mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime); if (CollUtil.isEmpty(mailTemplateDOList)) { return; } // 写入缓存 - mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); } @Override public Long create(MailTemplateCreateReqVO createReqVO) { - // code 要校验唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 - this.validateMailTemplateOnlyByCode(createReqVO.getCode()); + //要校验存在 + this.validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); return mailTemplateDO.getId(); } @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // 校验是否存在 - this.validateMailTemplateExists(updateReqVO.getId()); + // 校验是否唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -108,7 +103,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -127,43 +123,45 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } + // TODO @@wangjingyi:单词拼写错误 DONE @Override - public void sendMail(MailReqVO mailReqVO) { - // TODO @@wangjingyi:发送的时候,参考下短信; - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", mailReqVO.getFrom() - ); - String content = mailReqVO.getContent(); - Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = StrUtil.format(mailTemplateDO.getContent(), params); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - - //发送 - MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); - } - - // TODO @@wangjingyi:单词拼写错误 - @Override - public String formateMailTemplateContent(String content, Map params) { + public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); } private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { + if (mailTemplateCache.get(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); + private void validateMailTemplateOnlyByCode(Long id ,String code){ + mailTemplateCache.forEach((key,value)->{ + if (value.getCode().equals(code)){ + if (!key.equals(id)){ + throw exception(MAIL_TEMPLATE_EXISTS); + } + } + }); + } + /** + * 如果邮件模板发生变化,从数据库中获取最新的全量邮件模板。 + * 如果未发生变化,则返回空 + * + * @param maxUpdateTime 当前邮件模板的最大更新时间 + * @return 邮件模板列表 + */ + private List loadMailTemplateIfUpdate(Date maxUpdateTime) { + // 第一步,判断是否要更新。 + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailTemplateIfUpdate][首次加载全量邮件模板]"); + } else { // 判断数据库中是否有更新的邮件模板 + if (mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime) == 0) { + return null; + } + log.info("[loadSmsTemplateIfUpdate][增量加载全量邮件模板]"); } + // 第二步,如果有更新,则从数据库加载所有邮件模板 + return mailTemplateMapper.selectList(); } } From 8d6a4d40a08a6f265a848d412ad53c3278578f39 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 04:36:32 +0800 Subject: [PATCH 20/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/dataobject/mail/MailAccountDO.java | 2 ++ .../yudao/module/system/dal/mysql/mail/MailAccountMapper.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index d285adec5..7b17104ec 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -24,6 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ + @TableField("`from`") private String from; /** * 用户名 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 420b24eeb..e869ecf22 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("form" , pageReqVO.getFrom()) + .likeIfPresent("from" , pageReqVO.getFrom()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) From c3335ba2cacf436b14da2dbe95994fd29b7dc514 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:41:11 +0800 Subject: [PATCH 21/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/vo/account/MailAccountBaseVO.java | 4 ++-- .../admin/mail/vo/account/MailAccountPageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailAccountDO.java | 3 +-- .../system/dal/mysql/mail/MailAccountMapper.java | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index b785b74cc..8e392d476 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -13,11 +13,11 @@ public class MailAccountBaseVO { @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱必填") - private String from; + @Email(message = "必须是Email格式") + private String fromAddress; @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") - @Email(message = "必须是Email格式") private String username; @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 2ae2ad162..327c8465d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -14,7 +14,7 @@ import lombok.ToString; public class MailAccountPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") - private String from; + private String fromAddress; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") private String username; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 7b17104ec..910440df7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -25,8 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ - @TableField("`from`") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index e869ecf22..1e4f263ac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("from" , pageReqVO.getFrom()) + .likeIfPresent("from_address" , pageReqVO.getFromAddress()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) @@ -27,18 +27,18 @@ public interface MailAccountMapper extends BaseMapperX { default MailAccountDO selectByUserName(String userName){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); - }; + } default MailAccountDO selectByUserNameAndId(String userName,Long id){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName) .neIfPresent("id" , id)); - }; + } default MailAccountDO selectOneByFrom(String from){ return selectOne(new QueryWrapperX() - .eqIfPresent("from" , from)); - }; + .eqIfPresent("from_address" , from)); + } @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") Long selectCountByUpdateTimeGt(Date maxUpdateTime); From 63983bbab3d48b22847c22a589f51dc520795f11 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:52:34 +0800 Subject: [PATCH 22/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/convert/mail/MailAccountConvert.java | 8 ++++---- .../module/system/dal/dataobject/mail/MailLogDO.java | 2 +- .../module/system/mq/message/mail/MailSendMessage.java | 2 +- .../module/system/mq/producer/mail/MailProducer.java | 2 +- .../system/service/mail/impl/MailLogServiceImpl.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index f2228e170..b60ac088f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -29,18 +29,18 @@ public interface MailAccountConvert { .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) .setAuth(true) - .setFrom(mailAccountDO.getFrom()) + .setFrom(mailAccountDO.getFromAddress()) .setUser(mailAccountDO.getUsername()) .setPass(mailAccountDO.getPassword()) .setSslEnable(mailAccountDO.getSslEnable()); - }; + } default Map convertToMap(MailAccountDO mailAccountDO , String content) { Map map = new HashMap<>(); - map.put("from" , mailAccountDO.getFrom()); + map.put("from_address" , mailAccountDO.getFromAddress()); map.put("username" , mailAccountDO.getUsername()); map.put("content" , content); return map; - }; + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 7454d2acb..97cc51f4c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -39,7 +39,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号 */ - private String from; + private String fromAddress; /** * 模版主键 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 3df7c6dcf..fd1d68f6f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -26,7 +26,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index db8bbebf6..3b6745c26 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -57,7 +57,7 @@ public class MailProducer { public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { MailSendMessage message = new MailSendMessage(); message.setContent(content); - message.setFrom(mailAccountDO.getFrom()); + message.setFromAddress(mailAccountDO.getFromAddress()); message.setHost(mailAccountDO.getHost()); message.setPort(mailAccountDO.getPort()); message.setPassword(mailAccountDO.getPassword()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 76a7198ab..e251cc82e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -43,7 +43,7 @@ public class MailLogServiceImpl implements MailLogService { @Override public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); logDOBuilder.content(content); logDOBuilder.title(title); From 1464f7d399de68de75a6fb84aef8b58783982a16 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 17 May 2022 20:07:50 +0800 Subject: [PATCH 23/41] =?UTF-8?q?code=20review=20=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/test/TestDemoServiceImpl.java | 2 +- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/vo/log/MailLogPageReqVO.java | 3 ++ .../admin/mail/vo/send/MailReqVO.java | 1 - .../convert/mail/MailTemplateConvert.java | 2 ++ .../system/dal/dataobject/mail/MailLogDO.java | 1 - .../system/service/mail/MailLogService.java | 29 +++++++-------- .../service/mail/MailTemplateService.java | 8 +++-- .../service/mail/impl/MailLogServiceImpl.java | 36 ++++++++++++------- .../mail/impl/MailTemplateServiceImpl.java | 16 +++------ 10 files changed, 54 insertions(+), 46 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java index 92153b022..731a29ccc 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java @@ -79,7 +79,7 @@ public class TestDemoServiceImpl implements TestDemoService { @Override public PageResult getTestDemoPage(TestDemoPageReqVO pageReqVO) { -// testDemoMapper.selectList2(); + testDemoMapper.selectList2(); return testDemoMapper.selectPage(pageReqVO); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 32ba7181e..cb6db27e1 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -128,7 +128,7 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); // ========== 邮箱模版 1002021000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 9928a7746..67f91735b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -17,6 +17,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { + + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 65142ee3f..560c3bf42 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -34,5 +34,4 @@ public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该 @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 87fd8efe7..46a25b9e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -11,6 +11,7 @@ import java.util.List; @Mapper public interface MailTemplateConvert { + MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); MailTemplateDO convert(MailTemplateBaseVO baseVO); @@ -20,4 +21,5 @@ public interface MailTemplateConvert { PageResult convertPage(PageResult pageResult); List convertList02(List list); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 97cc51f4c..2472cd95f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -80,7 +80,6 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送结果 - * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index da35012e2..98a445c8a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -20,37 +20,38 @@ public interface MailLogService { /** * 邮箱日志分页 * - * @param pageVO - * @return + * @param pageVO 分页参数 + * @return 分页结果 */ PageResult getMailLogPage(MailLogPageReqVO pageVO); /** * 邮箱日志数组信息 * - * @param exportReqVO - * @return + * @param exportReqVO 导出筛选请求 + * @return 导出的日志数据 */ List getMailLogList(MailLogExportReqVO exportReqVO); /** * 创建邮箱日志 * - * @param mailAccountDO 邮箱账号信息 - * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param mailAccountDO 邮箱账号信息 + * @param template 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); /** * 更新邮件发送结果 * - * @param logId 发送日志Id - * @param result 发送结果 默认返回messageId + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId */ void updateMailSendResult(Long logId, String result); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 873d337f4..16d65b4f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -1,7 +1,6 @@ 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.send.MailReqVO; 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; @@ -68,8 +67,9 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** - *从缓存中获取邮箱模版 + * 从缓存中获取邮箱模版 * * @param code 模板编码 * @return 邮箱模板 @@ -78,9 +78,11 @@ public interface MailTemplateService { /** * 邮件模版内容合成 + * * @param content 邮箱模版 * @param params 合成参数 - * @return + * @return 格式化后的内容 */ String formatMailTemplateContent(String content, Map params); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index e251cc82e..afc7dcb93 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -27,6 +27,7 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { + // TODO @wangjingyi:private,然后使用 @Resource @Autowired MailLogMapper mailLogMapper; @@ -41,25 +42,34 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); - logDOBuilder.accountId(mailAccountDO.getId()); - logDOBuilder.content(content); - logDOBuilder.title(title); - logDOBuilder.templateCode(mailTemplateDO.getCode()); - logDOBuilder.templateId(mailTemplateDO.getId()); - logDOBuilder.to(tos.toString()); - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() : MailSendStatusEnum.IGNORE.getStatus()); + // 设置邮箱相关字段 + // TODO @wangjingyi:userId、userType + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); + logDOBuilder.accountId(mailAccountDO.getId()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 + logDOBuilder.to(tos.toString()); + // 设置模板相关字段 + // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams + logDOBuilder.templateId(template.getId()); + logDOBuilder.templateCode(template.getCode()); + logDOBuilder.title(title); + logDOBuilder.content(content); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 + logDOBuilder.sendTime(new Date()); - MailLogDO mailLogDO = logDOBuilder.build(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); + // 插入数据库 + MailLogDO logDO = logDOBuilder.build(); + mailLogMapper.insert(logDO); + return logDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 DONE + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 89a0b43ea..9f8315458 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -3,20 +3,13 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; 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.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -36,7 +29,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; /** - * 邮箱模版 服务实现类 + * 邮箱模版 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -48,6 +41,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource private MailProducer mailProducer; @@ -61,7 +55,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { @@ -78,8 +71,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { - //要校验存在 - this.validateMailTemplateExists(createReqVO.getId()); + // 要校验存在 + validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); // TODO @wangjingyi:mq 更新 DONE @@ -123,7 +116,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } - // TODO @@wangjingyi:单词拼写错误 DONE @Override public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From 0ddb50be579f87bafe1c577e485646b1c56994f7 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Mon, 11 Jul 2022 15:02:06 +0800 Subject: [PATCH 24/41] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E7=A0=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/mail/dto/MailSendReqDTO.java | 26 +++++----- .../system/enums/ErrorCodeConstants.java | 1 + .../enums/mail/MailLogUserTypeEnum.java | 22 ++++++++ .../admin/mail/vo/log/MailLogPageReqVO.java | 4 +- .../system/dal/dataobject/mail/MailLogDO.java | 45 +++++++++++------ .../dal/dataobject/mail/MailTemplateDO.java | 9 +++- .../mail/MailTemplateRefreshConsumer.java | 1 - .../mq/message/mail/MailSendMessage.java | 7 ++- .../system/mq/producer/mail/MailProducer.java | 33 ++++++------ .../system/service/mail/MailLogService.java | 20 ++++++-- .../system/service/mail/MailSendService.java | 8 +-- .../service/mail/impl/MailLogServiceImpl.java | 49 +++++++++++------- .../mail/impl/MailSendServiceImpl.java | 50 ++++++++++--------- .../mail/impl/MailTemplateServiceImpl.java | 2 +- 14 files changed, 175 insertions(+), 102 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java index a3b0f2e35..caa69678c 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -7,32 +7,32 @@ import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.Map; @ApiModel("管理后台 - 邮件发送 Req VO") @Data public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "邮箱账号不能为空") - @Email(message = "邮箱账号格式错误") - private String from; + @ApiModelProperty(value = "用户编码",required = true) + @NotNull(message = "用户编码不能为空") + private String userId; - @ApiModelProperty(value = "标题",example = "标题") - private String title; - - @ApiModelProperty(value = "内容",example = "内容") - private String content; + @ApiModelProperty(value = "用户类型",required = true) + @NotNull(message = "用户类型不能为空") + private String userType; @ApiModelProperty(value = "邮箱模版id",example = "1024") - @NotNull(message = "邮箱模版id不能为空") - private Integer templateId; + @NotNull(message = "邮箱模版编码不能为空") + private Integer templateCode; + + @ApiModelProperty(value = "邮箱参数") + @NotNull(message = "模版参数不能为空") + private Map templateParams; @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件",example = "附件编码") - private List fileIds; } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index cb6db27e1..4147383ae 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -131,5 +131,6 @@ public interface ErrorCodeConstants { ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java new file mode 100644 index 000000000..4154c9bc1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件日志用户类型 + * + * @author wangjingyi + */ +@Getter +@AllArgsConstructor +public enum MailLogUserTypeEnum { + + COMMON (10), + VIP (20); + + /** + * 类型 + */ + private final int userType; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 67f91735b..680fe6d1f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -18,9 +18,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { - // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 DONE - @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱" , example = "yudaoyuanma@123.com") private String from; @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 2472cd95f..d4b0e5f81 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,16 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; import java.io.Serializable; import java.util.Date; +import java.util.Map; /** * 邮箱日志 @@ -29,15 +33,29 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long id; + /** + * 用户编码 + */ + private Long userId; + + /** + * 用户类型 + * + * 冗余 {@link MailLogUserTypeEnum#getUserType} + */ + private Integer userType; + // TODO @wangjingyi:accountId /** * 邮箱账号编号 */ private Long accountId; - // TODO @wangjingyi:如果是冗余字段,记得 @ 下; + // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE /** * 邮箱账号 + * + * 冗余 {@link MailAccountDO} */ private String fromAddress; @@ -47,30 +65,22 @@ public class MailLogDO extends BaseDO implements Serializable { private Long templateId; /** - * 模版编号 + * 模版内容 */ - private String templateCode; + private String templateContent; /** - * 标题 + * 基于 {@link MailTemplateDO#getParams()} 输入后的参数 */ - private String title; - - /** - * 内容 - */ - private String content; - - /** - * 收件人 - */ - private String to; + @TableField(typeHandler = JacksonTypeHandler.class) + private Map templateParams; /** * 发送时间 */ private Date sendTime; + //=========接收相关字段========= /** * 发送状态 * @@ -83,5 +93,10 @@ public class MailLogDO extends BaseDO implements Serializable { */ private String sendResult; + /** + * 消息ID + */ + private String messageId; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index 96f9ba4ab..c4708657f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; +import java.util.List; /** * 邮箱模版 @@ -43,6 +45,11 @@ public class MailTemplateDO extends BaseDO { * 内容 */ private String content; + /** + * 参数数组(自动根据内容生成) + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List params; /** * 状态 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java index b4eac0165..199b147c8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index fd1d68f6f..6e8c46668 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.mq.message.mail; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage; import lombok.Data; import lombok.EqualsAndHashCode; @@ -46,7 +47,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 收件人 */ @NotNull(message = "收件人不能为空") - private List tos; + private String to; /** * 标题 */ @@ -69,6 +70,10 @@ public class MailSendMessage extends AbstractStreamMessage { * 是否开启 SSL */ private Boolean sslEnable; + /** + * 邮箱模板参数 + */ + private List> templateParams; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index 3b6745c26..50c505512 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -7,9 +7,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -48,25 +45,27 @@ public class MailProducer { /** * 发送 {@link MailSendMessage} 消息 * + * @param sendLogId 发送日志编码 * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 邮箱模版信息 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 邮箱模版参数 + * @param to 收件人 */ - public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List> templateParams,String to) { MailSendMessage message = new MailSendMessage(); - message.setContent(content); - message.setFromAddress(mailAccountDO.getFromAddress()); - message.setHost(mailAccountDO.getHost()); - message.setPort(mailAccountDO.getPort()); - message.setPassword(mailAccountDO.getPassword()); - message.setUsername(mailAccountDO.getUsername()); - message.setSslEnable(mailAccountDO.getSslEnable()); - message.setTemplateCode(mailTemplateDO.getCode()); - message.setTitle(title); - message.setTos(tos); - message.setLogId(sendLogId); + message.setContent(content) + .setFromAddress(mailAccountDO.getFromAddress()) + .setHost(mailAccountDO.getHost()) + .setPort(mailAccountDO.getPort()) + .setPassword(mailAccountDO.getPassword()) + .setUsername(mailAccountDO.getUsername()) + .setSslEnable(mailAccountDO.getSslEnable()) + .setTemplateCode(mailTemplateDO.getCode()) + .setTitle(mailTemplateDO.getTitle()) + .setTo(to) + .setLogId(sendLogId) + .setTemplateParams(templateParams); redisMQTemplate.send(message); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 98a445c8a..6b04f7a74 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; +import java.util.Map; /** * 邮箱日志服务类 @@ -36,15 +37,16 @@ public interface MailLogService { /** * 创建邮箱日志 * + * @param userId 用户编码 + * @param userType 用户类型 + * @param to 收件人 * @param mailAccountDO 邮箱账号信息 * @param template 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateContent 模版内容 + * @param templateParams 模版参数 * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend); /** * 更新邮件发送结果 @@ -54,4 +56,12 @@ public interface MailLogService { */ void updateMailSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param exception 发送结果 + */ + void updateFailMailSendResult(Long logId, String exception); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java index 31f6a3f3e..615b34fcf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -26,10 +26,12 @@ public interface MailSendService { * @param templateCode 邮件模版编码 * @param from 邮箱 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 模版参数 + * @param to 收件人 + * @param userId 用户编码 + * @param userType 用户类型 */ - void sendMail(String templateCode, String from , String content , List tos , String title); + void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams); /** * 执行真正的邮件发送 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index afc7dcb93..a7bf04fc7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -13,8 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -27,9 +29,9 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { - // TODO @wangjingyi:private,然后使用 @Resource - @Autowired - MailLogMapper mailLogMapper; + // TODO @wangjingyi:private,然后使用 @Resource DONE + @Resource + private MailLogMapper mailLogMapper; @Override public PageResult getMailLogPage(MailLogPageReqVO pageVO) { @@ -42,26 +44,29 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。DONE // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() - : MailSendStatusEnum.IGNORE.getStatus()); - // 设置邮箱相关字段 - // TODO @wangjingyi:userId、userType + : MailSendStatusEnum.IGNORE.getStatus()) + // 设置邮箱相关字段 + .fromAddress(mailAccountDO.getFromAddress()) + .accountId(mailAccountDO.getId()) + // TODO @wangjingyi:userId、userType + //用户信息 + .userId(userId).userType(userType) + //模版信息 + .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent); + + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); - // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 - logDOBuilder.to(tos.toString()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE // 设置模板相关字段 // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams - logDOBuilder.templateId(template.getId()); - logDOBuilder.templateCode(template.getCode()); - logDOBuilder.title(title); - logDOBuilder.content(content); - // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 DONE + //logDOBuilder.sendTime(new Date()); // 插入数据库 MailLogDO logDO = logDOBuilder.build(); @@ -69,14 +74,20 @@ public class MailLogServiceImpl implements MailLogService { return logDO.getId(); } - // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。DONE @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.id(logId); - logDOBuilder.sendResult(result); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(result).messageId(result).sendStatus(MailSendStatusEnum.SUCCESS.getStatus()); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); } + @Override + public void updateFailMailSendResult(Long logId, String exception) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(exception).sendStatus(MailSendStatusEnum.FAILURE.getStatus()); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 6b0cccd83..9a9e9fe50 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -2,17 +2,18 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -34,9 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Validated @Slf4j public class MailSendServiceImpl implements MailSendService { - - @Resource - private MailTemplateMapper mailTemplateMapper; + @Resource private MailAccountMapper mailAccountMapper; @Resource @@ -48,7 +48,7 @@ public class MailSendServiceImpl implements MailSendService { @Override - public void sendMail(String templateCode, String from , String content , List tos , String title) { + public void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams) { // TODO @@wangjingyi:发送的时候,参考下短信;DONE //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); @@ -58,14 +58,11 @@ public class MailSendServiceImpl implements MailSendService { MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); - Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - + Long sendLogId = mailLogService.createMailLog(userId,userType,to,mailAccountDO , mailTemplateDO , content, templateParams, isSend); + List> newTemplateParams = buildTemplateParams(mailTemplateDO,templateParams); // 发送 MQ 消息,异步执行发送短信 if (isSend) { - mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + mailProducer.sendMailSendMessage(sendLogId,mailAccountDO , mailTemplateDO ,content, newTemplateParams,to); } } @@ -84,10 +81,10 @@ public class MailSendServiceImpl implements MailSendService { MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); //发送邮件 try{ - String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + String messageId = MailUtil.send(account,message.getTo(),message.getTitle(),message.getContent(),false,null); mailLogService.updateMailSendResult(message.getLogId() , messageId); }catch (Exception e){ - mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + mailLogService.updateFailMailSendResult(message.getLogId() , e.getMessage()); } } @@ -99,16 +96,21 @@ public class MailSendServiceImpl implements MailSendService { } return mailTemplateDO; } - - private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { - throw exception(MAIL_TEMPLATE_NOT_EXISTS); - } - } - - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); - } + /** + * 将参数模板,处理成有序的 KeyValue 数组 + * + * @param template 邮箱模板 + * @param templateParams 原始参数 + * @return 处理后的参数 + */ + @VisibleForTesting + public List> buildTemplateParams(MailTemplateDO template, Map templateParams) { + return template.getParams().stream().map(key -> { + Object value = templateParams.get(key); + if (value == null) { + throw exception(MAIL_SEND_TEMPLATE_PARAM_MISS, key); + } + return new KeyValue<>(key, value); + }).collect(Collectors.toList()); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9f8315458..3fcac8b9e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -83,7 +83,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // 校验是否唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。DONE this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); From 0262fa5c153628e63c6c266026c7bb7a06d49f1a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 17:48:09 +0800 Subject: [PATCH 25/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20account=20=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/api/mail/MailSendApi.java | 30 +++ .../system/api/mail/dto/MailSendReqDTO.java | 38 --- .../mail/dto/MailSendSingleToUserReqDTO.java | 39 +++ .../system/enums/ErrorCodeConstants.java | 9 +- .../enums/mail/MailLogUserTypeEnum.java | 22 -- .../system/api/mail/MailSendApiImpl.java | 14 +- .../admin/mail/MailAccountController.java | 23 +- .../mail/vo/account/MailAccountBaseVO.java | 34 ++- .../vo/account/MailAccountCreateReqVO.java | 3 - .../mail/vo/account/MailAccountPageReqVO.java | 15 +- .../mail/vo/account/MailAccountRespVO.java | 25 ++ .../vo/account/MailAccountSimpleRespVO.java | 17 ++ .../vo/account/MailAccountUpdateReqVO.java | 3 - .../convert/mail/MailAccountConvert.java | 29 ++- .../dal/dataobject/mail/MailAccountDO.java | 9 +- .../system/dal/dataobject/mail/MailLogDO.java | 54 +++-- .../dal/dataobject/mail/MailTemplateDO.java | 7 +- .../dal/mysql/mail/MailAccountMapper.java | 28 +-- .../dal/mysql/mail/MailTemplateMapper.java | 8 +- .../system/mq/producer/mail/MailProducer.java | 2 +- .../service/mail/MailAccountService.java | 6 +- .../service/mail/MailTemplateService.java | 8 + .../mail/impl/MailAccountServiceImpl.java | 113 +++------ .../service/mail/impl/MailLogServiceImpl.java | 5 +- .../mail/impl/MailTemplateServiceImpl.java | 14 +- .../service/sms/SmsChannelServiceImpl.java | 2 +- yudao-ui-admin/src/api/system/mail/account.js | 44 ++++ .../src/views/system/mail/account/index.vue | 226 ++++++++++++++++++ 28 files changed, 555 insertions(+), 272 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java delete mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java create mode 100755 yudao-ui-admin/src/api/system/mail/account.js create mode 100755 yudao-ui-admin/src/views/system/mail/account/index.vue diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java index 2ffe0d7cb..3885259f2 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java @@ -1,4 +1,34 @@ package cn.iocoder.yudao.module.system.api.mail; +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO; + +import javax.validation.Valid; + +/** + * 邮箱发送 API 接口 + * + * @author 芋道源码 + */ public interface MailSendApi { + + /** + * 发送单条邮箱给 Admin 用户 + * + * 在 mail 为空时,使用 userId 加载对应 Admin 的邮箱 + * + * @param reqDTO 发送请求 + * @return 发送日志编号 + */ + Long sendSingleSmsToAdmin(@Valid MailSendSingleToUserReqDTO reqDTO); + + /** + * 发送单条邮箱给 Member 用户 + * + * 在 mail 为空时,使用 userId 加载对应 Member 的邮箱 + * + * @param reqDTO 发送请求 + * @return 发送日志编号 + */ + Long sendSingleSmsToMember(@Valid MailSendSingleToUserReqDTO reqDTO); + } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java deleted file mode 100644 index caa69678c..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.system.api.mail.dto; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Map; - -@ApiModel("管理后台 - 邮件发送 Req VO") -@Data -public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - - @ApiModelProperty(value = "用户编码",required = true) - @NotNull(message = "用户编码不能为空") - private String userId; - - @ApiModelProperty(value = "用户类型",required = true) - @NotNull(message = "用户类型不能为空") - private String userType; - - @ApiModelProperty(value = "邮箱模版id",example = "1024") - @NotNull(message = "邮箱模版编码不能为空") - private Integer templateCode; - - @ApiModelProperty(value = "邮箱参数") - @NotNull(message = "模版参数不能为空") - private Map templateParams; - - @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "收件人不能为空") - private List tos; - - - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java new file mode 100644 index 000000000..e2ede96ae --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.api.mail.dto; + +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import java.util.Map; + +/** + * 邮件发送 Request DTO + * + * @author wangjingqi + */ +@Data +public class MailSendSingleToUserReqDTO { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private String userId; + /** + * 邮箱 + */ + @Email + private String mail; + + /** + * 邮件模板编号 + */ + @NotNull(message = "邮件模板编号不能为空") + private String templateCode; + /** + * 邮件模板参数 + */ + @NotNull(message = "邮件模板参数不能为空") + private Map templateParams; + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index ead06b204..135248867 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/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 { ErrorCode OAUTH2_CODE_NOT_EXISTS = new ErrorCode(1002022000, "code 不存在"); ErrorCode OAUTH2_CODE_EXPIRE = new ErrorCode(1002022001, "code 已过期"); - // TODO @芋艿:需要重新搞下 mail 错误码 - - // ========== 邮箱账号 1002020000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + // ========== 邮箱账号 1002023000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002023000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002023001, "无法删除,该邮箱账号还有邮件模板"); // ========== 邮箱模版 1002021000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java deleted file mode 100644 index 4154c9bc1..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.system.enums.mail; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 邮件日志用户类型 - * - * @author wangjingyi - */ -@Getter -@AllArgsConstructor -public enum MailLogUserTypeEnum { - - COMMON (10), - VIP (20); - - /** - * 类型 - */ - private final int userType; -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java index cce0ed388..eaad0f8ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.api.mail; +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -10,5 +11,16 @@ import org.springframework.validation.annotation.Validated; */ @Service @Validated -public class MailSendApiImpl implements MailSendApi{ +public class MailSendApiImpl implements MailSendApi { + + @Override + public Long sendSingleSmsToAdmin(MailSendSingleToUserReqDTO reqDTO) { + return null; + } + + @Override + public Long sendSingleSmsToMember(MailSendSingleToUserReqDTO reqDTO) { + return null; + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 17a305c48..a18fb137b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/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; 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.MailAccountBaseVO; -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.send.MailReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -36,14 +32,14 @@ public class MailAccountController { @ApiOperation("创建邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:create')") public CommonResult createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) { - return success(mailAccountService.create(createReqVO)); + return success(mailAccountService.createMailAccount(createReqVO)); } @PutMapping("/update") @ApiOperation("修改邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:update')") public CommonResult updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) { - mailAccountService.update(updateReqVO); + mailAccountService.updateMailAccount(updateReqVO); return success(true); } @@ -52,18 +48,15 @@ public class MailAccountController { @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") public CommonResult deleteMailAccount(@RequestParam Long id) { - mailAccountService.delete(id); + mailAccountService.deleteMailAccount(id); return success(true); } - // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE - @GetMapping("/get") @ApiOperation("获得邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:get')") - public CommonResult getMailAccount(@RequestParam("id") Long id) { + public CommonResult getMailAccount(@RequestParam("id") Long id) { MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); } @@ -76,14 +69,10 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE - @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") - public CommonResult> getSimpleMailAccountList() { + public CommonResult> getSimpleMailAccountList() { List list = mailAccountService.getMailAccountList(); - // 排序后,返回给前端 - list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 8e392d476..7a3f2347f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -1,33 +1,41 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; -import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱账号基类 Base VO") +/** + * 邮箱账号 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ @Data public class MailAccountBaseVO { - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "邮箱必填") - @Email(message = "必须是Email格式") - private String fromAddress; + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱不能为空") + @Email(message = "必须是 Email 格式") + private String mail; - @ApiModelProperty(value = "用户名",required = true,example = "yudao") - @NotNull(message = "用户名必填") + @ApiModelProperty(value = "用户名", required = true, example = "yudao") + @NotNull(message = "用户名不能为空") private String username; - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") - @NotNull(message = "网站必填") + @ApiModelProperty(value = "密码", required = true, example = "123456") + @NotNull(message = "密码必填") + private String password; + + @ApiModelProperty(value = "网站", required = true, example = "www.iocoder.cn") + @NotNull(message = "网站不能为空") private String host; - @ApiModelProperty(value = "端口",required = true,example = "80") + @ApiModelProperty(value = "端口", required = true, example = "80") + @NotNull(message = "端口不能为空") private Integer port; - @ApiModelProperty(value = "是否开启ssl",required = true,example = "2") - @NotNull(message = "是否开启ssl必填") + @ApiModelProperty(value = "是否开启 ssl", required = true, example = "true") + @NotNull(message = "是否开启 ssl 必填") private Boolean sslEnable; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 476a3077a..2bcca7850 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/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; @ToString(callSuper = true) public class MailAccountCreateReqVO extends MailAccountBaseVO { - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 327c8465d..9e5869172 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/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; @ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") - private String fromAddress; + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com") + private String mail; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") private String username; - @ApiModelProperty(value = "密码" , required = true , example = "123456") - private String password; - - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") - private String host; - - @ApiModelProperty(value = "端口" , required = true , example = "80") - private String port; - - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") - private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java new file mode 100644 index 000000000..9eef7281a --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +@ApiModel("管理后台 - 邮箱账号 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailAccountRespVO extends MailAccountBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private LocalDateTime createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java new file mode 100644 index 000000000..93118388e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("管理后台 - 邮箱账号的精简 Response VO") +@Data +public class MailAccountSimpleRespVO { + + @ApiModelProperty(value = "邮箱比那好", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "邮箱", required = true, example = "768541388@qq.com") + private String mail; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 4544e95b5..43a13ad18 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/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 { @NotNull(message = "编号不能为空") private Long id; - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index b60ac088f..daadbfe5a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/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; 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.MailAccountBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO; +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.mq.message.mail.MailSendMessage; import org.mapstruct.Mapper; @@ -14,30 +16,33 @@ import java.util.Map; @Mapper public interface MailAccountConvert { + MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class); - MailAccountDO convert (MailAccountBaseVO mailAccountBaseVO); + MailAccountDO convert(MailAccountBaseVO bean); - MailAccountBaseVO convert (MailAccountDO mailAccountDO); + MailAccountRespVO convert(MailAccountDO bean); - PageResult convertPage(PageResult pageResult); + PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); - default MailAccount convertAccount(MailSendMessage mailAccountDO){ + // TODO 芋艿:改下 + default MailAccount convertAccount(MailSendMessage bean) { return new MailAccount() - .setHost(mailAccountDO.getHost()) - .setPort(mailAccountDO.getPort()) + .setHost(bean.getHost()) + .setPort(bean.getPort()) .setAuth(true) - .setFrom(mailAccountDO.getFromAddress()) - .setUser(mailAccountDO.getUsername()) - .setPass(mailAccountDO.getPassword()) - .setSslEnable(mailAccountDO.getSslEnable()); + .setFrom(bean.getFromAddress()) + .setUser(bean.getUsername()) + .setPass(bean.getPassword()) + .setSslEnable(bean.getSslEnable()); } + // TODO 芋艿:改下 default Map convertToMap(MailAccountDO mailAccountDO , String content) { Map map = new HashMap<>(); - map.put("from_address" , mailAccountDO.getFromAddress()); + map.put("from_address" , mailAccountDO.getMail()); map.put("username" , mailAccountDO.getUsername()); map.put("content" , content); return map; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 910440df7..33e6859e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; /** - * 邮箱账号 - * 配置发送邮箱的账号 + * 邮箱账号 DO + * + * 用途:配置发送邮箱的账号 * * @author wangjingyi * @since 2022-03-21 @@ -25,7 +25,8 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ - private String fromAddress; + private String mail; + /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index d4b0e5f81..598b52cfc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -13,7 +13,7 @@ import java.util.Date; import java.util.Map; /** - * 邮箱日志 + * 邮箱日志 DO * 记录每一次邮件的发送 * * @author wangjingyi @@ -29,7 +29,7 @@ import java.util.Map; public class MailLogDO extends BaseDO implements Serializable { /** - * 主键 + * 日志编号,自增 */ private Long id; @@ -37,62 +37,74 @@ public class MailLogDO extends BaseDO implements Serializable { * 用户编码 */ private Long userId; - /** * 用户类型 * - * 冗余 {@link MailLogUserTypeEnum#getUserType} + * 枚举 {@link UserTypeEnum} */ private Integer userType; + /** + * 接收邮箱地址 + */ + private String toMail; - // TODO @wangjingyi:accountId /** * 邮箱账号编号 + * + * 关联 {@link MailAccountDO#getId()} */ private Long accountId; - - // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE /** - * 邮箱账号 + * 发送邮箱地址 * - * 冗余 {@link MailAccountDO} + * 冗余 {@link MailAccountDO#getMail()} */ - private String fromAddress; + private String fromMail; + // ========= 模板相关字段 ========= /** - * 模版主键 + * 模版编号 + * + * 关联 {@link MailTemplateDO#getId()} */ private Long templateId; - + /** + * 末班编码 + * + * 冗余 {@link MailTemplateDO#getCode()} + */ + private String templateCode; /** * 模版内容 + * + * 基于 {@link MailTemplateDO#getContent()} 格式化后的内容 */ private String templateContent; - /** + * 模版参数 + * * 基于 {@link MailTemplateDO#getParams()} 输入后的参数 */ @TableField(typeHandler = JacksonTypeHandler.class) private Map templateParams; - /** - * 发送时间 - */ - private Date sendTime; - - //=========接收相关字段========= + // ========= 发送相关字段 ========= /** * 发送状态 * * 枚举 {@link MailSendStatusEnum} */ private Integer sendStatus; + /** + * 发送时间 + */ + private Date sendTime; + // ========= 接收相关字段 ========= /** * 发送结果 */ private String sendResult; - /** * 消息ID */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index c4708657f..c3c1cae83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/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; import java.util.List; /** - * 邮箱模版 + * 邮箱模版 DO * * @author wangjingyi * @since 2022-03-21 @@ -34,9 +34,12 @@ public class MailTemplateDO extends BaseDO { */ private String code; /** - * 邮箱账号主键 + * 发送的邮箱账号编号 + * + * 关联 {@link MailAccountDO#getId()} */ private Long accountId; + /** * 标题 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 1e4f263ac..24ce1ef06 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.util.Date; @Mapper public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { - return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("from_address" , pageReqVO.getFromAddress()) - .likeIfPresent("host" , pageReqVO.getHost()) - .likeIfPresent("username" , pageReqVO.getUsername()) - .eqIfPresent("password" , pageReqVO.getPassword()) - .eqIfPresent("port" , pageReqVO.getPort()) - ); - } - - default MailAccountDO selectByUserName(String userName){ - return selectOne(new QueryWrapperX() - .eqIfPresent("username" , userName)); - } - - default MailAccountDO selectByUserNameAndId(String userName,Long id){ - return selectOne(new QueryWrapperX() - .eqIfPresent("username" , userName) - .neIfPresent("id" , id)); + return selectPage(pageReqVO, new LambdaQueryWrapperX() + .likeIfPresent(MailAccountDO::getMail, pageReqVO.getMail()) + .likeIfPresent(MailAccountDO::getUsername , pageReqVO.getUsername())); } default MailAccountDO selectOneByFrom(String from){ @@ -40,6 +22,4 @@ public interface MailAccountMapper extends BaseMapperX { .eqIfPresent("from_address" , from)); } - @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index d7d1cd73c..86bb5e8f5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/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; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -36,5 +37,10 @@ public interface MailTemplateMapper extends BaseMapperX { default MailTemplateDO selectOneByAccountId(Long accountId){ return selectOne(new QueryWrapperX() .eqIfPresent("account_id" , accountId)); - }; + } + + default Long selectCountByAccountId(Long accountId) { + return selectCount(MailTemplateDO::getAccountId, accountId); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index 50c505512..8b92ee953 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/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 { public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List> templateParams,String to) { MailSendMessage message = new MailSendMessage(); message.setContent(content) - .setFromAddress(mailAccountDO.getFromAddress()) + .setFromAddress(mailAccountDO.getMail()) .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) .setPassword(mailAccountDO.getPassword()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index fe0615f4f..2c90a9121 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/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 { * @param createReqVO 邮箱账号信息 * @return 编号 */ - Long create(@Valid MailAccountCreateReqVO createReqVO); + Long createMailAccount(@Valid MailAccountCreateReqVO createReqVO); /** * 修改邮箱账号 * * @param updateReqVO 邮箱账号信息 */ - void update(@Valid MailAccountUpdateReqVO updateReqVO); + void updateMailAccount(@Valid MailAccountUpdateReqVO updateReqVO); /** * 删除邮箱账号 * * @param id 编号 */ - void delete(Long id); + void deleteMailAccount(Long id); /** * 获取邮箱账号信息 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 16d65b4f9..662d77623 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/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 { */ String formatMailTemplateContent(String content, Map params); + /** + * 获得指定邮箱账号下的邮件模板数量 + * + * @param accountId 账号编号 + * @return 数量 + */ + long countByAccountId(Long accountId); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 3ae44693b..2da58091b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,32 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.util.Date; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; - +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS; /** * 邮箱账号 Service 实现类 @@ -43,7 +39,7 @@ public class MailAccountServiceImpl implements MailAccountService { private MailAccountMapper mailAccountMapper; @Resource - private MailTemplateMapper mailTemplateMapper; + private MailTemplateService mailTemplateService; @Resource private MailProducer mailProducer; @@ -56,75 +52,61 @@ public class MailAccountServiceImpl implements MailAccountService { */ private volatile Map mailAccountCache; - /** - * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile Date maxUpdateTime; - @Override @PostConstruct public void initLocalCache() { - List mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime); - if (CollUtil.isEmpty(mailAccountDOList)) { - return; - } + // 第一步:查询数据 + List accounts = mailAccountMapper.selectList(); + log.info("[initLocalCache][缓存邮箱账号,数量:{}]", accounts.size()); - // 写入缓存 - mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId); - maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime); - log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size()); - } - - private List loadMailAccountIfUpdate(Date maxUpdateTime) { - //第一步 判断是否需要更新 - if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]"); - }else{ // 判断数据库中是否有更新的账号信息 - if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - return null; - } - log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]"); - } - return mailAccountMapper.selectList(); + // 第二步:构建缓存 + mailAccountCache = convertMap(accounts, MailAccountDO::getId); } @Override - public Long create(MailAccountCreateReqVO createReqVO) { - // username 要校验唯一 - this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); - mailAccountMapper.insert(mailAccountDO); + public Long createMailAccount(MailAccountCreateReqVO createReqVO) { + // 插入 + MailAccountDO account = MailAccountConvert.INSTANCE.convert(createReqVO); + mailAccountMapper.insert(account); - // 更新 + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); - return mailAccountDO.getId(); + return account.getId(); } @Override - public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE - this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId()); - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); + public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) { // 校验是否存在 - validateMailAccountExists(mailAccountDO.getId()); + validateMailAccountExists(updateReqVO.getId()); // 更新 + MailAccountDO updateObj = MailAccountConvert.INSTANCE.convert(updateReqVO); + mailAccountMapper.updateById(updateObj); + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); - mailAccountMapper.updateById(mailAccountDO); } @Override - public void delete(Long id) { + public void deleteMailAccount(Long id) { // 校验是否存在账号 validateMailAccountExists(id); // 校验是否存在关联模版 - validateMailTemplateByAccountId(id); + if (mailTemplateService.countByAccountId(id) > 0) { + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); + } + // 删除 mailAccountMapper.deleteById(id); - // 更新 + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); } + private void validateMailAccountExists(Long id) { + if (mailAccountMapper.selectById(id) == null) { + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + } + @Override public MailAccountDO getMailAccount(Long id) { return mailAccountMapper.selectById(id); @@ -140,33 +122,4 @@ public class MailAccountServiceImpl implements MailAccountService { return mailAccountMapper.selectList(); } - private void validateMailAccountExists(Long id) { - if (mailAccountMapper.selectById(id) == null) { - throw exception(MAIL_ACCOUNT_NOT_EXISTS); - } - } - - private void validateMailAccountOnlyByUserName(String userName){ - mailAccountCache.forEach((key,value)->{ - if(value.getUsername().equals(userName)){ - throw exception(MAIL_ACCOUNT_EXISTS); - } - }); - } - private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){ - mailAccountCache.forEach((key , value)->{ - if (value.getUsername().equals(userName)){ - if (!key.equals(id)){ - throw exception(MAIL_ACCOUNT_EXISTS); - } - } - }); - } - private void validateMailTemplateByAccountId(Long accountId){ - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); - if (mailTemplateDO != null) { - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE - throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); - } - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index a7bf04fc7..c489ad9bb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/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; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -51,7 +50,7 @@ public class MailLogServiceImpl implements MailLogService { logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() : MailSendStatusEnum.IGNORE.getStatus()) // 设置邮箱相关字段 - .fromAddress(mailAccountDO.getFromAddress()) + .fromMail(mailAccountDO.getMail()) .accountId(mailAccountDO.getId()) // TODO @wangjingyi:userId、userType //用户信息 @@ -60,7 +59,7 @@ public class MailLogServiceImpl implements MailLogService { .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent); - logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); + logDOBuilder.fromMail(mailAccountDO.getMail()); logDOBuilder.accountId(mailAccountDO.getId()); // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE // 设置模板相关字段 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 3fcac8b9e..9ae635cee 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/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 { */ private volatile Map mailTemplateCache; - private volatile Date maxUpdateTime; - @Override @PostConstruct public void initLocalCache() { - List mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime); + if (true) { + return; + } + List mailTemplateDOList = this.loadMailTemplateIfUpdate(null); if (CollUtil.isEmpty(mailTemplateDOList)) { return; } // 写入缓存 mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); - maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); } @@ -156,4 +156,10 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 第二步,如果有更新,则从数据库加载所有邮件模板 return mailTemplateMapper.selectList(); } + + @Override + public long countByAccountId(Long accountId) { + return mailTemplateMapper.selectCountByAccountId(accountId); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java index 592864651..d126fbf0f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java +++ b/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 { public void deleteSmsChannel(Long id) { // 校验存在 this.validateSmsChannelExists(id); - // 校验是否有字典数据 + // 校验是否有在使用该账号的模版 if (smsTemplateService.countByChannelId(id) > 0) { throw exception(SMS_CHANNEL_HAS_CHILDREN); } diff --git a/yudao-ui-admin/src/api/system/mail/account.js b/yudao-ui-admin/src/api/system/mail/account.js new file mode 100755 index 000000000..171fe553f --- /dev/null +++ b/yudao-ui-admin/src/api/system/mail/account.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 创建邮箱账号 +export function createMailAccount(data) { + return request({ + url: '/system/mail-account/create', + method: 'post', + data: data + }) +} + +// 更新邮箱账号 +export function updateMailAccount(data) { + return request({ + url: '/system/mail-account/update', + method: 'put', + data: data + }) +} + +// 删除邮箱账号 +export function deleteMailAccount(id) { + return request({ + url: '/system/mail-account/delete?id=' + id, + method: 'delete' + }) +} + +// 获得邮箱账号 +export function getMailAccount(id) { + return request({ + url: '/system/mail-account/get?id=' + id, + method: 'get' + }) +} + +// 获得邮箱账号分页 +export function getMailAccountPage(query) { + return request({ + url: '/system/mail-account/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/views/system/mail/account/index.vue b/yudao-ui-admin/src/views/system/mail/account/index.vue new file mode 100755 index 000000000..f3821d8bc --- /dev/null +++ b/yudao-ui-admin/src/views/system/mail/account/index.vue @@ -0,0 +1,226 @@ + + + From ea39dcc5c803ffd0a569243cb2a678ebc0d04b1b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 20:44:48 +0800 Subject: [PATCH 26/41] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20template=20=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 8 +- .../admin/mail/MailTemplateController.java | 35 +-- .../mail/vo/account/MailAccountBaseVO.java | 8 +- .../vo/account/MailAccountSimpleRespVO.java | 2 +- .../mail/vo/template/MailTemplateBaseVO.java | 41 +-- .../vo/template/MailTemplateCreateReqVO.java | 3 +- .../vo/template/MailTemplatePageReqVO.java | 41 ++- .../mail/vo/template/MailTemplateRespVO.java | 25 +- .../vo/template/MailTemplateSimpleRespVO.java | 17 ++ .../vo/template/MailTemplateUpdateReqVO.java | 3 +- .../convert/mail/MailTemplateConvert.java | 11 +- .../dal/dataobject/mail/MailAccountDO.java | 4 +- .../system/dal/dataobject/mail/MailLogDO.java | 12 +- .../dal/dataobject/mail/MailTemplateDO.java | 6 +- .../dal/mysql/mail/MailTemplateMapper.java | 33 +-- .../service/mail/MailTemplateService.java | 36 +-- .../mail/impl/MailTemplateServiceImpl.java | 120 ++++---- .../src/main/resources/application.yaml | 3 + yudao-ui-admin/src/api/system/mail/account.js | 8 + .../src/api/system/mail/template.js | 44 +++ .../src/views/system/mail/account/index.vue | 20 +- .../src/views/system/mail/template/index.vue | 269 ++++++++++++++++++ 22 files changed, 550 insertions(+), 199 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java create mode 100755 yudao-ui-admin/src/api/system/mail/template.js create mode 100755 yudao-ui-admin/src/views/system/mail/template/index.vue diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 135248867..577fcb2ad 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -145,9 +145,9 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002023000, "邮箱账号不存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002023001, "无法删除,该邮箱账号还有邮件模板"); - // ========== 邮箱模版 1002021000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); + // ========== 邮箱模版 1002024000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002024000, "邮件模版不存在"); + ErrorCode MAIL_TEMPLATE_CODE_EXISTS = new ErrorCode(1002024001, "邮件模版 code({}) 已存在"); + ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); // TODO 优化 } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index 2fae6164b..741462c95 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -2,7 +2,6 @@ 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.send.MailReqVO; 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; @@ -10,13 +9,11 @@ import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; - -import java.util.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -26,37 +23,35 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { - // TODO @wangjingyi:private DONE - @Autowired + @Resource private MailTemplateService mailTempleService; @PostMapping("/create") - @ApiOperation("创建邮箱模版") + @ApiOperation("创建邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:create')") public CommonResult createMailTemplate(@Valid @RequestBody MailTemplateCreateReqVO createReqVO){ - return success(mailTempleService.create(createReqVO)); + return success(mailTempleService.createMailTemplate(createReqVO)); } @PutMapping("/update") - @ApiOperation("修改邮箱模版") + @ApiOperation("修改邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:update')") public CommonResult updateMailTemplate(@Valid @RequestBody MailTemplateUpdateReqVO updateReqVO){ - mailTempleService.update(updateReqVO); + mailTempleService.updateMailTemplate(updateReqVO); return success(true); } @DeleteMapping("/delete") - @ApiOperation("删除邮箱模版") + @ApiOperation("删除邮件模版") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:delete')") - public CommonResult deleteMailTemplate(@Valid @RequestBody Long id) { - mailTempleService.delete(id); + public CommonResult deleteMailTemplate(@RequestParam("id") Long id) { + mailTempleService.deleteMailTemplate(id); return success(true); } - // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 DONE RespVO中需要BaseVO 中哪些字段 - @GetMapping("/get") - @ApiOperation("获得邮箱模版") + @ApiOperation("获得邮件模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:get')") public CommonResult getMailTemplate(@RequestParam("id") Long id) { @@ -65,7 +60,7 @@ public class MailTemplateController { } @GetMapping("/page") - @ApiOperation("获得邮箱模版分页") + @ApiOperation("获得邮件模版分页") @PreAuthorize("@ss.hasPermission('system:mail-template:query')") public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); @@ -73,11 +68,9 @@ public class MailTemplateController { } @GetMapping("/list-all-simple") - @ApiOperation(value = "获得邮箱模版精简列表") - public CommonResult> getSimpleTemplateList() { + @ApiOperation(value = "获得邮件模版精简列表") + public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); - // 排序后,返回给前端 - list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 7a3f2347f..ef18cb6ac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -26,12 +26,12 @@ public class MailAccountBaseVO { @NotNull(message = "密码必填") private String password; - @ApiModelProperty(value = "网站", required = true, example = "www.iocoder.cn") - @NotNull(message = "网站不能为空") + @ApiModelProperty(value = "SMTP 服务器域名", required = true, example = "www.iocoder.cn") + @NotNull(message = "SMTP 服务器域名不能为空") private String host; - @ApiModelProperty(value = "端口", required = true, example = "80") - @NotNull(message = "端口不能为空") + @ApiModelProperty(value = "SMTP 服务器端口", required = true, example = "80") + @NotNull(message = "SMTP 服务器端口不能为空") private Integer port; @ApiModelProperty(value = "是否开启 ssl", required = true, example = "true") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java index 93118388e..96916a715 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java @@ -8,7 +8,7 @@ import lombok.Data; @Data public class MailAccountSimpleRespVO { - @ApiModelProperty(value = "邮箱比那好", required = true, example = "1024") + @ApiModelProperty(value = "邮箱编号", required = true, example = "1024") private Long id; @ApiModelProperty(value = "邮箱", required = true, example = "768541388@qq.com") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index 1e44336aa..e2835debd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -1,44 +1,47 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; -import io.swagger.annotations.ApiModel; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱模版基类 Base VO") +/** + * 邮件模版 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ @Data public class MailTemplateBaseVO { - @ApiModelProperty("主键") - @NotNull(message = "主键不能为空") - private Long id; - @ApiModelProperty("名称") + @ApiModelProperty(value = "模版名称", required = true, example = "测试名字") @NotNull(message = "名称不能为空") private String name; - @ApiModelProperty("标识") - @NotNull(message = "邮箱模版code不能为空") + @ApiModelProperty(value = "模版编号", required = true, example = "test") + @NotNull(message = "模版编号不能为空") private String code; - @ApiModelProperty("发件人") - @NotNull(message = "发件人不能为空") - @Email(message = "发件人格式有误") - private String username; + @ApiModelProperty(value = "发送的邮箱账号编号", required = true, example = "1") + @NotNull(message = "发送的邮箱账号编号不能为空") + private Long accountId; - @ApiModelProperty("标题") - @NotNull(message = "标题不能为空") + @ApiModelProperty(value = "发送人名称", example = "芋头") + private String nickname; + + @ApiModelProperty(value = "标题", required = true, example = "注册成功") + @NotEmpty(message = "标题不能为空") private String title; - @ApiModelProperty("内容") - @NotNull(message = "内容不能为空") + @ApiModelProperty(value = "内容", required = true, example = "你好,注册成功啦") + @NotEmpty(message = "内容不能为空") private String content; - @ApiModelProperty("状态") + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") @NotNull(message = "状态不能为空") private Integer status; - @ApiModelProperty("备注") + @ApiModelProperty(value = "备注", example = "奥特曼") private String remark; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java index 2311cb087..6eab6e9ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java @@ -5,11 +5,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -@ApiModel("管理后台 - 邮箱模版创建 Request VO") +@ApiModel("管理后台 - 邮件模版创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailTemplateCreateReqVO extends MailTemplateBaseVO { - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index a48c5a91a..f3cec08f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -6,33 +6,32 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; -@ApiModel("管理后台 - 邮箱模版分页 Request VO") +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 邮件模版分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailTemplatePageReqVO extends PageParam { - @ApiModelProperty("主键") - private Long id; - @ApiModelProperty("名称") - private String name; - - @ApiModelProperty("标识") - private String code; - - @ApiModelProperty("发件人") - private String username; - - @ApiModelProperty("标题") - private String title; - - @ApiModelProperty("内容") - private String content; - - @ApiModelProperty("状态") + @ApiModelProperty(value = "状态", example = "1", notes = "参见 CommonStatusEnum 枚举") private Integer status; - @ApiModelProperty("备注") - private String remark; + @ApiModelProperty(value = "标识", example = "code_1024", notes = "模糊匹配") + private String code; + + @ApiModelProperty(value = "名称", example = "芋头", notes = "模糊匹配") + private String name; + + @ApiModelProperty(value = "账号编号", example = "2048") + private Long accountId; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java index 33683b1c5..a2153f9cd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -1,4 +1,27 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; -public class MailTemplateRespVO extends MailTemplateBaseVO{ +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; +import java.util.List; + +@ApiModel("管理后台 - 邮件末班 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailTemplateRespVO extends MailTemplateBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "参数数组", example = "name,code") + private List params; + + @ApiModelProperty(value = "创建时间", required = true) + private LocalDateTime createTime; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java new file mode 100644 index 000000000..2ff488036 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("管理后台 - 邮件模版的精简 Response VO") +@Data +public class MailTemplateSimpleRespVO { + + @ApiModelProperty(value = "模版编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "模版名字", required = true, example = "哒哒哒") + private String name; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java index 82d9997be..5dfa377a2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java @@ -8,7 +8,7 @@ import lombok.ToString; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱模版修改 Request VO") +@ApiModel("管理后台 - 邮件模版修改 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -17,4 +17,5 @@ public class MailTemplateUpdateReqVO extends MailTemplateBaseVO { @ApiModelProperty(value = "编号", required = true, example = "1024") @NotNull(message = "编号不能为空") private Long id; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 46a25b9e2..4430ffb05 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -1,8 +1,7 @@ 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.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,12 +13,14 @@ public interface MailTemplateConvert { MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); - MailTemplateDO convert(MailTemplateBaseVO baseVO); + MailTemplateDO convert(MailTemplateUpdateReqVO bean); - MailTemplateRespVO convert(MailTemplateDO mailTemplateDO); + MailTemplateDO convert(MailTemplateCreateReqVO bean); + + MailTemplateRespVO convert(MailTemplateDO bean); PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 33e6859e2..b5d349439 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -36,11 +36,11 @@ public class MailAccountDO extends BaseDO { */ private String password; /** - * 主机 + * SMTP 服务器域名 */ private String host; /** - * 端口 + * SMTP 服务器端口 */ private Integer port; /** diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 598b52cfc..ddd0f7158 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -69,11 +69,21 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long templateId; /** - * 末班编码 + * 模版编码 * * 冗余 {@link MailTemplateDO#getCode()} */ private String templateCode; + /** + * 模版发送人名称 + * + * 冗余 {@link MailTemplateDO#getNickname()} + */ + private String templateNickname; + /** + * 模版标题 + */ + private String templateTitle; /** * 模版内容 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index c3c1cae83..f669b455f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/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; import java.util.List; /** - * 邮箱模版 DO + * 邮件模版 DO * * @author wangjingyi * @since 2022-03-21 @@ -40,6 +40,10 @@ public class MailTemplateDO extends BaseDO { */ private Long accountId; + /** + * 发送人名称 + */ + private String nickname; /** * 标题 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 86bb5e8f5..f03aa4ae9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; @@ -11,36 +12,24 @@ import org.apache.ibatis.annotations.Select; import java.util.Date; - @Mapper public interface MailTemplateMapper extends BaseMapperX { default PageResult selectPage(MailTemplatePageReqVO pageReqVO){ - return selectPage(pageReqVO , new QueryWrapperX() - .likeIfPresent("name" , pageReqVO.getName()) - .likeIfPresent("username" , pageReqVO.getUsername()) - .likeIfPresent("title" , pageReqVO.getTitle()) - .likeIfPresent("content" , pageReqVO.getContent()) - .eqIfPresent("status" , pageReqVO.getStatus()) - .likeIfPresent("remark" , pageReqVO.getRemark()) - ); - } - - default MailTemplateDO selectOneByCode(String code){ - return selectOne(new QueryWrapperX() - .eqIfPresent("code" , code)); - }; - - @Select("SELECT COUNT(*) FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") - Long selectByMaxUpdateTime(Date maxUpdateTime); - - default MailTemplateDO selectOneByAccountId(Long accountId){ - return selectOne(new QueryWrapperX() - .eqIfPresent("account_id" , accountId)); + return selectPage(pageReqVO , new LambdaQueryWrapperX() + .eqIfPresent(MailTemplateDO::getStatus, pageReqVO.getStatus()) + .likeIfPresent(MailTemplateDO::getCode, pageReqVO.getCode()) + .likeIfPresent(MailTemplateDO::getName, pageReqVO.getName()) + .eqIfPresent(MailTemplateDO::getAccountId, pageReqVO.getAccountId()) + .betweenIfPresent(MailTemplateDO::getCreateTime, pageReqVO.getCreateTime())); } default Long selectCountByAccountId(Long accountId) { return selectCount(MailTemplateDO::getAccountId, accountId); } + default MailTemplateDO selectByCode(String code) { + return selectOne(MailTemplateDO::getCode, code); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 662d77623..704f7d653 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; /** - * 邮箱模版服务类 + * 邮件模版 Service 接口 * * @author wangjingyi * @since 2022-03-21 @@ -19,34 +19,34 @@ import java.util.Map; public interface MailTemplateService { /** - * 初始化邮箱模版的本地缓存 + * 初始化邮件模版的本地缓存 */ void initLocalCache(); /** - * 邮箱模版创建 + * 邮件模版创建 * - * @param createReqVO 邮箱信息 + * @param createReqVO 邮件信息 * @return 编号 */ - Long create(@Valid MailTemplateCreateReqVO createReqVO); + Long createMailTemplate(@Valid MailTemplateCreateReqVO createReqVO); /** - * 邮箱模版修改 + * 邮件模版修改 * - * @param updateReqVO 邮箱信息 + * @param updateReqVO 邮件信息 */ - void update(@Valid MailTemplateUpdateReqVO updateReqVO); + void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO); /** - * 邮箱模版删除 + * 邮件模版删除 * * @param id 编号 */ - void delete(Long id); + void deleteMailTemplate(Long id); /** - * 获取邮箱模版 + * 获取邮件模版 * * @param id 编号 * @return 邮件模版 @@ -54,39 +54,39 @@ public interface MailTemplateService { MailTemplateDO getMailTemplate(Long id); /** - * 获取邮箱模版分页 + * 获取邮件模版分页 * * @param pageReqVO 模版信息 - * @return 邮箱模版分页信息 + * @return 邮件模版分页信息 */ PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO); /** - * 获取邮箱模板数组 + * 获取邮件模板数组 * * @return 模版数组 */ List getMailTemplateList(); /** - * 从缓存中获取邮箱模版 + * 从缓存中获取邮件模版 * * @param code 模板编码 - * @return 邮箱模板 + * @return 邮件模板 */ MailTemplateDO getMailTemplateByCodeFromCache(String code); /** * 邮件模版内容合成 * - * @param content 邮箱模版 + * @param content 邮件模版 * @param params 合成参数 * @return 格式化后的内容 */ String formatMailTemplateContent(String content, Map params); /** - * 获得指定邮箱账号下的邮件模板数量 + * 获得指定邮件账号下的邮件模板数量 * * @param accountId 账号编号 * @return 数量 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9ae635cee..753614683 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; 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; @@ -13,6 +15,7 @@ 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.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -25,8 +28,8 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 邮箱模版 Service 实现类 @@ -47,56 +50,71 @@ public class MailTemplateServiceImpl implements MailTemplateService { /** * 邮件模板缓存 - * key:邮箱模板编码 {@link MailTemplateDO#getId()} + * key:邮件模版标识 {@link MailTemplateDO#getCode()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - private volatile Map mailTemplateCache; + private volatile Map mailTemplateCache; @Override @PostConstruct public void initLocalCache() { - if (true) { - return; - } - List mailTemplateDOList = this.loadMailTemplateIfUpdate(null); - if (CollUtil.isEmpty(mailTemplateDOList)) { - return; - } + // 第一步:查询数据 + List templates = mailTemplateMapper.selectList(); + log.info("[initLocalCache][缓存邮件模版,数量:{}]", templates.size()); - // 写入缓存 - mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); - log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); + // 第二步:构建缓存 + mailTemplateCache = convertMap(templates, MailTemplateDO::getCode); } @Override - public Long create(MailTemplateCreateReqVO createReqVO) { - // 要校验存在 - validateMailTemplateExists(createReqVO.getId()); - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); - mailTemplateMapper.insert(mailTemplateDO); - // TODO @wangjingyi:mq 更新 DONE + public Long createMailTemplate(MailTemplateCreateReqVO createReqVO) { + // 校验 code 是否唯一 + validateCodeUnique(null, createReqVO.getCode()); + + // 插入 + MailTemplateDO template = MailTemplateConvert.INSTANCE.convert(createReqVO); + mailTemplateMapper.insert(template); + // 发送刷新消息 mailProducer.sendMailTemplateRefreshMessage(); - return mailTemplateDO.getId(); + return template.getId(); } @Override - public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // 校验是否唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。DONE - this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); - mailTemplateMapper.updateById(mailTemplateDO); - // TODO @wangjingyi:mq 更新 DONE - mailProducer.sendMailTemplateRefreshMessage(); - } - - @Override - public void delete(Long id) { + public void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO) { // 校验是否存在 - this.validateMailTemplateExists(id); + validateMailTemplateExists(updateReqVO.getId()); + // 校验 code 是否唯一 + validateCodeUnique(updateReqVO.getId(),updateReqVO.getCode()); + + // 更新 + MailTemplateDO updateObj = MailTemplateConvert.INSTANCE.convert(updateReqVO); + mailTemplateMapper.updateById(updateObj); + // 发送刷新消息 + mailProducer.sendMailTemplateRefreshMessage(); + } + + @VisibleForTesting + public void validateCodeUnique(Long id, String code) { + MailTemplateDO template = mailTemplateMapper.selectByCode(code); + if (template == null) { + return; + } + // 存在 template 记录的情况下 + if (id == null // 新增时,说明重复 + || ObjUtil.notEqual(id, template.getId())) { // 更新时,如果 id 不一致,说明重复 + throw exception(MAIL_TEMPLATE_CODE_EXISTS); + } + } + + @Override + public void deleteMailTemplate(Long id) { + // 校验是否存在 + validateMailTemplateExists(id); + + // 删除 mailTemplateMapper.deleteById(id); - // TODO @wangjingyi:mq 更新 DONE + // 发送刷新消息 mailProducer.sendMailTemplateRefreshMessage(); } @@ -122,41 +140,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { } private void validateMailTemplateExists(Long id) { - if (mailTemplateCache.get(id) == null) { + if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnlyByCode(Long id ,String code){ - mailTemplateCache.forEach((key,value)->{ - if (value.getCode().equals(code)){ - if (!key.equals(id)){ - throw exception(MAIL_TEMPLATE_EXISTS); - } - } - }); - } - /** - * 如果邮件模板发生变化,从数据库中获取最新的全量邮件模板。 - * 如果未发生变化,则返回空 - * - * @param maxUpdateTime 当前邮件模板的最大更新时间 - * @return 邮件模板列表 - */ - private List loadMailTemplateIfUpdate(Date maxUpdateTime) { - // 第一步,判断是否要更新。 - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadMailTemplateIfUpdate][首次加载全量邮件模板]"); - } else { // 判断数据库中是否有更新的邮件模板 - if (mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime) == 0) { - return null; - } - log.info("[loadSmsTemplateIfUpdate][增量加载全量邮件模板]"); - } - // 第二步,如果有更新,则从数据库加载所有邮件模板 - return mailTemplateMapper.selectList(); - } - @Override public long countByAccountId(Long accountId) { return mailTemplateMapper.selectCountByAccountId(accountId); diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 325e88f42..e1bcb137e 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -138,6 +138,9 @@ yudao: - system_sms_log - system_sensitive_word - system_oauth2_client + - system_mail_account + - system_mail_template + - system_mail_log - infra_codegen_column - infra_codegen_table - infra_test_demo diff --git a/yudao-ui-admin/src/api/system/mail/account.js b/yudao-ui-admin/src/api/system/mail/account.js index 171fe553f..0868e4f37 100755 --- a/yudao-ui-admin/src/api/system/mail/account.js +++ b/yudao-ui-admin/src/api/system/mail/account.js @@ -42,3 +42,11 @@ export function getMailAccountPage(query) { params: query }) } + +// 获取邮箱账号的精简信息列表 +export function getSimpleMailAccountList() { + return request({ + url: '/system/mail-account/list-all-simple', + method: 'get', + }) +} diff --git a/yudao-ui-admin/src/api/system/mail/template.js b/yudao-ui-admin/src/api/system/mail/template.js new file mode 100755 index 000000000..ee5d8d454 --- /dev/null +++ b/yudao-ui-admin/src/api/system/mail/template.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 创建邮件模版 +export function createMailTemplate(data) { + return request({ + url: '/system/mail-template/create', + method: 'post', + data: data + }) +} + +// 更新邮件模版 +export function updateMailTemplate(data) { + return request({ + url: '/system/mail-template/update', + method: 'put', + data: data + }) +} + +// 删除邮件模版 +export function deleteMailTemplate(id) { + return request({ + url: '/system/mail-template/delete?id=' + id, + method: 'delete' + }) +} + +// 获得邮件模版 +export function getMailTemplate(id) { + return request({ + url: '/system/mail-template/get?id=' + id, + method: 'get' + }) +} + +// 获得邮件模版分页 +export function getMailTemplatePage(query) { + return request({ + url: '/system/mail-template/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/views/system/mail/account/index.vue b/yudao-ui-admin/src/views/system/mail/account/index.vue index f3821d8bc..96e3cc461 100755 --- a/yudao-ui-admin/src/views/system/mail/account/index.vue +++ b/yudao-ui-admin/src/views/system/mail/account/index.vue @@ -29,8 +29,8 @@ - - + +