From 3b42b7061000c66eea944bdc22b9f8ca2ec50fa0 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 23 Mar 2022 20:59:46 +0800 Subject: [PATCH 01/67] =?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 0000000000..d6ba85dcd2 --- /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 0000000000..710e3f4d32 --- /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 0000000000..7b76958d18 --- /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 0000000000..4f74da0c86 --- /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 0000000000..465bff31ff --- /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 0000000000..c5d90dfd19 --- /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 0000000000..b909e0c373 --- /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 0000000000..3a13d1b4b0 --- /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 0000000000..576c23bdd7 --- /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 0000000000..7432fdde3e --- /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 0000000000..0460cc7b22 --- /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 0000000000..38f787131d --- /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 0000000000..ff5043878b --- /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 0000000000..507b64b9ad --- /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 0000000000..b50ca35b59 --- /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 0000000000..4b17a3e21d --- /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 0000000000..e59cb01ba1 --- /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/67] =?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 d6ba85dcd2..c625b7cda8 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 4f74da0c86..07352140c3 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 576c23bdd7..d4855c1b29 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 38f787131d..b7ffbfa417 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 b50ca35b59..e1ef51267f 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/67] =?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 6b44615ce4..0cdab761cb 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 0000000000..5cace63780 --- /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 710e3f4d32..2bc87c6ac9 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 7b76958d18..7a4151fbed 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 c625b7cda8..0000000000 --- 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 07352140c3..7b65a08768 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 0000000000..b07801ceed --- /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 0000000000..6ddbc2ae6f --- /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 0000000000..9482ce474e --- /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 0000000000..a288dd84a1 --- /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 465bff31ff..0000000000 --- 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 c5d90dfd19..195bc0bb0c 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 b909e0c373..0d435a8c36 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 3a13d1b4b0..c48de644d1 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 0000000000..f7e06862f8 --- /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 7432fdde3e..2f6912812e 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 0460cc7b22..0264ca301c 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 d4855c1b29..0000000000 --- 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 0000000000..759263a40c --- /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 ff5043878b..d5442936f9 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 507b64b9ad..3c14626f94 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 b7ffbfa417..0000000000 --- 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 0000000000..11625a7bc9 --- /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 4b17a3e21d..af2ff6694e 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 e59cb01ba1..be83bccc8c 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 e1ef51267f..0000000000 --- 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/67] =?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 2bc87c6ac9..6615448d35 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 0000000000..80b6e8828e --- /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 0000000000..e6eee9f192 --- /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 0000000000..0c86969807 --- /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 0000000000..a12953af41 --- /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 0000000000..9bbf35179a --- /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 0000000000..4175508866 --- /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 0d435a8c36..ae3d603da8 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 2f6912812e..51be490190 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 d5442936f9..79d38730d6 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 af2ff6694e..2daeeab3e8 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/67] =?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 0cdab761cb..7def300428 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 5cace63780..9b62bf2332 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 6615448d35..f6375f290a 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 0000000000..988882d839 --- /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 7a4151fbed..0000000000 --- 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 80b6e8828e..eec39193c5 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 e6eee9f192..03d439f334 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 a12953af41..7ed4419b78 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 9bbf35179a..c3c5a2fdd4 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 0000000000..b0577b44e0 --- /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 0000000000..e18c39026e --- /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 0000000000..5725febd01 --- /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 0000000000..ed0d882bbd --- /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 0000000000..3f4693bcb0 --- /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 ae3d603da8..8183174a1f 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 c48de644d1..e2d5a6d8cb 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 51be490190..a8b8ccf61b 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 0000000000..06e76d9ab7 --- /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 0264ca301c..0000000000 --- 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 0000000000..3aaf72a48b --- /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 3c14626f94..0000000000 --- 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 0000000000..377bbd6584 --- /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 be83bccc8c..0000000000 --- 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/67] =?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 9b62bf2332..33469e3c23 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 0000000000..41d9d03b48 --- /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 195bc0bb0c..2147af7fe4 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 759263a40c..3cc0acb023 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 11625a7bc9..98aa646c7f 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/67] =?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 a288dd84a1..fe768efbdd 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 98aa646c7f..0c0d86eba4 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/67] =?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 7def300428..8520cb1155 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/67] =?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 33469e3c23..0fb95087a0 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 b07801ceed..9dc6819620 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 9482ce474e..925e7cd44e 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 41d9d03b48..4d1bd9a5fa 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 3cc0acb023..464c432050 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 0c0d86eba4..c4610222ad 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/67] =?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 4d1bd9a5fa..0bd9d5d22e 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 fe768efbdd..8dbfbc58d9 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/67] =?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 0fb95087a0..2d2eb959b5 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 7b65a08768..49400316b6 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 9dc6819620..8585e9d75c 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 6ddbc2ae6f..520f319982 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 925e7cd44e..43a13ad18b 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 eec39193c5..04679c7f03 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 03d439f334..442a101a30 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 0c86969807..7f737ae4bf 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 7ed4419b78..9928a77469 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 c3c5a2fdd4..af8e81698d 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 b0577b44e0..b718e29187 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 e18c39026e..2311cb087b 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 5725febd01..398e6ac03b 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 ed0d882bbd..82d9997bee 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 464c432050..5b8a07b34a 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 79d38730d6..fa195259bf 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 3aaf72a48b..da68a43d06 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 2daeeab3e8..7e4950f6d3 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 377bbd6584..92db1d83cb 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/67] =?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 f7e06862f8..effeed1b9e 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 c4610222ad..8c8900dcfd 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/67] =?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 2d2eb959b5..660ea4ab46 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 988882d839..258dc38566 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 2147af7fe4..a7db818609 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 effeed1b9e..6785e33ec3 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 5b8a07b34a..572aa3ffb7 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 da68a43d06..98fe87ef9e 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 8c8900dcfd..4cb5ed0e26 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 92db1d83cb..9fd80bdfe1 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/67] =?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 660ea4ab46..c16c7a60ba 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 f6375f290a..1cad6a02ab 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 258dc38566..cffd7f980d 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 49400316b6..870d06e48b 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 0bd9d5d22e..de75cddc9a 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 b718e29187..074ed69d2a 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 a7db818609..0d603cb99d 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 8183174a1f..4fc0c0a5cc 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 e2d5a6d8cb..83ebb533d9 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 6785e33ec3..d0a43e6796 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 06e76d9ab7..635a2bf907 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 572aa3ffb7..9792c6cc5e 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 98fe87ef9e..1511309eb9 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 4cb5ed0e26..fa2f8879ee 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 7e4950f6d3..c6b492498b 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 9fd80bdfe1..7ce118303d 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/67] =?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 870d06e48b..67cf9ba3a3 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 de75cddc9a..4ce06a718f 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 074ed69d2a..e3c9797ab7 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 0d603cb99d..d285adec5b 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 4fc0c0a5cc..f6b9e689c4 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 83ebb533d9..b86e39e95e 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 d0a43e6796..8697b21514 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 635a2bf907..d65887e54a 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 9792c6cc5e..c1289154f8 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 1511309eb9..1071eae5d2 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 fa2f8879ee..aa1fb1d467 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 7ce118303d..2bd74ac4cc 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/67] =?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 73bb614cd7..42c887c561 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 0000000000..8cca217789 --- /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 0000000000..c83b1e5f1e --- /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 0000000000..a17260410a --- /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 0000000000..3244dfe761 --- /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 0000000000..c33b4be3e3 --- /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 0000000000..a53a3b9897 --- /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 0000000000..11f27f58a6 --- /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 0000000000..b4a94a6347 --- /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 0000000000..14bdeacd89 --- /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 0000000000..097c8e095f --- /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 0000000000..9923bd3df4 --- /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 0000000000..457ad7e370 --- /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 0000000000..711d369502 --- /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 0000000000..51d2f1fcae --- /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 0000000000..e5ef74cf33 --- /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 0000000000..95c3c31a3e --- /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 0000000000..1f19ac12bd --- /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 0000000000..2ffe0d7cb7 --- /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 0000000000..a3b0f2e354 --- /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 8520cb1155..07322ccd72 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 0000000000..8936ea9c79 --- /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 b297830b5a..65dc74d03e 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 0000000000..cce0ed3883 --- /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 67cf9ba3a3..d8650b52e8 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 442a101a30..d341ce6789 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 af8e81698d..024e075f44 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 4ce06a718f..65142ee3fa 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 e3c9797ab7..1e44336aac 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 398e6ac03b..a48c5a91af 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 f6b9e689c4..7454d2acb3 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 b86e39e95e..96f9ba4ab0 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 8697b21514..651f5c75fd 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 d65887e54a..a5cbf0b2a3 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 4b02f760ea..978ea59973 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 aee02c76e9..275a458250 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 0000000000..ed82c24a4d --- /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 fa195259bf..0a5d25ba2c 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 0000000000..31f6a3f3e7 --- /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 1071eae5d2..b8101f0af7 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 aa1fb1d467..36ca05213f 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 c6b492498b..bdceb0d727 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 0000000000..61e428048d --- /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 2bd74ac4cc..e1d2121863 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/67] =?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 c16c7a60ba..864c106d63 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 cffd7f980d..f75c8daadd 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 520f319982..2ae2ad1624 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 c1289154f8..e8937d9730 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 0a5d25ba2c..f5d4174111 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 b8101f0af7..99b8fafeff 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 36ca05213f..06945127cf 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 bdceb0d727..7c1b277da0 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 61e428048d..f2146f0270 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 e1d2121863..f3d85841ef 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/67] =?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 42c887c561..73bb614cd7 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 8cca217789..0000000000 --- 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 c83b1e5f1e..0000000000 --- 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 a17260410a..0000000000 --- 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 3244dfe761..0000000000 --- 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 c33b4be3e3..0000000000 --- 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 a53a3b9897..0000000000 --- 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 11f27f58a6..0000000000 --- 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 b4a94a6347..0000000000 --- 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 14bdeacd89..0000000000 --- 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 097c8e095f..0000000000 --- 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 9923bd3df4..0000000000 --- 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 457ad7e370..0000000000 --- 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 711d369502..0000000000 --- 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 51d2f1fcae..0000000000 --- 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 e5ef74cf33..0000000000 --- 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 95c3c31a3e..0000000000 --- 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 1f19ac12bd..0000000000 --- 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 07322ccd72..d514345dab 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 2240f3b955..e23ba8ab86 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 3f4693bcb0..35c6c0a9bc 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 f2146f0270..bc4b496f1e 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/67] =?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 d514345dab..32ba7181eb 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 864c106d63..17a305c481 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 f75c8daadd..2fae6164b8 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 d8650b52e8..b785b74cc0 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 8585e9d75c..476a3077aa 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 43a13ad18b..4544e95b55 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 0000000000..33683b1c58 --- /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 8dbfbc58d9..f2228e1702 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 35c6c0a9bc..87fd8efe7a 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 651f5c75fd..420b24eeb2 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 a5cbf0b2a3..d7d1cd73c9 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 0000000000..b4eac0165e --- /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 0000000000..d5eafb04d9 --- /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 275a458250..3df7c6dcff 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 0000000000..476411ca1b --- /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 ed82c24a4d..db8bbebf64 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 e8937d9730..fe0615f4f9 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 f5d4174111..da35012e25 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 99b8fafeff..873d337f4a 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 06945127cf..3ae44693ba 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 7c1b277da0..76a7198aba 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 bc4b496f1e..6b0cccd832 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 f3d85841ef..89a0b43eae 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/67] =?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 d285adec5b..7b17104ec1 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 420b24eeb2..e869ecf227 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/67] =?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 b785b74cc0..8e392d4766 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 2ae2ad1624..327c8465de 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 7b17104ec1..910440df7a 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 e869ecf227..1e4f263acd 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/67] =?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 f2228e1702..b60ac088ff 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 7454d2acb3..97cc51f4ca 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 3df7c6dcff..fd1d68f6f1 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 db8bbebf64..3b6745c26b 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 76a7198aba..e251cc82ed 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/67] =?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 92153b0226..731a29cccf 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 32ba7181eb..cb6db27e1d 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 9928a77469..67f91735b1 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 65142ee3fa..560c3bf424 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 87fd8efe7a..46a25b9e2a 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 97cc51f4ca..2472cd95fa 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 da35012e25..98a445c8ae 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 873d337f4a..16d65b4f9c 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 e251cc82ed..afc7dcb938 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 89a0b43eae..9f8315458c 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/67] =?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 a3b0f2e354..caa69678c2 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 cb6db27e1d..4147383ae5 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 0000000000..4154c9bc1c --- /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 67f91735b1..680fe6d1f6 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 2472cd95fa..d4b0e5f811 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 96f9ba4ab0..c4708657f5 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 b4eac0165e..199b147c80 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 fd1d68f6f1..6e8c46668e 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 3b6745c26b..50c5055123 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 98a445c8ae..6b04f7a74f 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 31f6a3f3e7..615b34fcf9 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 afc7dcb938..a7bf04fc76 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 6b0cccd832..9a9e9fe50c 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 9f8315458c..3fcac8b9e5 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 bb78a58029db52df14b3812300b07c144a5d0b48 Mon Sep 17 00:00:00 2001 From: xrcoder <53924337@qq.com> Date: Sat, 6 Aug 2022 09:08:38 +0800 Subject: [PATCH 25/67] =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86=EF=BC=8C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=9A=E4=B9=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/notify/NotifyMessageSendApi.java | 34 +++++++ .../dto/NotifySendSingleToUserReqDTO.java | 33 +++++++ .../system/enums/ErrorCodeConstants.java | 6 ++ .../enums/notify/NotifyReadStatusEnum.java | 22 +++++ .../api/notify/NotifyMessageSendApiImpl.java | 39 ++++++++ .../admin/notify/NotifyMessageController.java | 73 ++++++++++++++ .../notify/NotifyTemplateController.java | 99 +++++++++++++++++++ .../notify/UserNotifyMessageController.java | 83 ++++++++++++++++ .../vo/message/NotifyMessageBaseVO.java | 40 ++++++++ .../vo/message/NotifyMessageCreateReqVO.java | 15 +++ .../vo/message/NotifyMessagePageReqVO.java | 27 +++++ .../vo/message/NotifyMessageRespVO.java | 19 ++++ .../vo/message/NotifyMessageUpdateReqVO.java | 20 ++++ .../vo/template/NotifyTemplateBaseVO.java | 34 +++++++ .../template/NotifyTemplateCreateReqVO.java | 12 +++ .../vo/template/NotifyTemplateExcelVO.java | 42 ++++++++ .../template/NotifyTemplateExportReqVO.java | 28 ++++++ .../vo/template/NotifyTemplatePageReqVO.java | 30 ++++++ .../vo/template/NotifyTemplateRespVO.java | 19 ++++ .../template/NotifyTemplateUpdateReqVO.java | 17 ++++ .../convert/notify/NotifyMessageConvert.java | 34 +++++++ .../convert/notify/NotifyTemplateConvert.java | 37 +++++++ .../dataobject/notify/NotifyMessageDO.java | 59 +++++++++++ .../dataobject/notify/NotifyTemplateDO.java | 55 +++++++++++ .../dal/mysql/notify/NotifyMessageMapper.java | 25 +++++ .../mysql/notify/NotifyTemplateMapper.java | 39 ++++++++ .../service/notify/NotifyMessageService.java | 65 ++++++++++++ .../notify/NotifyMessageServiceImpl.java | 78 +++++++++++++++ .../service/notify/NotifyTemplateService.java | 74 ++++++++++++++ .../notify/NotifyTemplateServiceImpl.java | 86 ++++++++++++++++ 30 files changed, 1244 insertions(+) create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApi.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/dto/NotifySendSingleToUserReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplatePageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApi.java new file mode 100644 index 0000000000..b5885e7ef9 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApi.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.system.api.notify; + +import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; + +import javax.validation.Valid; + +/** + * 站内信发送 API 接口 + * + * @author xrcoder + */ +public interface NotifyMessageSendApi { + + /** + * 发送单条站内信给 Admin 用户 + *

+ * 在 mobile 为空时,使用 userId 加载对应 Admin 的手机号 + * + * @param reqDTO 发送请求 + * @return 发送消息ID + */ + Long sendSingleMessageToAdmin(@Valid NotifySendSingleToUserReqDTO reqDTO); + + /** + * 发送单条站内信给 Member 用户 + *

+ * 在 mobile 为空时,使用 userId 加载对应 Member 的手机号 + * + * @param reqDTO 发送请求 + * @return 发送消息ID + */ + Long sendSingleMessageToMember(@Valid NotifySendSingleToUserReqDTO reqDTO); + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/dto/NotifySendSingleToUserReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/dto/NotifySendSingleToUserReqDTO.java new file mode 100644 index 0000000000..502d3eb306 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/notify/dto/NotifySendSingleToUserReqDTO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.system.api.notify.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Map; + +/** + * 站内信发送给 Admin 或者 Member 用户 + * + * @author xrcoder + */ +@Data +public class NotifySendSingleToUserReqDTO { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Long userId; + + /** + * 站内信模板编号 + */ + @NotEmpty(message = "站内信模板编号不能为空") + private String templateCode; + + /** + * 站内信模板参数 + */ + 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 2f39519a3d..321599f002 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 @@ -142,4 +142,10 @@ public interface ErrorCodeConstants { ErrorCode OAUTH2_CODE_NOT_EXISTS = new ErrorCode(1002022000, "code 不存在"); ErrorCode OAUTH2_CODE_EXPIRE = new ErrorCode(1002022000, "code 已过期"); + // ========== 站内信模版 1002023000 ========== + ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1002023000, "站内信模版不存在"); + + // ========== 站内信 1002024000 ========== + ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在"); + } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java new file mode 100644 index 0000000000..f0af060daa --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.system.enums.notify; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 站内信阅读状态枚举类 + * + * @author xrcoder + */ +@Getter +@AllArgsConstructor +public enum NotifyReadStatusEnum { + + UNREAD(0), + READ(1); + + /** + * 类型 + */ + private final Integer status; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java new file mode 100644 index 0000000000..6861ff8c5e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.api.notify; + +import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; +import org.springframework.stereotype.Service; + +/** + * 站内信发送 API 接口 + * + * @author xrcoder + */ +@Service +public class NotifyMessageSendApiImpl implements NotifyMessageSendApi { + + /** + * 发送单条站内信给 Admin 用户 + *

+ * 在 mobile 为空时,使用 userId 加载对应 Admin 的手机号 + * + * @param reqDTO 发送请求 + * @return 发送消息ID + */ + @Override + public Long sendSingleMessageToAdmin(NotifySendSingleToUserReqDTO reqDTO) { + return null; + } + + /** + * 发送单条站内信给 Member 用户 + *

+ * 在 mobile 为空时,使用 userId 加载对应 Member 的手机号 + * + * @param reqDTO 发送请求 + * @return 发送消息ID + */ + @Override + public Long sendSingleMessageToMember(NotifySendSingleToUserReqDTO reqDTO) { + return null; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java new file mode 100644 index 0000000000..0f52903772 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -0,0 +1,73 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; +import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Api(tags = "管理后台 - 站内信") +@RestController +@RequestMapping("/system/notify-message") +@Validated +public class NotifyMessageController { + + @Resource + private NotifyMessageService notifyMessageService; + + @PostMapping("/create") + @ApiOperation("创建站内信") + @PreAuthorize("@ss.hasPermission('system:notify-message:create')") + public CommonResult createNotifyMessage(@Valid @RequestBody NotifyMessageCreateReqVO createReqVO) { + return success(notifyMessageService.createNotifyMessage(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新站内信") + @PreAuthorize("@ss.hasPermission('system:notify-message:update')") + public CommonResult updateNotifyMessage(@Valid @RequestBody NotifyMessageUpdateReqVO updateReqVO) { + notifyMessageService.updateNotifyMessage(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除站内信") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:notify-message:delete')") + public CommonResult deleteNotifyMessage(@RequestParam("id") Long id) { + notifyMessageService.deleteNotifyMessage(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得站内信") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:notify-message:query')") + public CommonResult getNotifyMessage(@RequestParam("id") Long id) { + NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); + return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); + } + + @GetMapping("/page") + @ApiOperation("获得站内信分页") + @PreAuthorize("@ss.hasPermission('system:notify-message:query')") + public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { + PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); + return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java new file mode 100644 index 0000000000..fe7f8a1a25 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java @@ -0,0 +1,99 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify; + +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.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; +import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Api(tags = "管理后台 - 站内信模版") +@RestController +@RequestMapping("/system/notify-template") +@Validated +public class NotifyTemplateController { + + @Resource + private NotifyTemplateService notifyTemplateService; + + @PostMapping("/create") + @ApiOperation("创建站内信模版") + @PreAuthorize("@ss.hasPermission('system:notify-template:create')") + public CommonResult createNotifyTemplate(@Valid @RequestBody NotifyTemplateCreateReqVO createReqVO) { + return success(notifyTemplateService.createNotifyTemplate(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新站内信模版") + @PreAuthorize("@ss.hasPermission('system:notify-template:update')") + public CommonResult updateNotifyTemplate(@Valid @RequestBody NotifyTemplateUpdateReqVO updateReqVO) { + notifyTemplateService.updateNotifyTemplate(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除站内信模版") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:notify-template:delete')") + public CommonResult deleteNotifyTemplate(@RequestParam("id") Long id) { + notifyTemplateService.deleteNotifyTemplate(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得站内信模版") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:notify-template:query')") + public CommonResult getNotifyTemplate(@RequestParam("id") Long id) { + NotifyTemplateDO notifyTemplate = notifyTemplateService.getNotifyTemplate(id); + return success(NotifyTemplateConvert.INSTANCE.convert(notifyTemplate)); + } + + @GetMapping("/list") + @ApiOperation("获得站内信模版列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('system:notify-template:query')") + public CommonResult> getNotifyTemplateList(@RequestParam("ids") Collection ids) { + List list = notifyTemplateService.getNotifyTemplateList(ids); + return success(NotifyTemplateConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得站内信模版分页") + @PreAuthorize("@ss.hasPermission('system:notify-template:query')") + public CommonResult> getNotifyTemplatePage(@Valid NotifyTemplatePageReqVO pageVO) { + PageResult pageResult = notifyTemplateService.getNotifyTemplatePage(pageVO); + return success(NotifyTemplateConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出站内信模版 Excel") + @PreAuthorize("@ss.hasPermission('system:notify-template:export')") + @OperateLog(type = EXPORT) + public void exportNotifyTemplateExcel(@Valid NotifyTemplateExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = notifyTemplateService.getNotifyTemplateList(exportReqVO); + // 导出 Excel + List datas = NotifyTemplateConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java new file mode 100644 index 0000000000..c74291d585 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java @@ -0,0 +1,83 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; +import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 管理后台 - 站内信-消息中心 + * + * @author xrcoder + */ +@Api(tags = "管理后台 - 站内信-消息中心") +@RestController +@RequestMapping("/system/user/notify-message") +@Validated +public class UserNotifyMessageController { + + @Resource + private NotifyMessageService notifyMessageService; + + + @GetMapping("/page") + @ApiOperation("获得站内信分页") + public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { + PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); + return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/latest/list") + @ApiOperation("获得最新10站内信列表") + public CommonResult> getNotifyLatestMessageList() { + return success(Collections.emptyList()); + } + + @GetMapping("/unread/count") + @ApiOperation("获得未读站内信数量") + public CommonResult getUnreadNotifyMessageCount() { + return success(1L); + } + + @GetMapping("/read") + @ApiOperation("获得站内信") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + public CommonResult readNotifyMessage(@RequestParam("id") Long id) { + NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); + // TODO 记录消息已读。 + return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); + } + + @GetMapping("/read/list") + @ApiOperation("批量标记已读") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + return success(Boolean.TRUE); + } + + @GetMapping("/read/all") + @ApiOperation("所有未读消息标记已读") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + public CommonResult batchUpdateAllNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + return success(Boolean.TRUE); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java new file mode 100644 index 0000000000..b19480e715 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** +* 站内信 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class NotifyMessageBaseVO { + + @ApiModelProperty(value = "用户编号", required = true) + @NotNull(message = "用户编号不能为空") + private Long userId; + + @ApiModelProperty(value = "用户类型", required = true) + @NotNull(message = "用户类型不能为空") + private Integer userType; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "内容", required = true) + @NotNull(message = "内容不能为空") + private String content; + + @ApiModelProperty(value = "是否已读 0-未读 1-已读") + private Boolean readStatus; + + @ApiModelProperty(value = "阅读时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date readTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java new file mode 100644 index 0000000000..61a0e56669 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; + +import lombok.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 站内信创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyMessageCreateReqVO extends NotifyMessageBaseVO { + + @ApiModelProperty(value = "站内信模版编号") + private Long templateId; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java new file mode 100644 index 0000000000..8331d1b5fe --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +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 NotifyMessagePageReqVO extends PageParam { + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "是否已读 0-未读 1-已读") + private Boolean readStatus; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date[] createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java new file mode 100644 index 0000000000..530b368c11 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 站内信 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyMessageRespVO extends NotifyMessageBaseVO { + + @ApiModelProperty(value = "ID", required = true) + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java new file mode 100644 index 0000000000..3576cca9f3 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; + +import lombok.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 站内信更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyMessageUpdateReqVO extends NotifyMessageBaseVO { + + @ApiModelProperty(value = "ID", required = true) + @NotNull(message = "ID不能为空") + private Long id; + + @ApiModelProperty(value = "站内信模版编号") + private Long templateId; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java new file mode 100644 index 0000000000..371239455c --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +/** +* 站内信模版 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class NotifyTemplateBaseVO { + + @ApiModelProperty(value = "模版编码", required = true) + @NotNull(message = "模版编码不能为空") + private String code; + + @ApiModelProperty(value = "模版标题", required = true) + @NotNull(message = "模版标题不能为空") + private String title; + + @ApiModelProperty(value = "模版内容", required = true) + @NotNull(message = "模版内容不能为空") + private String content; + + @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true) + @NotNull(message = "状态:1-启用 0-禁用不能为空") + private String status; + + @ApiModelProperty(value = "备注") + private String remarks; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java new file mode 100644 index 0000000000..e39a2774a2 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java @@ -0,0 +1,12 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 站内信模版创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyTemplateCreateReqVO extends NotifyTemplateBaseVO { + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java new file mode 100644 index 0000000000..e0402da8ce --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + + +/** + * 站内信模版 Excel VO + * + * @author 芋道源码 + */ +@Data +public class NotifyTemplateExcelVO { + + @ExcelProperty("ID") + private Long id; + + @ExcelProperty("模版编码") + private String code; + + @ExcelProperty("模版标题") + private String title; + + @ExcelProperty("模版内容") + private String content; + + @ExcelProperty(value = "状态:1-启用 0-禁用", converter = DictConvert.class) + @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String status; + + @ExcelProperty("备注") + private String remarks; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java new file mode 100644 index 0000000000..a9f8877e22 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 站内信模版 Excel 导出 Request VO", description = "参数和 NotifyTemplatePageReqVO 是一致的") +@Data +public class NotifyTemplateExportReqVO { + + @ApiModelProperty(value = "模版编码") + private String code; + + @ApiModelProperty(value = "模版标题") + private String title; + + @ApiModelProperty(value = "状态:1-启用 0-禁用") + private String status; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date[] createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplatePageReqVO.java new file mode 100644 index 0000000000..7a8145b677 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplatePageReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +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 NotifyTemplatePageReqVO extends PageParam { + + @ApiModelProperty(value = "模版编码") + private String code; + + @ApiModelProperty(value = "模版标题") + private String title; + + @ApiModelProperty(value = "状态:1-启用 0-禁用") + private String status; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date[] createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java new file mode 100644 index 0000000000..52dd3656e2 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 站内信模版 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyTemplateRespVO extends NotifyTemplateBaseVO { + + @ApiModelProperty(value = "ID", required = true) + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java new file mode 100644 index 0000000000..267159447b --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import lombok.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 站内信模版更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class NotifyTemplateUpdateReqVO extends NotifyTemplateBaseVO { + + @ApiModelProperty(value = "ID", required = true) + @NotNull(message = "ID不能为空") + private Long id; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java new file mode 100644 index 0000000000..b5bce25d43 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.system.convert.notify; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; + +/** + * 站内信 Convert + * + * @author xrcoder + */ +@Mapper +public interface NotifyMessageConvert { + + NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); + + NotifyMessageDO convert(NotifyMessageCreateReqVO bean); + + NotifyMessageDO convert(NotifyMessageUpdateReqVO bean); + + NotifyMessageRespVO convert(NotifyMessageDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java new file mode 100644 index 0000000000..8d58067b9f --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.system.convert.notify; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExcelVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; + +/** + * 站内信模版 Convert + * + * @author xrcoder + */ +@Mapper +public interface NotifyTemplateConvert { + + NotifyTemplateConvert INSTANCE = Mappers.getMapper(NotifyTemplateConvert.class); + + NotifyTemplateDO convert(NotifyTemplateCreateReqVO bean); + + NotifyTemplateDO convert(NotifyTemplateUpdateReqVO bean); + + NotifyTemplateRespVO convert(NotifyTemplateDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java new file mode 100644 index 0000000000..c826c9d106 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.notify; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 站内信 DO + * + * @author xrcoder + */ +@TableName("system_notify_message") +@KeySequence("system_notify_message_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class NotifyMessageDO extends BaseDO { + + /** + * ID + */ + @TableId + private Long id; + /** + * 站内信模版编号 + */ + private Long templateId; + /** + * 用户编号 + */ + private Long userId; + /** + * 用户类型 + */ + private Integer userType; + /** + * 标题 + */ + private String title; + /** + * 内容 + */ + private String content; + /** + * 是否已读 0-未读 1-已读 + * + * 枚举 {@link TODO system_notify_message_read_status 对应的类} + */ + private Boolean readStatus; + /** + * 阅读时间 + */ + private Date readTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java new file mode 100644 index 0000000000..aa7cce11e1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.notify; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 站内信模版 DO + * + * @author xrcoder + */ +@TableName("system_notify_template") +@KeySequence("system_notify_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class NotifyTemplateDO extends BaseDO { + + /** + * ID + */ + @TableId + private Long id; + /** + * 模版编码 + */ + private String code; + /** + * 模版标题 + */ + private String title; + /** + * 模版内容 + */ + private String content; + /** + * 参数数组 + */ + private String params; + /** + * 状态:1-启用 0-禁用 + * + * 枚举 {@link TODO common_status 对应的类} + */ + private String status; + /** + * 备注 + */ + private String remarks; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java new file mode 100644 index 0000000000..2a7293d107 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.system.dal.mysql.notify; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 站内信 Mapper + * + * @author xrcoder + */ +@Mapper +public interface NotifyMessageMapper extends BaseMapperX { + + default PageResult selectPage(NotifyMessagePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) + .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) + .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(NotifyMessageDO::getId)); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java new file mode 100644 index 0000000000..115055b097 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.dal.mysql.notify; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 站内信模版 Mapper + * + * @author xrcoder + */ +@Mapper +public interface NotifyTemplateMapper extends BaseMapperX { + + default PageResult selectPage(NotifyTemplatePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(NotifyTemplateDO::getCode, reqVO.getCode()) + .eqIfPresent(NotifyTemplateDO::getTitle, reqVO.getTitle()) + .eqIfPresent(NotifyTemplateDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(NotifyTemplateDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(NotifyTemplateDO::getId)); + } + + default List selectList(NotifyTemplateExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(NotifyTemplateDO::getCode, reqVO.getCode()) + .eqIfPresent(NotifyTemplateDO::getTitle, reqVO.getTitle()) + .eqIfPresent(NotifyTemplateDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(NotifyTemplateDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(NotifyTemplateDO::getId)); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java new file mode 100644 index 0000000000..42b4f05ead --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 站内信 Service 接口 + * + * @author xrcoder + */ +public interface NotifyMessageService { + + /** + * 创建站内信 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createNotifyMessage(@Valid NotifyMessageCreateReqVO createReqVO); + + /** + * 更新站内信 + * + * @param updateReqVO 更新信息 + */ + void updateNotifyMessage(@Valid NotifyMessageUpdateReqVO updateReqVO); + + /** + * 删除站内信 + * + * @param id 编号 + */ + void deleteNotifyMessage(Long id); + + /** + * 获得站内信 + * + * @param id 编号 + * @return 站内信 + */ + NotifyMessageDO getNotifyMessage(Long id); + + /** + * 获得站内信列表 + * + * @param ids 编号 + * @return 站内信列表 + */ + List getNotifyMessageList(Collection ids); + + /** + * 获得站内信分页 + * + * @param pageReqVO 分页查询 + * @return 站内信分页 + */ + PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java new file mode 100644 index 0000000000..25a6f94a6f --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; +import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_MESSAGE_NOT_EXISTS; + +/** + * 站内信 Service 实现类 + * + * @author xrcoder + */ +@Service +@Validated +public class NotifyMessageServiceImpl implements NotifyMessageService { + + @Resource + private NotifyMessageMapper notifyMessageMapper; + + @Override + public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) { + // 插入 + NotifyMessageDO notifyMessage = NotifyMessageConvert.INSTANCE.convert(createReqVO); + notifyMessageMapper.insert(notifyMessage); + // 返回 + return notifyMessage.getId(); + } + + @Override + public void updateNotifyMessage(NotifyMessageUpdateReqVO updateReqVO) { + // 校验存在 + this.validateNotifyMessageExists(updateReqVO.getId()); + // 更新 + NotifyMessageDO updateObj = NotifyMessageConvert.INSTANCE.convert(updateReqVO); + notifyMessageMapper.updateById(updateObj); + } + + @Override + public void deleteNotifyMessage(Long id) { + // 校验存在 + this.validateNotifyMessageExists(id); + // 删除 + notifyMessageMapper.deleteById(id); + } + + private void validateNotifyMessageExists(Long id) { + if (notifyMessageMapper.selectById(id) == null) { + throw exception(NOTIFY_MESSAGE_NOT_EXISTS); + } + } + + @Override + public NotifyMessageDO getNotifyMessage(Long id) { + return notifyMessageMapper.selectById(id); + } + + @Override + public List getNotifyMessageList(Collection ids) { + return notifyMessageMapper.selectBatchIds(ids); + } + + @Override + public PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { + return notifyMessageMapper.selectPage(pageReqVO); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java new file mode 100644 index 0000000000..744d5585eb --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 站内信模版 Service 接口 + * + * @author xrcoder + */ +public interface NotifyTemplateService { + + /** + * 创建站内信模版 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createNotifyTemplate(@Valid NotifyTemplateCreateReqVO createReqVO); + + /** + * 更新站内信模版 + * + * @param updateReqVO 更新信息 + */ + void updateNotifyTemplate(@Valid NotifyTemplateUpdateReqVO updateReqVO); + + /** + * 删除站内信模版 + * + * @param id 编号 + */ + void deleteNotifyTemplate(Long id); + + /** + * 获得站内信模版 + * + * @param id 编号 + * @return 站内信模版 + */ + NotifyTemplateDO getNotifyTemplate(Long id); + + /** + * 获得站内信模版列表 + * + * @param ids 编号 + * @return 站内信模版列表 + */ + List getNotifyTemplateList(Collection ids); + + /** + * 获得站内信模版分页 + * + * @param pageReqVO 分页查询 + * @return 站内信模版分页 + */ + PageResult getNotifyTemplatePage(NotifyTemplatePageReqVO pageReqVO); + + /** + * 获得站内信模版列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 站内信模版列表 + */ + List getNotifyTemplateList(NotifyTemplateExportReqVO exportReqVO); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java new file mode 100644 index 0000000000..eb43af802c --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; + +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; + +/** + * 站内信模版 Service 实现类 + * + * @author xrcoder + */ +@Service +@Validated +public class NotifyTemplateServiceImpl implements NotifyTemplateService { + + @Resource + private NotifyTemplateMapper notifyTemplateMapper; + + @Override + public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) { + // 插入 + NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO); + notifyTemplateMapper.insert(notifyTemplate); + // 返回 + return notifyTemplate.getId(); + } + + @Override + public void updateNotifyTemplate(NotifyTemplateUpdateReqVO updateReqVO) { + // 校验存在 + this.validateNotifyTemplateExists(updateReqVO.getId()); + // 更新 + NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO); + notifyTemplateMapper.updateById(updateObj); + } + + @Override + public void deleteNotifyTemplate(Long id) { + // 校验存在 + this.validateNotifyTemplateExists(id); + // 删除 + notifyTemplateMapper.deleteById(id); + } + + private void validateNotifyTemplateExists(Long id) { + if (notifyTemplateMapper.selectById(id) == null) { + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); + } + } + + @Override + public NotifyTemplateDO getNotifyTemplate(Long id) { + return notifyTemplateMapper.selectById(id); + } + + @Override + public List getNotifyTemplateList(Collection ids) { + return notifyTemplateMapper.selectBatchIds(ids); + } + + @Override + public PageResult getNotifyTemplatePage(NotifyTemplatePageReqVO pageReqVO) { + return notifyTemplateMapper.selectPage(pageReqVO); + } + + @Override + public List getNotifyTemplateList(NotifyTemplateExportReqVO exportReqVO) { + return notifyTemplateMapper.selectList(exportReqVO); + } + +} From d16f873521d24892f1148cfa9b43f01e94514e04 Mon Sep 17 00:00:00 2001 From: xrcoder <53924337@qq.com> Date: Sat, 6 Aug 2022 10:03:09 +0800 Subject: [PATCH 26/67] =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 1 + .../vo/template/NotifyTemplateRespVO.java | 3 + .../dataobject/notify/NotifyTemplateDO.java | 27 ++- .../mysql/notify/NotifyTemplateMapper.java | 9 + .../notify/NotifyTemplateRefreshConsumer.java | 29 ++++ .../notify/NotifyTemplateRefreshMessage.java | 21 +++ .../mq/producer/notify/NotifyProducer.java | 33 ++++ .../service/notify/NotifyTemplateService.java | 24 +++ .../notify/NotifyTemplateServiceImpl.java | 159 +++++++++++++++++- 9 files changed, 290 insertions(+), 16 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/notify/NotifyTemplateRefreshConsumer.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/notify/NotifyTemplateRefreshMessage.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/notify/NotifyProducer.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 321599f002..078deb7f4a 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 @@ -144,6 +144,7 @@ public interface ErrorCodeConstants { // ========== 站内信模版 1002023000 ========== ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1002023000, "站内信模版不存在"); + ErrorCode NOTIFY_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002023001, "已经存在编码为【{}】的站内信模板"); // ========== 站内信 1002024000 ========== ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java index 52dd3656e2..f77126f6ca 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java @@ -13,6 +13,9 @@ public class NotifyTemplateRespVO extends NotifyTemplateBaseVO { @ApiModelProperty(value = "ID", required = true) private Long id; + @ApiModelProperty(value = "参数数组", example = "name,code") + private List params; + @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java index aa7cce11e1..2066f0b239 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java @@ -1,16 +1,22 @@ package cn.iocoder.yudao.module.system.dal.dataobject.notify; -import lombok.*; -import java.util.*; -import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import lombok.*; + +import java.util.List; /** * 站内信模版 DO * * @author xrcoder */ -@TableName("system_notify_template") +@TableName(value = "system_notify_template", autoResultMap = true) @KeySequence("system_notify_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @@ -25,28 +31,35 @@ public class NotifyTemplateDO extends BaseDO { */ @TableId private Long id; + /** * 模版编码 */ private String code; + /** * 模版标题 */ private String title; + /** * 模版内容 */ private String content; + /** * 参数数组 */ - private String params; + @TableField(typeHandler = JacksonTypeHandler.class) + private List params; + /** * 状态:1-启用 0-禁用 - * - * 枚举 {@link TODO common_status 对应的类} + *

+ * 枚举 {@link CommonStatusEnum} */ private String status; + /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java index 115055b097..c71a054b1d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyTemplateMapper.java @@ -8,7 +8,9 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; /** * 站内信模版 Mapper @@ -18,6 +20,13 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface NotifyTemplateMapper extends BaseMapperX { + @Select("SELECT COUNT(*) FROM system_notify_template WHERE update_time > #{maxUpdateTime}") + Long selectCountByUpdateTimeGt(Date maxUpdateTime); + + default NotifyTemplateDO selectByCode(String code) { + return selectOne(NotifyTemplateDO::getCode, code); + } + default PageResult selectPage(NotifyTemplatePageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(NotifyTemplateDO::getCode, reqVO.getCode()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/notify/NotifyTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/notify/NotifyTemplateRefreshConsumer.java new file mode 100644 index 0000000000..c2d8133b39 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/notify/NotifyTemplateRefreshConsumer.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.system.mq.consumer.notify; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; +import cn.iocoder.yudao.module.system.mq.message.notify.NotifyTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 针对 {@link NotifyTemplateRefreshMessage} 的消费者 + * + * @author xrcoder + */ +@Component +@Slf4j +public class NotifyTemplateRefreshConsumer extends AbstractChannelMessageListener { + + @Resource + private NotifyTemplateService notifyTemplateService; + + @Override + public void onMessage(NotifyTemplateRefreshMessage message) { + log.info("[onMessage][收到 NotifyTemplate 刷新消息]"); + notifyTemplateService.initLocalCache(); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/notify/NotifyTemplateRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/notify/NotifyTemplateRefreshMessage.java new file mode 100644 index 0000000000..3eddf0bc6b --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/notify/NotifyTemplateRefreshMessage.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.system.mq.message.notify; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 站内信模板的数据刷新 Message + * + * @author xrcoder + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class NotifyTemplateRefreshMessage extends AbstractChannelMessage { + + @Override + public String getChannel() { + return "system.notify-template.refresh"; + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/notify/NotifyProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/notify/NotifyProducer.java new file mode 100644 index 0000000000..3affe2c2f6 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/notify/NotifyProducer.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.system.mq.producer.notify; + +import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; +import cn.iocoder.yudao.module.system.mq.message.notify.NotifyTemplateRefreshMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * Notify 站内信相关消息的 Producer + * + * @author xrcoder + * @since 2022-08-06 + */ +@Slf4j +@Component +public class NotifyProducer { + + @Resource + private RedisMQTemplate redisMQTemplate; + + + /** + * 发送 {@link NotifyTemplateRefreshMessage} 消息 + */ + public void sendNotifyTemplateRefreshMessage() { + NotifyTemplateRefreshMessage message = new NotifyTemplateRefreshMessage(); + redisMQTemplate.send(message); + } + + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java index 744d5585eb..f7a9318a11 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.Notify import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; /** * 站内信模版 Service 接口 @@ -17,6 +18,29 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; */ public interface NotifyTemplateService { + /** + * 初始化站内信模板的本地缓存 + */ + void initLocalCache(); + + /** + * 获得站内信模板,从缓存中 + * + * @param code 模板编码 + * @return 站内信模板 + */ + NotifyTemplateDO getNotifyTemplateByCodeFromCache(String code); + + + /** + * 格式化站内信内容 + * + * @param content 站内信模板的内容 + * @param params 站内信内容的参数 + * @return 格式化后的内容 + */ + String formatNotifyTemplateContent(String content, Map params); + /** * 创建站内信模版 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index eb43af802c..65b71d92ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -1,23 +1,34 @@ package cn.iocoder.yudao.module.system.service.notify; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ReUtil; +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.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.notify.NotifyProducer; +import com.google.common.annotations.VisibleForTesting; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; -import java.util.*; - -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; -import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; +import javax.annotation.Resource; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; 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.NOTIFY_TEMPLATE_CODE_DUPLICATE; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_TEMPLATE_NOT_EXISTS; /** * 站内信模版 Service 实现类 @@ -26,16 +37,123 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; */ @Service @Validated +@Slf4j public class NotifyTemplateServiceImpl implements NotifyTemplateService { + /** + * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 + * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 + */ + private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; + + /** + * 正则表达式,匹配 {} 中的变量 + */ + private static final Pattern PATTERN_PARAMS = Pattern.compile("\\{(.*?)}"); + @Resource private NotifyTemplateMapper notifyTemplateMapper; + @Resource + private NotifyProducer notifyProducer; + + /** + * 站内信模板缓存 + * key:站内信模板编码 {@link NotifyTemplateDO#getCode()} + *

+ * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map notifyTemplateCache; + + /** + * 缓存站内信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 + */ + private volatile Date maxUpdateTime; + + /** + * 初始化站内信模板的本地缓存 + */ + @Override + public void initLocalCache() { + // 获取站内信模板列表,如果有更新 + List notifyTemplateList = this.loadNotifyTemplateIfUpdate(maxUpdateTime); + if (CollUtil.isEmpty(notifyTemplateList)) { + return; + } + + // 写入缓存 + notifyTemplateCache = CollectionUtils.convertMap(notifyTemplateList, NotifyTemplateDO::getCode); + maxUpdateTime = CollectionUtils.getMaxValue(notifyTemplateList, NotifyTemplateDO::getUpdateTime); + log.info("[initLocalCache][初始化 NotifyTemplate 数量为 {}]", notifyTemplateList.size()); + + } + + /** + * 如果站内信模板发生变化,从数据库中获取最新的全量站内信模板。 + * 如果未发生变化,则返回空 + * + * @param maxUpdateTime 当前站内信模板的最大更新时间 + * @return 站内信模板列表 + */ + private List loadNotifyTemplateIfUpdate(Date maxUpdateTime) { + // 第一步,判断是否要更新。 + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadNotifyTemplateIfUpdate][首次加载全量站内信模板]"); + } else { // 判断数据库中是否有更新的站内信模板 + if (notifyTemplateMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { + return null; + } + log.info("[loadNotifyTemplateIfUpdate][增量加载全量站内信模板]"); + } + // 第二步,如果有更新,则从数据库加载所有站内信模板 + return notifyTemplateMapper.selectList(); + } + + @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) + public void schedulePeriodicRefresh() { + initLocalCache(); + } + + + /** + * 获得站内信模板,从缓存中 + * + * @param code 模板编码 + * @return 站内信模板 + */ + @Override + public NotifyTemplateDO getNotifyTemplateByCodeFromCache(String code) { + return notifyTemplateCache.get(code); + } + + /** + * 格式化站内信内容 + * + * @param content 站内信模板的内容 + * @param params 站内信内容的参数 + * @return 格式化后的内容 + */ + @Override + public String formatNotifyTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + + @VisibleForTesting + public List parseTemplateContentParams(String content) { + return ReUtil.findAllGroup1(PATTERN_PARAMS, content); + } + @Override public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) { + // 校验站内信编码是否重复 + checkNotifyTemplateCodeDuplicate(null, createReqVO.getCode()); + // 插入 NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO); + notifyTemplate.setParams(parseTemplateContentParams(notifyTemplate.getContent())); notifyTemplateMapper.insert(notifyTemplate); + // 发送刷新消息 + notifyProducer.sendNotifyTemplateRefreshMessage(); // 返回 return notifyTemplate.getId(); } @@ -44,9 +162,16 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { public void updateNotifyTemplate(NotifyTemplateUpdateReqVO updateReqVO) { // 校验存在 this.validateNotifyTemplateExists(updateReqVO.getId()); + // 校验站内信编码是否重复 + checkNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); + // 更新 NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO); + updateObj.setParams(parseTemplateContentParams(updateObj.getContent())); + notifyTemplateMapper.updateById(updateObj); + // 发送刷新消息 + notifyProducer.sendNotifyTemplateRefreshMessage(); } @Override @@ -55,6 +180,8 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { this.validateNotifyTemplateExists(id); // 删除 notifyTemplateMapper.deleteById(id); + // 发送刷新消息 + notifyProducer.sendNotifyTemplateRefreshMessage(); } private void validateNotifyTemplateExists(Long id) { @@ -83,4 +210,18 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { return notifyTemplateMapper.selectList(exportReqVO); } + @VisibleForTesting + public void checkNotifyTemplateCodeDuplicate(Long id, String code) { + NotifyTemplateDO template = notifyTemplateMapper.selectByCode(code); + if (template == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的字典类型 + if (id == null) { + throw exception(NOTIFY_TEMPLATE_CODE_DUPLICATE, code); + } + if (!template.getId().equals(id)) { + throw exception(NOTIFY_TEMPLATE_CODE_DUPLICATE, code); + } + } } From af4290784e852ba0f673e848af75955f03eca7c4 Mon Sep 17 00:00:00 2001 From: xrcoder <53924337@qq.com> Date: Sat, 6 Aug 2022 10:47:54 +0800 Subject: [PATCH 27/67] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=AB=99=E5=86=85=E4=BF=A1=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=9C=AA=E8=AF=BB?= =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E6=95=B0=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 1 + .../notify/UserNotifyMessageController.java | 16 +++++- .../vo/message/NotifyMessagePageReqVO.java | 6 +++ .../dal/mysql/notify/NotifyMessageMapper.java | 14 ++++- .../service/notify/NotifyMessageService.java | 17 ++++-- .../notify/NotifyMessageServiceImpl.java | 52 ++++++++++++++++++- 6 files changed, 99 insertions(+), 7 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 078deb7f4a..a126aee6e9 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,6 +145,7 @@ public interface ErrorCodeConstants { // ========== 站内信模版 1002023000 ========== ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1002023000, "站内信模版不存在"); ErrorCode NOTIFY_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002023001, "已经存在编码为【{}】的站内信模板"); + ErrorCode NOTIFY_TEMPLATE_PARAM_MISS = new ErrorCode(1002023002, "模板参数({})缺失"); // ========== 站内信 1002024000 ========== ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java index c74291d585..eaae42e81e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; @@ -23,6 +25,7 @@ import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; /** * 管理后台 - 站内信-消息中心 @@ -42,6 +45,8 @@ public class UserNotifyMessageController { @GetMapping("/page") @ApiOperation("获得站内信分页") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { + pageVO.setUserId(getLoginUserId()); + pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } @@ -49,13 +54,22 @@ public class UserNotifyMessageController { @GetMapping("/latest/list") @ApiOperation("获得最新10站内信列表") public CommonResult> getNotifyLatestMessageList() { + NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); + reqVO.setUserId(getLoginUserId()); + reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); + reqVO.setPageNo(1); + reqVO.setPageSize(10); + PageResult pageResult = notifyMessageService.getNotifyMessagePage(reqVO); + if (CollUtil.isNotEmpty(pageResult.getList())) { + return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList())); + } return success(Collections.emptyList()); } @GetMapping("/unread/count") @ApiOperation("获得未读站内信数量") public CommonResult getUnreadNotifyMessageCount() { - return success(1L); + return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); } @GetMapping("/read") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java index 8331d1b5fe..6db082d2cc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java @@ -24,4 +24,10 @@ public class NotifyMessagePageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private Date[] createTime; + + @ApiModelProperty(value = "用户编号", hidden = true) + private Long userId; + + @ApiModelProperty(value = "用户类型", hidden = true) + private Integer userType; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 2a7293d107..899208b8b3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.system.dal.mysql.notify; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 站内信 Mapper * @@ -20,6 +23,15 @@ public interface NotifyMessageMapper extends BaseMapperX { .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId()) + .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType()) .orderByDesc(NotifyMessageDO::getId)); } + + default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) { + return selectCount(new LambdaQueryWrapperX() + .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getUserId, userId) + .eq(NotifyMessageDO::getUserType, userType)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index 42b4f05ead..847ab9a4b7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -1,13 +1,14 @@ package cn.iocoder.yudao.module.system.service.notify; -import java.util.*; -import javax.validation.*; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; /** * 站内信 Service 接口 @@ -62,4 +63,12 @@ public interface NotifyMessageService { */ PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO); + /** + * 统计用户未读站内信条数 + * + * @param userId 用户ID + * @param userType 用户类型 + * @return 返回未读站内信条数 + */ + Long getUnreadNotifyMessageCount(Long userId, Integer userType); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 25a6f94a6f..c37ada4fd5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -1,21 +1,26 @@ package cn.iocoder.yudao.module.system.service.notify; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; 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.NOTIFY_MESSAGE_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 站内信 Service 实现类 @@ -29,6 +34,39 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @Resource private NotifyMessageMapper notifyMessageMapper; + @Resource + private NotifyTemplateService notifyTemplateService; + + + @VisibleForTesting + public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) { + // 获得站内信模板。考虑到效率,从缓存中获取 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode); + // 站内信模板不存在 + if (template == null) { + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); + } + return template; + } + + /** + * 将参数模板,处理成有序的 KeyValue 数组 + * + * @param template 站内信模板 + * @param templateParams 原始参数 + * @return 处理后的参数 + */ + @VisibleForTesting + public List> buildTemplateParams(NotifyTemplateDO template, Map templateParams) { + return template.getParams().stream().map(key -> { + Object value = templateParams.get(key); + if (value == null) { + throw exception(NOTIFY_TEMPLATE_PARAM_MISS, key); + } + return new KeyValue<>(key, value); + }).collect(Collectors.toList()); + } + @Override public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) { // 插入 @@ -75,4 +113,16 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { public PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { return notifyMessageMapper.selectPage(pageReqVO); } + + /** + * 统计用户未读站内信条数 + * + * @param userId 用户ID + * @param userType 用户类型 + * @return 返回未读站内信条数 + */ + @Override + public Long getUnreadNotifyMessageCount(Long userId, Integer userType) { + return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType); + } } From 7d6737479c0a5266f96241641a1be6d7d85412e9 Mon Sep 17 00:00:00 2001 From: xrcoder <53924337@qq.com> Date: Sat, 6 Aug 2022 10:53:36 +0800 Subject: [PATCH 28/67] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=B1=BB=E9=AA=8C=E8=AF=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notify/vo/message/NotifyMessageBaseVO.java | 12 ++++++++---- .../notify/vo/template/NotifyTemplateBaseVO.java | 11 +++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java index b19480e715..ca77eaccb3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotNull; +import java.util.Date; + import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; /** @@ -21,6 +24,7 @@ public class NotifyMessageBaseVO { @ApiModelProperty(value = "用户类型", required = true) @NotNull(message = "用户类型不能为空") + @InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}") private Integer userType; @ApiModelProperty(value = "标题") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java index 371239455c..bff746e14c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; /** * 站内信模版 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -26,6 +28,7 @@ public class NotifyTemplateBaseVO { @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true) @NotNull(message = "状态:1-启用 0-禁用不能为空") + @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") private String status; @ApiModelProperty(value = "备注") From 872107b319973655e11c716a2cf922348d3febb9 Mon Sep 17 00:00:00 2001 From: xrcoder <53924337@qq.com> Date: Sat, 6 Aug 2022 11:30:12 +0800 Subject: [PATCH 29/67] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=AB=99=E5=86=85?= =?UTF-8?q?=E4=BF=A1=E9=98=85=E8=AF=BB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 1 + .../notify/UserNotifyMessageController.java | 9 ++- .../vo/message/NotifyMessageBaseVO.java | 2 +- .../vo/message/NotifyMessagePageReqVO.java | 2 +- .../dataobject/notify/NotifyMessageDO.java | 4 +- .../dal/mysql/notify/NotifyMessageMapper.java | 7 ++ .../service/notify/NotifyMessageService.java | 24 +++++++ .../notify/NotifyMessageServiceImpl.java | 71 +++++++++++++++++++ 8 files changed, 113 insertions(+), 7 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 a126aee6e9..91dae4dfed 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 @@ -149,5 +149,6 @@ public interface ErrorCodeConstants { // ========== 站内信 1002024000 ========== ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在"); + ErrorCode NOTIFY_MESSAGE_ID_PARAM_ERROR = new ErrorCode(1002024001, "站内信ID错误"); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java index eaae42e81e..4104acdc1e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyM import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -77,7 +78,8 @@ public class UserNotifyMessageController { @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) public CommonResult readNotifyMessage(@RequestParam("id") Long id) { NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); - // TODO 记录消息已读。 + // 记录消息已读。 + notifyMessageService.updateNotifyMessageReadStatus(id, NotifyReadStatusEnum.READ.getStatus()); return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); } @@ -85,13 +87,14 @@ public class UserNotifyMessageController { @ApiOperation("批量标记已读") @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); return success(Boolean.TRUE); } @GetMapping("/read/all") @ApiOperation("所有未读消息标记已读") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - public CommonResult batchUpdateAllNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + public CommonResult batchUpdateAllNotifyMessageReadStatus() { + notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(Boolean.TRUE); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java index ca77eaccb3..e7f7439c26 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java @@ -35,7 +35,7 @@ public class NotifyMessageBaseVO { private String content; @ApiModelProperty(value = "是否已读 0-未读 1-已读") - private Boolean readStatus; + private Integer readStatus; @ApiModelProperty(value = "阅读时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java index 6db082d2cc..7f24c61c0f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java @@ -18,7 +18,7 @@ public class NotifyMessagePageReqVO extends PageParam { private String title; @ApiModelProperty(value = "是否已读 0-未读 1-已读") - private Boolean readStatus; + private Integer readStatus; @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java index c826c9d106..714ec4498a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java @@ -48,9 +48,9 @@ public class NotifyMessageDO extends BaseDO { /** * 是否已读 0-未读 1-已读 * - * 枚举 {@link TODO system_notify_message_read_status 对应的类} + * 枚举 {@link cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum} */ - private Boolean readStatus; + private Integer readStatus; /** * 阅读时间 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 899208b8b3..2c9137f11d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -34,4 +34,11 @@ public interface NotifyMessageMapper extends BaseMapperX { .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } + + default List selectUnreadListByUserIdAndUserType(Long userId, Integer userType) { + return selectList(new LambdaQueryWrapperX() + .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getUserId, userId) + .eq(NotifyMessageDO::getUserType, userType)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index 847ab9a4b7..f74a394b71 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -71,4 +71,28 @@ public interface NotifyMessageService { * @return 返回未读站内信条数 */ Long getUnreadNotifyMessageCount(Long userId, Integer userType); + + /** + * 修改站内信阅读状态 + * + * @param id 站内信编号 + * @param status 状态 + */ + void updateNotifyMessageReadStatus(Long id, Integer status); + + /** + * 批量修改站内信阅读状态 + * + * @param ids 站内信编号集合 + * @param userId 用户ID + */ + void batchUpdateNotifyMessageReadStatus(Collection ids, Long userId); + + /** + * 批量修改用户所有未读消息标记已读 + * + * @param userId 用户ID + * @param userType 用户类型 + */ + void batchUpdateAllNotifyMessageReadStatus(Long userId, Integer userType); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index c37ada4fd5..4c385ee485 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.system.service.notify; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; 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.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; @@ -9,6 +12,7 @@ import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -125,4 +129,71 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { public Long getUnreadNotifyMessageCount(Long userId, Integer userType) { return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType); } + + /** + * 修改站内信阅读状态 + * + * @param id 站内信编号 + * @param status 状态 + */ + @Override + public void updateNotifyMessageReadStatus(Long id, Integer status) { + // 校验消息是否存在 + this.validateNotifyMessageExists(id); + // 更新状态 + batchUpdateReadStatus(CollectionUtils.singleton(id)); + } + + /** + * 批量修改站内信阅读状态 + * + * @param ids 站内信编号集合 + * @param userId 用户ID + */ + @Override + public void batchUpdateNotifyMessageReadStatus(Collection ids, Long userId) { + List list = getNotifyMessageList(ids); + if (CollUtil.isEmpty(list)) { + throw exception(NOTIFY_MESSAGE_NOT_EXISTS); + } + // 验证站内信是否是属于用户 + for (NotifyMessageDO messageDO : list) { + checkNotifyMessageIdValid(messageDO, userId); + } + batchUpdateReadStatus(ids); + } + + @VisibleForTesting + public void checkNotifyMessageIdValid(NotifyMessageDO notifyMessageDO, Long userId) { + if (!NumberUtil.equals(notifyMessageDO.getUserId(), userId)) { + throw exception(NOTIFY_MESSAGE_ID_PARAM_ERROR); + } + } + + /** + * 批量修改用户所有未读消息标记已读 + * + * @param userId 用户ID + * @param userType 用户类型 + */ + @Override + public void batchUpdateAllNotifyMessageReadStatus(Long userId, Integer userType) { + List list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType); + if (CollUtil.isNotEmpty(list)) { + batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId)); + + } + } + + private void batchUpdateReadStatus(Collection ids) { + if (CollUtil.isNotEmpty(ids)) { + for (Long id : ids) { + NotifyMessageDO updateObj = new NotifyMessageDO(); + updateObj.setId(id); + updateObj.setReadStatus(NotifyReadStatusEnum.READ.getStatus()); + notifyMessageMapper.updateById(updateObj); + } + } + + } } From 131adad9c070e650fea9e644f1cca391987152e0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 21 Nov 2022 11:52:55 +0800 Subject: [PATCH 30/67] =?UTF-8?q?review=20=E9=83=A8=E5=88=86=E7=AB=99?= =?UTF-8?q?=E5=86=85=E4=BF=A1=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/notify/NotifyReadStatusEnum.java | 22 ------------------- .../notify/UserNotifyMessageController.java | 6 +---- .../dataobject/notify/NotifyMessageDO.java | 22 +++++++++++++------ .../dataobject/notify/NotifyTemplateDO.java | 12 +++------- 4 files changed, 19 insertions(+), 43 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java deleted file mode 100644 index f0af060daa..0000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/notify/NotifyReadStatusEnum.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.system.enums.notify; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 站内信阅读状态枚举类 - * - * @author xrcoder - */ -@Getter -@AllArgsConstructor -public enum NotifyReadStatusEnum { - - UNREAD(0), - READ(1); - - /** - * 类型 - */ - private final Integer status; -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java index 4104acdc1e..430c3ade83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java @@ -28,11 +28,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -/** - * 管理后台 - 站内信-消息中心 - * - * @author xrcoder - */ +// TODO 芋艿:合并到 合并到 NotifyTemplateController 中 @Api(tags = "管理后台 - 站内信-消息中心") @RestController @RequestMapping("/system/user/notify-message") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java index 714ec4498a..5a923998ac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java @@ -1,9 +1,13 @@ package cn.iocoder.yudao.module.system.dal.dataobject.notify; -import lombok.*; -import java.util.*; -import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.util.Date; /** * 站内信 DO @@ -27,14 +31,20 @@ public class NotifyMessageDO extends BaseDO { private Long id; /** * 站内信模版编号 + * + * 关联 {@link NotifyTemplateDO#getId()} */ private Long templateId; /** * 用户编号 + * + * 关联 MemberUserDO 的 id 字段、或者 AdminUserDO 的 id 字段 */ private Long userId; /** * 用户类型 + * + * 枚举 {@link UserTypeEnum} */ private Integer userType; /** @@ -46,11 +56,9 @@ public class NotifyMessageDO extends BaseDO { */ private String content; /** - * 是否已读 0-未读 1-已读 - * - * 枚举 {@link cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum} + * 是否已读 */ - private Integer readStatus; + private Boolean readStatus; /** * 阅读时间 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java index 2066f0b239..ab8b128eaf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java @@ -31,38 +31,32 @@ public class NotifyTemplateDO extends BaseDO { */ @TableId private Long id; - /** * 模版编码 */ private String code; - /** * 模版标题 */ private String title; - /** * 模版内容 */ private String content; - /** * 参数数组 */ @TableField(typeHandler = JacksonTypeHandler.class) private List params; - /** - * 状态:1-启用 0-禁用 - *

+ * 状态 + * * 枚举 {@link CommonStatusEnum} */ private String status; - /** * 备注 */ - private String remarks; + private String remark; } From e8dd66c6f848963e4b4329e14ecac3c80a18d844 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 21 Nov 2022 13:01:16 +0800 Subject: [PATCH 31/67] =?UTF-8?q?review=20=E9=83=A8=E5=88=86=E7=AB=99?= =?UTF-8?q?=E5=86=85=E4=BF=A1=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/notify/NotifyMessageController.java | 27 +------------------ .../notify/NotifyTemplateController.java | 15 ++++------- .../notify/UserNotifyMessageController.java | 8 +++++- .../vo/message/NotifyMessageCreateReqVO.java | 15 ----------- .../vo/message/NotifyMessagePageReqVO.java | 13 ++++++--- .../vo/message/NotifyMessageUpdateReqVO.java | 20 -------------- .../service/notify/NotifyMessageService.java | 25 ----------------- .../notify/NotifyMessageServiceImpl.java | 27 +------------------ .../service/notify/NotifyTemplateService.java | 12 +++++---- .../notify/NotifyTemplateServiceImpl.java | 1 - 10 files changed, 30 insertions(+), 133 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java index 0f52903772..7c65e49612 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; @@ -30,30 +28,6 @@ public class NotifyMessageController { @Resource private NotifyMessageService notifyMessageService; - @PostMapping("/create") - @ApiOperation("创建站内信") - @PreAuthorize("@ss.hasPermission('system:notify-message:create')") - public CommonResult createNotifyMessage(@Valid @RequestBody NotifyMessageCreateReqVO createReqVO) { - return success(notifyMessageService.createNotifyMessage(createReqVO)); - } - - @PutMapping("/update") - @ApiOperation("更新站内信") - @PreAuthorize("@ss.hasPermission('system:notify-message:update')") - public CommonResult updateNotifyMessage(@Valid @RequestBody NotifyMessageUpdateReqVO updateReqVO) { - notifyMessageService.updateNotifyMessage(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @ApiOperation("删除站内信") - @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('system:notify-message:delete')") - public CommonResult deleteNotifyMessage(@RequestParam("id") Long id) { - notifyMessageService.deleteNotifyMessage(id); - return success(true); - } - @GetMapping("/get") @ApiOperation("获得站内信") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -70,4 +44,5 @@ public class NotifyMessageController { PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index fe7f8a1a25..2be58771d6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java @@ -19,12 +19,12 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; +// TODO 芋艿:VO 类上的 swagger 注解完善下,例如说 swagger,枚举等等 @Api(tags = "管理后台 - 站内信模版") @RestController @RequestMapping("/system/notify-template") @@ -67,15 +67,6 @@ public class NotifyTemplateController { return success(NotifyTemplateConvert.INSTANCE.convert(notifyTemplate)); } - @GetMapping("/list") - @ApiOperation("获得站内信模版列表") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - @PreAuthorize("@ss.hasPermission('system:notify-template:query')") - public CommonResult> getNotifyTemplateList(@RequestParam("ids") Collection ids) { - List list = notifyTemplateService.getNotifyTemplateList(ids); - return success(NotifyTemplateConvert.INSTANCE.convertList(list)); - } - @GetMapping("/page") @ApiOperation("获得站内信模版分页") @PreAuthorize("@ss.hasPermission('system:notify-template:query')") @@ -96,4 +87,8 @@ public class NotifyTemplateController { ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas); } + // TODO @芋艿:参考 SmsTemplateController 的 sendNotify 写一个发送站内信的接口 + + // TODO @芋艿:参考 SmsSendServiceImpl,新建一个 NotifySendServiceImpl,用于提供出来给发送消息。注意,不要考虑异步发送,直接 insert 就可以了。也不用考虑发送后的回调 + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java index 430c3ade83..04bd09160e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java @@ -38,7 +38,7 @@ public class UserNotifyMessageController { @Resource private NotifyMessageService notifyMessageService; - + // TODO 芋艿:和 NotifyMessageController 的 page 合并 @GetMapping("/page") @ApiOperation("获得站内信分页") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { @@ -48,6 +48,7 @@ public class UserNotifyMessageController { return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } + // TODO @芋艿:url 改成 get-recent-list;方法名也改下。默认传入 size = 10; @GetMapping("/latest/list") @ApiOperation("获得最新10站内信列表") public CommonResult> getNotifyLatestMessageList() { @@ -56,6 +57,7 @@ public class UserNotifyMessageController { reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); reqVO.setPageNo(1); reqVO.setPageSize(10); + // TODO 芋艿:不要用分页写; PageResult pageResult = notifyMessageService.getNotifyMessagePage(reqVO); if (CollUtil.isNotEmpty(pageResult.getList())) { return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList())); @@ -63,12 +65,14 @@ public class UserNotifyMessageController { return success(Collections.emptyList()); } + // TODO @芋艿:get-unread-count @GetMapping("/unread/count") @ApiOperation("获得未读站内信数量") public CommonResult getUnreadNotifyMessageCount() { return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); } + // TODO @芋艿:把 get 站内信,和更新站内信已经读分开。其中更新单条和多条,使用一个接口就好列 @GetMapping("/read") @ApiOperation("获得站内信") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -79,6 +83,7 @@ public class UserNotifyMessageController { return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); } + // TODO @芋艿:PutMapping;update-list-read @GetMapping("/read/list") @ApiOperation("批量标记已读") @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @@ -87,6 +92,7 @@ public class UserNotifyMessageController { return success(Boolean.TRUE); } + // TODO @芋艿:PutMapping:update-all-read @GetMapping("/read/all") @ApiOperation("所有未读消息标记已读") public CommonResult batchUpdateAllNotifyMessageReadStatus() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java deleted file mode 100644 index 61a0e56669..0000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; - -import lombok.*; -import io.swagger.annotations.*; - -@ApiModel("管理后台 - 站内信创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyMessageCreateReqVO extends NotifyMessageBaseVO { - - @ApiModelProperty(value = "站内信模版编号") - private Long templateId; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java index 7f24c61c0f..443f3729a7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java @@ -1,11 +1,15 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; 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.util.Date; + import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @ApiModel("管理后台 - 站内信分页 Request VO") @@ -18,12 +22,13 @@ public class NotifyMessagePageReqVO extends PageParam { private String title; @ApiModelProperty(value = "是否已读 0-未读 1-已读") - private Integer readStatus; + private Boolean readStatus; @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private Date[] createTime; + // TODO 芋艿:去掉 userId 和 userType,不要在 VO 里 @ApiModelProperty(value = "用户编号", hidden = true) private Long userId; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java deleted file mode 100644 index 3576cca9f3..0000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; - -import lombok.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; - -@ApiModel("管理后台 - 站内信更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyMessageUpdateReqVO extends NotifyMessageBaseVO { - - @ApiModelProperty(value = "ID", required = true) - @NotNull(message = "ID不能为空") - private Long id; - - @ApiModelProperty(value = "站内信模版编号") - private Long templateId; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index f74a394b71..e6057bef03 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -1,12 +1,9 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import javax.validation.Valid; import java.util.Collection; import java.util.List; @@ -17,28 +14,6 @@ import java.util.List; */ public interface NotifyMessageService { - /** - * 创建站内信 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createNotifyMessage(@Valid NotifyMessageCreateReqVO createReqVO); - - /** - * 更新站内信 - * - * @param updateReqVO 更新信息 - */ - void updateNotifyMessage(@Valid NotifyMessageUpdateReqVO updateReqVO); - - /** - * 删除站内信 - * - * @param id 编号 - */ - void deleteNotifyMessage(Long id); - /** * 获得站内信 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 4c385ee485..8150ee4533 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -71,32 +71,6 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { }).collect(Collectors.toList()); } - @Override - public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) { - // 插入 - NotifyMessageDO notifyMessage = NotifyMessageConvert.INSTANCE.convert(createReqVO); - notifyMessageMapper.insert(notifyMessage); - // 返回 - return notifyMessage.getId(); - } - - @Override - public void updateNotifyMessage(NotifyMessageUpdateReqVO updateReqVO) { - // 校验存在 - this.validateNotifyMessageExists(updateReqVO.getId()); - // 更新 - NotifyMessageDO updateObj = NotifyMessageConvert.INSTANCE.convert(updateReqVO); - notifyMessageMapper.updateById(updateObj); - } - - @Override - public void deleteNotifyMessage(Long id) { - // 校验存在 - this.validateNotifyMessageExists(id); - // 删除 - notifyMessageMapper.deleteById(id); - } - private void validateNotifyMessageExists(Long id) { if (notifyMessageMapper.selectById(id) == null) { throw exception(NOTIFY_MESSAGE_NOT_EXISTS); @@ -185,6 +159,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { } } + // TODO 芋艿:批量更新,不要单条遍历哈。 private void batchUpdateReadStatus(Collection ids) { if (CollUtil.isNotEmpty(ids)) { for (Long id : ids) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java index f7a9318a11..cb2a5576c7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java @@ -1,21 +1,23 @@ package cn.iocoder.yudao.module.system.service.notify; -import java.util.*; -import javax.validation.*; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; +import java.util.Map; /** * 站内信模版 Service 接口 * * @author xrcoder */ +// TODO 芋艿:缺少单测,可以参考 SmsTemplateServiceTest 写下 public interface NotifyTemplateService { /** diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index 65b71d92ea..1342fe03b0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -114,7 +114,6 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { initLocalCache(); } - /** * 获得站内信模板,从缓存中 * From f77522980f9898594e54ac115e4b3fc903c837c4 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Wed, 23 Nov 2022 12:26:51 +0800 Subject: [PATCH 32/67] =?UTF-8?q?fix(=E7=AB=99=E5=86=85=E4=BF=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=B0=83=E6=95=B4):=20=E6=8E=A5=E5=8F=A3fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notify/NotifyMessageController.java | 45 ++++++++ .../notify/NotifyTemplateController.java | 16 ++- .../notify/UserNotifyMessageController.java | 102 ------------------ .../vo/message/NotifyMessageBaseVO.java | 4 +- .../vo/template/NotifyTemplateBaseVO.java | 2 +- .../vo/template/NotifyTemplateExcelVO.java | 5 +- .../template/NotifyTemplateExportReqVO.java | 2 +- .../vo/template/NotifyTemplateSendReqVO.java | 24 +++++ .../convert/notify/NotifyMessageConvert.java | 6 -- .../dataobject/notify/NotifyTemplateDO.java | 2 +- .../dal/mysql/notify/NotifyMessageMapper.java | 16 ++- .../service/notify/NotifyMessageService.java | 10 +- .../notify/NotifyMessageServiceImpl.java | 26 ++--- .../service/notify/NotifySendService.java | 51 +++++++++ .../service/notify/NotifySendServiceImpl.java | 77 +++++++++++++ 15 files changed, 248 insertions(+), 140 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java index 7c65e49612..7e14b86c7c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; @@ -17,7 +19,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Api(tags = "管理后台 - 站内信") @RestController @@ -41,8 +48,46 @@ public class NotifyMessageController { @ApiOperation("获得站内信分页") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { + pageVO.setUserId(getLoginUserId()); + pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/get-recent-list") + @ApiOperation("获取当前用户最新站内信,默认10条") + @ApiImplicitParam(name = "size", value = "10", defaultValue = "10", dataTypeClass = Integer.class) + public CommonResult> getRecentList(@RequestParam(name = "size", defaultValue = "10") Integer size) { + NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); + reqVO.setUserId(getLoginUserId()); + reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); + + List pageResult = notifyMessageService.getNotifyMessageList(reqVO, size); + if (CollUtil.isNotEmpty(pageResult)) { + return success(NotifyMessageConvert.INSTANCE.convertList(pageResult)); + } + return success(Collections.emptyList()); + } + + @GetMapping("/get-unread-count") + @ApiOperation("获得未读站内信数量") + public CommonResult getUnreadCount() { + return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); + } + + @GetMapping("/update-list-read") + @ApiOperation("批量标记已读") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); + return success(Boolean.TRUE); + } + + @GetMapping("/update-all-read") + @ApiOperation("所有未读消息标记已读") + public CommonResult batchUpdateAllNotifyMessageReadStatus() { + notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); + return success(Boolean.TRUE); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index 2be58771d6..aa57a795ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.service.notify.NotifySendService; import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -24,7 +25,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -// TODO 芋艿:VO 类上的 swagger 注解完善下,例如说 swagger,枚举等等 @Api(tags = "管理后台 - 站内信模版") @RestController @RequestMapping("/system/notify-template") @@ -34,6 +34,10 @@ public class NotifyTemplateController { @Resource private NotifyTemplateService notifyTemplateService; + @Resource + private NotifySendService notifySendService; + + @PostMapping("/create") @ApiOperation("创建站内信模版") @PreAuthorize("@ss.hasPermission('system:notify-template:create')") @@ -87,8 +91,10 @@ public class NotifyTemplateController { ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas); } - // TODO @芋艿:参考 SmsTemplateController 的 sendNotify 写一个发送站内信的接口 - - // TODO @芋艿:参考 SmsSendServiceImpl,新建一个 NotifySendServiceImpl,用于提供出来给发送消息。注意,不要考虑异步发送,直接 insert 就可以了。也不用考虑发送后的回调 - + @PostMapping("/send-notify") + @ApiOperation("发送站内信") + public CommonResult sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) { + return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(), + sendReqVO.getTemplateId(), sendReqVO.getTemplateParams())); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java deleted file mode 100644 index 04bd09160e..0000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; -import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; -import javax.validation.Valid; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; - -// TODO 芋艿:合并到 合并到 NotifyTemplateController 中 -@Api(tags = "管理后台 - 站内信-消息中心") -@RestController -@RequestMapping("/system/user/notify-message") -@Validated -public class UserNotifyMessageController { - - @Resource - private NotifyMessageService notifyMessageService; - - // TODO 芋艿:和 NotifyMessageController 的 page 合并 - @GetMapping("/page") - @ApiOperation("获得站内信分页") - public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { - pageVO.setUserId(getLoginUserId()); - pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); - PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); - } - - // TODO @芋艿:url 改成 get-recent-list;方法名也改下。默认传入 size = 10; - @GetMapping("/latest/list") - @ApiOperation("获得最新10站内信列表") - public CommonResult> getNotifyLatestMessageList() { - NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); - reqVO.setUserId(getLoginUserId()); - reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); - reqVO.setPageNo(1); - reqVO.setPageSize(10); - // TODO 芋艿:不要用分页写; - PageResult pageResult = notifyMessageService.getNotifyMessagePage(reqVO); - if (CollUtil.isNotEmpty(pageResult.getList())) { - return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList())); - } - return success(Collections.emptyList()); - } - - // TODO @芋艿:get-unread-count - @GetMapping("/unread/count") - @ApiOperation("获得未读站内信数量") - public CommonResult getUnreadNotifyMessageCount() { - return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); - } - - // TODO @芋艿:把 get 站内信,和更新站内信已经读分开。其中更新单条和多条,使用一个接口就好列 - @GetMapping("/read") - @ApiOperation("获得站内信") - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - public CommonResult readNotifyMessage(@RequestParam("id") Long id) { - NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); - // 记录消息已读。 - notifyMessageService.updateNotifyMessageReadStatus(id, NotifyReadStatusEnum.READ.getStatus()); - return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); - } - - // TODO @芋艿:PutMapping;update-list-read - @GetMapping("/read/list") - @ApiOperation("批量标记已读") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { - notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); - return success(Boolean.TRUE); - } - - // TODO @芋艿:PutMapping:update-all-read - @GetMapping("/read/all") - @ApiOperation("所有未读消息标记已读") - public CommonResult batchUpdateAllNotifyMessageReadStatus() { - notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); - return success(Boolean.TRUE); - } -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java index e7f7439c26..62d8a31130 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java @@ -34,8 +34,8 @@ public class NotifyMessageBaseVO { @NotNull(message = "内容不能为空") private String content; - @ApiModelProperty(value = "是否已读 0-未读 1-已读") - private Integer readStatus; + @ApiModelProperty(value = "是否已读 false-未读 true-已读") + private Boolean readStatus; @ApiModelProperty(value = "阅读时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java index bff746e14c..84aa4b6865 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java @@ -29,7 +29,7 @@ public class NotifyTemplateBaseVO { @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true) @NotNull(message = "状态:1-启用 0-禁用不能为空") @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") - private String status; + private Integer status; @ApiModelProperty(value = "备注") private String remarks; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java index e0402da8ce..6790f1858a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; import lombok.*; import java.util.*; import io.swagger.annotations.*; @@ -30,8 +31,8 @@ public class NotifyTemplateExcelVO { private String content; @ExcelProperty(value = "状态:1-启用 0-禁用", converter = DictConvert.class) - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 - private String status; + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; @ExcelProperty("备注") private String remarks; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java index a9f8877e22..b3a9979336 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java @@ -19,7 +19,7 @@ public class NotifyTemplateExportReqVO { private String title; @ApiModelProperty(value = "状态:1-启用 0-禁用") - private String status; + private Integer status; @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java new file mode 100644 index 0000000000..abfcb2b369 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.Map; + +@ApiModel("管理后台 - 站内信模板的发送 Request VO") +@Data +public class NotifyTemplateSendReqVO { + + @ApiModelProperty(value = "用户id", required = true, example = "01") + @NotNull(message = "用户id不能为空") + private Long userId; + + @ApiModelProperty(value = "模板Id", required = true, example = "01") + @NotNull(message = "模板Id不能为空") + private Long templateId; + + @ApiModelProperty(value = "模板参数") + private Map templateParams; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java index b5bce25d43..a111827fe9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java @@ -4,9 +4,7 @@ import java.util.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; @@ -21,10 +19,6 @@ public interface NotifyMessageConvert { NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); - NotifyMessageDO convert(NotifyMessageCreateReqVO bean); - - NotifyMessageDO convert(NotifyMessageUpdateReqVO bean); - NotifyMessageRespVO convert(NotifyMessageDO bean); List convertList(List list); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java index ab8b128eaf..28fa834067 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java @@ -53,7 +53,7 @@ public class NotifyTemplateDO extends BaseDO { * * 枚举 {@link CommonStatusEnum} */ - private String status; + private Integer status; /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 2c9137f11d..9523264d10 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -28,16 +27,27 @@ public interface NotifyMessageMapper extends BaseMapperX { .orderByDesc(NotifyMessageDO::getId)); } + default List selectList(NotifyMessagePageReqVO reqVO, Integer size) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) + .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) + .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId()) + .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType()) + .orderByDesc(NotifyMessageDO::getId) + .last("limit " + size)); + } + default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) { return selectCount(new LambdaQueryWrapperX() - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getReadStatus, false) .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } default List selectUnreadListByUserIdAndUserType(Long userId, Integer userType) { return selectList(new LambdaQueryWrapperX() - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getReadStatus, false) .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index e6057bef03..10f3975059 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -30,6 +30,14 @@ public interface NotifyMessageService { */ List getNotifyMessageList(Collection ids); + /** + * 获得站内信集合 + * + * @param pageReqVO 分页查询 + * @return 站内信分页 + */ + List getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size); + /** * 获得站内信分页 * @@ -53,7 +61,7 @@ public interface NotifyMessageService { * @param id 站内信编号 * @param status 状态 */ - void updateNotifyMessageReadStatus(Long id, Integer status); + void updateNotifyMessageReadStatus(Long id, Boolean status); /** * 批量修改站内信阅读状态 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 8150ee4533..0597fd6898 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -5,14 +5,11 @@ import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; 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.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -87,6 +84,11 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { return notifyMessageMapper.selectBatchIds(ids); } + @Override + public List getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) { + return notifyMessageMapper.selectList(pageReqVO, size); + } + @Override public PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { return notifyMessageMapper.selectPage(pageReqVO); @@ -111,7 +113,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { * @param status 状态 */ @Override - public void updateNotifyMessageReadStatus(Long id, Integer status) { + public void updateNotifyMessageReadStatus(Long id, Boolean status) { // 校验消息是否存在 this.validateNotifyMessageExists(id); // 更新状态 @@ -155,20 +157,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { List list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType); if (CollUtil.isNotEmpty(list)) { batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId)); - } } - // TODO 芋艿:批量更新,不要单条遍历哈。 private void batchUpdateReadStatus(Collection ids) { - if (CollUtil.isNotEmpty(ids)) { - for (Long id : ids) { - NotifyMessageDO updateObj = new NotifyMessageDO(); - updateObj.setId(id); - updateObj.setReadStatus(NotifyReadStatusEnum.READ.getStatus()); - notifyMessageMapper.updateById(updateObj); - } - } - + NotifyMessageDO updateObj = new NotifyMessageDO(); + updateObj.setReadStatus(false); + notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX().in(NotifyMessageDO::getId, ids)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java new file mode 100644 index 0000000000..bbf8c2dc51 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import java.util.List; +import java.util.Map; + +public interface NotifySendService { + + + /** + * 发送单条站内信给管理后台的用户 + * + * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 + * + * @param userId 用户编号 + * @param templateId 短信模板编号 + * @param templateParams 短信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotifyToAdmin(Long userId, + Long templateId, Map templateParams); + /** + * 发送单条站内信给用户 APP 的用户 + * + * 在 mobile 为空时,使用 userId 加载对应会员的手机号 + * + * @param userId 用户编号 + * @param templateId 站内信模板编号 + * @param templateParams 站内信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotifyToMember(Long userId, + Long templateId, Map templateParams); + + /** + * 发送单条站内信给用户 + * + * @param userId 用户编号 + * @param userType 用户类型 + * @param templateId 站内信模板编号 + * @param templateParams 站内信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotify( Long userId, Integer userType, + Long templateId, Map templateParams); + + default void sendBatchNotify(List mobiles, List userIds, Integer userType, + String templateCode, Map templateParams) { + throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!"); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java new file mode 100644 index 0000000000..63237e79b6 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import com.google.common.annotations.VisibleForTesting; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; + +/** + * 站内信发送 Service 实现类 + * + * @author xrcoder + */ +@Service +@Validated +@Slf4j +public class NotifySendServiceImpl implements NotifySendService { + + @Resource + private NotifyTemplateService notifyTemplateService; + + @Resource + private NotifyMessageMapper notifyMessageMapper; + + @Override + public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map templateParams) { + + return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams); + } + + @Override + public Long sendSingleNotifyToMember(Long userId, Long templateId, Map templateParams) { + return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams); + } + + @Override + public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map templateParams) { + // 校验短信模板是否合法 + NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId); + String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); + + // todo 模板状态未开启时的业务 + NotifyMessageDO notifyMessageDO = new NotifyMessageDO(); + notifyMessageDO.setContent(content); + notifyMessageDO.setTitle(template.getTitle()); + notifyMessageDO.setReadStatus(false); + notifyMessageDO.setReadTime(new Date()); + notifyMessageDO.setTemplateId(templateId); + notifyMessageDO.setUserId(userId); + notifyMessageDO.setUserType(userType); + notifyMessageMapper.insert(notifyMessageDO); + return notifyMessageDO.getId(); + } + + // 此注解的含义 + @VisibleForTesting + public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) { + // 获得短信模板。考虑到效率,从缓存中获取 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId); + // 短信模板不存在 + if (template == null) { + throw exception(NOTICE_NOT_FOUND); + } + return template; + } + +} From 826a564abd022c973190391d5729b1766100579f Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Sat, 17 Dec 2022 16:41:14 +0800 Subject: [PATCH 33/67] =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notify/NotifyLogController.java | 54 +++ .../admin/notify/NotifyMessageController.java | 16 +- .../notify/NotifyTemplateController.java | 2 +- .../admin/notify/vo/log/NotifyLogBaseVO.java | 44 +++ .../notify/vo/log/NotifyLogPageReqVO.java | 30 ++ .../vo/message/NotifyMessageBaseVO.java | 28 +- .../vo/message/NotifyMessagePageReqVO.java | 7 - .../vo/message/NotifyMessageRespVO.java | 3 - .../vo/template/NotifyTemplateSendReqVO.java | 6 +- .../convert/notify/NotifyLogConvert.java | 23 ++ .../convert/notify/NotifyMessageConvert.java | 8 +- .../dataobject/notify/NotifyMessageDO.java | 18 + .../dal/mysql/notify/NotifyMessageMapper.java | 22 +- .../service/notify/NotifyLogService.java | 24 ++ .../service/notify/NotifyLogServiceImpl.java | 35 ++ .../service/notify/NotifyMessageService.java | 9 +- .../notify/NotifyMessageServiceImpl.java | 15 +- .../service/notify/NotifySendService.java | 12 +- .../service/notify/NotifySendServiceImpl.java | 32 +- .../notify/NotifyTemplateServiceImpl.java | 2 +- .../src/api/system/notify/myNotify.js | 38 ++ .../src/api/system/notify/notifyLog.js | 11 + .../src/api/system/notify/notifyTemplate.js | 64 ++++ yudao-ui-admin/src/utils/dict.js | 1 + .../src/views/system/notify/myNotify.vue | 143 ++++++++ .../src/views/system/notify/notifyLog.vue | 120 +++++++ .../views/system/notify/notifyTemplate.vue | 339 ++++++++++++++++++ 27 files changed, 1029 insertions(+), 77 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyLogController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogBaseVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogPageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyLogConvert.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogServiceImpl.java create mode 100644 yudao-ui-admin/src/api/system/notify/myNotify.js create mode 100644 yudao-ui-admin/src/api/system/notify/notifyLog.js create mode 100644 yudao-ui-admin/src/api/system/notify/notifyTemplate.js create mode 100644 yudao-ui-admin/src/views/system/notify/myNotify.vue create mode 100644 yudao-ui-admin/src/views/system/notify/notifyLog.vue create mode 100644 yudao-ui-admin/src/views/system/notify/notifyTemplate.vue diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyLogController.java new file mode 100644 index 0000000000..84152df7d3 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyLogController.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogPageReqVO; +import cn.iocoder.yudao.module.system.convert.notify.NotifyLogConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.service.notify.NotifyLogService; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + *

+ * + *

+ * + * @author LuoWenFeng + */ +@Api(tags = "管理后台 - 站内信发送日志") +@RestController +@RequestMapping("/system/notify-log") +@Validated +public class NotifyLogController { + + @Resource + private NotifyLogService notifyLogService; + + @Resource + private AdminUserService userService; + + @GetMapping("/page") + @ApiOperation("获得发送站内信日志分页") + public CommonResult> getNotifyLogPage(@Valid NotifyLogPageReqVO pageVO) { + PageResult pageResult = notifyLogService.getNotifyMessageSendPage(pageVO); + PageResult result = NotifyLogConvert.INSTANCE.convertPage(pageResult); + result.getList().forEach(v -> { + v.setReceiveUserName(userService.getUser(v.getUserId()).getNickname()); + }); + return success(result); + } + + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java index 7e14b86c7c..67b0d5d587 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -18,15 +18,13 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; - -import java.util.Collection; import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -@Api(tags = "管理后台 - 站内信") +@Api(tags = "管理后台 - 我的站内信") @RestController @RequestMapping("/system/notify-message") @Validated @@ -48,8 +46,6 @@ public class NotifyMessageController { @ApiOperation("获得站内信分页") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { - pageVO.setUserId(getLoginUserId()); - pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } @@ -59,9 +55,6 @@ public class NotifyMessageController { @ApiImplicitParam(name = "size", value = "10", defaultValue = "10", dataTypeClass = Integer.class) public CommonResult> getRecentList(@RequestParam(name = "size", defaultValue = "10") Integer size) { NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); - reqVO.setUserId(getLoginUserId()); - reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); - List pageResult = notifyMessageService.getNotifyMessageList(reqVO, size); if (CollUtil.isNotEmpty(pageResult)) { return success(NotifyMessageConvert.INSTANCE.convertList(pageResult)); @@ -75,19 +68,20 @@ public class NotifyMessageController { return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); } - @GetMapping("/update-list-read") + @PutMapping("/update-list-read") @ApiOperation("批量标记已读") @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + public CommonResult batchUpdateNotifyMessageReadStatus(@RequestBody List ids) { notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); return success(Boolean.TRUE); } - @GetMapping("/update-all-read") + @PutMapping("/update-all-read") @ApiOperation("所有未读消息标记已读") public CommonResult batchUpdateAllNotifyMessageReadStatus() { notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(Boolean.TRUE); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index aa57a795ea..b0aad865ed 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java @@ -95,6 +95,6 @@ public class NotifyTemplateController { @ApiOperation("发送站内信") public CommonResult sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) { return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(), - sendReqVO.getTemplateId(), sendReqVO.getTemplateParams())); + sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams())); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogBaseVO.java new file mode 100644 index 0000000000..e24a7d49bc --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogBaseVO.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.log; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 站内信 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class NotifyLogBaseVO { + + @ApiModelProperty(value = "模版编码") + private String templateCode; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "内容", required = true) + private String content; + + @ApiModelProperty(value = "发送时间", required = true) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date sendTime; + + @ApiModelProperty(value = "芋艿", required = true) + private String receiveUserName; + + @ApiModelProperty(value = "1", required = true) + private Long userId; + + @ApiModelProperty(value = "是否已读 false-未读 true-已读") + private Boolean readStatus; + + @ApiModelProperty(value = "阅读时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date readTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogPageReqVO.java new file mode 100644 index 0000000000..aefd60498f --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/log/NotifyLogPageReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.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.util.Date; + +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 NotifyLogPageReqVO extends PageParam { + + @ApiModelProperty(value = "模版编码") + private String templateCode; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date[] sendTime; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java index 62d8a31130..f8d5d814a4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java @@ -1,39 +1,33 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; -import javax.validation.constraints.NotNull; import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; /** -* 站内信 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ + * 站内信 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ @Data public class NotifyMessageBaseVO { - @ApiModelProperty(value = "用户编号", required = true) - @NotNull(message = "用户编号不能为空") - private Long userId; - - @ApiModelProperty(value = "用户类型", required = true) - @NotNull(message = "用户类型不能为空") - @InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}") - private Integer userType; - @ApiModelProperty(value = "标题") private String title; - @ApiModelProperty(value = "内容", required = true) - @NotNull(message = "内容不能为空") + @ApiModelProperty(value = "内容") private String content; + @ApiModelProperty(value = "发送时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date sendTime; + + @ApiModelProperty(value = "芋艿") + private String sendUserName; + @ApiModelProperty(value = "是否已读 false-未读 true-已读") private Boolean readStatus; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java index 443f3729a7..3d786796b7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java @@ -28,11 +28,4 @@ public class NotifyMessagePageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private Date[] createTime; - // TODO 芋艿:去掉 userId 和 userType,不要在 VO 里 - - @ApiModelProperty(value = "用户编号", hidden = true) - private Long userId; - - @ApiModelProperty(value = "用户类型", hidden = true) - private Integer userType; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java index 530b368c11..306b7bd28d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java @@ -13,7 +13,4 @@ public class NotifyMessageRespVO extends NotifyMessageBaseVO { @ApiModelProperty(value = "ID", required = true) private Long id; - @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java index abfcb2b369..7a04db5dc4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java @@ -15,9 +15,9 @@ public class NotifyTemplateSendReqVO { @NotNull(message = "用户id不能为空") private Long userId; - @ApiModelProperty(value = "模板Id", required = true, example = "01") - @NotNull(message = "模板Id不能为空") - private Long templateId; + @ApiModelProperty(value = "模板编码", required = true, example = "01") + @NotNull(message = "模板编码不能为空") + private String templateCode; @ApiModelProperty(value = "模板参数") private Map templateParams; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyLogConvert.java new file mode 100644 index 0000000000..07e3dfb858 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyLogConvert.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.system.convert.notify; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogBaseVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + *

+ * + *

+ * + * @author LuoWenFeng + */ +@Mapper +public interface NotifyLogConvert { + + NotifyLogConvert INSTANCE = Mappers.getMapper(NotifyLogConvert.class); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java index a111827fe9..4a393d30c8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java @@ -1,13 +1,12 @@ package cn.iocoder.yudao.module.system.convert.notify; -import java.util.*; - import cn.iocoder.yudao.framework.common.pojo.PageResult; - import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; + +import java.util.List; /** * 站内信 Convert @@ -25,4 +24,5 @@ public interface NotifyMessageConvert { PageResult convertPage(PageResult page); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java index 5a923998ac..b431795cf3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java @@ -35,6 +35,12 @@ public class NotifyMessageDO extends BaseDO { * 关联 {@link NotifyTemplateDO#getId()} */ private Long templateId; + /** + * 站内信模版编码 + * + * 关联 {@link NotifyTemplateDO#getCode()} + */ + private String templateCode; /** * 用户编号 * @@ -55,6 +61,18 @@ public class NotifyMessageDO extends BaseDO { * 内容 */ private String content; + /** + * 发送时间 + */ + private Date sendTime; + /** + * 发送用户id + */ + private Long sendUserId; + /** + * 发送用户名 + */ + private String sendUserName; /** * 是否已读 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 9523264d10..7b599e25e8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.notify; 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.module.system.controller.admin.notify.vo.log.NotifyLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import org.apache.ibatis.annotations.Mapper; @@ -17,23 +18,31 @@ import java.util.List; @Mapper public interface NotifyMessageMapper extends BaseMapperX { - default PageResult selectPage(NotifyMessagePageReqVO reqVO) { + default PageResult selectPage(NotifyMessagePageReqVO reqVO, Long userId, Integer userType) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId()) - .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType()) + .eq(NotifyMessageDO::getUserId, userId) + .eq(NotifyMessageDO::getUserType, userType) .orderByDesc(NotifyMessageDO::getId)); } - default List selectList(NotifyMessagePageReqVO reqVO, Integer size) { + default PageResult selectSendPage(NotifyLogPageReqVO reqVO, Long userId) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) + .betweenIfPresent(NotifyMessageDO::getSendTime, reqVO.getSendTime()) + .eq(NotifyMessageDO::getSendUserId, userId) + .orderByDesc(NotifyMessageDO::getId)); + } + + default List selectList(NotifyMessagePageReqVO reqVO, Integer size, Long userId, Integer userType) { return selectList(new LambdaQueryWrapperX() .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId()) - .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType()) + .eqIfPresent(NotifyMessageDO::getUserId, userId) + .eqIfPresent(NotifyMessageDO::getUserType, userType) .orderByDesc(NotifyMessageDO::getId) .last("limit " + size)); } @@ -51,4 +60,5 @@ public interface NotifyMessageMapper extends BaseMapperX { .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java new file mode 100644 index 0000000000..272648c9c0 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; + +/** + *

+ * 站内信日志 Service 接口 + *

+ * + * @author LuoWenFeng + */ +public interface NotifyLogService { + + + /** + * 获得站内信发送分页 + * + * @param pageReqVO 分页查询 + * @return 站内信分页 + */ + PageResult getNotifyMessageSendPage(NotifyLogPageReqVO pageReqVO); +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogServiceImpl.java new file mode 100644 index 0000000000..be95d8a6dd --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogServiceImpl.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +/** + *

+ * 站内信日志 Service 实现类 + * + *

+ * + * @author LuoWenFeng + */ +@Service +@Validated +public class NotifyLogServiceImpl implements NotifyLogService { + + @Resource + private NotifyMessageMapper notifyMessageMapper; + + @Override + public PageResult getNotifyMessageSendPage(NotifyLogPageReqVO pageReqVO) { + return notifyMessageMapper.selectSendPage(pageReqVO, getLoginUserId()); + } + + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index 10f3975059..bb8d7e9232 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -49,7 +49,7 @@ public interface NotifyMessageService { /** * 统计用户未读站内信条数 * - * @param userId 用户ID + * @param userId 用户ID * @param userType 用户类型 * @return 返回未读站内信条数 */ @@ -58,7 +58,7 @@ public interface NotifyMessageService { /** * 修改站内信阅读状态 * - * @param id 站内信编号 + * @param id 站内信编号 * @param status 状态 */ void updateNotifyMessageReadStatus(Long id, Boolean status); @@ -66,7 +66,7 @@ public interface NotifyMessageService { /** * 批量修改站内信阅读状态 * - * @param ids 站内信编号集合 + * @param ids 站内信编号集合 * @param userId 用户ID */ void batchUpdateNotifyMessageReadStatus(Collection ids, Long userId); @@ -74,8 +74,9 @@ public interface NotifyMessageService { /** * 批量修改用户所有未读消息标记已读 * - * @param userId 用户ID + * @param userId 用户ID * @param userType 用户类型 */ void batchUpdateAllNotifyMessageReadStatus(Long userId, Integer userType); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 0597fd6898..fdfff486e5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -16,11 +17,13 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.Date; 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.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -86,12 +89,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @Override public List getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) { - return notifyMessageMapper.selectList(pageReqVO, size); + return notifyMessageMapper.selectList(pageReqVO, size, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); } @Override public PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { - return notifyMessageMapper.selectPage(pageReqVO); + return notifyMessageMapper.selectPage(pageReqVO, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); } /** @@ -160,9 +163,15 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { } } + + /** + * 批量修改阅读状态为已读 + * @param ids + */ private void batchUpdateReadStatus(Collection ids) { NotifyMessageDO updateObj = new NotifyMessageDO(); - updateObj.setReadStatus(false); + updateObj.setReadStatus(true); + updateObj.setReadTime(new Date()); notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX().in(NotifyMessageDO::getId, ids)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java index bbf8c2dc51..68e9a78c48 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java @@ -12,36 +12,36 @@ public interface NotifySendService { * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 * * @param userId 用户编号 - * @param templateId 短信模板编号 + * @param templateCode 短信模板编号 * @param templateParams 短信模板参数 * @return 发送日志编号 */ Long sendSingleNotifyToAdmin(Long userId, - Long templateId, Map templateParams); + String templateCode, Map templateParams); /** * 发送单条站内信给用户 APP 的用户 * * 在 mobile 为空时,使用 userId 加载对应会员的手机号 * * @param userId 用户编号 - * @param templateId 站内信模板编号 + * @param templateCode 站内信模板编号 * @param templateParams 站内信模板参数 * @return 发送日志编号 */ Long sendSingleNotifyToMember(Long userId, - Long templateId, Map templateParams); + String templateCode, Map templateParams); /** * 发送单条站内信给用户 * * @param userId 用户编号 * @param userType 用户类型 - * @param templateId 站内信模板编号 + * @param templateCode 站内信模板编号 * @param templateParams 站内信模板参数 * @return 发送日志编号 */ Long sendSingleNotify( Long userId, Integer userType, - Long templateId, Map templateParams); + String templateCode, Map templateParams); default void sendBatchNotify(List mobiles, List userIds, Integer userType, String templateCode, Map templateParams) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java index 63237e79b6..984fc196bc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java @@ -3,7 +3,9 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -14,6 +16,7 @@ import java.util.Date; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; /** @@ -32,41 +35,48 @@ public class NotifySendServiceImpl implements NotifySendService { @Resource private NotifyMessageMapper notifyMessageMapper; - @Override - public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map templateParams) { + @Resource + private AdminUserService userService; - return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams); + @Override + public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map templateParams) { + + return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams); } @Override - public Long sendSingleNotifyToMember(Long userId, Long templateId, Map templateParams) { - return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams); + public Long sendSingleNotifyToMember(Long userId, String templateCode, Map templateParams) { + return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); } @Override - public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map templateParams) { + public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map templateParams) { // 校验短信模板是否合法 - NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId); + NotifyTemplateDO template = this.checkNotifyTemplateValid(templateCode); String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); + AdminUserDO sendUser = userService.getUser(getLoginUserId()); // todo 模板状态未开启时的业务 NotifyMessageDO notifyMessageDO = new NotifyMessageDO(); notifyMessageDO.setContent(content); notifyMessageDO.setTitle(template.getTitle()); notifyMessageDO.setReadStatus(false); - notifyMessageDO.setReadTime(new Date()); - notifyMessageDO.setTemplateId(templateId); + notifyMessageDO.setTemplateId(template.getId()); + notifyMessageDO.setTemplateCode(templateCode); notifyMessageDO.setUserId(userId); notifyMessageDO.setUserType(userType); + notifyMessageDO.setSendTime(new Date()); + notifyMessageDO.setSendUserId(sendUser.getId()); + notifyMessageDO.setSendUserName(sendUser.getUsername()); notifyMessageMapper.insert(notifyMessageDO); return notifyMessageDO.getId(); } // 此注解的含义 @VisibleForTesting - public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) { + public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) { // 获得短信模板。考虑到效率,从缓存中获取 - NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId); + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode); // 短信模板不存在 if (template == null) { throw exception(NOTICE_NOT_FOUND); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index 1342fe03b0..fe5058074e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -109,7 +109,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { return notifyTemplateMapper.selectList(); } - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) + @Scheduled(fixedDelay = SCHEDULER_PERIOD) public void schedulePeriodicRefresh() { initLocalCache(); } diff --git a/yudao-ui-admin/src/api/system/notify/myNotify.js b/yudao-ui-admin/src/api/system/notify/myNotify.js new file mode 100644 index 0000000000..cd37fd8988 --- /dev/null +++ b/yudao-ui-admin/src/api/system/notify/myNotify.js @@ -0,0 +1,38 @@ +import request from '@/utils/request' + + +// 获得我的站内信分页 +export function getNotifyMessagePage(query) { + return request({ + url: '/system/notify-message/page', + method: 'get', + params: query + }) +} + +// 获得单条我的站内信 +export function getNotifyMessage(query) { + return request({ + url: '/system/notify-message/get', + method: 'get', + params: query + }) +} + +// 批量标记已读 +export function updateNotifyMessageListRead(data) { + return request({ + url: '/system/notify-message/update-list-read', + method: 'put', + data: data + }) +} + +// 所有未读消息标记已读 +export function updateNotifyMessageAllRead(data) { + return request({ + url: '/system/notify-message/update-all-read', + method: 'put', + data: data + }) +} diff --git a/yudao-ui-admin/src/api/system/notify/notifyLog.js b/yudao-ui-admin/src/api/system/notify/notifyLog.js new file mode 100644 index 0000000000..de9e9f1ad3 --- /dev/null +++ b/yudao-ui-admin/src/api/system/notify/notifyLog.js @@ -0,0 +1,11 @@ +import request from '@/utils/request' + + +// 获得我的站内信分页 +export function getNotifyLogPage(query) { + return request({ + url: '/system/notify-log/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/api/system/notify/notifyTemplate.js b/yudao-ui-admin/src/api/system/notify/notifyTemplate.js new file mode 100644 index 0000000000..59c0365406 --- /dev/null +++ b/yudao-ui-admin/src/api/system/notify/notifyTemplate.js @@ -0,0 +1,64 @@ +import request from '@/utils/request' + +// 创建站内信模板 +export function createNotifyTemplate(data) { + return request({ + url: '/system/notify-template/create', + method: 'post', + data: data + }) +} + +// 更新站内信模板 +export function updateNotifyTemplate(data) { + return request({ + url: '/system/notify-template/update', + method: 'put', + data: data + }) +} + +// 删除站内信模板 +export function deleteNotifyTemplate(id) { + return request({ + url: '/system/notify-template/delete?id=' + id, + method: 'delete' + }) +} + +// 获得站内信模板 +export function getNotifyTemplate(id) { + return request({ + url: '/system/notify-template/get?id=' + id, + method: 'get' + }) +} + +// 获得站内信模板分页 +export function getNotifyTemplatePage(query) { + return request({ + url: '/system/notify-template/page', + method: 'get', + params: query + }) +} + +// 创建站内信模板 +export function sendNotify(data) { + return request({ + url: '/system/notify-template/send-notify', + method: 'post', + data: data + }) +} + +// 导出站内信模板 Excel +export function exportNotifyTemplateExcel(query) { + return request({ + url: '/system/notify-template/export-excel', + method: 'get', + params: query, + responseType: 'blob' + }) +} + diff --git a/yudao-ui-admin/src/utils/dict.js b/yudao-ui-admin/src/utils/dict.js index 1ddde889a7..4ed01e9a9e 100644 --- a/yudao-ui-admin/src/utils/dict.js +++ b/yudao-ui-admin/src/utils/dict.js @@ -24,6 +24,7 @@ export const DICT_TYPE = { SYSTEM_SMS_RECEIVE_STATUS: 'system_sms_receive_status', SYSTEM_ERROR_CODE_TYPE: 'system_error_code_type', SYSTEM_OAUTH2_GRANT_TYPE: 'system_oauth2_grant_type', + SYSTEM_NOTIFY_READ_STATUS: "system_notify_read_status", // ========== INFRA 模块 ========== INFRA_BOOLEAN_STRING: 'infra_boolean_string', diff --git a/yudao-ui-admin/src/views/system/notify/myNotify.vue b/yudao-ui-admin/src/views/system/notify/myNotify.vue new file mode 100644 index 0000000000..1c8a1b58a9 --- /dev/null +++ b/yudao-ui-admin/src/views/system/notify/myNotify.vue @@ -0,0 +1,143 @@ + + + diff --git a/yudao-ui-admin/src/views/system/notify/notifyLog.vue b/yudao-ui-admin/src/views/system/notify/notifyLog.vue new file mode 100644 index 0000000000..7e9eb5610c --- /dev/null +++ b/yudao-ui-admin/src/views/system/notify/notifyLog.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/yudao-ui-admin/src/views/system/notify/notifyTemplate.vue b/yudao-ui-admin/src/views/system/notify/notifyTemplate.vue new file mode 100644 index 0000000000..9fa396839c --- /dev/null +++ b/yudao-ui-admin/src/views/system/notify/notifyTemplate.vue @@ -0,0 +1,339 @@ + + + From ed2d19541164df791de1fbf15c45ed677726855e Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Sat, 17 Dec 2022 16:42:40 +0800 Subject: [PATCH 34/67] =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/dal/mysql/notify/NotifyMessageMapper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 7b599e25e8..4704192448 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -32,6 +32,7 @@ public interface NotifyMessageMapper extends BaseMapperX { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) .betweenIfPresent(NotifyMessageDO::getSendTime, reqVO.getSendTime()) + .eqIfPresent(NotifyMessageDO::getTemplateCode, reqVO.getTemplateCode()) .eq(NotifyMessageDO::getSendUserId, userId) .orderByDesc(NotifyMessageDO::getId)); } From 5cac636f325250e5d7d5ff033761b6fc54a4afed Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Sat, 17 Dec 2022 17:30:05 +0800 Subject: [PATCH 35/67] =?UTF-8?q?feature(=E7=AB=99=E5=86=85=E4=BF=A1?= =?UTF-8?q?=E5=BC=80=E5=8F=91):=20=E6=B7=BB=E5=8A=A0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/ruoyi-vue-pro.sql | 83 ++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/sql/mysql/ruoyi-vue-pro.sql b/sql/mysql/ruoyi-vue-pro.sql index 683206e6f7..dc3661448f 100644 --- a/sql/mysql/ruoyi-vue-pro.sql +++ b/sql/mysql/ruoyi-vue-pro.sql @@ -1330,6 +1330,9 @@ INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `st INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1158, 3, 'implicit', 'implicit', 'system_oauth2_grant_type', 0, 'success', '', '简化模式', '1', '2022-05-12 00:23:40', '1', '2022-05-11 16:26:05', b'0'); INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1159, 4, 'client_credentials', 'client_credentials', 'system_oauth2_grant_type', 0, 'default', '', '客户端模式', '1', '2022-05-12 00:23:51', '1', '2022-05-11 16:26:08', b'0'); INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1160, 5, 'refresh_token', 'refresh_token', 'system_oauth2_grant_type', 0, 'info', '', '刷新模式', '1', '2022-05-12 00:24:02', '1', '2022-05-11 16:26:11', b'0'); +INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1162, 0, '已读', 'true', 'system_notify_read_status', 0, 'success', '', NULL, '1', '2022-12-16 17:48:28', '1', '2022-12-17 03:32:09', b'0'); +INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1163, 1, '未读', 'false', 'system_notify_read_status', 0, 'info', '', NULL, '1', '2022-12-16 17:48:43', '1', '2022-12-17 03:32:11', b'0'); + COMMIT; -- ---------------------------- @@ -1395,6 +1398,8 @@ INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creat INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (145, '角色类型', 'system_role_type', 0, '角色类型', '1', '2022-02-16 13:01:46', '1', '2022-02-16 13:01:46', b'0'); INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (146, '文件存储器', 'infra_file_storage', 0, '文件存储器', '1', '2022-03-15 00:24:38', '1', '2022-03-15 00:24:38', b'0'); INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (147, 'OAuth 2.0 授权类型', 'system_oauth2_grant_type', 0, 'OAuth 2.0 授权类型(模式)', '1', '2022-05-12 00:20:52', '1', '2022-05-11 16:25:49', b'0'); +INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (149, '站内信读取状态', 'system_notify_read_status', 0, '站内信读取状态', '1', '2022-12-16 17:47:35', '1', '2022-12-17 03:25:08', b'0'); + COMMIT; -- ---------------------------- @@ -1712,6 +1717,21 @@ INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_i INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1267, '客户端删除', 'system:oauth2-client:delete', 3, 4, 1263, '', '', '', 0, b'1', b'1', '', '2022-05-10 16:26:33', '1', '2022-05-11 00:31:33', b'0'); INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1281, '可视化报表', '', 1, 12, 0, '/visualization', 'chart', NULL, 0, b'1', b'1', '1', '2022-07-10 20:22:15', '1', '2022-07-10 20:33:30', b'0'); INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1282, '积木报表', '', 2, 1, 1281, 'jimu-report', 'example', 'visualization/jmreport/index', 0, b'1', b'1', '1', '2022-07-10 20:26:36', '1', '2022-07-28 21:17:34', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2030, '站内信', '', 1, 14, 1, 'notify', 'build', '', 0, b'1', b'1', '1', '2022-12-16 11:27:45', '1', '2022-12-16 11:44:11', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2031, '站内信模板', '', 2, 1, 2030, 'notify-template', 'build', 'system/notify/notifyTemplate', 0, b'1', b'1', '1', '2022-12-16 11:35:14', '1', '2022-12-16 11:44:43', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2032, '我的站内信', '', 2, 2, 2030, 'my-notify', 'checkbox', 'system/notify/myNotify', 0, b'1', b'1', '1', '2022-12-16 11:35:58', '1', '2022-12-16 11:44:48', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2033, '查询', 'system:notify-template:query', 3, 1, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 11:36:57', '1', '2022-12-16 11:36:57', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2034, '创建', 'system:notify-template:create', 3, 2, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 11:43:16', '1', '2022-12-16 12:06:48', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2035, '更新', 'system:notify-template:update', 3, 3, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 12:06:41', '1', '2022-12-16 12:06:41', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2036, '删除', 'system:notify-template:delete', 3, 4, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 12:07:03', '1', '2022-12-16 12:07:03', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2037, '导出', 'system:notify-template:export', 3, 5, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 12:07:20', '1', '2022-12-16 12:07:20', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2038, '发送', 'system:notify-template:send-notify', 3, 6, 2031, '', '', '', 0, b'1', b'1', '1', '2022-12-16 15:21:16', '1', '2022-12-16 15:21:16', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2039, '日志', '', 2, 3, 2030, 'notify-log', 'post', 'system/notify/notifyLog', 0, b'1', b'1', '1', '2022-12-16 17:29:00', '1', '2022-12-17 16:07:58', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2040, '查询', 'system:notify-log:query', 3, 1, 2039, '', '', '', 0, b'1', b'1', '1', '2022-12-16 17:29:23', '1', '2022-12-16 17:29:23', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2041, '撤销', 'system:notify-log:cancel', 3, 2, 2039, '', '', '', 0, b'1', b'1', '1', '2022-12-16 17:30:13', '1', '2022-12-16 17:30:13', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2042, '查询', 'system:my-notify:query', 3, 1, 2032, '', '', '', 0, b'1', b'1', '1', '2022-12-16 17:31:31', '1', '2022-12-16 17:31:31', b'0'); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2043, '读取', 'system:my-notify:query', 3, 2, 2032, '', '', '', 0, b'1', b'1', '1', '2022-12-16 17:32:03', '1', '2022-12-16 09:32:20', b'1'); + COMMIT; -- ---------------------------- @@ -2661,4 +2681,65 @@ SET FOREIGN_KEY_CHECKS = 1; -- 积木报表菜单 INSERT INTO `system_menu` VALUES (1281, '可视化报表', '', 1, 12, 0, '/visualization', 'chart', NULL, 0, b'1', b'1', '1', '2022-07-10 20:22:15', '1', '2022-07-10 20:33:30', b'0'); -INSERT INTO `system_menu` VALUES (1282, '积木报表', '', 2, 1, 1281, 'jm-report', '#', 'visualization/jm/index', 0, b'1', b'1', '1', '2022-07-10 20:26:36', '1', '2022-07-10 20:33:26', b'0'); \ No newline at end of file +INSERT INTO `system_menu` VALUES (1282, '积木报表', '', 2, 1, 1281, 'jm-report', '#', 'visualization/jm/index', 0, b'1', b'1', '1', '2022-07-10 20:26:36', '1', '2022-07-10 20:33:26', b'0'); + +-- ---------------------------- +-- Table structure for system_notify_message +-- ---------------------------- +DROP TABLE IF EXISTS `system_notify_message`; + +CREATE TABLE `system_notify_message` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户ID', + `template_id` int DEFAULT NULL COMMENT '模板id', + `template_code` varchar(64) DEFAULT NULL COMMENT '模板编码', + `title` varchar(100) DEFAULT NULL COMMENT '模板标题', + `content` varchar(255) DEFAULT NULL COMMENT '模板内容', + `send_time` datetime DEFAULT NULL COMMENT '发送时间', + `send_user_id` int DEFAULT NULL COMMENT '发送用户id', + `send_user_name` varchar(30) DEFAULT NULL COMMENT '发送用户名', + `user_id` bigint DEFAULT NULL COMMENT '用户id', + `user_type` bit(2) DEFAULT NULL COMMENT '用户类型', + `read_status` bit(1) DEFAULT NULL COMMENT '阅读状态 0未读 1已读', + `read_time` datetime DEFAULT NULL COMMENT '阅读时间', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + `creator` varchar(64) DEFAULT NULL COMMENT '创建者', + `updater` varchar(64) DEFAULT NULL COMMENT '更新者', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', + PRIMARY KEY (`id`) +) ENGINE=InnoDB COMMENT = '站内信消息表'; + +-- ---------------------------- +-- Records of system_notify_message +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- Table structure for system_notify_template +-- ---------------------------- +DROP TABLE IF EXISTS `system_notify_template`; + +CREATE TABLE `system_notify_template` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `code` varchar(64) DEFAULT NULL COMMENT '模版编码', + `title` varchar(255) DEFAULT NULL COMMENT '模版标题', + `content` varchar(255) DEFAULT NULL COMMENT '模版内容', + `params` varchar(255) DEFAULT NULL COMMENT '参数数组', + `status` bit(1) DEFAULT NULL COMMENT '状态', + `remark` varchar(60) DEFAULT NULL COMMENT '备注', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + `creator` varchar(64) DEFAULT NULL COMMENT '创建者', + `updater` varchar(64) DEFAULT NULL COMMENT '更新者', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` int DEFAULT NULL COMMENT '租户id', + PRIMARY KEY (`id`) +) ENGINE=InnoDB COMMENT = '站内信模板表'; + +-- ---------------------------- +-- Records of system_notify_template +-- ---------------------------- +BEGIN; +COMMIT; \ No newline at end of file From 491921d5aefd36470ef38682a0bfe2385d7823d6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 23 Dec 2022 18:41:41 +0800 Subject: [PATCH 36/67] =?UTF-8?q?code=20review=20=E7=AB=99=E5=86=85?= =?UTF-8?q?=E4=BF=A1=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/dal/dataobject/notify/NotifyMessageDO.java | 2 ++ .../module/system/service/notify/NotifyLogService.java | 4 ++-- .../system/service/notify/NotifyMessageServiceImpl.java | 6 ++++-- .../module/system/service/notify/NotifySendServiceImpl.java | 5 +++-- .../system/service/notify/NotifyTemplateServiceImpl.java | 1 - 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java index b431795cf3..fe80784a8b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java @@ -61,10 +61,12 @@ public class NotifyMessageDO extends BaseDO { * 内容 */ private String content; + // TODO @luowenfeng:是不是创建时间,直接作为发送时间; /** * 发送时间 */ private Date sendTime; + // TODO @luowenfeng:是不是不用发送 id 和名字😑? /** * 发送用户id */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java index 272648c9c0..290b8f2b97 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyLogService.java @@ -5,14 +5,13 @@ import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogPa import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; /** - *

* 站内信日志 Service 接口 - *

* * @author LuoWenFeng */ public interface NotifyLogService { + // TODO @LuoWenFeng:NotifyLogService=》NotifyMessageService /** * 获得站内信发送分页 @@ -21,4 +20,5 @@ public interface NotifyLogService { * @return 站内信分页 */ PageResult getNotifyMessageSendPage(NotifyLogPageReqVO pageReqVO); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index fdfff486e5..f8ddad0cf5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -163,15 +163,17 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { } } - /** * 批量修改阅读状态为已读 - * @param ids + * + * @param ids 站内变编号数组 */ private void batchUpdateReadStatus(Collection ids) { NotifyMessageDO updateObj = new NotifyMessageDO(); updateObj.setReadStatus(true); updateObj.setReadTime(new Date()); + // TODO @luowenfeng:涉及到 mybatis 的操作,都要隐藏到 mapper 中; notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX().in(NotifyMessageDO::getId, ids)); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java index 984fc196bc..e72bd6c866 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java @@ -19,6 +19,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; +// TODO @luowenfeng:可以直接合并到 NotifyMessageService 中;之前 sms 台复杂,所以没合并。 /** * 站内信发送 Service 实现类 * @@ -40,7 +41,6 @@ public class NotifySendServiceImpl implements NotifySendService { @Override public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map templateParams) { - return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams); } @@ -54,9 +54,10 @@ public class NotifySendServiceImpl implements NotifySendService { // 校验短信模板是否合法 NotifyTemplateDO template = this.checkNotifyTemplateValid(templateCode); String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); + // 获得用户 AdminUserDO sendUser = userService.getUser(getLoginUserId()); - // todo 模板状态未开启时的业务 + // todo 模板状态未开启时的业务;如果未开启,就直接 return 好了; NotifyMessageDO notifyMessageDO = new NotifyMessageDO(); notifyMessageDO.setContent(content); notifyMessageDO.setTitle(template.getTitle()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index fe5058074e..7bfa9027ce 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -85,7 +85,6 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { notifyTemplateCache = CollectionUtils.convertMap(notifyTemplateList, NotifyTemplateDO::getCode); maxUpdateTime = CollectionUtils.getMaxValue(notifyTemplateList, NotifyTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 NotifyTemplate 数量为 {}]", notifyTemplateList.size()); - } /** From 0262fa5c153628e63c6c266026c7bb7a06d49f1a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 17:48:09 +0800 Subject: [PATCH 37/67] =?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 2ffe0d7cb7..3885259f26 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 caa69678c2..0000000000 --- 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 0000000000..e2ede96aea --- /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 ead06b2042..135248867d 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 4154c9bc1c..0000000000 --- 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 cce0ed3883..eaad0f8abd 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 17a305c481..a18fb137b2 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 8e392d4766..7a3f2347fd 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 476a3077aa..2bcca7850a 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 327c8465de..9e5869172f 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 0000000000..9eef7281a8 --- /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 0000000000..93118388e3 --- /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 4544e95b55..43a13ad18b 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 b60ac088ff..daadbfe5a6 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 910440df7a..33e6859e24 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 d4b0e5f811..598b52cfca 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 c4708657f5..c3c1cae83e 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 1e4f263acd..24ce1ef067 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 d7d1cd73c9..86bb5e8f5f 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 50c5055123..8b92ee9536 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 fe0615f4f9..2c90a91219 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 16d65b4f9c..662d77623a 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 3ae44693ba..2da58091bc 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 a7bf04fc76..c489ad9bb2 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 3fcac8b9e5..9ae635cee6 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 592864651e..d126fbf0f4 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 0000000000..171fe553fc --- /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 0000000000..f3821d8bcd --- /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 38/67] =?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 135248867d..577fcb2ade 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 2fae6164b8..741462c950 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 7a3f2347fd..ef18cb6ac5 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 93118388e3..96916a7151 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 1e44336aac..e2835debd4 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 2311cb087b..6eab6e9ab8 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 a48c5a91af..f3cec08f9b 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 33683b1c58..a2153f9cdc 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 0000000000..2ff4880368 --- /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 82d9997bee..5dfa377a2a 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 46a25b9e2a..4430ffb05d 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 33e6859e24..b5d349439c 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 598b52cfca..ddd0f71584 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 c3c1cae83e..f669b455f0 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 86bb5e8f5f..f03aa4ae99 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 662d77623a..704f7d6537 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 9ae635cee6..753614683f 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 325e88f423..e1bcb137e8 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 171fe553fc..0868e4f37a 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 0000000000..ee5d8d4540 --- /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 f3821d8bcd..96e3cc4616 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 @@ - - + +