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

+ * 前端控制器 + *

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

+ * 前端控制器 + *

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

+ * 前端控制器 + *

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

+ * + *

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

+ * + *

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

+ * + *

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

+ * Mapper 接口 + *

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

+ * Mapper 接口 + *

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

+ * Mapper 接口 + *

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

+ * 服务类 + *

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

+ * 服务类 + *

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

+ * 服务类 + *

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

+ * 服务实现类 + *

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

+ * 服务实现类 + *

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

+ * 服务实现类 + *

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

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

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

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

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

- * 前端控制器 - *

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

+ * 前端控制器 + *

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

- * 前端控制器 - *

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

+ * 前端控制器 + *

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

- * 前端控制器 - *

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

- * - *

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

- * - *

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

+ * + *

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

- * - *

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

+ * 邮箱账号 + *

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

- * Mapper 接口 - *

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

+ * Mapper 接口 + *

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

- * Mapper 接口 - *

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

+ * Mapper 接口 + *

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

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -@Mapper -public interface SystemMailAccountMapper extends BaseMapperX { - - default PageResult selectPage(PageParam pageParam) { - return selectPage(pageParam, new QueryWrapperX()); - } - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java new file mode 100644 index 000000000..759263a40 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.system.service.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; + +import java.util.List; + + +/** + *

+ * 邮箱账号 Service 接口 + *

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

- * 服务类 - *

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

+ * 服务类 + *

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

- * 服务类 - *

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

+ * 服务类 + *

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

- * 服务类 - *

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

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

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

- * 服务实现类 - *

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

+ * 服务实现类 + *

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

- * 服务实现类 - *

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

+ * 服务实现类 + *

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

- * 服务实现类 - *

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

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

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

- * Mapper 接口 - *

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

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

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

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

- * 邮箱日志功能 - *

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

- * 前端控制器 - *

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

- * + * 邮箱日志 *

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

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

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

- * Mapper 接口 - *

- * - * @author wangjingyi - * @since 2022-03-21 - */ -public interface MailTempleMapper extends BaseMapper { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java new file mode 100644 index 000000000..3aaf72a48 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.system.service.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; + +import java.util.List; + +/** + *

+ * 服务类 + *

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

- * 服务类 - *

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

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

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

- * 服务实现类 - *

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

* 邮箱账号 Service 接口 - *

+ *

// TODO wangjingyi:不用

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

* 邮箱账号 Service 接口 - *

// TODO wangjingyi:不用

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

- * 服务类 - *

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

- * 服务类 - *

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

* 邮箱日志实现类 - *

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

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

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

* 邮箱账号 Service 实现类 - *

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

* 邮箱日志 - *

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

* 邮箱模版 - *

* * @author wangjingyi * @since 2022-03-21 @@ -24,48 +15,42 @@ import lombok.experimental.Accessors; @TableName(value = "system_mail_template", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class MailTemplateDO extends BaseDO implements Serializable { +public class MailTemplateDO extends BaseDO { /** * 主键 */ private Long id; - /** * 模版名称 */ private String name; - /** * 模版编号 */ private String code; - + // TODO @wangjingyi:应该使用 accountId 呀 /** * 用户名 */ private String username; - /** * 标题 */ private String title; - /** * 内容 */ private String content; - /** * 状态 + * + * 枚举 {@link CommonStatusEnum} */ - private String status; - + private String status; // TODO @wangjingyi:Integer /** * 备注 */ private String remark; - } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index d0a43e679..8697b2151 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,8 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import org.apache.ibatis.annotations.Mapper; -import java.util.Map; - @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -23,7 +21,8 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - QueryWrapperX queryWrapperX = new QueryWrapperX(); + // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); + QueryWrapperX queryWrapperX = new QueryWrapperX<>(); queryWrapperX.eqIfPresent("username", userName); return this.selectOne(queryWrapperX); }; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 635a2bf90..d65887e54 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -23,6 +23,7 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ + // TODO @wangjingyi:优先使用 lambada 查询 return selectOne("code" , code); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 9792c6cc5..c1289154f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; @@ -19,10 +18,8 @@ import java.util.List; */ public interface MailAccountService { - // TODO @wangjingyi:注释,完整;参数校验还是要做的; - /** - * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 + * 创建邮箱账号 * * @param createReqVO 邮箱账号信息 * @return 编号 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1511309eb..1071eae5d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ public interface MailTemplateService { /** * 邮箱模版创建 + * * @param createReqVO 邮箱信息 * @return 编号 */ @@ -27,12 +28,14 @@ public interface MailTemplateService { /** * 邮箱模版修改 + * * @param updateReqVO 邮箱信息 */ void update(@Valid MailTemplateUpdateReqVO updateReqVO); /** * 邮箱模版删除 + * * @param id 编号 */ void delete(Long id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index fa2f8879e..aa1fb1d46 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.module.system.service.mail.impl; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -18,9 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; @@ -54,7 +47,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 + // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 @@ -64,6 +57,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { + // TODO @wangjingyi:删除时,要判断是否有使用的模板 // 校验是否存在 this.validateMailAccountExists(id); mailAccountMapper.deleteById(id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 7ce118303..2bd74ac4c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -15,15 +15,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; -import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +55,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); + this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailTemplateExists(mailTemplateDO.getId()); @@ -85,6 +82,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void sendMail(MailReqVO mailReqVO) { + // TODO @@wangjingyi:发送的时候,参考下短信; MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); //查询账号信息 MailAccountDO mailAccountDO = mailAccountMapper.selectOne( From d7305739d3fcef6efe25c12d33c02b903c181308 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 30 Apr 2022 21:31:55 +0800 Subject: [PATCH 16/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 + .../pom.xml | 65 +++++++++++ .../config/YudaoMailAutoConfiguration.java | 21 ++++ .../mail/core/client/MailClient.java | 23 ++++ .../mail/core/client/MailClientFactory.java | 5 + .../mail/core/client/MailCodeMapping.java | 17 +++ .../mail/core/client/MailCommonResult.java | 68 +++++++++++ .../core/client/dto/MailReceiveRespDTO.java | 48 ++++++++ .../mail/core/client/dto/MailSendRespDTO.java | 18 +++ .../core/client/dto/MailTemplateRespDTO.java | 31 +++++ .../core/client/impl/AbstractMailClient.java | 14 +++ .../client/impl/MailClientFactoryImpl.java | 39 +++++++ .../client/impl/hutool/HutoolMailClient.java | 29 +++++ .../impl/hutool/HutoolMailCodeMapping.java | 20 ++++ .../mail/core/enums/MailChannelEnum.java | 32 ++++++ .../MailFrameworkErrorCodeConstants.java | 47 ++++++++ .../enums/MailTemplateAuditStatusEnum.java | 21 ++++ .../core/property/MailChannelProperties.java | 52 +++++++++ .../module/system/api/mail/MailSendApi.java | 4 + .../system/api/mail/dto/MailSendReqDTO.java | 38 +++++++ .../system/enums/ErrorCodeConstants.java | 1 + .../system/enums/mail/MailSendStatusEnum.java | 24 ++++ .../yudao-module-system-impl/pom.xml | 5 + .../system/api/mail/MailSendApiImpl.java | 14 +++ .../mail/vo/account/MailAccountBaseVO.java | 22 ++-- .../admin/mail/vo/log/MailLogExcelVO.java | 5 +- .../admin/mail/vo/log/MailLogRespVO.java | 2 +- .../admin/mail/vo/send/MailReqVO.java | 14 ++- .../mail/vo/template/MailTemplateBaseVO.java | 12 +- .../vo/template/MailTemplatePageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailLogDO.java | 22 ++-- .../dal/dataobject/mail/MailTemplateDO.java | 9 +- .../dal/mysql/mail/MailAccountMapper.java | 7 +- .../dal/mysql/mail/MailTemplateMapper.java | 15 ++- .../mq/consumer/mail/MailSendConsumer.java | 8 +- .../mq/message/mail/MailSendMessage.java | 26 +++-- .../system/mq/producer/mail/MailProducer.java | 65 +++++++++++ .../system/service/mail/MailLogService.java | 16 +++ .../system/service/mail/MailSendService.java | 41 +++++++ .../service/mail/MailTemplateService.java | 17 +++ .../mail/impl/MailAccountServiceImpl.java | 20 +++- .../service/mail/impl/MailLogServiceImpl.java | 42 +++++++ .../mail/impl/MailSendServiceImpl.java | 107 ++++++++++++++++++ .../mail/impl/MailTemplateServiceImpl.java | 55 ++++++++- 44 files changed, 1085 insertions(+), 59 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 73bb614cd..42c887c56 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,6 +30,7 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms + yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml new file mode 100644 index 000000000..8cca21778 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml @@ -0,0 +1,65 @@ + + + + cn.iocoder.boot + yudao-framework + ${revision} + + 4.0.0 + yudao-spring-boot-starter-biz-mail + jar + + + + cn.iocoder.boot + yudao-common + + + + + org.springframework.boot + spring-boot-starter + + + + + io.opentracing + opentracing-util + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + + + + + com.google.guava + guava + true + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + + jakarta.validation + jakarta.validation-api + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java new file mode 100644 index 000000000..c83b1e5f1 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.config; + +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 邮箱配置类 + * + * @author 芋道源码 + */ +@Configuration +public class YudaoMailAutoConfiguration { + + @Bean + public MailClientFactory mailClientFactory() { + return new MailClientFactoryImpl(); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java new file mode 100644 index 000000000..a17260410 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import java.util.List; + +/** + * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 + * + * @author wangjingyi + * @date 2021/4/19 19:21 + */ +public interface MailClient { + + /** + * 发送邮件 + * + * @param from 邮箱账号 + * @param content 内容 + * @param title 标题 + * @param tos 收件人 + * @return 邮件发送结果 + */ + String sendMail(String from, String content, String title, List tos); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java new file mode 100644 index 000000000..3244dfe76 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java @@ -0,0 +1,5 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +public interface MailClientFactory { + MailClient getMailClient(); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java new file mode 100644 index 000000000..c33b4be3e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +import java.util.function.Function; + +/** + * 将 API 的错误码,转换为通用的错误码 + * + * @see MailCommonResult + * @see MailFrameworkErrorCodeConstants + * + * @author 芋道源码 + */ +public interface MailCodeMapping extends Function { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java new file mode 100644 index 000000000..a53a3b989 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.hutool.core.exceptions.ExceptionUtil; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +/** + * 短信的 CommonResult 拓展类 + * + * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 + * + * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 + * + * @author 芋道源码 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailCommonResult extends CommonResult { + + /** + * API 返回错误码 + * + * 由于第三方的错误码可能是字符串,所以使用 String 类型 + */ + private String apiCode; + /** + * API 返回提示 + */ + private String apiMsg; + + /** + * API 请求编号 + */ + private String apiRequestId; + + private MailCommonResult() { + } + + public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, + T data, MailCodeMapping codeMapping) { + Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); + MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); + result.setData(data); + // 翻译错误码 + if (codeMapping != null) { + ErrorCode errorCode = codeMapping.apply(apiCode); + if (errorCode == null) { + errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; + } + result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); + } + return result; + } + + public static MailCommonResult error(Throwable ex) { + MailCommonResult result = new MailCommonResult<>(); + result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); + result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); + return result; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java new file mode 100644 index 000000000..11f27f58a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * 消息接收 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailReceiveRespDTO { + + /** + * 是否接收成功 + */ + private Boolean success; + /** + * API 接收结果的编码 + */ + private String errorCode; + /** + * API 接收结果的说明 + */ + private String errorMsg; + + /** + * 手机号 + */ + private String mobile; + /** + * 用户接收时间 + */ + private Date receiveTime; + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + /** + * 短信日志编号 + * + * 对应 SysSmsLogDO 的编号 + */ + private Long logId; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java new file mode 100644 index 000000000..b4a94a634 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信发送 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailSendRespDTO { + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java new file mode 100644 index 000000000..14bdeacd8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信模板 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailTemplateRespDTO { + + /** + * 模板编号 + */ + private String id; + /** + * 短信内容 + */ + private String content; + /** + * 审核状态 + * + */ + private Integer auditStatus; + /** + * 审核未通过的理由 + */ + private String auditReason; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java new file mode 100644 index 000000000..097c8e095 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +/** + * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 + * + * @author zzf + * @date 2021/2/1 9:28 + */ +@Slf4j +public abstract class AbstractMailClient implements MailClient { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java new file mode 100644 index 000000000..9923bd3df --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import cn.iocoder.yudao.framework.mail.core.client.MailClient; +import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +@Validated +@Slf4j +public class MailClientFactoryImpl implements MailClientFactory { + + private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); + + public MailClientFactoryImpl (){ + Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { + AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); + channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); + }); + } + + private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { + switch (mailChannelEnum){ + case HUTOOL: return new HutoolMailClient(); + } + // 创建失败,错误日志 + 抛出异常 + log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); + throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); + } + + @Override + public MailClient getMailClient() { + return channelCodeClients.get("HUTOOL"); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java new file mode 100644 index 000000000..457ad7e37 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + + +/** + * 邮件客户端实现 + * + * @author wangjingyi + * @date 2021/4/25 14:25 + */ +@Slf4j +public class HutoolMailClient extends AbstractMailClient { + + @Override + public String sendMail(String from, String content, String title, List tos) { + try{ + return MailUtil.send(from , title , content , false , null); + }catch (Exception e){ + log.error(e.getMessage()); + } + return ""; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java new file mode 100644 index 000000000..711d36950 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; + +/** + * 阿里云的 SmsCodeMapping 实现类 + * + * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 + * + * @author 芋道源码 + */ +public class HutoolMailCodeMapping implements MailCodeMapping { + + @Override + public ErrorCode apply(String apiCode) { + return null; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java new file mode 100644 index 000000000..51d2f1fca --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.hutool.core.util.ArrayUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信渠道枚举 + * + * @author zzf + * @date 2021/1/25 10:56 + */ +@Getter +@AllArgsConstructor +public enum MailChannelEnum { + HUTOOL("HUTOOL" , "HUTOOL"), + ; + + /** + * 编码 + */ + private final String code; + /** + * 名字 + */ + private final String name; + + public static MailChannelEnum getByCode(String code) { + return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java new file mode 100644 index 000000000..e5ef74cf3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * 短信框架的错误码枚举 + * + * 短信框架,使用 2-001-000-000 段 + * + * @author 芋道源码 + */ +public interface MailFrameworkErrorCodeConstants { + + ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); + + // ========== 权限 / 限流等相关 2001000100 ========== + + ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); + // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 + ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); + + // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 + ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); + // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 + ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); + + ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); + + // ========== 模板相关 2001000200 ========== + ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 + ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); + + // ========== 签名相关 2001000300 ========== + ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); + + // ========== 账户相关 2001000400 ========== + ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); + ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); + + // ========== 其它相关 2001000900 开头 ========== + ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); + ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); + ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); + + ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java new file mode 100644 index 000000000..95c3c31a3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信模板的审核状态枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum MailTemplateAuditStatusEnum { + + CHECKING(1), + SUCCESS(2), + FAIL(3); + + private final Integer status; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java new file mode 100644 index 000000000..1f19ac12b --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.framework.mail.core.property; + +import lombok.Data; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 短信渠道配置类 + * + * @author zzf + * @date 2021/1/25 17:01 + */ +@Data +@Validated +public class MailChannelProperties { + + /** + * 渠道编号 + */ + @NotNull(message = "短信渠道 ID 不能为空") + private Long id; + /** + * 短信签名 + */ + @NotEmpty(message = "短信签名不能为空") + private String signature; + /** + * 渠道编码 + * + * 枚举 {@link MailChannelEnum} + */ + @NotEmpty(message = "渠道编码不能为空") + private String code; + /** + * 短信 API 的账号 + */ + @NotEmpty(message = "短信 API 的账号不能为空") + private String apiKey; + /** + * 短信 API 的秘钥 + */ + @NotEmpty(message = "短信 API 的秘钥不能为空") + private String apiSecret; + /** + * 短信发送回调 URL + */ + private String callbackUrl; + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java new file mode 100644 index 000000000..2ffe0d7cb --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.api.mail; + +public interface MailSendApi { +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java new file mode 100644 index 000000000..a3b0f2e35 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.system.api.mail.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel("管理后台 - 邮件发送 Req VO") +@Data +public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 + + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") + private String from; + + @ApiModelProperty(value = "标题",example = "标题") + private String title; + + @ApiModelProperty(value = "内容",example = "内容") + private String content; + + @ApiModelProperty(value = "邮箱模版id",example = "1024") + @NotNull(message = "邮箱模版id不能为空") + private Integer templateId; + + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "收件人不能为空") + private List tos; + + @ApiModelProperty(value = "附件",example = "附件编码") + private List fileIds; + + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 8520cb115..07322ccd7 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -126,5 +126,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002020000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java new file mode 100644 index 000000000..8936ea9c7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件的发送状态枚举 + * + * @author wangjingyi + * @date 2022/4/10 13:39 + */ +@Getter +@AllArgsConstructor +public enum MailSendStatusEnum { + + INIT(0), // 初始化 + SUCCESS(10), // 发送成功 + FAILURE(20), // 发送失败 + IGNORE(30), // 忽略,即不发送 + ; + + private final int status; + +} diff --git a/yudao-module-system/yudao-module-system-impl/pom.xml b/yudao-module-system/yudao-module-system-impl/pom.xml index b297830b5..65dc74d03 100644 --- a/yudao-module-system/yudao-module-system-impl/pom.xml +++ b/yudao-module-system/yudao-module-system-impl/pom.xml @@ -47,6 +47,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict + + cn.iocoder.boot + yudao-spring-boot-starter-biz-mail + cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission @@ -102,6 +106,7 @@ yudao-spring-boot-starter-excel + diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java new file mode 100644 index 000000000..cce0ed388 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.system.api.mail; + +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +/** + * 邮件发送 API 接口 + * + * @author wangjingyi + */ +@Service +@Validated +public class MailSendApiImpl implements MailSendApi{ +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 67cf9ba3a..d8650b52e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -4,28 +4,34 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data -public class MailAccountBaseVO { // TODO @wangjingqi:1), 不用空格;2)from、username、password、host、sslEnable 都要参数校验,非空;3)username 要 Email 格式;port Integer; +public class MailAccountBaseVO { - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱必填") private String from; - @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") + @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码" , required = true , example = "123456") + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") private String password; - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") + @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") + @NotNull(message = "网站必填") private String host; - @ApiModelProperty(value = "端口" , required = true , example = "80") - private String port; + @ApiModelProperty(value = "端口",required = true,example = "80") + private Integer port; - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") + @ApiModelProperty(value = "是否开启ssl",required = true,example = "2") + @NotNull(message = "是否开启ssl必填") private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java index 442a101a3..d341ce678 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -6,6 +6,7 @@ import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; +import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -30,10 +31,10 @@ public class MailLogExcelVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @ExcelProperty(value = "发送时间" ) - private Timestamp sendTime; + private Date sendTime; @ExcelProperty(value = "发送状态") - private Boolean sendStatus; + private Integer sendStatus; @ExcelProperty(value = "发送结果") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index af8e81698..024e075f4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -36,7 +36,7 @@ public class MailLogRespVO { private Timestamp sendTime; @ApiModelProperty(value = "发送状态" , required = false , example = "1") - private Boolean sendStatus; + private Integer sendStatus; @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 4ce06a718..65142ee3f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; @@ -11,25 +12,26 @@ import java.util.List; @Data public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") private String from; - @ApiModelProperty(value = "标题" , example = "标题") + @ApiModelProperty(value = "标题",example = "标题") private String title; - @ApiModelProperty(value = "内容" , example = "内容") + @ApiModelProperty(value = "内容",example = "内容") private String content; - @ApiModelProperty(value = "邮箱模版id" , example = "1024") + @ApiModelProperty(value = "邮箱模版id",example = "1024") @NotNull(message = "邮箱模版id不能为空") private Integer templateId; - @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件" , example = "附件编码") + @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index e3c9797ab..1e44336aa 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -4,15 +4,18 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data -public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不完善;2)id、name、code、username、title、content、status 是不是要参数校验呀 +public class MailTemplateBaseVO { @ApiModelProperty("主键") + @NotNull(message = "主键不能为空") private Long id; @ApiModelProperty("名称") + @NotNull(message = "名称不能为空") private String name; @ApiModelProperty("标识") @@ -20,16 +23,21 @@ public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不 private String code; @ApiModelProperty("发件人") + @NotNull(message = "发件人不能为空") + @Email(message = "发件人格式有误") private String username; @ApiModelProperty("标题") + @NotNull(message = "标题不能为空") private String title; @ApiModelProperty("内容") + @NotNull(message = "内容不能为空") private String content; @ApiModelProperty("状态") - private String status; + @NotNull(message = "状态不能为空") + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index 398e6ac03..a48c5a91a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -31,7 +31,7 @@ public class MailTemplatePageReqVO extends PageParam { private String content; @ApiModelProperty("状态") - private String status; + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index f6b9e689c..7454d2acb 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import java.io.Serializable; -import java.sql.Timestamp; +import java.util.Date; /** * 邮箱日志 @@ -18,6 +18,10 @@ import java.sql.Timestamp; @TableName(value = "system_mail_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@AllArgsConstructor +@NoArgsConstructor public class MailLogDO extends BaseDO implements Serializable { /** @@ -29,7 +33,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号编号 */ - private String accountCode; + private Long accountId; // TODO @wangjingyi:如果是冗余字段,记得 @ 下; /** @@ -40,7 +44,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 模版主键 */ - private String templateId; + private Long templateId; /** * 模版编号 @@ -65,16 +69,18 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送时间 */ - private Timestamp sendTime; + private Date sendTime; /** * 发送状态 + * + * 枚举 {@link MailSendStatusEnum} */ - // TODO @wangjingyi:四个状态,参考短信模块 - private Boolean sendStatus; + private Integer sendStatus; /** * 发送结果 + * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index b86e39e95..96f9ba4ab 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Date; + /** * 邮箱模版 * @@ -29,11 +31,10 @@ public class MailTemplateDO extends BaseDO { * 模版编号 */ private String code; - // TODO @wangjingyi:应该使用 accountId 呀 /** - * 用户名 + * 邮箱账号主键 */ - private String username; + private Long accountId; /** * 标题 */ @@ -47,7 +48,7 @@ public class MailTemplateDO extends BaseDO { * * 枚举 {@link CommonStatusEnum} */ - private String status; // TODO @wangjingyi:Integer + private Integer status; /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 8697b2151..651f5c75f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -21,9 +22,7 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - queryWrapperX.eqIfPresent("username", userName); - return this.selectOne(queryWrapperX); + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index d65887e54..a5cbf0b2a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -6,6 +6,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper @@ -23,7 +26,15 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ - // TODO @wangjingyi:优先使用 lambada 查询 - return selectOne("code" , code); + return selectOne(new QueryWrapperX() + .eqIfPresent("code" , code)); + }; + + @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectByMaxUpdateTime(Date maxUpdateTime); + + default MailTemplateDO selectOneByAccountId(Long accountId){ + return selectOne(new QueryWrapperX() + .eqIfPresent("account_id" , accountId)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java index 4b02f760e..978ea5997 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java @@ -2,17 +2,23 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -// TODO 芋艿:这个暂未实现 +import javax.annotation.Resource; + + @Component @Slf4j public class MailSendConsumer extends AbstractStreamMessageListener { + @Resource + private MailSendService mailSendService; @Override public void onMessage(MailSendMessage message) { log.info("[onMessage][消息内容({})]", message); + mailSendService.doSendMail(message); } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index aee02c76e..275a45825 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; +import java.util.List; import java.util.Map; /** @@ -16,29 +17,34 @@ import java.util.Map; @EqualsAndHashCode(callSuper = true) public class MailSendMessage extends AbstractStreamMessage { + /** + * 日志id + */ + @NotNull(message = "邮箱日志id不能为空") + private Long logId; /** * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String address; + private String from; /** - * 短信模板编号 + * 邮箱模板编号 */ - @NotNull(message = "短信模板编号不能为空") + @NotNull(message = "邮箱模板编号不能为空") private String templateCode; /** - * 短信模板参数 + * 收件人 */ - private Map templateParams; - + @NotNull(message = "收件人不能为空") + private List tos; /** - * 用户编号,允许空 + * 标题 */ - private Integer userId; + private String title; /** - * 用户类型,允许空 + * 内容 */ - private Integer userType; + private String content; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java new file mode 100644 index 000000000..ed82c24a4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.system.mq.producer.mail; + +import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Mail 邮件相关消息的 Producer + * + * @author wangjingyi + * @date 2021/4/19 13:33 + */ +@Slf4j +@Component +public class MailProducer { + + @Resource + private RedisMQTemplate redisMQTemplate; + + /** + * 发送 {@link SmsChannelRefreshMessage} 消息 + */ + public void sendMailChannelRefreshMessage() { + SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link SmsTemplateRefreshMessage} 消息 + */ + public void sendMailTemplateRefreshMessage() { + SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link MailSendMessage} 消息 + * + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 邮箱模版信息 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + MailSendMessage message = new MailSendMessage(); + message.setContent(content); + message.setFrom(mailAccountDO.getFrom()); + message.setTemplateCode(mailTemplateDO.getCode()); + message.setTitle(title); + message.setTos(tos); + message.setLogId(sendLogId); + redisMQTemplate.send(message); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index fa195259b..0a5d25ba2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -4,7 +4,9 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; @@ -28,4 +30,18 @@ public interface MailLogService { * @return */ List getMailLogList(MailLogExportReqVO exportReqVO); + + /** + * 创建邮箱日志 + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 + */ + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + + Long updateSmsSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java new file mode 100644 index 000000000..31f6a3f3e --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.system.service.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * 邮箱模版服务类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailSendService { + + /** + * 发送邮件 + * + * @param templateCode 邮件模版编码 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + void sendMail(String templateCode, String from , String content , List tos , String title); + + /** + * 执行真正的邮件发送 + * 注意,该方法仅仅提供给 MQ Consumer 使用 + * + * @param message 邮件 + */ + void doSendMail(MailSendMessage message); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1071eae5d..b8101f0af 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import javax.validation.Valid; import java.util.List; +import java.util.Map; /** * 邮箱模版服务类 @@ -18,6 +19,7 @@ import java.util.List; */ public interface MailTemplateService { + void initLocalCache(); /** * 邮箱模版创建 * @@ -62,6 +64,13 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** + *从缓存中获取邮箱模版 + * + * @param code 模板编码 + * @return 邮箱模板 + */ + MailTemplateDO getMailTemplateByCodeFromCache(String code); /** * 发送邮件 @@ -69,4 +78,12 @@ public interface MailTemplateService { * @param mailReqVO 邮件发送信息 */ void sendMail(MailReqVO mailReqVO); + + /** + * 邮件模版内容合成 + * @param content 邮箱模版 + * @param params 合成参数 + * @return + */ + String formateMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index aa1fb1d46..36ca05213 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -16,8 +17,7 @@ import javax.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -47,8 +47,8 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 - this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); + // username 要校验唯一 + this.validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailAccountExists(mailAccountDO.getId()); @@ -57,9 +57,10 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { - // TODO @wangjingyi:删除时,要判断是否有使用的模板 - // 校验是否存在 + // 校验是否存在账号 this.validateMailAccountExists(id); + // 校验是否存在关联模版 + this.validateMailTemplateByAccountId(id); mailAccountMapper.deleteById(id); } @@ -90,4 +91,11 @@ public class MailAccountServiceImpl implements MailAccountService { throw exception(MAIL_ACCOUNT_EXISTS); } } + + private void validateMailTemplateByAccountId(Long accountId){ + MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); + if (mailTemplateDO != null) { + throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + } + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index c6b492498..bdceb0d72 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -4,14 +4,21 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.sql.Timestamp; +import java.util.Date; import java.util.List; +import java.util.Objects; /** * 邮箱日志实现类 @@ -35,4 +42,39 @@ public class MailLogServiceImpl implements MailLogService { public List getMailLogList(MailLogExportReqVO exportReqVO) { return mailLogMapper.selectList(exportReqVO); } + + @Override + public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.accountId(mailAccountDO.getId()); + logDOBuilder.content(content); + logDOBuilder.title(title); + logDOBuilder.templateCode(mailTemplateDO.getCode()); + logDOBuilder.templateId(mailTemplateDO.getId()); + logDOBuilder.to(tos.toString()); + logDOBuilder.sendTime(new Date()); + logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() + : MailSendStatusEnum.IGNORE.getStatus()); + + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } + + @Override + public Long updateSmsSendResult(Long logId, String result) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId); + logDOBuilder.sendResult(result); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + return logId; + } + + public Long create(){ + MailLogDO mailLogDO = new MailLogDO(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java new file mode 100644 index 000000000..61e428048 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -0,0 +1,107 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.hutool.extra.mail.MailAccount; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; +import cn.iocoder.yudao.module.system.service.mail.MailLogService; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; + +/** + * 邮箱模版 服务实现类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +@Validated +@Slf4j +public class MailSendServiceImpl implements MailSendService { + + @Resource + private MailTemplateMapper mailTemplateMapper; + @Resource + private MailAccountMapper mailAccountMapper; + @Resource + private MailTemplateService mailTemplateService; + @Resource + private MailLogService mailLogService; + @Resource + private MailClientFactory mailClientFactory; + @Resource + private MailProducer mailProducer; + + + @Override + public void sendMail(String templateCode, String from , String content , List tos , String title) { + // TODO @@wangjingyi:发送的时候,参考下短信; + MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); + // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 + Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from", from + ); + Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); + content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); + + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); + + // 发送 MQ 消息,异步执行发送短信 + if (isSend) { + mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + } + } + + @Override + public void doSendMail(MailSendMessage message) { + MailClient mailClient = mailClientFactory.getMailClient(); + String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + mailLogService.updateSmsSendResult(message.getLogId() , result); + } + + private MailTemplateDO checkMailTemplateValid(String templateCode) { + MailTemplateDO mailTemplateDO = mailTemplateService.getMailTemplateByCodeFromCache(templateCode); + if (mailTemplateDO == null){ + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + return mailTemplateDO; + } + + private void validateMailTemplateExists(Long id) { + if (mailTemplateMapper.selectById(id) == null) { + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + } + + private void validateMailTemplateOnlyByCode(String code){ + if (mailTemplateMapper.selectOneByCode(code) != null) { + throw exception(MAIL_TEMPLATE_EXISTS); + } + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 2bd74ac4c..e1d212186 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; @@ -13,14 +15,18 @@ import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Date; import java.util.List; import java.util.Map; @@ -36,6 +42,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL */ @Service @Validated +@Slf4j public class MailTemplateServiceImpl implements MailTemplateService { @Resource @@ -43,6 +50,38 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailAccountMapper mailAccountMapper; + private volatile List mailTemplateDOList; + + /** + * 邮件模板缓存 + * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailTemplateCache; + + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + if(maxUpdateTime == null){ + mailTemplateDOList = mailTemplateMapper.selectList(); + }else{ + if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ + return; + } + } + if (CollUtil.isEmpty(mailTemplateDOList)) { + return; + } + + // 写入缓存 + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); + log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); + } + @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 @@ -54,11 +93,9 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailTemplateExists(mailTemplateDO.getId()); + this.validateMailTemplateExists(updateReqVO.getId()); + MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); } @@ -80,6 +117,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public List getMailTemplateList() {return mailTemplateMapper.selectList();} + @Override + public MailTemplateDO getMailTemplateByCodeFromCache(String code) { + return mailTemplateCache.get(code); + } + @Override public void sendMail(MailReqVO mailReqVO) { // TODO @@wangjingyi:发送的时候,参考下短信; @@ -102,6 +144,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + @Override + public String formateMailTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + private void validateMailTemplateExists(Long id) { if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); From 0b0e37a3d50f05b6518acdaed2f761a81f9bfd17 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 2 May 2022 23:21:45 +0800 Subject: [PATCH 17/80] =?UTF-8?q?code=20review=20=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 6 +++++- .../admin/mail/MailTemplateController.java | 3 +++ .../mail/vo/account/MailAccountPageReqVO.java | 1 + .../service/mail/MailAccountService.java | 1 - .../system/service/mail/MailLogService.java | 19 ++++++++++------- .../service/mail/MailTemplateService.java | 1 + .../mail/impl/MailAccountServiceImpl.java | 21 ++++++++++++------- .../service/mail/impl/MailLogServiceImpl.java | 3 ++- .../mail/impl/MailSendServiceImpl.java | 2 +- .../mail/impl/MailTemplateServiceImpl.java | 6 ++++++ 10 files changed, 44 insertions(+), 19 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index c16c7a60b..864c106d6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -24,7 +24,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - @Api(tags = "管理后台 - 邮件账号") @RestController @RequestMapping("/system/mail-account") @@ -57,6 +56,9 @@ public class MailAccountController { return success(true); } + // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + @GetMapping("/get") @ApiOperation("获得邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -74,6 +76,8 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") public CommonResult> getSimpleMailAccountList() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index cffd7f980..f75c8daad 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -29,6 +29,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { + // TODO @wangjingyi:private @Autowired MailTemplateService mailTempleService; @@ -55,6 +56,8 @@ public class MailTemplateController { return success(true); } + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 520f31998..2ae2ad162 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -12,6 +12,7 @@ import lombok.ToString; @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index c1289154f..e8937d973 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; import java.util.List; - /** * 邮箱账号 Service 接口 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 0a5d25ba2..f5d417411 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail; - import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -11,14 +10,16 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; /** - * 邮箱日志服务类 + * 邮箱日志服务类 * * @author wangjingyi * @since 2022-03-21 */ public interface MailLogService { + /** * 邮箱日志分页 + * * @param pageVO * @return */ @@ -26,6 +27,7 @@ public interface MailLogService { /** * 邮箱日志数组信息 + * * @param exportReqVO * @return */ @@ -33,13 +35,14 @@ public interface MailLogService { /** * 创建邮箱日志 - * @param mailAccountDO 邮箱账号信息 + * + * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index b8101f0af..99b8fafef 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ import java.util.Map; public interface MailTemplateService { void initLocalCache(); + /** * 邮箱模版创建 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 36ca05213..06945127c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** - * 邮箱账号 Service 实现类 + * 邮箱账号 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -39,28 +39,34 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); + validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); + + // 更新 return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 - this.validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 + validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); + validateMailAccountExists(mailAccountDO.getId()); + + // 更新 mailAccountMapper.updateById(mailAccountDO); } @Override public void delete(Long id) { // 校验是否存在账号 - this.validateMailAccountExists(id); + validateMailAccountExists(id); // 校验是否存在关联模版 - this.validateMailTemplateByAccountId(id); + validateMailTemplateByAccountId(id); + + // 删除 mailAccountMapper.deleteById(id); } @@ -95,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService { private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS throw exception(MAIL_RELATE_TEMPLATE_EXISTS); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index bdceb0d72..7c1b277da 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -62,6 +61,7 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } + // TODO @wangjingyi:不需要返回 id 呀 @Override public Long updateSmsSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); @@ -72,6 +72,7 @@ public class MailLogServiceImpl implements MailLogService { return logId; } + // TODO @wangjingyi:无用的方法,需要进行删除 public Long create(){ MailLogDO mailLogDO = new MailLogDO(); mailLogMapper.insert(mailLogDO); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 61e428048..f2146f027 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; @@ -80,6 +79,7 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 MailClient mailClient = mailClientFactory.getMailClient(); String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); mailLogService.updateSmsSendResult(message.getLogId() , result); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index e1d212186..f3d85841e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -62,6 +62,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 @Override @PostConstruct public void initLocalCache() { @@ -85,9 +86,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 this.validateMailTemplateOnlyByCode(createReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); + // TODO @wangjingyi:mq 更新 return mailTemplateDO.getId(); } @@ -97,6 +100,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { this.validateMailTemplateExists(updateReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); + // TODO @wangjingyi:mq 更新 } @Override @@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); + // TODO @wangjingyi:mq 更新 } @Override @@ -144,6 +149,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + // TODO @@wangjingyi:单词拼写错误 @Override public String formateMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From ea92b8412173b0ef0c65e30e9cbebcd56e029ed6 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 4 May 2022 22:31:12 +0800 Subject: [PATCH 18/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4mail-module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 - .../pom.xml | 65 ------------------ .../config/YudaoMailAutoConfiguration.java | 21 ------ .../mail/core/client/MailClient.java | 23 ------- .../mail/core/client/MailClientFactory.java | 5 -- .../mail/core/client/MailCodeMapping.java | 17 ----- .../mail/core/client/MailCommonResult.java | 68 ------------------- .../core/client/dto/MailReceiveRespDTO.java | 48 ------------- .../mail/core/client/dto/MailSendRespDTO.java | 18 ----- .../core/client/dto/MailTemplateRespDTO.java | 31 --------- .../core/client/impl/AbstractMailClient.java | 14 ---- .../client/impl/MailClientFactoryImpl.java | 39 ----------- .../client/impl/hutool/HutoolMailClient.java | 29 -------- .../impl/hutool/HutoolMailCodeMapping.java | 20 ------ .../mail/core/enums/MailChannelEnum.java | 32 --------- .../MailFrameworkErrorCodeConstants.java | 47 ------------- .../enums/MailTemplateAuditStatusEnum.java | 21 ------ .../core/property/MailChannelProperties.java | 52 -------------- .../system/enums/ErrorCodeConstants.java | 18 +++-- .../yudao-module-system-biz/pom.xml | 4 -- .../convert/mail/MailTemplateConvert.java | 4 -- .../mail/impl/MailSendServiceImpl.java | 10 +-- 22 files changed, 14 insertions(+), 573 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 42c887c56..73bb614cd 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,7 +30,6 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms - yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml deleted file mode 100644 index 8cca21778..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - cn.iocoder.boot - yudao-framework - ${revision} - - 4.0.0 - yudao-spring-boot-starter-biz-mail - jar - - - - cn.iocoder.boot - yudao-common - - - - - org.springframework.boot - spring-boot-starter - - - - - io.opentracing - opentracing-util - - - - - cn.iocoder.boot - yudao-spring-boot-starter-test - test - - - - - com.google.guava - guava - true - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - - - - jakarta.validation - jakarta.validation-api - - - org.projectlombok - lombok - - - - \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java deleted file mode 100644 index c83b1e5f1..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.config; - -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * 邮箱配置类 - * - * @author 芋道源码 - */ -@Configuration -public class YudaoMailAutoConfiguration { - - @Bean - public MailClientFactory mailClientFactory() { - return new MailClientFactoryImpl(); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java deleted file mode 100644 index a17260410..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import java.util.List; - -/** - * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 - * - * @author wangjingyi - * @date 2021/4/19 19:21 - */ -public interface MailClient { - - /** - * 发送邮件 - * - * @param from 邮箱账号 - * @param content 内容 - * @param title 标题 - * @param tos 收件人 - * @return 邮件发送结果 - */ - String sendMail(String from, String content, String title, List tos); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java deleted file mode 100644 index 3244dfe76..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -public interface MailClientFactory { - MailClient getMailClient(); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java deleted file mode 100644 index c33b4be3e..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -import java.util.function.Function; - -/** - * 将 API 的错误码,转换为通用的错误码 - * - * @see MailCommonResult - * @see MailFrameworkErrorCodeConstants - * - * @author 芋道源码 - */ -public interface MailCodeMapping extends Function { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java deleted file mode 100644 index a53a3b989..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -/** - * 短信的 CommonResult 拓展类 - * - * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 - * - * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 - * - * @author 芋道源码 - */ -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailCommonResult extends CommonResult { - - /** - * API 返回错误码 - * - * 由于第三方的错误码可能是字符串,所以使用 String 类型 - */ - private String apiCode; - /** - * API 返回提示 - */ - private String apiMsg; - - /** - * API 请求编号 - */ - private String apiRequestId; - - private MailCommonResult() { - } - - public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, - T data, MailCodeMapping codeMapping) { - Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); - MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); - result.setData(data); - // 翻译错误码 - if (codeMapping != null) { - ErrorCode errorCode = codeMapping.apply(apiCode); - if (errorCode == null) { - errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; - } - result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); - } - return result; - } - - public static MailCommonResult error(Throwable ex) { - MailCommonResult result = new MailCommonResult<>(); - result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); - result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); - return result; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java deleted file mode 100644 index 11f27f58a..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -import java.util.Date; - -/** - * 消息接收 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailReceiveRespDTO { - - /** - * 是否接收成功 - */ - private Boolean success; - /** - * API 接收结果的编码 - */ - private String errorCode; - /** - * API 接收结果的说明 - */ - private String errorMsg; - - /** - * 手机号 - */ - private String mobile; - /** - * 用户接收时间 - */ - private Date receiveTime; - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - /** - * 短信日志编号 - * - * 对应 SysSmsLogDO 的编号 - */ - private Long logId; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java deleted file mode 100644 index b4a94a634..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信发送 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailSendRespDTO { - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java deleted file mode 100644 index 14bdeacd8..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信模板 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailTemplateRespDTO { - - /** - * 模板编号 - */ - private String id; - /** - * 短信内容 - */ - private String content; - /** - * 审核状态 - * - */ - private Integer auditStatus; - /** - * 审核未通过的理由 - */ - private String auditReason; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java deleted file mode 100644 index 097c8e095..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; - -/** - * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 - * - * @author zzf - * @date 2021/2/1 9:28 - */ -@Slf4j -public abstract class AbstractMailClient implements MailClient { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java deleted file mode 100644 index 9923bd3df..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import cn.iocoder.yudao.framework.mail.core.client.MailClient; -import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -@Validated -@Slf4j -public class MailClientFactoryImpl implements MailClientFactory { - - private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); - - public MailClientFactoryImpl (){ - Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { - AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); - channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); - }); - } - - private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { - switch (mailChannelEnum){ - case HUTOOL: return new HutoolMailClient(); - } - // 创建失败,错误日志 + 抛出异常 - log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); - } - - @Override - public MailClient getMailClient() { - return channelCodeClients.get("HUTOOL"); - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java deleted file mode 100644 index 457ad7e37..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.hutool.extra.mail.MailUtil; -import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; - - -/** - * 邮件客户端实现 - * - * @author wangjingyi - * @date 2021/4/25 14:25 - */ -@Slf4j -public class HutoolMailClient extends AbstractMailClient { - - @Override - public String sendMail(String from, String content, String title, List tos) { - try{ - return MailUtil.send(from , title , content , false , null); - }catch (Exception e){ - log.error(e.getMessage()); - } - return ""; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java deleted file mode 100644 index 711d36950..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; - -/** - * 阿里云的 SmsCodeMapping 实现类 - * - * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 - * - * @author 芋道源码 - */ -public class HutoolMailCodeMapping implements MailCodeMapping { - - @Override - public ErrorCode apply(String apiCode) { - return null; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java deleted file mode 100644 index 51d2f1fca..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.hutool.core.util.ArrayUtil; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信渠道枚举 - * - * @author zzf - * @date 2021/1/25 10:56 - */ -@Getter -@AllArgsConstructor -public enum MailChannelEnum { - HUTOOL("HUTOOL" , "HUTOOL"), - ; - - /** - * 编码 - */ - private final String code; - /** - * 名字 - */ - private final String name; - - public static MailChannelEnum getByCode(String code) { - return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java deleted file mode 100644 index e5ef74cf3..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; - -/** - * 短信框架的错误码枚举 - * - * 短信框架,使用 2-001-000-000 段 - * - * @author 芋道源码 - */ -public interface MailFrameworkErrorCodeConstants { - - ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); - - // ========== 权限 / 限流等相关 2001000100 ========== - - ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); - // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 - ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); - - // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 - ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); - // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 - ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); - - ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); - - // ========== 模板相关 2001000200 ========== - ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 - ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); - - // ========== 签名相关 2001000300 ========== - ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); - - // ========== 账户相关 2001000400 ========== - ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); - ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); - - // ========== 其它相关 2001000900 开头 ========== - ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); - ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); - ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); - - ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java deleted file mode 100644 index 95c3c31a3..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信模板的审核状态枚举 - * - * @author 芋道源码 - */ -@AllArgsConstructor -@Getter -public enum MailTemplateAuditStatusEnum { - - CHECKING(1), - SUCCESS(2), - FAIL(3); - - private final Integer status; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java deleted file mode 100644 index 1f19ac12b..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.property; - -import lombok.Data; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 短信渠道配置类 - * - * @author zzf - * @date 2021/1/25 17:01 - */ -@Data -@Validated -public class MailChannelProperties { - - /** - * 渠道编号 - */ - @NotNull(message = "短信渠道 ID 不能为空") - private Long id; - /** - * 短信签名 - */ - @NotEmpty(message = "短信签名不能为空") - private String signature; - /** - * 渠道编码 - * - * 枚举 {@link MailChannelEnum} - */ - @NotEmpty(message = "渠道编码不能为空") - private String code; - /** - * 短信 API 的账号 - */ - @NotEmpty(message = "短信 API 的账号不能为空") - private String apiKey; - /** - * 短信 API 的秘钥 - */ - @NotEmpty(message = "短信 API 的秘钥不能为空") - private String apiSecret; - /** - * 短信发送回调 URL - */ - private String callbackUrl; - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 07322ccd7..d514345da 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -119,13 +119,17 @@ public interface ErrorCodeConstants { ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002018001, "社交解绑失败,非当前用户绑定"); ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002018002, "社交授权失败,找不到对应的用户"); - // ========== 邮箱账号 1002019000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019001, "邮箱账号存在"); + // ========== 系统铭感词 1002019000 ========= + ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1002019000, "系统敏感词在所有标签中都不存在"); + ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1002019001, "系统敏感词已在标签中存在"); - // ========== 邮箱模版 1002020000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); + // ========== 邮箱账号 1002020000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + + // ========== 邮箱模版 1002021000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml index 2240f3b95..e23ba8ab8 100644 --- a/yudao-module-system/yudao-module-system-biz/pom.xml +++ b/yudao-module-system/yudao-module-system-biz/pom.xml @@ -42,10 +42,6 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict - - cn.iocoder.boot - yudao-spring-boot-starter-biz-mail - cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 3f4693bcb..35c6c0a9b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -1,11 +1,7 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvertImpl; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index f2146f027..bc4b496f1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -13,10 +13,8 @@ import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; import javax.annotation.Resource; import java.util.List; @@ -46,8 +44,6 @@ public class MailSendServiceImpl implements MailSendService { @Resource private MailLogService mailLogService; @Resource - private MailClientFactory mailClientFactory; - @Resource private MailProducer mailProducer; @@ -80,9 +76,9 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - MailClient mailClient = mailClientFactory.getMailClient(); - String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - mailLogService.updateSmsSendResult(message.getLogId() , result); + //MailClient mailClient = mailClientFactory.getMailClient(); + //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + //mailLogService.updateSmsSendResult(message.getLogId() , result); } private MailTemplateDO checkMailTemplateValid(String templateCode) { From 8bc5254e308ab0d774635f0629bc508f58c8041a Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 03:06:00 +0800 Subject: [PATCH 19/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=20=E4=BF=AE=E6=94=B9=E6=A0=A1=E9=AA=8C=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/MailAccountController.java | 4 +- .../admin/mail/MailTemplateController.java | 25 ++--- .../mail/vo/account/MailAccountBaseVO.java | 4 - .../vo/account/MailAccountCreateReqVO.java | 6 ++ .../vo/account/MailAccountUpdateReqVO.java | 3 + .../mail/vo/template/MailTemplateRespVO.java | 4 + .../convert/mail/MailAccountConvert.java | 3 +- .../convert/mail/MailTemplateConvert.java | 7 +- .../dal/mysql/mail/MailAccountMapper.java | 17 ++++ .../dal/mysql/mail/MailTemplateMapper.java | 2 +- .../mail/MailTemplateRefreshConsumer.java | 29 ++++++ .../mail/MailAccountRefreshMessage.java | 19 ++++ .../mq/message/mail/MailSendMessage.java | 24 +++++ .../mail/MailTemplateRefreshMessage.java | 19 ++++ .../system/mq/producer/mail/MailProducer.java | 19 ++-- .../service/mail/MailAccountService.java | 5 + .../system/service/mail/MailLogService.java | 8 +- .../service/mail/MailTemplateService.java | 12 +-- .../mail/impl/MailAccountServiceImpl.java | 86 +++++++++++++--- .../service/mail/impl/MailLogServiceImpl.java | 13 +-- .../mail/impl/MailSendServiceImpl.java | 41 +++++--- .../mail/impl/MailTemplateServiceImpl.java | 98 +++++++++---------- 23 files changed, 318 insertions(+), 132 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index d514345da..32ba7181e 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -130,6 +130,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002021000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 864c106d6..17a305c48 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -57,7 +57,7 @@ public class MailAccountController { } // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE @GetMapping("/get") @ApiOperation("获得邮箱账号") @@ -76,7 +76,7 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index f75c8daad..2fae6164b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -29,9 +26,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { - // TODO @wangjingyi:private + // TODO @wangjingyi:private DONE @Autowired - MailTemplateService mailTempleService; + private MailTemplateService mailTempleService; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -56,13 +53,13 @@ public class MailTemplateController { return success(true); } - // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 DONE RespVO中需要BaseVO 中哪些字段 @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:get')") - public CommonResult getMailTemplate(@RequestParam("id") Long id) { + public CommonResult getMailTemplate(@RequestParam("id") Long id) { MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id); return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); } @@ -70,25 +67,17 @@ public class MailTemplateController { @GetMapping("/page") @ApiOperation("获得邮箱模版分页") @PreAuthorize("@ss.hasPermission('system:mail-template:query')") - public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { + public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); } @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱模版精简列表") - public CommonResult> getSimpleTemplateList() { + public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); // 排序后,返回给前端 list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } - - @PostMapping("/send") - @ApiOperation("发送邮件") - @PreAuthorize("@ss.hasPermission('system:mail-template:send')") - public CommonResult sendMail(@Valid @RequestBody MailReqVO mailReqVO){ - mailTempleService.sendMail(mailReqVO); - return success(true); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index d8650b52e..b785b74cc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -20,10 +20,6 @@ public class MailAccountBaseVO { @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") @NotNull(message = "网站必填") private String host; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 8585e9d75..476a3077a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -1,14 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 邮箱账号创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountCreateReqVO extends MailAccountBaseVO { + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 43a13ad18..4544e95b5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -18,4 +18,7 @@ public class MailAccountUpdateReqVO extends MailAccountBaseVO { @NotNull(message = "编号不能为空") private Long id; + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java new file mode 100644 index 000000000..33683b1c5 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +public class MailTemplateRespVO extends MailTemplateBaseVO{ +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index 8dbfbc58d..f2228e170 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -4,6 +4,7 @@ import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,7 +24,7 @@ public interface MailAccountConvert { List convertList02(List list); - default MailAccount convertAccount(MailAccountDO mailAccountDO){ + default MailAccount convertAccount(MailSendMessage mailAccountDO){ return new MailAccount() .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 35c6c0a9b..87fd8efe7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,9 +15,9 @@ public interface MailTemplateConvert { MailTemplateDO convert(MailTemplateBaseVO baseVO); - MailTemplateBaseVO convert(MailTemplateDO mailTemplateDO); + MailTemplateRespVO convert(MailTemplateDO mailTemplateDO); - PageResult convertPage(PageResult pageResult); + PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 651f5c75f..420b24eeb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,6 +7,9 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -25,4 +28,18 @@ public interface MailAccountMapper extends BaseMapperX { return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); }; + + default MailAccountDO selectByUserNameAndId(String userName,Long id){ + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName) + .neIfPresent("id" , id)); + }; + + default MailAccountDO selectOneByFrom(String from){ + return selectOne(new QueryWrapperX() + .eqIfPresent("from" , from)); + }; + + @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") + Long selectCountByUpdateTimeGt(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index a5cbf0b2a..d7d1cd73c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -30,7 +30,7 @@ public interface MailTemplateMapper extends BaseMapperX { .eqIfPresent("code" , code)); }; - @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + @Select("SELECT COUNT(*) FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") Long selectByMaxUpdateTime(Date maxUpdateTime); default MailTemplateDO selectOneByAccountId(Long accountId){ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java new file mode 100644 index 000000000..b4eac0165 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.system.mq.consumer.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 针对 {@link MailTemplateRefreshMessage} 的消费者 + * + * @author wangjingyi + */ +@Component +@Slf4j +public class MailTemplateRefreshConsumer extends AbstractChannelMessageListener { + + @Resource + private MailTemplateService mailTemplateService; + + @Override + public void onMessage(MailTemplateRefreshMessage message) { + log.info("[onMessage][收到 MailTemplate 刷新信息]"); + mailTemplateService.initLocalCache(); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java new file mode 100644 index 000000000..d5eafb04d --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱账号的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailAccountRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-account.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 275a45825..3df7c6dcf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -27,6 +27,16 @@ public class MailSendMessage extends AbstractStreamMessage { */ @NotNull(message = "邮箱地址不能为空") private String from; + /** + * 用户名 + */ + @NotNull(message = "用户名不能为空") + private String username; + /** + * 密码 + */ + @NotNull(message = "密码不能为空") + private String password; /** * 邮箱模板编号 */ @@ -45,6 +55,20 @@ public class MailSendMessage extends AbstractStreamMessage { * 内容 */ private String content; + /** + * 主机 + */ + @NotNull(message = "host不能为空") + private String host; + /** + * 端口 + */ + @NotNull(message = "端口号不能为空") + private Integer port; + /** + * 是否开启 SSL + */ + private Boolean sslEnable; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java new file mode 100644 index 000000000..476411ca1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱模板的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailTemplateRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-template.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index ed82c24a4..db8bbebf6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -4,7 +4,9 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; @@ -28,18 +30,18 @@ public class MailProducer { private RedisMQTemplate redisMQTemplate; /** - * 发送 {@link SmsChannelRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailChannelRefreshMessage() { - SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + public void sendMailTemplateRefreshMessage() { + MailTemplateRefreshMessage message = new MailTemplateRefreshMessage(); redisMQTemplate.send(message); } /** - * 发送 {@link SmsTemplateRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailTemplateRefreshMessage() { - SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + public void sendMailAccountRefreshMessage() { + MailAccountRefreshMessage message = new MailAccountRefreshMessage(); redisMQTemplate.send(message); } @@ -56,6 +58,11 @@ public class MailProducer { MailSendMessage message = new MailSendMessage(); message.setContent(content); message.setFrom(mailAccountDO.getFrom()); + message.setHost(mailAccountDO.getHost()); + message.setPort(mailAccountDO.getPort()); + message.setPassword(mailAccountDO.getPassword()); + message.setUsername(mailAccountDO.getUsername()); + message.setSslEnable(mailAccountDO.getSslEnable()); message.setTemplateCode(mailTemplateDO.getCode()); message.setTitle(title); message.setTos(tos); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index e8937d973..fe0615f4f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -17,6 +17,11 @@ import java.util.List; */ public interface MailAccountService { + /** + * 初始化邮箱账号的本地缓存 + */ + void initLocalCache(); + /** * 创建邮箱账号 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index f5d417411..da35012e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -46,5 +46,11 @@ public interface MailLogService { */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); - Long updateSmsSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId + */ + void updateMailSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 99b8fafef..873d337f4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -19,6 +19,9 @@ import java.util.Map; */ public interface MailTemplateService { + /** + * 初始化邮箱模版的本地缓存 + */ void initLocalCache(); /** @@ -73,18 +76,11 @@ public interface MailTemplateService { */ MailTemplateDO getMailTemplateByCodeFromCache(String code); - /** - * 发送邮件 - * - * @param mailReqVO 邮件发送信息 - */ - void sendMail(MailReqVO mailReqVO); - /** * 邮件模版内容合成 * @param content 邮箱模版 * @param params 合成参数 * @return */ - String formateMailTemplateContent(String content, Map params); + String formatMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 06945127c..3ae44693b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,20 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.util.Date; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -28,6 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; */ @Service @Validated +@Slf4j public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -36,26 +45,71 @@ public class MailAccountServiceImpl implements MailAccountService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource + private MailProducer mailProducer; + + /** + * 邮箱账号缓存 + * key:邮箱账号编码 {@link MailAccountDO#getId()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailAccountCache; + + /** + * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 + */ + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + List mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime); + if (CollUtil.isEmpty(mailAccountDOList)) { + return; + } + + // 写入缓存 + mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId); + maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime); + log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size()); + } + + private List loadMailAccountIfUpdate(Date maxUpdateTime) { + //第一步 判断是否需要更新 + if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]"); + }else{ // 判断数据库中是否有更新的账号信息 + if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { + return null; + } + log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]"); + } + return mailAccountMapper.selectList(); + } + @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - validateMailAccountOnlyByUserName(createReqVO.getUsername()); + this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); // 更新 + mailProducer.sendMailAccountRefreshMessage(); return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 - validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE + this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 validateMailAccountExists(mailAccountDO.getId()); // 更新 + mailProducer.sendMailAccountRefreshMessage(); mailAccountMapper.updateById(mailAccountDO); } @@ -65,9 +119,10 @@ public class MailAccountServiceImpl implements MailAccountService { validateMailAccountExists(id); // 校验是否存在关联模版 validateMailTemplateByAccountId(id); - // 删除 mailAccountMapper.deleteById(id); + // 更新 + mailProducer.sendMailAccountRefreshMessage(); } @Override @@ -92,17 +147,26 @@ public class MailAccountServiceImpl implements MailAccountService { } private void validateMailAccountOnlyByUserName(String userName){ - MailAccountDO mailAccountDO = mailAccountMapper.selectByUserName(userName); - if (mailAccountDO != null) { - throw exception(MAIL_ACCOUNT_EXISTS); - } + mailAccountCache.forEach((key,value)->{ + if(value.getUsername().equals(userName)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + }); + } + private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){ + mailAccountCache.forEach((key , value)->{ + if (value.getUsername().equals(userName)){ + if (!key.equals(id)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + } + }); } - private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS - throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); } } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 7c1b277da..76a7198ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -8,13 +8,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; -import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.Objects; @@ -61,21 +59,14 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 + // TODO @wangjingyi:不需要返回 id 呀 DONE @Override - public Long updateSmsSendResult(Long logId, String result) { + public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); logDOBuilder.id(logId); logDOBuilder.sendResult(result); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); - return logId; } - // TODO @wangjingyi:无用的方法,需要进行删除 - public Long create(){ - MailLogDO mailLogDO = new MailLogDO(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index bc4b496f1..6b0cccd83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; @@ -21,8 +22,7 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 邮箱模版 服务实现类 @@ -49,36 +49,47 @@ public class MailSendServiceImpl implements MailSendService { @Override public void sendMail(String templateCode, String from , String content , List tos , String title) { - // TODO @@wangjingyi:发送的时候,参考下短信; + // TODO @@wangjingyi:发送的时候,参考下短信;DONE + //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", from - ); + //校验账号信息是否合法 + MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); // 后续功能 TODO :附件查询 //List fileIds = mailSendVO.getFileIds(); - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - // 发送 MQ 消息,异步执行发送短信 if (isSend) { mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); } } + private MailAccountDO checkMailAccountValid(String from) { + MailAccountDO mailAccountDO = mailAccountMapper.selectOneByFrom(from); + if(null == mailAccountDO){ + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + return mailAccountDO; + } + @Override public void doSendMail(MailSendMessage message) { - // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - //MailClient mailClient = mailClientFactory.getMailClient(); - //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - //mailLogService.updateSmsSendResult(message.getLogId() , result); + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 DONE + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); + //发送邮件 + try{ + String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + mailLogService.updateMailSendResult(message.getLogId() , messageId); + }catch (Exception e){ + mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + } + } private MailTemplateDO checkMailTemplateValid(String templateCode) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index f3d85841e..89a0b43ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -48,59 +49,53 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; @Resource - private MailAccountMapper mailAccountMapper; - - private volatile List mailTemplateDOList; + private MailProducer mailProducer; /** * 邮件模板缓存 - * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * key:邮箱模板编码 {@link MailTemplateDO#getId()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - private volatile Map mailTemplateCache; + private volatile Map mailTemplateCache; private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { - if(maxUpdateTime == null){ - mailTemplateDOList = mailTemplateMapper.selectList(); - }else{ - if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ - return; - } - } + List mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime); if (CollUtil.isEmpty(mailTemplateDOList)) { return; } // 写入缓存 - mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); } @Override public Long create(MailTemplateCreateReqVO createReqVO) { - // code 要校验唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 - this.validateMailTemplateOnlyByCode(createReqVO.getCode()); + //要校验存在 + this.validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); return mailTemplateDO.getId(); } @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // 校验是否存在 - this.validateMailTemplateExists(updateReqVO.getId()); + // 校验是否唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -108,7 +103,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -127,43 +123,45 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } + // TODO @@wangjingyi:单词拼写错误 DONE @Override - public void sendMail(MailReqVO mailReqVO) { - // TODO @@wangjingyi:发送的时候,参考下短信; - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", mailReqVO.getFrom() - ); - String content = mailReqVO.getContent(); - Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = StrUtil.format(mailTemplateDO.getContent(), params); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - - //发送 - MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); - } - - // TODO @@wangjingyi:单词拼写错误 - @Override - public String formateMailTemplateContent(String content, Map params) { + public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); } private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { + if (mailTemplateCache.get(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); + private void validateMailTemplateOnlyByCode(Long id ,String code){ + mailTemplateCache.forEach((key,value)->{ + if (value.getCode().equals(code)){ + if (!key.equals(id)){ + throw exception(MAIL_TEMPLATE_EXISTS); + } + } + }); + } + /** + * 如果邮件模板发生变化,从数据库中获取最新的全量邮件模板。 + * 如果未发生变化,则返回空 + * + * @param maxUpdateTime 当前邮件模板的最大更新时间 + * @return 邮件模板列表 + */ + private List loadMailTemplateIfUpdate(Date maxUpdateTime) { + // 第一步,判断是否要更新。 + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailTemplateIfUpdate][首次加载全量邮件模板]"); + } else { // 判断数据库中是否有更新的邮件模板 + if (mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime) == 0) { + return null; + } + log.info("[loadSmsTemplateIfUpdate][增量加载全量邮件模板]"); } + // 第二步,如果有更新,则从数据库加载所有邮件模板 + return mailTemplateMapper.selectList(); } } From 8d6a4d40a08a6f265a848d412ad53c3278578f39 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 04:36:32 +0800 Subject: [PATCH 20/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/dataobject/mail/MailAccountDO.java | 2 ++ .../yudao/module/system/dal/mysql/mail/MailAccountMapper.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index d285adec5..7b17104ec 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -24,6 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ + @TableField("`from`") private String from; /** * 用户名 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 420b24eeb..e869ecf22 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("form" , pageReqVO.getFrom()) + .likeIfPresent("from" , pageReqVO.getFrom()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) From c3335ba2cacf436b14da2dbe95994fd29b7dc514 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:41:11 +0800 Subject: [PATCH 21/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/vo/account/MailAccountBaseVO.java | 4 ++-- .../admin/mail/vo/account/MailAccountPageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailAccountDO.java | 3 +-- .../system/dal/mysql/mail/MailAccountMapper.java | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index b785b74cc..8e392d476 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -13,11 +13,11 @@ public class MailAccountBaseVO { @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱必填") - private String from; + @Email(message = "必须是Email格式") + private String fromAddress; @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") - @Email(message = "必须是Email格式") private String username; @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 2ae2ad162..327c8465d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -14,7 +14,7 @@ import lombok.ToString; public class MailAccountPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") - private String from; + private String fromAddress; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") private String username; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 7b17104ec..910440df7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -25,8 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ - @TableField("`from`") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index e869ecf22..1e4f263ac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("from" , pageReqVO.getFrom()) + .likeIfPresent("from_address" , pageReqVO.getFromAddress()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) @@ -27,18 +27,18 @@ public interface MailAccountMapper extends BaseMapperX { default MailAccountDO selectByUserName(String userName){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); - }; + } default MailAccountDO selectByUserNameAndId(String userName,Long id){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName) .neIfPresent("id" , id)); - }; + } default MailAccountDO selectOneByFrom(String from){ return selectOne(new QueryWrapperX() - .eqIfPresent("from" , from)); - }; + .eqIfPresent("from_address" , from)); + } @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") Long selectCountByUpdateTimeGt(Date maxUpdateTime); From 63983bbab3d48b22847c22a589f51dc520795f11 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:52:34 +0800 Subject: [PATCH 22/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/convert/mail/MailAccountConvert.java | 8 ++++---- .../module/system/dal/dataobject/mail/MailLogDO.java | 2 +- .../module/system/mq/message/mail/MailSendMessage.java | 2 +- .../module/system/mq/producer/mail/MailProducer.java | 2 +- .../system/service/mail/impl/MailLogServiceImpl.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index f2228e170..b60ac088f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -29,18 +29,18 @@ public interface MailAccountConvert { .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) .setAuth(true) - .setFrom(mailAccountDO.getFrom()) + .setFrom(mailAccountDO.getFromAddress()) .setUser(mailAccountDO.getUsername()) .setPass(mailAccountDO.getPassword()) .setSslEnable(mailAccountDO.getSslEnable()); - }; + } default Map convertToMap(MailAccountDO mailAccountDO , String content) { Map map = new HashMap<>(); - map.put("from" , mailAccountDO.getFrom()); + map.put("from_address" , mailAccountDO.getFromAddress()); map.put("username" , mailAccountDO.getUsername()); map.put("content" , content); return map; - }; + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 7454d2acb..97cc51f4c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -39,7 +39,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号 */ - private String from; + private String fromAddress; /** * 模版主键 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 3df7c6dcf..fd1d68f6f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -26,7 +26,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index db8bbebf6..3b6745c26 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -57,7 +57,7 @@ public class MailProducer { public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { MailSendMessage message = new MailSendMessage(); message.setContent(content); - message.setFrom(mailAccountDO.getFrom()); + message.setFromAddress(mailAccountDO.getFromAddress()); message.setHost(mailAccountDO.getHost()); message.setPort(mailAccountDO.getPort()); message.setPassword(mailAccountDO.getPassword()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 76a7198ab..e251cc82e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -43,7 +43,7 @@ public class MailLogServiceImpl implements MailLogService { @Override public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); logDOBuilder.content(content); logDOBuilder.title(title); From 1464f7d399de68de75a6fb84aef8b58783982a16 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 17 May 2022 20:07:50 +0800 Subject: [PATCH 23/80] =?UTF-8?q?code=20review=20=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/test/TestDemoServiceImpl.java | 2 +- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/vo/log/MailLogPageReqVO.java | 3 ++ .../admin/mail/vo/send/MailReqVO.java | 1 - .../convert/mail/MailTemplateConvert.java | 2 ++ .../system/dal/dataobject/mail/MailLogDO.java | 1 - .../system/service/mail/MailLogService.java | 29 +++++++-------- .../service/mail/MailTemplateService.java | 8 +++-- .../service/mail/impl/MailLogServiceImpl.java | 36 ++++++++++++------- .../mail/impl/MailTemplateServiceImpl.java | 16 +++------ 10 files changed, 54 insertions(+), 46 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java index 92153b022..731a29ccc 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java @@ -79,7 +79,7 @@ public class TestDemoServiceImpl implements TestDemoService { @Override public PageResult getTestDemoPage(TestDemoPageReqVO pageReqVO) { -// testDemoMapper.selectList2(); + testDemoMapper.selectList2(); return testDemoMapper.selectPage(pageReqVO); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 32ba7181e..cb6db27e1 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -128,7 +128,7 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); // ========== 邮箱模版 1002021000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 9928a7746..67f91735b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -17,6 +17,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { + + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 65142ee3f..560c3bf42 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -34,5 +34,4 @@ public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该 @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 87fd8efe7..46a25b9e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -11,6 +11,7 @@ import java.util.List; @Mapper public interface MailTemplateConvert { + MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); MailTemplateDO convert(MailTemplateBaseVO baseVO); @@ -20,4 +21,5 @@ public interface MailTemplateConvert { PageResult convertPage(PageResult pageResult); List convertList02(List list); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 97cc51f4c..2472cd95f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -80,7 +80,6 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送结果 - * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index da35012e2..98a445c8a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -20,37 +20,38 @@ public interface MailLogService { /** * 邮箱日志分页 * - * @param pageVO - * @return + * @param pageVO 分页参数 + * @return 分页结果 */ PageResult getMailLogPage(MailLogPageReqVO pageVO); /** * 邮箱日志数组信息 * - * @param exportReqVO - * @return + * @param exportReqVO 导出筛选请求 + * @return 导出的日志数据 */ List getMailLogList(MailLogExportReqVO exportReqVO); /** * 创建邮箱日志 * - * @param mailAccountDO 邮箱账号信息 - * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param mailAccountDO 邮箱账号信息 + * @param template 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); /** * 更新邮件发送结果 * - * @param logId 发送日志Id - * @param result 发送结果 默认返回messageId + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId */ void updateMailSendResult(Long logId, String result); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 873d337f4..16d65b4f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; @@ -68,8 +67,9 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** - *从缓存中获取邮箱模版 + * 从缓存中获取邮箱模版 * * @param code 模板编码 * @return 邮箱模板 @@ -78,9 +78,11 @@ public interface MailTemplateService { /** * 邮件模版内容合成 + * * @param content 邮箱模版 * @param params 合成参数 - * @return + * @return 格式化后的内容 */ String formatMailTemplateContent(String content, Map params); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index e251cc82e..afc7dcb93 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -27,6 +27,7 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { + // TODO @wangjingyi:private,然后使用 @Resource @Autowired MailLogMapper mailLogMapper; @@ -41,25 +42,34 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); - logDOBuilder.accountId(mailAccountDO.getId()); - logDOBuilder.content(content); - logDOBuilder.title(title); - logDOBuilder.templateCode(mailTemplateDO.getCode()); - logDOBuilder.templateId(mailTemplateDO.getId()); - logDOBuilder.to(tos.toString()); - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() : MailSendStatusEnum.IGNORE.getStatus()); + // 设置邮箱相关字段 + // TODO @wangjingyi:userId、userType + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); + logDOBuilder.accountId(mailAccountDO.getId()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 + logDOBuilder.to(tos.toString()); + // 设置模板相关字段 + // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams + logDOBuilder.templateId(template.getId()); + logDOBuilder.templateCode(template.getCode()); + logDOBuilder.title(title); + logDOBuilder.content(content); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 + logDOBuilder.sendTime(new Date()); - MailLogDO mailLogDO = logDOBuilder.build(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); + // 插入数据库 + MailLogDO logDO = logDOBuilder.build(); + mailLogMapper.insert(logDO); + return logDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 DONE + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 89a0b43ea..9f8315458 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -3,20 +3,13 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -36,7 +29,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; /** - * 邮箱模版 服务实现类 + * 邮箱模版 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -48,6 +41,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource private MailProducer mailProducer; @@ -61,7 +55,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { @@ -78,8 +71,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { - //要校验存在 - this.validateMailTemplateExists(createReqVO.getId()); + // 要校验存在 + validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); // TODO @wangjingyi:mq 更新 DONE @@ -123,7 +116,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } - // TODO @@wangjingyi:单词拼写错误 DONE @Override public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From 0ddb50be579f87bafe1c577e485646b1c56994f7 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Mon, 11 Jul 2022 15:02:06 +0800 Subject: [PATCH 24/80] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E7=A0=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/mail/dto/MailSendReqDTO.java | 26 +++++----- .../system/enums/ErrorCodeConstants.java | 1 + .../enums/mail/MailLogUserTypeEnum.java | 22 ++++++++ .../admin/mail/vo/log/MailLogPageReqVO.java | 4 +- .../system/dal/dataobject/mail/MailLogDO.java | 45 +++++++++++------ .../dal/dataobject/mail/MailTemplateDO.java | 9 +++- .../mail/MailTemplateRefreshConsumer.java | 1 - .../mq/message/mail/MailSendMessage.java | 7 ++- .../system/mq/producer/mail/MailProducer.java | 33 ++++++------ .../system/service/mail/MailLogService.java | 20 ++++++-- .../system/service/mail/MailSendService.java | 8 +-- .../service/mail/impl/MailLogServiceImpl.java | 49 +++++++++++------- .../mail/impl/MailSendServiceImpl.java | 50 ++++++++++--------- .../mail/impl/MailTemplateServiceImpl.java | 2 +- 14 files changed, 175 insertions(+), 102 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java index a3b0f2e35..caa69678c 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -7,32 +7,32 @@ import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.Map; @ApiModel("管理后台 - 邮件发送 Req VO") @Data public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "邮箱账号不能为空") - @Email(message = "邮箱账号格式错误") - private String from; + @ApiModelProperty(value = "用户编码",required = true) + @NotNull(message = "用户编码不能为空") + private String userId; - @ApiModelProperty(value = "标题",example = "标题") - private String title; - - @ApiModelProperty(value = "内容",example = "内容") - private String content; + @ApiModelProperty(value = "用户类型",required = true) + @NotNull(message = "用户类型不能为空") + private String userType; @ApiModelProperty(value = "邮箱模版id",example = "1024") - @NotNull(message = "邮箱模版id不能为空") - private Integer templateId; + @NotNull(message = "邮箱模版编码不能为空") + private Integer templateCode; + + @ApiModelProperty(value = "邮箱参数") + @NotNull(message = "模版参数不能为空") + private Map templateParams; @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件",example = "附件编码") - private List fileIds; } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index cb6db27e1..4147383ae 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -131,5 +131,6 @@ public interface ErrorCodeConstants { ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java new file mode 100644 index 000000000..4154c9bc1 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件日志用户类型 + * + * @author wangjingyi + */ +@Getter +@AllArgsConstructor +public enum MailLogUserTypeEnum { + + COMMON (10), + VIP (20); + + /** + * 类型 + */ + private final int userType; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 67f91735b..680fe6d1f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -18,9 +18,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { - // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 DONE - @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱" , example = "yudaoyuanma@123.com") private String from; @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 2472cd95f..d4b0e5f81 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,16 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; import java.io.Serializable; import java.util.Date; +import java.util.Map; /** * 邮箱日志 @@ -29,15 +33,29 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long id; + /** + * 用户编码 + */ + private Long userId; + + /** + * 用户类型 + * + * 冗余 {@link MailLogUserTypeEnum#getUserType} + */ + private Integer userType; + // TODO @wangjingyi:accountId /** * 邮箱账号编号 */ private Long accountId; - // TODO @wangjingyi:如果是冗余字段,记得 @ 下; + // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE /** * 邮箱账号 + * + * 冗余 {@link MailAccountDO} */ private String fromAddress; @@ -47,30 +65,22 @@ public class MailLogDO extends BaseDO implements Serializable { private Long templateId; /** - * 模版编号 + * 模版内容 */ - private String templateCode; + private String templateContent; /** - * 标题 + * 基于 {@link MailTemplateDO#getParams()} 输入后的参数 */ - private String title; - - /** - * 内容 - */ - private String content; - - /** - * 收件人 - */ - private String to; + @TableField(typeHandler = JacksonTypeHandler.class) + private Map templateParams; /** * 发送时间 */ private Date sendTime; + //=========接收相关字段========= /** * 发送状态 * @@ -83,5 +93,10 @@ public class MailLogDO extends BaseDO implements Serializable { */ private String sendResult; + /** + * 消息ID + */ + private String messageId; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index 96f9ba4ab..c4708657f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; +import java.util.List; /** * 邮箱模版 @@ -43,6 +45,11 @@ public class MailTemplateDO extends BaseDO { * 内容 */ private String content; + /** + * 参数数组(自动根据内容生成) + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List params; /** * 状态 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java index b4eac0165..199b147c8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index fd1d68f6f..6e8c46668 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.mq.message.mail; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage; import lombok.Data; import lombok.EqualsAndHashCode; @@ -46,7 +47,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 收件人 */ @NotNull(message = "收件人不能为空") - private List tos; + private String to; /** * 标题 */ @@ -69,6 +70,10 @@ public class MailSendMessage extends AbstractStreamMessage { * 是否开启 SSL */ private Boolean sslEnable; + /** + * 邮箱模板参数 + */ + private List> templateParams; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index 3b6745c26..50c505512 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -7,9 +7,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -48,25 +45,27 @@ public class MailProducer { /** * 发送 {@link MailSendMessage} 消息 * + * @param sendLogId 发送日志编码 * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 邮箱模版信息 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 邮箱模版参数 + * @param to 收件人 */ - public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List> templateParams,String to) { MailSendMessage message = new MailSendMessage(); - message.setContent(content); - message.setFromAddress(mailAccountDO.getFromAddress()); - message.setHost(mailAccountDO.getHost()); - message.setPort(mailAccountDO.getPort()); - message.setPassword(mailAccountDO.getPassword()); - message.setUsername(mailAccountDO.getUsername()); - message.setSslEnable(mailAccountDO.getSslEnable()); - message.setTemplateCode(mailTemplateDO.getCode()); - message.setTitle(title); - message.setTos(tos); - message.setLogId(sendLogId); + message.setContent(content) + .setFromAddress(mailAccountDO.getFromAddress()) + .setHost(mailAccountDO.getHost()) + .setPort(mailAccountDO.getPort()) + .setPassword(mailAccountDO.getPassword()) + .setUsername(mailAccountDO.getUsername()) + .setSslEnable(mailAccountDO.getSslEnable()) + .setTemplateCode(mailTemplateDO.getCode()) + .setTitle(mailTemplateDO.getTitle()) + .setTo(to) + .setLogId(sendLogId) + .setTemplateParams(templateParams); redisMQTemplate.send(message); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 98a445c8a..6b04f7a74 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; +import java.util.Map; /** * 邮箱日志服务类 @@ -36,15 +37,16 @@ public interface MailLogService { /** * 创建邮箱日志 * + * @param userId 用户编码 + * @param userType 用户类型 + * @param to 收件人 * @param mailAccountDO 邮箱账号信息 * @param template 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateContent 模版内容 + * @param templateParams 模版参数 * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend); /** * 更新邮件发送结果 @@ -54,4 +56,12 @@ public interface MailLogService { */ void updateMailSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param exception 发送结果 + */ + void updateFailMailSendResult(Long logId, String exception); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java index 31f6a3f3e..615b34fcf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -26,10 +26,12 @@ public interface MailSendService { * @param templateCode 邮件模版编码 * @param from 邮箱 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 模版参数 + * @param to 收件人 + * @param userId 用户编码 + * @param userType 用户类型 */ - void sendMail(String templateCode, String from , String content , List tos , String title); + void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams); /** * 执行真正的邮件发送 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index afc7dcb93..a7bf04fc7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -13,8 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -27,9 +29,9 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { - // TODO @wangjingyi:private,然后使用 @Resource - @Autowired - MailLogMapper mailLogMapper; + // TODO @wangjingyi:private,然后使用 @Resource DONE + @Resource + private MailLogMapper mailLogMapper; @Override public PageResult getMailLogPage(MailLogPageReqVO pageVO) { @@ -42,26 +44,29 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。DONE // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() - : MailSendStatusEnum.IGNORE.getStatus()); - // 设置邮箱相关字段 - // TODO @wangjingyi:userId、userType + : MailSendStatusEnum.IGNORE.getStatus()) + // 设置邮箱相关字段 + .fromAddress(mailAccountDO.getFromAddress()) + .accountId(mailAccountDO.getId()) + // TODO @wangjingyi:userId、userType + //用户信息 + .userId(userId).userType(userType) + //模版信息 + .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent); + + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); - // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 - logDOBuilder.to(tos.toString()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE // 设置模板相关字段 // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams - logDOBuilder.templateId(template.getId()); - logDOBuilder.templateCode(template.getCode()); - logDOBuilder.title(title); - logDOBuilder.content(content); - // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 DONE + //logDOBuilder.sendTime(new Date()); // 插入数据库 MailLogDO logDO = logDOBuilder.build(); @@ -69,14 +74,20 @@ public class MailLogServiceImpl implements MailLogService { return logDO.getId(); } - // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。DONE @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.id(logId); - logDOBuilder.sendResult(result); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(result).messageId(result).sendStatus(MailSendStatusEnum.SUCCESS.getStatus()); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); } + @Override + public void updateFailMailSendResult(Long logId, String exception) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(exception).sendStatus(MailSendStatusEnum.FAILURE.getStatus()); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 6b0cccd83..9a9e9fe50 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -2,17 +2,18 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -34,9 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Validated @Slf4j public class MailSendServiceImpl implements MailSendService { - - @Resource - private MailTemplateMapper mailTemplateMapper; + @Resource private MailAccountMapper mailAccountMapper; @Resource @@ -48,7 +48,7 @@ public class MailSendServiceImpl implements MailSendService { @Override - public void sendMail(String templateCode, String from , String content , List tos , String title) { + public void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams) { // TODO @@wangjingyi:发送的时候,参考下短信;DONE //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); @@ -58,14 +58,11 @@ public class MailSendServiceImpl implements MailSendService { MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); - Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - + Long sendLogId = mailLogService.createMailLog(userId,userType,to,mailAccountDO , mailTemplateDO , content, templateParams, isSend); + List> newTemplateParams = buildTemplateParams(mailTemplateDO,templateParams); // 发送 MQ 消息,异步执行发送短信 if (isSend) { - mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + mailProducer.sendMailSendMessage(sendLogId,mailAccountDO , mailTemplateDO ,content, newTemplateParams,to); } } @@ -84,10 +81,10 @@ public class MailSendServiceImpl implements MailSendService { MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); //发送邮件 try{ - String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + String messageId = MailUtil.send(account,message.getTo(),message.getTitle(),message.getContent(),false,null); mailLogService.updateMailSendResult(message.getLogId() , messageId); }catch (Exception e){ - mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + mailLogService.updateFailMailSendResult(message.getLogId() , e.getMessage()); } } @@ -99,16 +96,21 @@ public class MailSendServiceImpl implements MailSendService { } return mailTemplateDO; } - - private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { - throw exception(MAIL_TEMPLATE_NOT_EXISTS); - } - } - - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); - } + /** + * 将参数模板,处理成有序的 KeyValue 数组 + * + * @param template 邮箱模板 + * @param templateParams 原始参数 + * @return 处理后的参数 + */ + @VisibleForTesting + public List> buildTemplateParams(MailTemplateDO template, Map templateParams) { + return template.getParams().stream().map(key -> { + Object value = templateParams.get(key); + if (value == null) { + throw exception(MAIL_SEND_TEMPLATE_PARAM_MISS, key); + } + return new KeyValue<>(key, value); + }).collect(Collectors.toList()); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9f8315458..3fcac8b9e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -83,7 +83,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // 校验是否唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。DONE this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); From 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/80] =?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 000000000..b5885e7ef --- /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 000000000..502d3eb30 --- /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 2f39519a3..321599f00 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 000000000..f0af060da --- /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 000000000..6861ff8c5 --- /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 000000000..0f5290377 --- /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 000000000..fe7f8a1a2 --- /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 000000000..c74291d58 --- /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 000000000..b19480e71 --- /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 000000000..61a0e5666 --- /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 000000000..8331d1b5f --- /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 000000000..530b368c1 --- /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 000000000..3576cca9f --- /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 000000000..371239455 --- /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 000000000..e39a2774a --- /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 000000000..e0402da8c --- /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 000000000..a9f8877e2 --- /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 000000000..7a8145b67 --- /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 000000000..52dd3656e --- /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 000000000..267159447 --- /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 000000000..b5bce25d4 --- /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 000000000..8d58067b9 --- /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 000000000..c826c9d10 --- /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 000000000..aa7cce11e --- /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 000000000..2a7293d10 --- /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 000000000..115055b09 --- /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 000000000..42b4f05ea --- /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 000000000..25a6f94a6 --- /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 000000000..744d5585e --- /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 000000000..eb43af802 --- /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/80] =?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 321599f00..078deb7f4 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 52dd3656e..f77126f6c 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 aa7cce11e..2066f0b23 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 115055b09..c71a054b1 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 000000000..c2d8133b3 --- /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 000000000..3eddf0bc6 --- /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 000000000..3affe2c2f --- /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 744d5585e..f7a9318a1 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 eb43af802..65b71d92e 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/80] =?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 078deb7f4..a126aee6e 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 c74291d58..eaae42e81 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 8331d1b5f..6db082d2c 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 2a7293d10..899208b8b 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 42b4f05ea..847ab9a4b 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 25a6f94a6..c37ada4fd 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/80] =?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 b19480e71..ca77eaccb 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 371239455..bff746e14 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/80] =?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 a126aee6e..91dae4dfe 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 eaae42e81..4104acdc1 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 ca77eaccb..e7f7439c2 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 6db082d2c..7f24c61c0 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 c826c9d10..714ec4498 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 899208b8b..2c9137f11 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 847ab9a4b..f74a394b7 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 c37ada4fd..4c385ee48 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/80] =?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 f0af060da..000000000 --- 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 4104acdc1..430c3ade8 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 714ec4498..5a923998a 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 2066f0b23..ab8b128ea 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/80] =?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 0f5290377..7c65e4961 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 fe7f8a1a2..2be58771d 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 430c3ade8..04bd09160 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 61a0e5666..000000000 --- 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 7f24c61c0..443f3729a 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 3576cca9f..000000000 --- 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 f74a394b7..e6057bef0 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 4c385ee48..8150ee453 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 f7a9318a1..cb2a5576c 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 65b71d92e..1342fe03b 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/80] =?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 7c65e4961..7e14b86c7 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 2be58771d..aa57a795e 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 04bd09160..000000000 --- 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 e7f7439c2..62d8a3113 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 bff746e14..84aa4b686 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 e0402da8c..6790f1858 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 a9f8877e2..b3a997933 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 000000000..abfcb2b36 --- /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 b5bce25d4..a111827fe 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 ab8b128ea..28fa83406 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 2c9137f11..9523264d1 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 e6057bef0..10f397505 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 8150ee453..0597fd689 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 000000000..bbf8c2dc5 --- /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 000000000..63237e79b --- /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/80] =?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 000000000..84152df7d --- /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 7e14b86c7..67b0d5d58 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 aa57a795e..b0aad865e 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 000000000..e24a7d49b --- /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 000000000..aefd60498 --- /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 62d8a3113..f8d5d814a 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 443f3729a..3d786796b 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 530b368c1..306b7bd28 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 abfcb2b36..7a04db5dc 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 000000000..07e3dfb85 --- /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 a111827fe..4a393d30c 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 5a923998a..b431795cf 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 9523264d1..7b599e25e 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 000000000..272648c9c --- /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 000000000..be95d8a6d --- /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 10f397505..bb8d7e923 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 0597fd689..fdfff486e 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 bbf8c2dc5..68e9a78c4 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 63237e79b..984fc196b 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 1342fe03b..fe5058074 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 000000000..cd37fd898 --- /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 000000000..de9e9f1ad --- /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 000000000..59c036540 --- /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 1ddde889a..4ed01e9a9 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 000000000..1c8a1b58a --- /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 000000000..7e9eb5610 --- /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 000000000..9fa396839 --- /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/80] =?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 7b599e25e..470419244 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/80] =?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 683206e6f..dc3661448 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/80] =?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 b431795cf..fe80784a8 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 272648c9c..290b8f2b9 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 fdfff486e..f8ddad0cf 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 984fc196b..e72bd6c86 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 fe5058074..7bfa9027c 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 e637bff8cdc7071a04489fcbe3ffa60dd5b7c344 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 10 Jan 2023 15:10:16 +0800 Subject: [PATCH 37/80] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20vo=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 + .../pom.xml | 26 ++++++++++ .../desensitize/annotation/Desensitize.java | 50 +++++++++++++++++++ .../constants/DesensitizeConstants.java | 24 +++++++++ .../enums/DesensitizationStrategyEnum.java | 49 ++++++++++++++++++ .../DefaultDesensitizationHandler.java | 10 ++++ .../handler/DesensitizationHandler.java | 13 +++++ 7 files changed, 173 insertions(+) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 3bfc020ba..0f20b1a78 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -41,6 +41,7 @@ yudao-spring-boot-starter-flowable yudao-spring-boot-starter-captcha yudao-spring-boot-starter-websocket + yudao-spring-boot-starter-biz-desensitize yudao-framework diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml new file mode 100644 index 000000000..4119f8ea7 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao-framework + 1.6.6-snapshot + + + yudao-spring-boot-starter-biz-desensitize + + + 11 + 11 + UTF-8 + + + + + cn.iocoder.boot + yudao-common + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java new file mode 100644 index 000000000..bf0f585c4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.framework.desensitize.annotation; + +import cn.iocoder.yudao.framework.desensitize.enums.DesensitizationStrategyEnum; +import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * Desensitize 注解配置会覆盖 DesensitizationStrategyEnum 配置 + */ +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Desensitize { + + /** + * 脱敏策略 + */ + DesensitizationStrategyEnum strategy(); + + /** + * 脱敏替换字符 + */ + String replacer(); + + /** + * 正则表达式 + */ + String regex(); + + /** + * 前缀保留长度 + */ + int preKeep(); + + /** + * 后缀保留长度 + */ + int suffixKeep(); + + /** + * 脱敏处理器 + */ + Class handler(); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java new file mode 100644 index 000000000..f883173c3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.framework.desensitize.constants; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class DesensitizeConstants { + + /** + * 默认正则 + */ + public static final String DEFAULT_REGEX = null; + + /** + * 默认保持长度 + */ + public static final int DEFAULT_KEEP_LENGTH = -1; + + /** + * 默认替换字符 + */ + public static final String DEFAULT_REPLACER = "****"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java new file mode 100644 index 000000000..89a1f63c8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java @@ -0,0 +1,49 @@ +package cn.iocoder.yudao.framework.desensitize.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_KEEP_LENGTH; +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REGEX; +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REPLACER; + +@Getter +@RequiredArgsConstructor +public enum DesensitizationStrategyEnum { + // 常用脱敏业务 + PHONE_NUMBER(DEFAULT_REGEX, 3, 4, DEFAULT_REPLACER), // 手机号;比如:13248765917脱敏之后为132****5917 + FIXED_PHONE(DEFAULT_REGEX, 4, 2, DEFAULT_REPLACER), // 固定电话;比如:01086551122脱敏之后为0108*****22 + ID_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 + BANK_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 银行卡号;比如:9988002866797031脱敏之后为998800********31 + CHINESE_NAME(DEFAULT_REGEX, 1, 0, "**"),// 中文名;比如:刘子豪脱敏之后为刘** + ADDRESS("[\\s\\S]+区", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 地址只显示到地区,不显示详细地址;比如:广州市天河区幸福小区102号脱敏之后为广州市天河区******** + EMAIL("(^.)[^@]*(@.*$)", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, "$1****$2"), // 邮箱;比如:example@gmail.com脱敏之后为e******@gmail.com + CAR_LICENSE(DEFAULT_REGEX, 3, 1, DEFAULT_REPLACER), // 车牌号;比如:粤A66666脱敏之后为粤A6***6 + PASSWORD(DEFAULT_REGEX, 0, 0, DEFAULT_REPLACER), // 密码;比如:123456脱敏之后为****** + + // 自定义脱敏业务 + REGEX(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 自定义正则表达式 + SLIDE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 滑动脱敏 + CUSTOM_HANDLE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER); // 自定义处理器 + ; + + /** + * 正则表达式 + */ + private final String regex; + + /** + * 前缀保留长度 + */ + private final int preKeep; + + /** + * 后缀保留长度 + */ + private final int suffixKeep; + + /** + * 脱敏替换字符 + */ + private final String replacer; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java new file mode 100644 index 000000000..4f8883c50 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +public class DefaultDesensitizationHandler implements DesensitizationHandler { + + @Override + public String handle(String origin) { + return origin; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java new file mode 100644 index 000000000..d718aae1b --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +public interface DesensitizationHandler { + + /** + * 脱敏 + * + * @param origin 原始字符串 + * @return 脱敏后的字符串 + */ + String handle(String origin); + +} From 5c8e41b84791cf92cc45896071a6b96b49ba20e3 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 12 Jan 2023 14:54:33 +0800 Subject: [PATCH 38/80] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20vo=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 21 ++++- .../desensitize/annotation/Desensitize.java | 40 +++------- .../annotation/RegexDesensitize.java | 33 ++++++++ .../annotation/SliderDesensitize.java | 39 ++++++++++ .../constraints/BankCardDesensitize.java | 21 +++++ .../constraints/CarLicenseDesensitize.java | 21 +++++ .../constraints/ChineseNameDesensitize.java | 21 +++++ .../constraints/EmailDesensitize.java | 21 +++++ .../constraints/FixedPhoneDesensitize.java | 21 +++++ .../constraints/IdCardDesensitize.java | 21 +++++ .../constraints/PasswordDesensitize.java | 21 +++++ .../constraints/PhoneNumberDesensitize.java | 21 +++++ .../constants/DesensitizeConstants.java | 24 ------ .../enums/DesensitizationStrategyEnum.java | 49 ------------ .../DefaultDesensitizationHandler.java | 10 --- .../handler/DesensitizationHandler.java | 2 +- .../handler/DesensitizationHandlerHolder.java | 34 +++++++++ .../handler/RegexDesensitizationHandler.java | 13 ++++ .../handler/SliderDesensitizationHandler.java | 39 ++++++++++ .../StringDesensitizeSerializer.java | 76 +++++++++++++++++++ .../handler/DesensitizationHandlerTest.java | 25 ++++++ 21 files changed, 457 insertions(+), 116 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml index 4119f8ea7..7f15d0d4c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - cn.iocoder.boot yudao-framework - 1.6.6-snapshot + cn.iocoder.boot + ${revision} yudao-spring-boot-starter-biz-desensitize @@ -22,5 +22,22 @@ cn.iocoder.boot yudao-common
+ + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java index bf0f585c4..65dd2108d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.framework.desensitize.annotation; -import cn.iocoder.yudao.framework.desensitize.enums.DesensitizationStrategyEnum; import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.serializer.StringDesensitizeSerializer; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -11,40 +13,18 @@ import java.lang.annotation.Target; /** - * Desensitize 注解配置会覆盖 DesensitizationStrategyEnum 配置 + * Desensitize 顶级脱敏注解 */ -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) @Documented +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@JsonSerialize(using = StringDesensitizeSerializer.class) public @interface Desensitize { - /** - * 脱敏策略 - */ - DesensitizationStrategyEnum strategy(); - - /** - * 脱敏替换字符 - */ - String replacer(); - - /** - * 正则表达式 - */ - String regex(); - - /** - * 前缀保留长度 - */ - int preKeep(); - - /** - * 后缀保留长度 - */ - int suffixKeep(); - /** * 脱敏处理器 */ - Class handler(); + Class desensitizationHandler(); + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java new file mode 100644 index 000000000..c2df586c4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.framework.desensitize.annotation; + +import cn.iocoder.yudao.framework.desensitize.handler.RegexDesensitizationHandler; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 正则脱敏注解 + */ +@Documented +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationHandler = RegexDesensitizationHandler.class) +public @interface RegexDesensitize { + /** + * 匹配的正则表达式(默认匹配所有) + */ + String regex() default "^[\\s\\S]*$"; + + /** + * 替换规则,会将匹配到的字符串全部替换成 replacer + * 例如:regex=123; replacer=****** + * 原始字符串 123456789 + * 脱敏后字符串 ******456789 + */ + String replacer() default "******"; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java new file mode 100644 index 000000000..ebafaa9bc --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.desensitize.annotation; + +import cn.iocoder.yudao.framework.desensitize.handler.SliderDesensitizationHandler; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 滑动脱敏注解 + */ +@Documented +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationHandler = SliderDesensitizationHandler.class) +public @interface SliderDesensitize { + + /** + * 后缀保留长度 + */ + int suffixKeep() default 0; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + + /** + * 前缀保留长度 + */ + int prefixKeep() default 0; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java new file mode 100644 index 000000000..8fa73169a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 银行卡号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 6, suffixKeep = 2, replacer = "*") // 银行卡号;比如:9988002866797031脱敏之后为998800********31 +public @interface BankCardDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java new file mode 100644 index 000000000..11f1f5814 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 车牌号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 3, suffixKeep = 1, replacer = "*") // 车牌号;比如:粤A66666脱敏之后为粤A6***6 +public @interface CarLicenseDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java new file mode 100644 index 000000000..97d2698ed --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 中文名 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 1, suffixKeep = 0, replacer = "*") // 中文名;比如:刘子豪脱敏之后为刘** +public @interface ChineseNameDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java new file mode 100644 index 000000000..142e7c0f6 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 邮箱 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@RegexDesensitize(regex = "(^.)[^@]*(@.*$)", replacer ="$1****$2") // 邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com +public @interface EmailDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java new file mode 100644 index 000000000..f91988735 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 固定电话 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 4, suffixKeep = 2, replacer = "*") // 固定电话;比如:01086551122脱敏之后为0108*****22 +public @interface FixedPhoneDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java new file mode 100644 index 000000000..921019c5d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 身份证 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 6, suffixKeep = 2, replacer = "*") // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 +public @interface IdCardDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java new file mode 100644 index 000000000..8d823a139 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 密码 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 0, suffixKeep = 0, replacer = "*") // 密码;比如:123456脱敏之后为****** +public @interface PasswordDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java new file mode 100644 index 000000000..0829c6a45 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.desensitize.annotation.constraints; + +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 手机号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@SliderDesensitize(prefixKeep = 3, suffixKeep = 4, replacer = "*") // 手机号;比如:13248765917脱敏之后为132****5917 +public @interface PhoneNumberDesensitize { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java deleted file mode 100644 index f883173c3..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.constants; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class DesensitizeConstants { - - /** - * 默认正则 - */ - public static final String DEFAULT_REGEX = null; - - /** - * 默认保持长度 - */ - public static final int DEFAULT_KEEP_LENGTH = -1; - - /** - * 默认替换字符 - */ - public static final String DEFAULT_REPLACER = "****"; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java deleted file mode 100644 index 89a1f63c8..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.enums; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_KEEP_LENGTH; -import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REGEX; -import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REPLACER; - -@Getter -@RequiredArgsConstructor -public enum DesensitizationStrategyEnum { - // 常用脱敏业务 - PHONE_NUMBER(DEFAULT_REGEX, 3, 4, DEFAULT_REPLACER), // 手机号;比如:13248765917脱敏之后为132****5917 - FIXED_PHONE(DEFAULT_REGEX, 4, 2, DEFAULT_REPLACER), // 固定电话;比如:01086551122脱敏之后为0108*****22 - ID_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 - BANK_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 银行卡号;比如:9988002866797031脱敏之后为998800********31 - CHINESE_NAME(DEFAULT_REGEX, 1, 0, "**"),// 中文名;比如:刘子豪脱敏之后为刘** - ADDRESS("[\\s\\S]+区", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 地址只显示到地区,不显示详细地址;比如:广州市天河区幸福小区102号脱敏之后为广州市天河区******** - EMAIL("(^.)[^@]*(@.*$)", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, "$1****$2"), // 邮箱;比如:example@gmail.com脱敏之后为e******@gmail.com - CAR_LICENSE(DEFAULT_REGEX, 3, 1, DEFAULT_REPLACER), // 车牌号;比如:粤A66666脱敏之后为粤A6***6 - PASSWORD(DEFAULT_REGEX, 0, 0, DEFAULT_REPLACER), // 密码;比如:123456脱敏之后为****** - - // 自定义脱敏业务 - REGEX(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 自定义正则表达式 - SLIDE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 滑动脱敏 - CUSTOM_HANDLE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER); // 自定义处理器 - ; - - /** - * 正则表达式 - */ - private final String regex; - - /** - * 前缀保留长度 - */ - private final int preKeep; - - /** - * 后缀保留长度 - */ - private final int suffixKeep; - - /** - * 脱敏替换字符 - */ - private final String replacer; -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java deleted file mode 100644 index 4f8883c50..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.handler; - -public class DefaultDesensitizationHandler implements DesensitizationHandler { - - @Override - public String handle(String origin) { - return origin; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java index d718aae1b..a5d06feb1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java @@ -8,6 +8,6 @@ public interface DesensitizationHandler { * @param origin 原始字符串 * @return 脱敏后的字符串 */ - String handle(String origin); + String desensitize(String origin, Object... arg); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java new file mode 100644 index 000000000..23336b0cf --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +import cn.hutool.core.util.ReflectUtil; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class DesensitizationHandlerHolder { + /** + * handler 缓存,默认初始化内置的处理器 + */ + private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<>() {{ + put(RegexDesensitizationHandler.class, new RegexDesensitizationHandler()); + put(SliderDesensitizationHandler.class, new SliderDesensitizationHandler()); + }}; + + public static DesensitizationHandler getDesensitizationHandler(Class clazz) { + DesensitizationHandler handler = HANDLER_MAP.get(clazz); + if (handler != null) { + return handler; + } + synchronized (DesensitizationHandlerHolder.class) { + handler = HANDLER_MAP.get(clazz); + // 双重校验锁 + if (handler != null) { + return handler; + } + handler = ReflectUtil.newInstanceIfPossible(clazz); + HANDLER_MAP.put(clazz, handler); + } + return handler; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java new file mode 100644 index 000000000..1846156d4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +public class RegexDesensitizationHandler implements DesensitizationHandler { + + @Override + public String desensitize(String origin, Object... arg) { + String regex = (String) arg[0]; + String replacer = (String) arg[1]; + + return origin.replaceAll(regex, replacer); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java new file mode 100644 index 000000000..81b9ccc50 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +public class SliderDesensitizationHandler implements DesensitizationHandler { + + @Override + public String desensitize(String origin, Object... arg) { + int prefixKeep = (Integer) arg[0]; + int suffixKeep = (Integer) arg[1]; + String replacer = (String) arg[2]; + + int length = origin.length(); + + // 原始字符串长度小于等于保留长度,则原始字符串全部替换 + if (prefixKeep >= length || suffixKeep >= length) { + return buildReplacerByLength(replacer, length); + } + + // 如果原始字符串小于等于前后缀保留字符串长度,则原始字符串全部替换 + if ((prefixKeep + suffixKeep) >= length) { + return buildReplacerByLength(replacer, length); + } + + int interval = length - prefixKeep - suffixKeep; + return origin.substring(0, prefixKeep) + + buildReplacerByLength(replacer, interval) + + origin.substring(prefixKeep + interval); + } + + /** + * 根据长度循环构建替换符 + * + * @param replacer 替换符 + * @param length 长度 + * @return 构建后的替换符 + */ + private String buildReplacerByLength(String replacer, int length) { + return String.valueOf(replacer).repeat(Math.max(0, length)); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java new file mode 100644 index 000000000..a43b3e28e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java @@ -0,0 +1,76 @@ +package cn.iocoder.yudao.framework.desensitize.serializer; + +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.desensitize.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandlerHolder; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.ContextualSerializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import java.io.IOException; +import java.lang.reflect.Field; + +/** + * 脱敏序列化器 + */ +public class StringDesensitizeSerializer extends StdSerializer implements ContextualSerializer { + private final DesensitizationHandler desensitizationHandler; + + protected StringDesensitizeSerializer(DesensitizationHandler desensitizationHandler) { + super(String.class); + this.desensitizationHandler = desensitizationHandler; + } + + + @Override + public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { + Desensitize annotation = beanProperty.getAnnotation(Desensitize.class); + if (annotation == null) { + return this; + } + + return new StringDesensitizeSerializer(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationHandler())); + } + + @Override + public void serialize(String value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { + if (StrUtil.isBlank(value)) { + gen.writeNull(); + return; + } + + String currentName = gen.getOutputContext().getCurrentName(); + Object currentValue = gen.getCurrentValue(); + Class currentValueClass = currentValue.getClass(); + Field field = ReflectUtil.getField(currentValueClass, currentName); + + // 滑动处理器 + SliderDesensitize sliderDesensitize = field.getAnnotation(SliderDesensitize.class); + if (sliderDesensitize != null) { + value = this.desensitizationHandler.desensitize(value, sliderDesensitize.prefixKeep(), sliderDesensitize.suffixKeep(), sliderDesensitize.replacer()); + } + + // 正则处理器 + RegexDesensitize regexDesensitize = field.getAnnotation(RegexDesensitize.class); + if (regexDesensitize != null) { + value = this.desensitizationHandler.desensitize(value, regexDesensitize.regex(), regexDesensitize.replacer()); + } + + // 自定义处理器 + Desensitize desensitize = field.getAnnotation(Desensitize.class); + if (desensitize != null) { + value = this.desensitizationHandler.desensitize(value); + } + + gen.writeString(value); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java new file mode 100644 index 000000000..63b4eaabf --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.handler; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class DesensitizationHandlerTest { + + @Test + public void testSliderDesensitizationHandler() { + DesensitizationHandler handler = DesensitizationHandlerHolder.getDesensitizationHandler(SliderDesensitizationHandler.class); + + Assertions.assertEquals("A****FG", handler.desensitize("ABCDEFG", 1, 2, "*")); + Assertions.assertEquals("芋**码", handler.desensitize("芋道源码", 1, 1, "*")); + Assertions.assertEquals("****", handler.desensitize("芋道源码", 4, 0, "*")); + } + + @Test + public void testRegexDesensitizationHandler() { + DesensitizationHandler handler = DesensitizationHandlerHolder.getDesensitizationHandler(RegexDesensitizationHandler.class); + + Assertions.assertEquals("e****@gmail.com", handler.desensitize("example@gmail.com", "(^.)[^@]*(@.*$)", "$1****$2")); + Assertions.assertEquals("***,铁***", handler.desensitize("他妈的,铁废物", "他妈的|去你大爷|卧槽|草泥马|废物", "***")); + } + +} From cd9bcda9350a28d6547af3a391fdea757ad8b8ea Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 12 Jan 2023 15:31:44 +0800 Subject: [PATCH 39/80] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20vo=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 5 ++++ .../StringDesensitizeSerializer.java | 29 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 7b056c46b..be2f14dd6 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -141,6 +141,11 @@ yudao-spring-boot-starter-captcha ${revision} + + cn.iocoder.boot + yudao-spring-boot-starter-biz-desensitize + ${revision} + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java index a43b3e28e..f90475d6d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.framework.desensitize.serializer; +import cn.hutool.core.annotation.AnnotationUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.desensitize.annotation.Desensitize; @@ -22,13 +24,19 @@ import java.lang.reflect.Field; * 脱敏序列化器 */ public class StringDesensitizeSerializer extends StdSerializer implements ContextualSerializer { - private final DesensitizationHandler desensitizationHandler; + private DesensitizationHandler desensitizationHandler; - protected StringDesensitizeSerializer(DesensitizationHandler desensitizationHandler) { + protected StringDesensitizeSerializer() { super(String.class); - this.desensitizationHandler = desensitizationHandler; } + public DesensitizationHandler getDesensitizationHandler() { + return desensitizationHandler; + } + + public void setDesensitizationHandler(DesensitizationHandler desensitizationHandler) { + this.desensitizationHandler = desensitizationHandler; + } @Override public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { @@ -36,8 +44,9 @@ public class StringDesensitizeSerializer extends StdSerializer implement if (annotation == null) { return this; } - - return new StringDesensitizeSerializer(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationHandler())); + StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); + serializer.setDesensitizationHandler(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationHandler())); + return serializer; } @Override @@ -53,19 +62,23 @@ public class StringDesensitizeSerializer extends StdSerializer implement Field field = ReflectUtil.getField(currentValueClass, currentName); // 滑动处理器 - SliderDesensitize sliderDesensitize = field.getAnnotation(SliderDesensitize.class); + SliderDesensitize sliderDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, SliderDesensitize.class)); if (sliderDesensitize != null) { value = this.desensitizationHandler.desensitize(value, sliderDesensitize.prefixKeep(), sliderDesensitize.suffixKeep(), sliderDesensitize.replacer()); + gen.writeString(value); + return; } // 正则处理器 - RegexDesensitize regexDesensitize = field.getAnnotation(RegexDesensitize.class); + RegexDesensitize regexDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, RegexDesensitize.class)); if (regexDesensitize != null) { value = this.desensitizationHandler.desensitize(value, regexDesensitize.regex(), regexDesensitize.replacer()); + gen.writeString(value); + return; } // 自定义处理器 - Desensitize desensitize = field.getAnnotation(Desensitize.class); + Desensitize desensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, Desensitize.class)); if (desensitize != null) { value = this.desensitizationHandler.desensitize(value); } From 70f15ab60db12282411bc6fd6e50acb7798b3f78 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 12 Jan 2023 15:43:31 +0800 Subject: [PATCH 40/80] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/desensitize/handler/DesensitizationHandler.java | 3 +++ .../desensitize/handler/DesensitizationHandlerHolder.java | 3 +++ .../desensitize/handler/RegexDesensitizationHandler.java | 3 +++ .../desensitize/handler/SliderDesensitizationHandler.java | 3 +++ 4 files changed, 12 insertions(+) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java index a5d06feb1..ba5a63bfb 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java @@ -1,5 +1,8 @@ package cn.iocoder.yudao.framework.desensitize.handler; +/** + * 脱敏处理器接口 + */ public interface DesensitizationHandler { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java index 23336b0cf..456d2b920 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java @@ -5,6 +5,9 @@ import cn.hutool.core.util.ReflectUtil; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +/** + * 脱敏处理器 Holder + */ public class DesensitizationHandlerHolder { /** * handler 缓存,默认初始化内置的处理器 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java index 1846156d4..63089054f 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java @@ -1,5 +1,8 @@ package cn.iocoder.yudao.framework.desensitize.handler; +/** + * 正则脱敏处理器 + */ public class RegexDesensitizationHandler implements DesensitizationHandler { @Override diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java index 81b9ccc50..2d8336d1f 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java @@ -1,5 +1,8 @@ package cn.iocoder.yudao.framework.desensitize.handler; +/** + * 滑动脱敏处理器 + */ public class SliderDesensitizationHandler implements DesensitizationHandler { @Override From 61a34ddac5478887621d05cd7cf9c6019a62f27b Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 12 Jan 2023 19:57:11 +0800 Subject: [PATCH 41/80] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20vo=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/DesensitizationHandler.java | 14 ++++++++++++- .../handler/RegexDesensitizationHandler.java | 9 ++++++++- .../handler/SliderDesensitizationHandler.java | 9 ++++++++- .../StringDesensitizeSerializer.java | 20 ++++++++++++++----- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java index ba5a63bfb..74870e771 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java @@ -1,16 +1,28 @@ package cn.iocoder.yudao.framework.desensitize.handler; +import java.lang.annotation.Annotation; + /** * 脱敏处理器接口 */ -public interface DesensitizationHandler { +public interface DesensitizationHandler { /** * 脱敏 * * @param origin 原始字符串 + * @param arg 参数 * @return 脱敏后的字符串 */ String desensitize(String origin, Object... arg); + /** + * 获取注解参数 + * + * @param anno 注解 + * @return 注解参数 + */ + default Object[] getAnnotationArgs(T anno) { + return new Object[0]; + } } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java index 63089054f..57fc71178 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.framework.desensitize.handler; +import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; + /** * 正则脱敏处理器 */ -public class RegexDesensitizationHandler implements DesensitizationHandler { +public class RegexDesensitizationHandler implements DesensitizationHandler { @Override public String desensitize(String origin, Object... arg) { @@ -13,4 +15,9 @@ public class RegexDesensitizationHandler implements DesensitizationHandler { return origin.replaceAll(regex, replacer); } + @Override + public Object[] getAnnotationArgs(RegexDesensitize anno) { + return new Object[]{anno.regex(), anno.replacer()}; + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java index 2d8336d1f..47887da39 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.framework.desensitize.handler; +import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; + /** * 滑动脱敏处理器 */ -public class SliderDesensitizationHandler implements DesensitizationHandler { +public class SliderDesensitizationHandler implements DesensitizationHandler { @Override public String desensitize(String origin, Object... arg) { @@ -29,6 +31,11 @@ public class SliderDesensitizationHandler implements DesensitizationHandler { origin.substring(prefixKeep + interval); } + @Override + public Object[] getAnnotationArgs(SliderDesensitize anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } + /** * 根据长度循环构建替换符 * diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java index f90475d6d..956be23f3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; /** @@ -64,7 +65,7 @@ public class StringDesensitizeSerializer extends StdSerializer implement // 滑动处理器 SliderDesensitize sliderDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, SliderDesensitize.class)); if (sliderDesensitize != null) { - value = this.desensitizationHandler.desensitize(value, sliderDesensitize.prefixKeep(), sliderDesensitize.suffixKeep(), sliderDesensitize.replacer()); + value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(sliderDesensitize)); gen.writeString(value); return; } @@ -72,15 +73,24 @@ public class StringDesensitizeSerializer extends StdSerializer implement // 正则处理器 RegexDesensitize regexDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, RegexDesensitize.class)); if (regexDesensitize != null) { - value = this.desensitizationHandler.desensitize(value, regexDesensitize.regex(), regexDesensitize.replacer()); + value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(regexDesensitize)); gen.writeString(value); return; } // 自定义处理器 - Desensitize desensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, Desensitize.class)); - if (desensitize != null) { - value = this.desensitizationHandler.desensitize(value); + Desensitize[] annotations = AnnotationUtil.getCombinationAnnotations(field, Desensitize.class); + if (ArrayUtil.isEmpty(annotations)) { + gen.writeString(value); + return; + } + + for (Annotation annotation : field.getAnnotations()) { + if (AnnotationUtil.hasAnnotation(annotation.annotationType(), Desensitize.class)) { + value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(annotation)); + gen.writeString(value); + return; + } } gen.writeString(value); From c60f8d6da293fadf36ffd7fd0ddbb0793beca99b Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 21:45:18 +0800 Subject: [PATCH 42/80] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20vo=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constraints/BankCardDesensitize.java | 21 ---------- .../constraints/CarLicenseDesensitize.java | 21 ---------- .../constraints/ChineseNameDesensitize.java | 21 ---------- .../constraints/EmailDesensitize.java | 21 ---------- .../constraints/FixedPhoneDesensitize.java | 21 ---------- .../constraints/IdCardDesensitize.java | 21 ---------- .../constraints/PasswordDesensitize.java | 21 ---------- .../constraints/PhoneNumberDesensitize.java | 21 ---------- .../base}/DesensitizationHandlerHolder.java | 9 ++-- .../base}/annotation/Desensitize.java | 9 ++-- .../base/handler/DesensitizationHandler.java | 19 +++++++++ .../regex/annotation/EmailDesensitize.java | 34 +++++++++++++++ .../regex}/annotation/RegexDesensitize.java | 7 ++-- .../AbstractRegexDesensitizationHandler.java | 25 +++++++++++ .../DefaultRegexDesensitizationHandler.java | 14 +++++++ .../handler/EmailDesensitizationHandler.java | 11 +++++ .../core/slider/annotation/BankCard.java | 41 +++++++++++++++++++ .../core/slider/annotation/CarLicense.java | 41 +++++++++++++++++++ .../core/slider/annotation/ChineseName.java | 41 +++++++++++++++++++ .../core/slider/annotation/FixedPhone.java | 41 +++++++++++++++++++ .../core/slider/annotation/IdCard.java | 41 +++++++++++++++++++ .../core/slider/annotation/Password.java | 41 +++++++++++++++++++ .../core/slider/annotation/PhoneNumber.java | 41 +++++++++++++++++++ .../slider/annotation/Slider.java} | 9 ++-- .../AbstractDesensitizationHandler.java} | 31 +++++++------- .../handler/BankCardDesensitization.java | 11 +++++ .../handler/CarLicenseDesensitization.java | 10 +++++ .../handler/ChineseNameDesensitization.java | 10 +++++ .../DefaultDesensitizationHandler.java | 14 +++++++ .../handler/FixedPhoneDesensitization.java | 10 +++++ .../slider/handler/IdCardDesensitization.java | 10 +++++ .../handler/PasswordDesensitization.java | 10 +++++ .../handler/PhoneNumberDesensitization.java | 11 +++++ .../handler/DesensitizationHandler.java | 28 ------------- .../handler/RegexDesensitizationHandler.java | 23 ----------- .../StringDesensitizeSerializer.java | 29 +++---------- .../handler/DesensitizationHandlerTest.java | 25 ----------- 37 files changed, 518 insertions(+), 296 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java rename yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/{handler => core/base}/DesensitizationHandlerHolder.java (66%) rename yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/{ => core/base}/annotation/Desensitize.java (71%) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java rename yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/{ => core/regex}/annotation/RegexDesensitize.java (71%) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java rename yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/{annotation/SliderDesensitize.java => core/slider/annotation/Slider.java} (70%) rename yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/{handler/SliderDesensitizationHandler.java => core/slider/handler/AbstractDesensitizationHandler.java} (60%) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java deleted file mode 100644 index 8fa73169a..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/BankCardDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 银行卡号 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 6, suffixKeep = 2, replacer = "*") // 银行卡号;比如:9988002866797031脱敏之后为998800********31 -public @interface BankCardDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java deleted file mode 100644 index 11f1f5814..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/CarLicenseDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 车牌号 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 3, suffixKeep = 1, replacer = "*") // 车牌号;比如:粤A66666脱敏之后为粤A6***6 -public @interface CarLicenseDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java deleted file mode 100644 index 97d2698ed..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/ChineseNameDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 中文名 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 1, suffixKeep = 0, replacer = "*") // 中文名;比如:刘子豪脱敏之后为刘** -public @interface ChineseNameDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java deleted file mode 100644 index 142e7c0f6..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/EmailDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 邮箱 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@RegexDesensitize(regex = "(^.)[^@]*(@.*$)", replacer ="$1****$2") // 邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com -public @interface EmailDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java deleted file mode 100644 index f91988735..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/FixedPhoneDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 固定电话 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 4, suffixKeep = 2, replacer = "*") // 固定电话;比如:01086551122脱敏之后为0108*****22 -public @interface FixedPhoneDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java deleted file mode 100644 index 921019c5d..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/IdCardDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 身份证 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 6, suffixKeep = 2, replacer = "*") // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 -public @interface IdCardDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java deleted file mode 100644 index 8d823a139..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PasswordDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 密码 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 0, suffixKeep = 0, replacer = "*") // 密码;比如:123456脱敏之后为****** -public @interface PasswordDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java deleted file mode 100644 index 0829c6a45..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/constraints/PhoneNumberDesensitize.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.annotation.constraints; - -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 手机号 - */ -@Documented -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@SliderDesensitize(prefixKeep = 3, suffixKeep = 4, replacer = "*") // 手机号;比如:13248765917脱敏之后为132****5917 -public @interface PhoneNumberDesensitize { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java similarity index 66% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java rename to yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java index 456d2b920..5787eae56 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerHolder.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java @@ -1,6 +1,9 @@ -package cn.iocoder.yudao.framework.desensitize.handler; +package cn.iocoder.yudao.framework.desensitize.core.base; import cn.hutool.core.util.ReflectUtil; +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -13,8 +16,8 @@ public class DesensitizationHandlerHolder { * handler 缓存,默认初始化内置的处理器 */ private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<>() {{ - put(RegexDesensitizationHandler.class, new RegexDesensitizationHandler()); - put(SliderDesensitizationHandler.class, new SliderDesensitizationHandler()); + put(DefaultRegexDesensitizationHandler.class, new DefaultRegexDesensitizationHandler()); + put(DefaultDesensitizationHandler.class, new DefaultDesensitizationHandler()); }}; public static DesensitizationHandler getDesensitizationHandler(Class clazz) { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java similarity index 71% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java rename to yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java index 65dd2108d..888330ebe 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.framework.desensitize.annotation; +package cn.iocoder.yudao.framework.desensitize.core.base.annotation; -import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; import cn.iocoder.yudao.framework.desensitize.serializer.StringDesensitizeSerializer; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -16,7 +16,7 @@ import java.lang.annotation.Target; * Desensitize 顶级脱敏注解 */ @Documented -@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +@Target({ ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @JsonSerialize(using = StringDesensitizeSerializer.class) @@ -25,6 +25,5 @@ public @interface Desensitize { /** * 脱敏处理器 */ - Class desensitizationHandler(); - + Class desensitizationBy(); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java new file mode 100644 index 000000000..9c10fb0ac --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.framework.desensitize.core.base.handler; + +import java.lang.annotation.Annotation; + +/** + * 脱敏处理器接口 + */ +public interface DesensitizationHandler { + + /** + * 脱敏 + * + * @param origin 原始字符串 + * @param anno 注解信息 + * @return 脱敏后的字符串 + */ + String desensitize(String origin, T anno); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java new file mode 100644 index 000000000..746e5503b --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.regex.handler.EmailDesensitizationHandler; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 邮箱 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = EmailDesensitizationHandler.class) // 邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com +public @interface EmailDesensitize { + /** + * 匹配的正则表达式(默认匹配所有) + */ + String regex() default "(^.)[^@]*(@.*$)"; + + /** + * 替换规则,会将匹配到的字符串全部替换成 replacer + * 例如:regex=123; replacer=****** + * 原始字符串 123456789 + * 脱敏后字符串 ******456789 + */ + String replacer() default "$1****$2"; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java similarity index 71% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java index c2df586c4..7ee6fadd5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/RegexDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java @@ -1,6 +1,7 @@ -package cn.iocoder.yudao.framework.desensitize.annotation; +package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; -import cn.iocoder.yudao.framework.desensitize.handler.RegexDesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import java.lang.annotation.Documented; @@ -16,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationHandler = RegexDesensitizationHandler.class) +@Desensitize(desensitizationBy = DefaultRegexDesensitizationHandler.class) public @interface RegexDesensitize { /** * 匹配的正则表达式(默认匹配所有) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java new file mode 100644 index 000000000..17c86055e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.regex.handler; + +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; + +import java.lang.annotation.Annotation; + +public abstract class AbstractRegexDesensitizationHandler implements DesensitizationHandler { + + @Override + public String desensitize(String origin, T anno) { + Object[] args = getArgs(anno); + String regex = (String) args[0]; + String replacer = (String) args[1]; + + return origin.replaceAll(regex, replacer); + } + + /** + * 获取注解的参数 + * + * @param anno 注解信息 + * @return 注解的参数 + */ + abstract Object[] getArgs(T anno); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java new file mode 100644 index 000000000..a21734909 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.desensitize.core.regex.handler; + +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; + +/** + * 正则脱敏处理器 + */ +public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { + + @Override + Object[] getArgs(RegexDesensitize anno) { + return new Object[]{anno.regex(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java new file mode 100644 index 000000000..9336351da --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.framework.desensitize.core.regex.handler; + +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; + +public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { + + @Override + Object[] getArgs(EmailDesensitize anno) { + return new Object[]{anno.regex(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java new file mode 100644 index 000000000..4402ab7d6 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.BankCardDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 银行卡号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = BankCardDesensitization.class)// 银行卡号;比如:9988002866797031脱敏之后为998800********31 +public @interface BankCard { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 6; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 2; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java new file mode 100644 index 000000000..898c9d4a7 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.CarLicenseDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 车牌号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = CarLicenseDesensitization.class) // 车牌号;比如:粤A66666脱敏之后为粤A6***6 +public @interface CarLicense { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 3; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 1; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java new file mode 100644 index 000000000..5b7e7e638 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.ChineseNameDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 中文名 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = ChineseNameDesensitization.class) // 中文名;比如:刘子豪脱敏之后为刘** +public @interface ChineseName { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 1; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 0; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java new file mode 100644 index 000000000..7833377c4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.FixedPhoneDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 固定电话 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = FixedPhoneDesensitization.class) // 固定电话;比如:01086551122脱敏之后为0108*****22 +public @interface FixedPhone { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 4; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 2; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java new file mode 100644 index 000000000..1f8c7a489 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.IdCardDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 身份证 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = IdCardDesensitization.class) // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 +public @interface IdCard { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 6; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 2; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java new file mode 100644 index 000000000..148189ffe --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PasswordDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 密码 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = PasswordDesensitization.class) // 密码;比如:123456脱敏之后为****** +public @interface Password { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 0; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 0; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java new file mode 100644 index 000000000..2ad620c0e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PhoneNumberDesensitization; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 手机号 + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@Desensitize(desensitizationBy = PhoneNumberDesensitization.class) // 手机号;比如:13248765917脱敏之后为132****5917 +public @interface PhoneNumber { + + /** + * 前缀保留长度 + */ + int prefixKeep() default 3; + + /** + * 后缀保留长度 + */ + int suffixKeep() default 4; + + /** + * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; + * 原始字符串 123456 + * 脱敏后 1***56 + */ + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java similarity index 70% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java index ebafaa9bc..c752df310 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/SliderDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java @@ -1,6 +1,7 @@ -package cn.iocoder.yudao.framework.desensitize.annotation; +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.handler.SliderDesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import java.lang.annotation.Documented; @@ -16,8 +17,8 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationHandler = SliderDesensitizationHandler.class) -public @interface SliderDesensitize { +@Desensitize(desensitizationBy = DefaultDesensitizationHandler.class) +public @interface Slider { /** * 后缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java similarity index 60% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java index 47887da39..92b8c0d6c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/SliderDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java @@ -1,17 +1,17 @@ -package cn.iocoder.yudao.framework.desensitize.handler; +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -/** - * 滑动脱敏处理器 - */ -public class SliderDesensitizationHandler implements DesensitizationHandler { +import java.lang.annotation.Annotation; + +public abstract class AbstractDesensitizationHandler implements DesensitizationHandler { @Override - public String desensitize(String origin, Object... arg) { - int prefixKeep = (Integer) arg[0]; - int suffixKeep = (Integer) arg[1]; - String replacer = (String) arg[2]; + public String desensitize(String origin, T anno) { + Object[] args = getArgs(anno); + int prefixKeep = (Integer) args[0]; + int suffixKeep = (Integer) args[1]; + String replacer = (String) args[2]; int length = origin.length(); @@ -31,10 +31,13 @@ public class SliderDesensitizationHandler implements DesensitizationHandler { + + @Override + Object[] getArgs(BankCard anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java new file mode 100644 index 000000000..d7cef7d2f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; + +public class CarLicenseDesensitization extends AbstractDesensitizationHandler { + @Override + Object[] getArgs(CarLicense anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java new file mode 100644 index 000000000..ba0a6607b --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; + +public class ChineseNameDesensitization extends AbstractDesensitizationHandler { + @Override + Object[] getArgs(ChineseName anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java new file mode 100644 index 000000000..3be33a0b8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; + +/** + * 滑动脱敏处理器 + */ +public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { + + @Override + Object[] getArgs(Slider anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java new file mode 100644 index 000000000..8fb71289f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; + +public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { + @Override + Object[] getArgs(FixedPhone anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java new file mode 100644 index 000000000..ce76b357e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; + +public class IdCardDesensitization extends AbstractDesensitizationHandler { + @Override + Object[] getArgs(IdCard anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java new file mode 100644 index 000000000..35a656c3d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; + +public class PasswordDesensitization extends AbstractDesensitizationHandler { + @Override + Object[] getArgs(Password anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java new file mode 100644 index 000000000..0525cb874 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; + +public class PhoneNumberDesensitization extends AbstractDesensitizationHandler { + + @Override + Object[] getArgs(PhoneNumber anno) { + return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java deleted file mode 100644 index 74870e771..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.handler; - -import java.lang.annotation.Annotation; - -/** - * 脱敏处理器接口 - */ -public interface DesensitizationHandler { - - /** - * 脱敏 - * - * @param origin 原始字符串 - * @param arg 参数 - * @return 脱敏后的字符串 - */ - String desensitize(String origin, Object... arg); - - /** - * 获取注解参数 - * - * @param anno 注解 - * @return 注解参数 - */ - default Object[] getAnnotationArgs(T anno) { - return new Object[0]; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java deleted file mode 100644 index 57fc71178..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/RegexDesensitizationHandler.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.handler; - -import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; - -/** - * 正则脱敏处理器 - */ -public class RegexDesensitizationHandler implements DesensitizationHandler { - - @Override - public String desensitize(String origin, Object... arg) { - String regex = (String) arg[0]; - String replacer = (String) arg[1]; - - return origin.replaceAll(regex, replacer); - } - - @Override - public Object[] getAnnotationArgs(RegexDesensitize anno) { - return new Object[]{anno.regex(), anno.replacer()}; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java index 956be23f3..0fbdb04f1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java @@ -4,11 +4,9 @@ import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.desensitize.annotation.Desensitize; -import cn.iocoder.yudao.framework.desensitize.annotation.RegexDesensitize; -import cn.iocoder.yudao.framework.desensitize.annotation.SliderDesensitize; -import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandlerHolder; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerHolder; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; import com.fasterxml.jackson.databind.JsonMappingException; @@ -46,7 +44,7 @@ public class StringDesensitizeSerializer extends StdSerializer implement return this; } StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); - serializer.setDesensitizationHandler(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationHandler())); + serializer.setDesensitizationHandler(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationBy())); return serializer; } @@ -62,22 +60,6 @@ public class StringDesensitizeSerializer extends StdSerializer implement Class currentValueClass = currentValue.getClass(); Field field = ReflectUtil.getField(currentValueClass, currentName); - // 滑动处理器 - SliderDesensitize sliderDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, SliderDesensitize.class)); - if (sliderDesensitize != null) { - value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(sliderDesensitize)); - gen.writeString(value); - return; - } - - // 正则处理器 - RegexDesensitize regexDesensitize = ArrayUtil.firstNonNull(AnnotationUtil.getCombinationAnnotations(field, RegexDesensitize.class)); - if (regexDesensitize != null) { - value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(regexDesensitize)); - gen.writeString(value); - return; - } - // 自定义处理器 Desensitize[] annotations = AnnotationUtil.getCombinationAnnotations(field, Desensitize.class); if (ArrayUtil.isEmpty(annotations)) { @@ -86,8 +68,9 @@ public class StringDesensitizeSerializer extends StdSerializer implement } for (Annotation annotation : field.getAnnotations()) { + if (AnnotationUtil.hasAnnotation(annotation.annotationType(), Desensitize.class)) { - value = this.desensitizationHandler.desensitize(value, this.desensitizationHandler.getAnnotationArgs(annotation)); + value = this.desensitizationHandler.desensitize(value, annotation); gen.writeString(value); return; } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java deleted file mode 100644 index 63b4eaabf..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandlerTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.handler; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class DesensitizationHandlerTest { - - @Test - public void testSliderDesensitizationHandler() { - DesensitizationHandler handler = DesensitizationHandlerHolder.getDesensitizationHandler(SliderDesensitizationHandler.class); - - Assertions.assertEquals("A****FG", handler.desensitize("ABCDEFG", 1, 2, "*")); - Assertions.assertEquals("芋**码", handler.desensitize("芋道源码", 1, 1, "*")); - Assertions.assertEquals("****", handler.desensitize("芋道源码", 4, 0, "*")); - } - - @Test - public void testRegexDesensitizationHandler() { - DesensitizationHandler handler = DesensitizationHandlerHolder.getDesensitizationHandler(RegexDesensitizationHandler.class); - - Assertions.assertEquals("e****@gmail.com", handler.desensitize("example@gmail.com", "(^.)[^@]*(@.*$)", "$1****$2")); - Assertions.assertEquals("***,铁***", handler.desensitize("他妈的,铁废物", "他妈的|去你大爷|卧槽|草泥马|废物", "***")); - } - -} From e5ab9b71b65c11c7ad300c2b225d98a19348b349 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 21:50:09 +0800 Subject: [PATCH 43/80] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/regex/annotation/EmailDesensitize.java | 9 +++------ .../desensitize/core/slider/annotation/BankCard.java | 7 ++----- .../desensitize/core/slider/annotation/CarLicense.java | 7 ++----- .../desensitize/core/slider/annotation/ChineseName.java | 7 ++----- .../desensitize/core/slider/annotation/FixedPhone.java | 7 ++----- .../desensitize/core/slider/annotation/IdCard.java | 7 ++----- .../desensitize/core/slider/annotation/Password.java | 7 ++----- .../desensitize/core/slider/annotation/PhoneNumber.java | 7 ++----- 8 files changed, 17 insertions(+), 41 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java index 746e5503b..ebd754b1e 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java @@ -17,18 +17,15 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = EmailDesensitizationHandler.class) // 邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com +@Desensitize(desensitizationBy = EmailDesensitizationHandler.class) public @interface EmailDesensitize { /** - * 匹配的正则表达式(默认匹配所有) + * 匹配的正则表达式 */ String regex() default "(^.)[^@]*(@.*$)"; /** - * 替换规则,会将匹配到的字符串全部替换成 replacer - * 例如:regex=123; replacer=****** - * 原始字符串 123456789 - * 脱敏后字符串 ******456789 + * 替换规则,邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com */ String replacer() default "$1****$2"; } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java index 4402ab7d6..4c41569e8 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = BankCardDesensitization.class)// 银行卡号;比如:9988002866797031脱敏之后为998800********31 +@Desensitize(desensitizationBy = BankCardDesensitization.class) public @interface BankCard { /** @@ -31,10 +31,7 @@ public @interface BankCard { int suffixKeep() default 2; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,银行卡号;比如:9988002866797031脱敏之后为998800********31 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java index 898c9d4a7..fb89ddb08 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = CarLicenseDesensitization.class) // 车牌号;比如:粤A66666脱敏之后为粤A6***6 +@Desensitize(desensitizationBy = CarLicenseDesensitization.class) public @interface CarLicense { /** @@ -31,10 +31,7 @@ public @interface CarLicense { int suffixKeep() default 1; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,车牌号;比如:粤A66666脱敏之后为粤A6***6 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java index 5b7e7e638..3b4a1a530 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = ChineseNameDesensitization.class) // 中文名;比如:刘子豪脱敏之后为刘** +@Desensitize(desensitizationBy = ChineseNameDesensitization.class) public @interface ChineseName { /** @@ -31,10 +31,7 @@ public @interface ChineseName { int suffixKeep() default 0; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,中文名;比如:刘子豪脱敏之后为刘** */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java index 7833377c4..663388d89 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = FixedPhoneDesensitization.class) // 固定电话;比如:01086551122脱敏之后为0108*****22 +@Desensitize(desensitizationBy = FixedPhoneDesensitization.class) public @interface FixedPhone { /** @@ -31,10 +31,7 @@ public @interface FixedPhone { int suffixKeep() default 2; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,固定电话;比如:01086551122脱敏之后为0108*****22 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java index 1f8c7a489..ac2ba9cd3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = IdCardDesensitization.class) // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 +@Desensitize(desensitizationBy = IdCardDesensitization.class) public @interface IdCard { /** @@ -31,10 +31,7 @@ public @interface IdCard { int suffixKeep() default 2; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,身份证号码;比如:530321199204074611脱敏之后为530321**********11 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java index 148189ffe..c4bb6e1eb 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = PasswordDesensitization.class) // 密码;比如:123456脱敏之后为****** +@Desensitize(desensitizationBy = PasswordDesensitization.class) public @interface Password { /** @@ -31,10 +31,7 @@ public @interface Password { int suffixKeep() default 0; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,密码;比如:123456脱敏之后为****** */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java index 2ad620c0e..c78354d15 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java @@ -17,7 +17,7 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = PhoneNumberDesensitization.class) // 手机号;比如:13248765917脱敏之后为132****5917 +@Desensitize(desensitizationBy = PhoneNumberDesensitization.class) public @interface PhoneNumber { /** @@ -31,10 +31,7 @@ public @interface PhoneNumber { int suffixKeep() default 4; /** - * 替换规则,会将前缀后缀保留后,全部替换成 replacer - * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; - * 原始字符串 123456 - * 脱敏后 1***56 + * 替换规则,手机号;比如:13248765917脱敏之后为132****5917 */ String replacer() default "*"; From 32d7d6ab2975f11e8d31ad4f7407a3023c7061df Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 17 Jan 2023 08:11:57 +0800 Subject: [PATCH 44/80] =?UTF-8?q?code=20review=20=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 5 ++++- .../core/base/DesensitizationHandlerHolder.java | 3 +++ .../core/base/annotation/Desensitize.java | 12 +++++++----- .../core/base/handler/DesensitizationHandler.java | 2 +- .../handler/AbstractRegexDesensitizationHandler.java | 2 ++ .../handler/AbstractDesensitizationHandler.java | 8 +++++--- .../serializer/StringDesensitizeSerializer.java | 7 ++++--- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml index 7f15d0d4c..1afb387b8 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml @@ -9,8 +9,11 @@ ${revision} + yudao-spring-boot-starter-biz-desensitize + + 11 11 @@ -40,4 +43,4 @@ test - \ No newline at end of file + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java index 5787eae56..95c193f6b 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java @@ -8,14 +8,17 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensi import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +// TODO @城:DesensitizationHandlerHolder =》 DesensitizationHandlerFactory? Holder 没有太多工厂的味道哈 /** * 脱敏处理器 Holder */ public class DesensitizationHandlerHolder { + /** * handler 缓存,默认初始化内置的处理器 */ private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<>() {{ + // TODO @城:这 2 个,是不是不用呀?需要的时候初始化 put(DefaultRegexDesensitizationHandler.class, new DefaultRegexDesensitizationHandler()); put(DefaultDesensitizationHandler.class, new DefaultDesensitizationHandler()); }}; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java index 888330ebe..b95ccd68d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java @@ -11,19 +11,21 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - +// TODO @城:每个接口上,author 写下哈。 +// TODO @城:Desensitize = 》DesensitizeBy +// TODO @城:Desensitize 类注释,方便读者阅读理解 /** * Desensitize 顶级脱敏注解 */ @Documented -@Target({ ElementType.ANNOTATION_TYPE}) +@Target(ElementType.ANNOTATION_TYPE) @Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside -@JsonSerialize(using = StringDesensitizeSerializer.class) +@JacksonAnnotationsInside // TODO @城:这个的作用,也可以写下 +@JsonSerialize(using = StringDesensitizeSerializer.class) // TODO @城:这个的作用,也可以写下 public @interface Desensitize { /** * 脱敏处理器 */ - Class desensitizationBy(); + Class desensitizationBy(); // TODO @城:desensitizationBy -> handler } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java index 9c10fb0ac..a4dd24665 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java @@ -11,7 +11,7 @@ public interface DesensitizationHandler { * 脱敏 * * @param origin 原始字符串 - * @param anno 注解信息 + * @param anno 注解信息 // TODO 不要这样的缩写哈,anno -> annotation * @return 脱敏后的字符串 */ String desensitize(String origin, T anno); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java index 17c86055e..a9d495adf 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java @@ -15,6 +15,8 @@ public abstract class AbstractRegexDesensitizationHandler return origin.replaceAll(regex, replacer); } + // TODO @城:是不是抽象两个方法,一个拿 regex;一个拿 replacer + /** * 获取注解的参数 * diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java index 92b8c0d6c..0b25cdbe5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java @@ -12,25 +12,26 @@ public abstract class AbstractDesensitizationHandler imple int prefixKeep = (Integer) args[0]; int suffixKeep = (Integer) args[1]; String replacer = (String) args[2]; - int length = origin.length(); - // 原始字符串长度小于等于保留长度,则原始字符串全部替换 + // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 if (prefixKeep >= length || suffixKeep >= length) { return buildReplacerByLength(replacer, length); } - // 如果原始字符串小于等于前后缀保留字符串长度,则原始字符串全部替换 + // 情况二:如果原始字符串小于等于前后缀保留字符串长度,则原始字符串全部替换 if ((prefixKeep + suffixKeep) >= length) { return buildReplacerByLength(replacer, length); } + // 情况三:TODO 城 int interval = length - prefixKeep - suffixKeep; return origin.substring(0, prefixKeep) + buildReplacerByLength(replacer, interval) + origin.substring(prefixKeep + interval); } + // TODO @城:类似,子类直接获取到参数哈 /** * 获取注解的参数 * @@ -49,4 +50,5 @@ public abstract class AbstractDesensitizationHandler imple private String buildReplacerByLength(String replacer, int length) { return String.valueOf(replacer).repeat(Math.max(0, length)); } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java index 0fbdb04f1..accfa77dd 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java @@ -19,16 +19,19 @@ import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +// TODO @城:挪到 base/serializer 包下 /** * 脱敏序列化器 */ public class StringDesensitizeSerializer extends StdSerializer implements ContextualSerializer { + private DesensitizationHandler desensitizationHandler; protected StringDesensitizeSerializer() { super(String.class); } + // TODO @城:get 和 set 方法是必须的么?如果是的话,可以换成 lombok 注解哈,简洁一点~ public DesensitizationHandler getDesensitizationHandler() { return desensitizationHandler; } @@ -55,6 +58,7 @@ public class StringDesensitizeSerializer extends StdSerializer implement return; } + // TODO @城:抽个 private getField 方法。让这个方法的逻辑主干,更清晰 String currentName = gen.getOutputContext().getCurrentName(); Object currentValue = gen.getCurrentValue(); Class currentValueClass = currentValue.getClass(); @@ -66,16 +70,13 @@ public class StringDesensitizeSerializer extends StdSerializer implement gen.writeString(value); return; } - for (Annotation annotation : field.getAnnotations()) { - if (AnnotationUtil.hasAnnotation(annotation.annotationType(), Desensitize.class)) { value = this.desensitizationHandler.desensitize(value, annotation); gen.writeString(value); return; } } - gen.writeString(value); } From 7b3fca28447d2947136048b5d5052462ffb44d96 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 17 Jan 2023 10:52:37 +0800 Subject: [PATCH 45/80] =?UTF-8?q?feat:=20=E8=84=B1=E6=95=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 2 +- yudao-framework/pom.xml | 2 +- .../AbstractRegexDesensitizationHandler.java | 27 ---------- .../handler/BankCardDesensitization.java | 11 ---- .../handler/CarLicenseDesensitization.java | 10 ---- .../handler/ChineseNameDesensitization.java | 10 ---- .../DefaultDesensitizationHandler.java | 14 ----- .../handler/FixedPhoneDesensitization.java | 10 ---- .../slider/handler/IdCardDesensitization.java | 10 ---- .../handler/PasswordDesensitization.java | 10 ---- .../handler/PhoneNumberDesensitization.java | 11 ---- .../pom.xml | 12 +---- .../base/DesensitizationHandlerFactory.java} | 15 ++---- .../core/base/annotation/DesensitizeBy.java} | 17 +++---- .../base/handler/DesensitizationHandler.java | 6 +-- .../StringDesensitizeSerializer.java | 51 ++++++++++--------- .../regex/annotation/EmailDesensitize.java | 9 ++-- .../regex/annotation/RegexDesensitize.java | 7 ++- .../AbstractRegexDesensitizationHandler.java | 37 ++++++++++++++ .../DefaultRegexDesensitizationHandler.java | 14 +++-- .../handler/EmailDesensitizationHandler.java | 14 ++++- .../core/slider/annotation/BankCard.java | 6 ++- .../core/slider/annotation/CarLicense.java | 6 ++- .../core/slider/annotation/ChineseName.java | 6 ++- .../core/slider/annotation/FixedPhone.java | 6 ++- .../core/slider/annotation/IdCard.java | 6 ++- .../core/slider/annotation/Password.java | 6 ++- .../core/slider/annotation/PhoneNumber.java | 6 ++- .../core/slider/annotation/Slider.java | 6 ++- .../AbstractDesensitizationHandler.java | 49 +++++++++++++----- .../handler/BankCardDesensitization.java | 27 ++++++++++ .../handler/CarLicenseDesensitization.java | 25 +++++++++ .../handler/ChineseNameDesensitization.java | 25 +++++++++ .../DefaultDesensitizationHandler.java | 25 +++++++++ .../handler/FixedPhoneDesensitization.java | 25 +++++++++ .../slider/handler/IdCardDesensitization.java | 25 +++++++++ .../handler/PasswordDesensitization.java | 25 +++++++++ .../handler/PhoneNumberDesensitization.java | 26 ++++++++++ 38 files changed, 390 insertions(+), 209 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/pom.xml (70%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java => yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java} (60%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java => yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java} (50%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java (62%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize => yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base}/serializer/StringDesensitizeSerializer.java (71%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java (85%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java (90%) create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java (54%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java (52%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java (91%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java (90%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java (91%) rename yudao-framework/{yudao-spring-boot-starter-biz-desensitize => yudao-spring-boot-starter-desensitize}/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java (53%) create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index be2f14dd6..f57f7a944 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -143,7 +143,7 @@ cn.iocoder.boot - yudao-spring-boot-starter-biz-desensitize + yudao-spring-boot-starter-desensitize ${revision} diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 0f20b1a78..12244f5ce 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -41,7 +41,7 @@ yudao-spring-boot-starter-flowable yudao-spring-boot-starter-captcha yudao-spring-boot-starter-websocket - yudao-spring-boot-starter-biz-desensitize + yudao-spring-boot-starter-desensitize yudao-framework diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java deleted file mode 100644 index a9d495adf..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.regex.handler; - -import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; - -import java.lang.annotation.Annotation; - -public abstract class AbstractRegexDesensitizationHandler implements DesensitizationHandler { - - @Override - public String desensitize(String origin, T anno) { - Object[] args = getArgs(anno); - String regex = (String) args[0]; - String replacer = (String) args[1]; - - return origin.replaceAll(regex, replacer); - } - - // TODO @城:是不是抽象两个方法,一个拿 regex;一个拿 replacer - - /** - * 获取注解的参数 - * - * @param anno 注解信息 - * @return 注解的参数 - */ - abstract Object[] getArgs(T anno); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java deleted file mode 100644 index 942ca258f..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; - -public class BankCardDesensitization extends AbstractDesensitizationHandler { - - @Override - Object[] getArgs(BankCard anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java deleted file mode 100644 index d7cef7d2f..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; - -public class CarLicenseDesensitization extends AbstractDesensitizationHandler { - @Override - Object[] getArgs(CarLicense anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java deleted file mode 100644 index ba0a6607b..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; - -public class ChineseNameDesensitization extends AbstractDesensitizationHandler { - @Override - Object[] getArgs(ChineseName anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java deleted file mode 100644 index 3be33a0b8..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; - -/** - * 滑动脱敏处理器 - */ -public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { - - @Override - Object[] getArgs(Slider anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java deleted file mode 100644 index 8fb71289f..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; - -public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { - @Override - Object[] getArgs(FixedPhone anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java deleted file mode 100644 index ce76b357e..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; - -public class IdCardDesensitization extends AbstractDesensitizationHandler { - @Override - Object[] getArgs(IdCard anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java deleted file mode 100644 index 35a656c3d..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; - -public class PasswordDesensitization extends AbstractDesensitizationHandler { - @Override - Object[] getArgs(Password anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java b/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java deleted file mode 100644 index 0525cb874..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; - -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; - -public class PhoneNumberDesensitization extends AbstractDesensitizationHandler { - - @Override - Object[] getArgs(PhoneNumber anno) { - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml b/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml similarity index 70% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml rename to yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml index 1afb387b8..53879bd0f 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml @@ -9,16 +9,8 @@ ${revision} - - yudao-spring-boot-starter-biz-desensitize - - - - - 11 - 11 - UTF-8 - + yudao-spring-boot-starter-desensitize + 脱敏组件 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java similarity index 60% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java index 95c193f6b..abd756ef2 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java @@ -2,33 +2,28 @@ package cn.iocoder.yudao.framework.desensitize.core.base; import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -// TODO @城:DesensitizationHandlerHolder =》 DesensitizationHandlerFactory? Holder 没有太多工厂的味道哈 /** * 脱敏处理器 Holder + * + * @author gaibu */ -public class DesensitizationHandlerHolder { +public class DesensitizationHandlerFactory { /** * handler 缓存,默认初始化内置的处理器 */ - private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<>() {{ - // TODO @城:这 2 个,是不是不用呀?需要的时候初始化 - put(DefaultRegexDesensitizationHandler.class, new DefaultRegexDesensitizationHandler()); - put(DefaultDesensitizationHandler.class, new DefaultDesensitizationHandler()); - }}; + private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap, DesensitizationHandler>(); public static DesensitizationHandler getDesensitizationHandler(Class clazz) { DesensitizationHandler handler = HANDLER_MAP.get(clazz); if (handler != null) { return handler; } - synchronized (DesensitizationHandlerHolder.class) { + synchronized (DesensitizationHandlerFactory.class) { handler = HANDLER_MAP.get(clazz); // 双重校验锁 if (handler != null) { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java similarity index 50% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java index b95ccd68d..d06e633a6 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.framework.desensitize.core.base.annotation; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.serializer.StringDesensitizeSerializer; +import cn.iocoder.yudao.framework.desensitize.core.base.serializer.StringDesensitizeSerializer; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -11,21 +11,20 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -// TODO @城:每个接口上,author 写下哈。 -// TODO @城:Desensitize = 》DesensitizeBy -// TODO @城:Desensitize 类注释,方便读者阅读理解 /** - * Desensitize 顶级脱敏注解 + * 顶级脱敏注解,自定义注解需要使用此注解。 + * + * @author gaibu */ @Documented @Target(ElementType.ANNOTATION_TYPE) @Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotationsInside // TODO @城:这个的作用,也可以写下 -@JsonSerialize(using = StringDesensitizeSerializer.class) // TODO @城:这个的作用,也可以写下 -public @interface Desensitize { +@JacksonAnnotationsInside // 此注解是其他所有 jackson 注解的元注解,打上了此注解的注解表明是 jackson 注解的一部分 +@JsonSerialize(using = StringDesensitizeSerializer.class) // 指定序列化器 +public @interface DesensitizeBy { /** * 脱敏处理器 */ - Class desensitizationBy(); // TODO @城:desensitizationBy -> handler + Class handler(); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java similarity index 62% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java index a4dd24665..e59d96cec 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java @@ -10,10 +10,10 @@ public interface DesensitizationHandler { /** * 脱敏 * - * @param origin 原始字符串 - * @param anno 注解信息 // TODO 不要这样的缩写哈,anno -> annotation + * @param origin 原始字符串 + * @param annotation 注解信息 * @return 脱敏后的字符串 */ - String desensitize(String origin, T anno); + String desensitize(String origin, T annotation); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java similarity index 71% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java index accfa77dd..85dee2f53 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.framework.desensitize.serializer; +package cn.iocoder.yudao.framework.desensitize.core.base.serializer; import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerHolder; +import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; import com.fasterxml.jackson.databind.JsonMappingException; @@ -14,40 +14,36 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import lombok.Getter; +import lombok.Setter; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; -// TODO @城:挪到 base/serializer 包下 /** * 脱敏序列化器 + * + * @author gaibu */ public class StringDesensitizeSerializer extends StdSerializer implements ContextualSerializer { + @Getter + @Setter private DesensitizationHandler desensitizationHandler; protected StringDesensitizeSerializer() { super(String.class); } - // TODO @城:get 和 set 方法是必须的么?如果是的话,可以换成 lombok 注解哈,简洁一点~ - public DesensitizationHandler getDesensitizationHandler() { - return desensitizationHandler; - } - - public void setDesensitizationHandler(DesensitizationHandler desensitizationHandler) { - this.desensitizationHandler = desensitizationHandler; - } - @Override public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { - Desensitize annotation = beanProperty.getAnnotation(Desensitize.class); + DesensitizeBy annotation = beanProperty.getAnnotation(DesensitizeBy.class); if (annotation == null) { return this; } StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); - serializer.setDesensitizationHandler(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationBy())); + serializer.setDesensitizationHandler(DesensitizationHandlerFactory.getDesensitizationHandler(annotation.handler())); return serializer; } @@ -57,21 +53,17 @@ public class StringDesensitizeSerializer extends StdSerializer implement gen.writeNull(); return; } - - // TODO @城:抽个 private getField 方法。让这个方法的逻辑主干,更清晰 - String currentName = gen.getOutputContext().getCurrentName(); - Object currentValue = gen.getCurrentValue(); - Class currentValueClass = currentValue.getClass(); - Field field = ReflectUtil.getField(currentValueClass, currentName); + // 获取序列化字段 + Field field = getField(gen); // 自定义处理器 - Desensitize[] annotations = AnnotationUtil.getCombinationAnnotations(field, Desensitize.class); + DesensitizeBy[] annotations = AnnotationUtil.getCombinationAnnotations(field, DesensitizeBy.class); if (ArrayUtil.isEmpty(annotations)) { gen.writeString(value); return; } for (Annotation annotation : field.getAnnotations()) { - if (AnnotationUtil.hasAnnotation(annotation.annotationType(), Desensitize.class)) { + if (AnnotationUtil.hasAnnotation(annotation.annotationType(), DesensitizeBy.class)) { value = this.desensitizationHandler.desensitize(value, annotation); gen.writeString(value); return; @@ -80,4 +72,17 @@ public class StringDesensitizeSerializer extends StdSerializer implement gen.writeString(value); } + /** + * 获取字段 + * + * @param gen JsonGenerator + * @return 字段 + */ + private Field getField(JsonGenerator gen) { + String currentName = gen.getOutputContext().getCurrentName(); + Object currentValue = gen.getCurrentValue(); + Class currentValueClass = currentValue.getClass(); + return ReflectUtil.getField(currentValueClass, currentName); + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java similarity index 85% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java index ebd754b1e..303320b70 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.regex.handler.EmailDesensitizationHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,17 +12,20 @@ import java.lang.annotation.Target; /** * 邮箱 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = EmailDesensitizationHandler.class) +@DesensitizeBy(handler = EmailDesensitizationHandler.class) public @interface EmailDesensitize { + /** * 匹配的正则表达式 */ - String regex() default "(^.)[^@]*(@.*$)"; + String regex() default "(^.)[^@]*(@.*$)"; /** * 替换规则,邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java index 7ee6fadd5..6c457fd0c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,13 +12,16 @@ import java.lang.annotation.Target; /** * 正则脱敏注解 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = DefaultRegexDesensitizationHandler.class) +@DesensitizeBy(handler = DefaultRegexDesensitizationHandler.class) public @interface RegexDesensitize { + /** * 匹配的正则表达式(默认匹配所有) */ diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java new file mode 100644 index 000000000..158c6de3d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.framework.desensitize.core.regex.handler; + +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; + +import java.lang.annotation.Annotation; + +/** + * 正则表达式脱敏处理器抽象类,已实现通用的方法 + * + * @author gaibu + */ +public abstract class AbstractRegexDesensitizationHandler implements DesensitizationHandler { + + @Override + public String desensitize(String origin, T annotation) { + String regex = getRegex(annotation); + String replacer = getReplacer(annotation); + + return origin.replaceAll(regex, replacer); + } + + /** + * 获取注解上的 regex 参数 + * + * @param annotation 注解信息 + * @return 正则表达式 + */ + abstract String getRegex(T annotation); + + /** + * 获取注解上的 replacer 参数 + * + * @param annotation 注解信息 + * @return 待替换的字符串 + */ + abstract String getReplacer(T annotation); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java similarity index 54% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java index a21734909..b3a788aa9 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java @@ -3,12 +3,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; /** - * 正则脱敏处理器 + * 默认正则脱敏处理器 + * + * @author gaibu */ public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { + @Override - Object[] getArgs(RegexDesensitize anno) { - return new Object[]{anno.regex(), anno.replacer()}; + String getRegex(RegexDesensitize annotation) { + return annotation.regex(); + } + + @Override + String getReplacer(RegexDesensitize annotation) { + return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java similarity index 52% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java index 9336351da..5313381c3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java @@ -2,10 +2,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; +/** + * 邮箱脱敏处理器 + * + * @author gaibu + */ public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { @Override - Object[] getArgs(EmailDesensitize anno) { - return new Object[]{anno.regex(), anno.replacer()}; + String getRegex(EmailDesensitize annotation) { + return annotation.regex(); + } + + @Override + String getReplacer(EmailDesensitize annotation) { + return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java index 4c41569e8..762ce3118 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.BankCardDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 银行卡号 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = BankCardDesensitization.class) +@DesensitizeBy(handler = BankCardDesensitization.class) public @interface BankCard { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java index fb89ddb08..d3d09ad42 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.CarLicenseDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 车牌号 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = CarLicenseDesensitization.class) +@DesensitizeBy(handler = CarLicenseDesensitization.class) public @interface CarLicense { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java index 3b4a1a530..92e46e594 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.ChineseNameDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 中文名 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = ChineseNameDesensitization.class) +@DesensitizeBy(handler = ChineseNameDesensitization.class) public @interface ChineseName { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java index 663388d89..867552164 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.FixedPhoneDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 固定电话 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = FixedPhoneDesensitization.class) +@DesensitizeBy(handler = FixedPhoneDesensitization.class) public @interface FixedPhone { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java similarity index 91% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java index ac2ba9cd3..7b976bac6 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.IdCardDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 身份证 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = IdCardDesensitization.class) +@DesensitizeBy(handler = IdCardDesensitization.class) public @interface IdCard { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java index c4bb6e1eb..bbe067ab7 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PasswordDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 密码 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = PasswordDesensitization.class) +@DesensitizeBy(handler = PasswordDesensitization.class) public @interface Password { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java index c78354d15..87d7893fe 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PhoneNumberDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 手机号 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = PhoneNumberDesensitization.class) +@DesensitizeBy(handler = PhoneNumberDesensitization.class) public @interface PhoneNumber { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java similarity index 91% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java index c752df310..4d3cac7a3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; @@ -12,12 +12,14 @@ import java.lang.annotation.Target; /** * 滑动脱敏注解 + * + * @author gaibu */ @Documented @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@Desensitize(desensitizationBy = DefaultDesensitizationHandler.class) +@DesensitizeBy(handler = DefaultDesensitizationHandler.class) public @interface Slider { /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java similarity index 53% rename from yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java index 0b25cdbe5..bd5ca926d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java @@ -4,14 +4,18 @@ import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationH import java.lang.annotation.Annotation; +/** + * 滑动脱敏处理器抽象类,已实现通用的方法 + * + * @author gaibu + */ public abstract class AbstractDesensitizationHandler implements DesensitizationHandler { @Override - public String desensitize(String origin, T anno) { - Object[] args = getArgs(anno); - int prefixKeep = (Integer) args[0]; - int suffixKeep = (Integer) args[1]; - String replacer = (String) args[2]; + public String desensitize(String origin, T annotation) { + int prefixKeep = getPrefixKeep(annotation); + int suffixKeep = getSuffixKeep(annotation); + String replacer = getReplacer(annotation); int length = origin.length(); // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 @@ -19,26 +23,41 @@ public abstract class AbstractDesensitizationHandler imple return buildReplacerByLength(replacer, length); } - // 情况二:如果原始字符串小于等于前后缀保留字符串长度,则原始字符串全部替换 + // 情况二:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 if ((prefixKeep + suffixKeep) >= length) { return buildReplacerByLength(replacer, length); } - // 情况三:TODO 城 + // 情况三:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 int interval = length - prefixKeep - suffixKeep; return origin.substring(0, prefixKeep) + buildReplacerByLength(replacer, interval) + origin.substring(prefixKeep + interval); } - // TODO @城:类似,子类直接获取到参数哈 /** - * 获取注解的参数 + * 前缀保留长度 * - * @param anno 注解信息 - * @return 注解的参数 + * @param annotation 注解信息 + * @return 前缀保留长度 */ - abstract Object[] getArgs(T anno); + abstract Integer getPrefixKeep(T annotation); + + /** + * 后缀保留长度 + * + * @param annotation 注解信息 + * @return 后缀保留长度 + */ + abstract Integer getSuffixKeep(T annotation); + + /** + * 替换符 + * + * @param annotation 注解信息 + * @return 替换符 + */ + abstract String getReplacer(T annotation); /** * 根据长度循环构建替换符 @@ -48,7 +67,11 @@ public abstract class AbstractDesensitizationHandler imple * @return 构建后的替换符 */ private String buildReplacerByLength(String replacer, int length) { - return String.valueOf(replacer).repeat(Math.max(0, length)); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < length; i++) { + builder.append(replacer); + } + return builder.toString(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java new file mode 100644 index 000000000..76e63a6b1 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; + +/** + * 银行卡脱敏处理器 + * + * @author gaibu + */ +public class BankCardDesensitization extends AbstractDesensitizationHandler { + + @Override + Integer getPrefixKeep(BankCard annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(BankCard annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(BankCard annotation) { + return annotation.replacer(); + } + +} \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java new file mode 100644 index 000000000..742851a31 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; + +/** + * 车牌号脱敏处理器 + * + * @author gaibu + */ +public class CarLicenseDesensitization extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(CarLicense annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(CarLicense annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(CarLicense annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java new file mode 100644 index 000000000..f7314867d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; + +/** + * 中文姓名脱敏处理器 + * + * @author gaibu + */ +public class ChineseNameDesensitization extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(ChineseName annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(ChineseName annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(ChineseName annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java new file mode 100644 index 000000000..0c498b071 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; + +/** + * 滑动脱敏处理器 + * + * @author gaibu + */ +public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(Slider annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(Slider annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(Slider annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java new file mode 100644 index 000000000..50672ce35 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; + +/** + * 固定电话脱敏处理器 + * + * @author gaibu + */ +public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(FixedPhone annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(FixedPhone annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(FixedPhone annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java new file mode 100644 index 000000000..657a19129 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; + +/** + * 身份证脱敏处理器 + * + * @author gaibu + */ +public class IdCardDesensitization extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(IdCard annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(IdCard annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(IdCard annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java new file mode 100644 index 000000000..d3561ce5d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; + +/** + * 密码脱敏处理器 + * + * @author gaibu + */ +public class PasswordDesensitization extends AbstractDesensitizationHandler { + @Override + Integer getPrefixKeep(Password annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(Password annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(Password annotation) { + return annotation.replacer(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java new file mode 100644 index 000000000..e6c11bd44 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; + +/** + * 手机号脱敏处理器 + * + * @author gaibu + */ +public class PhoneNumberDesensitization extends AbstractDesensitizationHandler { + + @Override + Integer getPrefixKeep(PhoneNumber annotation) { + return annotation.prefixKeep(); + } + + @Override + Integer getSuffixKeep(PhoneNumber annotation) { + return annotation.suffixKeep(); + } + + @Override + String getReplacer(PhoneNumber annotation) { + return annotation.replacer(); + } +} From 42bc0d1519783e877c3524c5296c31fab61b63a0 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 17 Jan 2023 11:28:33 +0800 Subject: [PATCH 46/80] =?UTF-8?q?feat:=20=E8=84=B1=E6=95=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{EmailDesensitize.java => Email.java} | 2 +- .../{RegexDesensitize.java => Regex.java} | 2 +- .../DefaultRegexDesensitizationHandler.java | 8 +- .../handler/EmailDesensitizationHandler.java | 8 +- .../core/slider/DesensitizeTest.java | 88 +++++++++++++++++++ .../core/slider/annotation/Address.java | 27 ++++++ .../core/slider/handler/AddressHandler.java | 11 +++ 7 files changed, 136 insertions(+), 10 deletions(-) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/{EmailDesensitize.java => Email.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/{RegexDesensitize.java => Regex.java} (96%) create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java index 303320b70..02d7043fe 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = EmailDesensitizationHandler.class) -public @interface EmailDesensitize { +public @interface Email { /** * 匹配的正则表达式 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java index 6c457fd0c..e5d2558fa 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = DefaultRegexDesensitizationHandler.class) -public @interface RegexDesensitize { +public @interface Regex { /** * 匹配的正则表达式(默认匹配所有) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java index b3a788aa9..9fa5d80d7 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java @@ -1,22 +1,22 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; /** * 默认正则脱敏处理器 * * @author gaibu */ -public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { +public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { @Override - String getRegex(RegexDesensitize annotation) { + String getRegex(Regex annotation) { return annotation.regex(); } @Override - String getReplacer(RegexDesensitize annotation) { + String getReplacer(Regex annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java index 5313381c3..b6692d448 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java @@ -1,21 +1,21 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; /** * 邮箱脱敏处理器 * * @author gaibu */ -public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { +public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { @Override - String getRegex(EmailDesensitize annotation) { + String getRegex(Email annotation) { return annotation.regex(); } @Override - String getReplacer(EmailDesensitize annotation) { + String getReplacer(Email annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java new file mode 100644 index 000000000..03db9cb72 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java @@ -0,0 +1,88 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider; + +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Address; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; +import lombok.Data; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DesensitizeTest extends BaseMockitoUnitTest { + + @Test + public void test() { + DesensitizeDemo desensitizeDemo = new DesensitizeDemo(); + desensitizeDemo.setUserName("芋道源码"); + desensitizeDemo.setBankCard("9988002866797031"); + desensitizeDemo.setCarLicense("粤A66666"); + desensitizeDemo.setFixedPhone("01086551122"); + desensitizeDemo.setIdCard("530321199204074611"); + desensitizeDemo.setPassword("123456"); + desensitizeDemo.setPhoneNumber("13248765917"); + desensitizeDemo.setSlider1("ABCDEFG"); + desensitizeDemo.setSlider2("ABCDEFG"); + desensitizeDemo.setSlider3("ABCDEFG"); + desensitizeDemo.setEmail("1@eamil.com"); + desensitizeDemo.setRegex("你好,我是芋道源码"); + desensitizeDemo.setAddress("北京市海淀区上地十街10号"); + desensitizeDemo.setOrigin("芋道源码"); + + DesensitizeDemo d = JsonUtils.parseObject(JsonUtils.toJsonString(desensitizeDemo), DesensitizeDemo.class); + assertEquals("芋***", d.getUserName()); + assertEquals("998800********31", d.getBankCard()); + assertEquals("粤A6***6", d.getCarLicense()); + assertEquals("0108*****22", d.getFixedPhone()); + assertEquals("530321**********11", d.getIdCard()); + assertEquals("******", d.getPassword()); + assertEquals("132****5917", d.getPhoneNumber()); + assertEquals("#######", d.getSlider1()); + assertEquals("ABC*EFG", d.getSlider2()); + assertEquals("*******", d.getSlider3()); + assertEquals("1****@eamil.com", d.getEmail()); + assertEquals("你好,我是*", d.getRegex()); + assertEquals("北京市海淀区上地十街10号*", d.getAddress()); + assertEquals("芋道源码", d.getOrigin()); + } + + @Data + public static class DesensitizeDemo { + @ChineseName + private String userName; + @BankCard + private String bankCard; + @CarLicense + private String carLicense; + @FixedPhone + private String fixedPhone; + @IdCard + private String idCard; + @Password + private String password; + @PhoneNumber + private String phoneNumber; + @Slider(prefixKeep = 6,suffixKeep = 1,replacer = "#") + private String slider1; + @Slider(prefixKeep = 3,suffixKeep = 3) + private String slider2; + @Slider(prefixKeep = 10) + private String slider3; + @Email + private String email; + @Regex(regex = "芋道源码",replacer = "*") + private String regex; + @Address + private String address; + private String origin; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java new file mode 100644 index 000000000..0cd338e1f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; + +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.AddressHandler; +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 地址 + * + * @author gaibu + */ +@Documented +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotationsInside +@DesensitizeBy(handler = AddressHandler.class) +public @interface Address { + + String replacer() default "*"; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java new file mode 100644 index 000000000..ef1a2bbf9 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; + +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Address; + +public class AddressHandler implements DesensitizationHandler
{ + @Override + public String desensitize(String origin, Address annotation) { + return origin + annotation.replacer(); + } +} From 6593ec4214ba27b87e890b759cc1b0a4db2e4236 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 19 Jan 2023 10:25:43 +0800 Subject: [PATCH 47/80] =?UTF-8?q?code=20review=20=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 2 +- .../base/DesensitizationHandlerFactory.java | 4 +++ .../core/base/annotation/DesensitizeBy.java | 4 ++- .../base/handler/DesensitizationHandler.java | 2 ++ .../StringDesensitizeSerializer.java | 15 +++++--- .../desensitize/core/package-info.java | 4 +++ .../core/regex/annotation/Email.java | 7 ++-- .../core/regex/annotation/Regex.java | 1 + .../AbstractRegexDesensitizationHandler.java | 5 +-- .../DefaultRegexDesensitizationHandler.java | 3 +- .../handler/EmailDesensitizationHandler.java | 3 +- .../{PhoneNumber.java => Mobile.java} | 6 ++-- .../core/slider/annotation/Password.java | 4 ++- .../AbstractDesensitizationHandler.java | 33 ++++++++--------- .../handler/BankCardDesensitization.java | 4 +-- .../handler/CarLicenseDesensitization.java | 2 +- .../handler/ChineseNameDesensitization.java | 4 ++- .../DefaultDesensitizationHandler.java | 2 +- .../handler/FixedPhoneDesensitization.java | 2 +- .../slider/handler/IdCardDesensitization.java | 2 +- ...zation.java => MobileDesensitization.java} | 12 +++---- .../handler/PasswordDesensitization.java | 2 +- .../core/{slider => }/DesensitizeTest.java | 36 ++++++++++++------- .../core/{slider => }/annotation/Address.java | 7 ++-- .../{slider => }/handler/AddressHandler.java | 12 +++++-- .../iocoder/yudao/framework/package-info.java | 3 ++ 26 files changed, 116 insertions(+), 65 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/package-info.java rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{PhoneNumber.java => Mobile.java} (88%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/{PhoneNumberDesensitization.java => MobileDesensitization.java} (54%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/{slider => }/DesensitizeTest.java (81%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/{slider => }/annotation/Address.java (70%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/{slider => }/handler/AddressHandler.java (50%) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml b/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml index 53879bd0f..c4a96ebe1 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml @@ -10,7 +10,7 @@ yudao-spring-boot-starter-desensitize - 脱敏组件 + 脱敏组件:支持 JSON 返回数据时,将邮箱、手机等字段进行脱敏 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java index abd756ef2..4c75cd957 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.framework.desensitize.core.base; +import cn.hutool.Hutool; +import cn.hutool.core.lang.Singleton; import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; @@ -18,11 +20,13 @@ public class DesensitizationHandlerFactory { */ private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap, DesensitizationHandler>(); + // TODO @唐:可以考虑,使用 hutool 提供的 Singleton.get() public static DesensitizationHandler getDesensitizationHandler(Class clazz) { DesensitizationHandler handler = HANDLER_MAP.get(clazz); if (handler != null) { return handler; } + // 不存在,则进行创建 synchronized (DesensitizationHandlerFactory.class) { handler = HANDLER_MAP.get(clazz); // 双重校验锁 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java index d06e633a6..0166cb6ef 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java @@ -12,7 +12,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * 顶级脱敏注解,自定义注解需要使用此注解。 + * 顶级脱敏注解,自定义注解需要使用此注解 * * @author gaibu */ @@ -26,5 +26,7 @@ public @interface DesensitizeBy { /** * 脱敏处理器 */ + @SuppressWarnings("rawtypes") Class handler(); + } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java index e59d96cec..470a0becf 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java @@ -4,6 +4,8 @@ import java.lang.annotation.Annotation; /** * 脱敏处理器接口 + * + * @author gaibu */ public interface DesensitizationHandler { diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java index 85dee2f53..3f85f88bd 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java @@ -24,8 +24,11 @@ import java.lang.reflect.Field; /** * 脱敏序列化器 * + * 实现 JSON 返回数据时,使用 {@link DesensitizationHandler} 对声明脱敏注解的字段,进行脱敏处理。 + * * @author gaibu */ +@SuppressWarnings("rawtypes") public class StringDesensitizeSerializer extends StdSerializer implements ContextualSerializer { @Getter @@ -37,17 +40,19 @@ public class StringDesensitizeSerializer extends StdSerializer implement } @Override - public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { + public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) { DesensitizeBy annotation = beanProperty.getAnnotation(DesensitizeBy.class); if (annotation == null) { return this; } + // 创建一个 StringDesensitizeSerializer 对象,使用 DesensitizeBy 对应的处理器 StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); serializer.setDesensitizationHandler(DesensitizationHandlerFactory.getDesensitizationHandler(annotation.handler())); return serializer; } @Override + @SuppressWarnings("unchecked") public void serialize(String value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { if (StrUtil.isBlank(value)) { gen.writeNull(); @@ -75,12 +80,12 @@ public class StringDesensitizeSerializer extends StdSerializer implement /** * 获取字段 * - * @param gen JsonGenerator + * @param generator JsonGenerator * @return 字段 */ - private Field getField(JsonGenerator gen) { - String currentName = gen.getOutputContext().getCurrentName(); - Object currentValue = gen.getCurrentValue(); + private Field getField(JsonGenerator generator) { + String currentName = generator.getOutputContext().getCurrentName(); + Object currentValue = generator.getCurrentValue(); Class currentValueClass = currentValue.getClass(); return ReflectUtil.getField(currentValueClass, currentName); } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/package-info.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/package-info.java new file mode 100644 index 000000000..d56282535 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/package-info.java @@ -0,0 +1,4 @@ +/** + * 脱敏组件:支持 JSON 返回数据时,将邮箱、手机等字段进行脱敏 + */ +package cn.iocoder.yudao.framework.desensitize.core; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java index 02d7043fe..686367c2f 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java @@ -10,8 +10,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +// TODO @唐:名字还是 Email=》EmailDesensitize 合适一点,避免和 Validator 的注解有点冲突 /** - * 邮箱 + * 邮箱脱敏注解 * * @author gaibu */ @@ -28,7 +29,9 @@ public @interface Email { String regex() default "(^.)[^@]*(@.*$)"; /** - * 替换规则,邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com + * 替换规则,邮箱; + * + * 比如:example@gmail.com 脱敏之后 为e****@gmail.com */ String replacer() default "$1****$2"; } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java index e5d2558fa..d0fddea6a 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java @@ -29,6 +29,7 @@ public @interface Regex { /** * 替换规则,会将匹配到的字符串全部替换成 replacer + * * 例如:regex=123; replacer=****** * 原始字符串 123456789 * 脱敏后字符串 ******456789 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java index 158c6de3d..f43431b1d 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java @@ -9,13 +9,13 @@ import java.lang.annotation.Annotation; * * @author gaibu */ -public abstract class AbstractRegexDesensitizationHandler implements DesensitizationHandler { +public abstract class AbstractRegexDesensitizationHandler + implements DesensitizationHandler { @Override public String desensitize(String origin, T annotation) { String regex = getRegex(annotation); String replacer = getReplacer(annotation); - return origin.replaceAll(regex, replacer); } @@ -34,4 +34,5 @@ public abstract class AbstractRegexDesensitizationHandler * @return 待替换的字符串 */ abstract String getReplacer(T annotation); + } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java index 9fa5d80d7..718380570 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java @@ -3,13 +3,12 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; /** - * 默认正则脱敏处理器 + * {@link Regex} 的正则脱敏处理器 * * @author gaibu */ public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { - @Override String getRegex(Regex annotation) { return annotation.regex(); diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java index b6692d448..ff77755e9 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; /** - * 邮箱脱敏处理器 + * {@link Email} 的脱敏处理器 * * @author gaibu */ @@ -18,4 +18,5 @@ public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHan String getReplacer(Email annotation) { return annotation.replacer(); } + } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java similarity index 88% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java index 87d7893fe..ca2f4f041 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; -import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PhoneNumberDesensitization; +import cn.iocoder.yudao.framework.desensitize.core.slider.handler.MobileDesensitization; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import java.lang.annotation.Documented; @@ -19,8 +19,8 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside -@DesensitizeBy(handler = PhoneNumberDesensitization.class) -public @interface PhoneNumber { +@DesensitizeBy(handler = MobileDesensitization.class) +public @interface Mobile { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java index bbe067ab7..f96e13b21 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java @@ -33,7 +33,9 @@ public @interface Password { int suffixKeep() default 0; /** - * 替换规则,密码;比如:123456脱敏之后为****** + * 替换规则,密码; + * + * 比如:123456脱敏之后为****** */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java index bd5ca926d..e41c57319 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java @@ -9,7 +9,8 @@ import java.lang.annotation.Annotation; * * @author gaibu */ -public abstract class AbstractDesensitizationHandler implements DesensitizationHandler { +public abstract class AbstractDesensitizationHandler + implements DesensitizationHandler { @Override public String desensitize(String origin, T annotation) { @@ -35,6 +36,21 @@ public abstract class AbstractDesensitizationHandler imple origin.substring(prefixKeep + interval); } + /** + * 根据长度循环构建替换符 + * + * @param replacer 替换符 + * @param length 长度 + * @return 构建后的替换符 + */ + private String buildReplacerByLength(String replacer, int length) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < length; i++) { + builder.append(replacer); + } + return builder.toString(); + } + /** * 前缀保留长度 * @@ -59,19 +75,4 @@ public abstract class AbstractDesensitizationHandler imple */ abstract String getReplacer(T annotation); - /** - * 根据长度循环构建替换符 - * - * @param replacer 替换符 - * @param length 长度 - * @return 构建后的替换符 - */ - private String buildReplacerByLength(String replacer, int length) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < length; i++) { - builder.append(replacer); - } - return builder.toString(); - } - } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java index 76e63a6b1..ca2e00c89 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; /** - * 银行卡脱敏处理器 + * {@link BankCard} 的脱敏处理器 * * @author gaibu */ @@ -24,4 +24,4 @@ public class BankCardDesensitization extends AbstractDesensitizationHandler { + @Override Integer getPrefixKeep(ChineseName annotation) { return annotation.prefixKeep(); @@ -22,4 +23,5 @@ public class ChineseNameDesensitization extends AbstractDesensitizationHandler { +public class MobileDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(PhoneNumber annotation) { + Integer getPrefixKeep(Mobile annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(PhoneNumber annotation) { + Integer getSuffixKeep(Mobile annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(PhoneNumber annotation) { + String getReplacer(Mobile annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java index d3561ce5d..26a7de496 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; /** - * 密码脱敏处理器 + * {@link Password} 的码脱敏处理器 * * @author gaibu */ diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java similarity index 81% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java index 03db9cb72..18f4faee2 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/DesensitizeTest.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java @@ -1,29 +1,33 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider; +package cn.iocoder.yudao.framework.desensitize.core; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Address; +import cn.iocoder.yudao.framework.desensitize.core.annotation.Address; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Mobile; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import lombok.Data; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; +/** + * {@link DesensitizeTest} 的单元测试 + */ public class DesensitizeTest extends BaseMockitoUnitTest { @Test public void test() { + // 准备参数 DesensitizeDemo desensitizeDemo = new DesensitizeDemo(); - desensitizeDemo.setUserName("芋道源码"); + desensitizeDemo.setNickname("芋道源码"); desensitizeDemo.setBankCard("9988002866797031"); desensitizeDemo.setCarLicense("粤A66666"); desensitizeDemo.setFixedPhone("01086551122"); @@ -33,13 +37,16 @@ public class DesensitizeTest extends BaseMockitoUnitTest { desensitizeDemo.setSlider1("ABCDEFG"); desensitizeDemo.setSlider2("ABCDEFG"); desensitizeDemo.setSlider3("ABCDEFG"); - desensitizeDemo.setEmail("1@eamil.com"); + desensitizeDemo.setEmail("1@email.com"); desensitizeDemo.setRegex("你好,我是芋道源码"); desensitizeDemo.setAddress("北京市海淀区上地十街10号"); desensitizeDemo.setOrigin("芋道源码"); + // 调用 DesensitizeDemo d = JsonUtils.parseObject(JsonUtils.toJsonString(desensitizeDemo), DesensitizeDemo.class); - assertEquals("芋***", d.getUserName()); + // 断言 + assertNotNull(d); + assertEquals("芋***", d.getNickname()); assertEquals("998800********31", d.getBankCard()); assertEquals("粤A6***6", d.getCarLicense()); assertEquals("0108*****22", d.getFixedPhone()); @@ -49,7 +56,7 @@ public class DesensitizeTest extends BaseMockitoUnitTest { assertEquals("#######", d.getSlider1()); assertEquals("ABC*EFG", d.getSlider2()); assertEquals("*******", d.getSlider3()); - assertEquals("1****@eamil.com", d.getEmail()); + assertEquals("1****@email.com", d.getEmail()); assertEquals("你好,我是*", d.getRegex()); assertEquals("北京市海淀区上地十街10号*", d.getAddress()); assertEquals("芋道源码", d.getOrigin()); @@ -57,8 +64,9 @@ public class DesensitizeTest extends BaseMockitoUnitTest { @Data public static class DesensitizeDemo { + @ChineseName - private String userName; + private String nickname; @BankCard private String bankCard; @CarLicense @@ -69,20 +77,22 @@ public class DesensitizeTest extends BaseMockitoUnitTest { private String idCard; @Password private String password; - @PhoneNumber + @Mobile private String phoneNumber; - @Slider(prefixKeep = 6,suffixKeep = 1,replacer = "#") + @Slider(prefixKeep = 6, suffixKeep = 1, replacer = "#") private String slider1; - @Slider(prefixKeep = 3,suffixKeep = 3) + @Slider(prefixKeep = 3, suffixKeep = 3) private String slider2; @Slider(prefixKeep = 10) private String slider3; @Email private String email; - @Regex(regex = "芋道源码",replacer = "*") + @Regex(regex = "芋道源码", replacer = "*") private String regex; @Address private String address; private String origin; + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/annotation/Address.java similarity index 70% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/annotation/Address.java index 0cd338e1f..735d25b34 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Address.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/annotation/Address.java @@ -1,7 +1,8 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; +package cn.iocoder.yudao.framework.desensitize.core.annotation; +import cn.iocoder.yudao.framework.desensitize.core.DesensitizeTest; import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; -import cn.iocoder.yudao.framework.desensitize.core.slider.handler.AddressHandler; +import cn.iocoder.yudao.framework.desensitize.core.handler.AddressHandler; import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import java.lang.annotation.Documented; @@ -13,6 +14,8 @@ import java.lang.annotation.Target; /** * 地址 * + * 用于 {@link DesensitizeTest} 测试使用 + * * @author gaibu */ @Documented diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/handler/AddressHandler.java similarity index 50% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/handler/AddressHandler.java index ef1a2bbf9..7a8455f8d 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AddressHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/handler/AddressHandler.java @@ -1,11 +1,19 @@ -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; +package cn.iocoder.yudao.framework.desensitize.core.handler; +import cn.iocoder.yudao.framework.desensitize.core.DesensitizeTest; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Address; +import cn.iocoder.yudao.framework.desensitize.core.annotation.Address; +/** + * {@link Address} 的脱敏处理器 + * + * 用于 {@link DesensitizeTest} 测试使用 + */ public class AddressHandler implements DesensitizationHandler
{ + @Override public String desensitize(String origin, Address annotation) { return origin + annotation.replacer(); } + } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/package-info.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/package-info.java index 8c69219d0..2dc531692 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/package-info.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/package-info.java @@ -1 +1,4 @@ +/** + * Web 框架,全局异常、API 日志等 + */ package cn.iocoder.yudao.framework; From 2aa208f44139270604724f2c505198829be1e2d8 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 19 Jan 2023 10:35:54 +0800 Subject: [PATCH 48/80] =?UTF-8?q?feat:=20=E8=84=B1=E6=95=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/DesensitizationHandlerFactory.java | 42 ------------------- .../StringDesensitizeSerializer.java | 5 +-- .../{Email.java => EmailDesensitize.java} | 3 +- .../handler/EmailDesensitizationHandler.java | 10 ++--- .../desensitize/core/DesensitizeTest.java | 4 +- 5 files changed, 10 insertions(+), 54 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/{Email.java => EmailDesensitize.java} (87%) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java deleted file mode 100644 index 4c75cd957..000000000 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.framework.desensitize.core.base; - -import cn.hutool.Hutool; -import cn.hutool.core.lang.Singleton; -import cn.hutool.core.util.ReflectUtil; -import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 脱敏处理器 Holder - * - * @author gaibu - */ -public class DesensitizationHandlerFactory { - - /** - * handler 缓存,默认初始化内置的处理器 - */ - private static final Map, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap, DesensitizationHandler>(); - - // TODO @唐:可以考虑,使用 hutool 提供的 Singleton.get() - public static DesensitizationHandler getDesensitizationHandler(Class clazz) { - DesensitizationHandler handler = HANDLER_MAP.get(clazz); - if (handler != null) { - return handler; - } - // 不存在,则进行创建 - synchronized (DesensitizationHandlerFactory.class) { - handler = HANDLER_MAP.get(clazz); - // 双重校验锁 - if (handler != null) { - return handler; - } - handler = ReflectUtil.newInstanceIfPossible(clazz); - HANDLER_MAP.put(clazz, handler); - } - return handler; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java index 3f85f88bd..2c15a747d 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java @@ -1,15 +1,14 @@ package cn.iocoder.yudao.framework.desensitize.core.base.serializer; import cn.hutool.core.annotation.AnnotationUtil; +import cn.hutool.core.lang.Singleton; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; -import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -47,7 +46,7 @@ public class StringDesensitizeSerializer extends StdSerializer implement } // 创建一个 StringDesensitizeSerializer 对象,使用 DesensitizeBy 对应的处理器 StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); - serializer.setDesensitizationHandler(DesensitizationHandlerFactory.getDesensitizationHandler(annotation.handler())); + serializer.setDesensitizationHandler(Singleton.get(annotation.handler())); return serializer; } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java similarity index 87% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java index 686367c2f..2e7ae3498 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Email.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java @@ -10,7 +10,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -// TODO @唐:名字还是 Email=》EmailDesensitize 合适一点,避免和 Validator 的注解有点冲突 /** * 邮箱脱敏注解 * @@ -21,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = EmailDesensitizationHandler.class) -public @interface Email { +public @interface EmailDesensitize { /** * 匹配的正则表达式 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java index ff77755e9..8d1867a64 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java @@ -1,21 +1,21 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; /** - * {@link Email} 的脱敏处理器 + * {@link EmailDesensitize} 的脱敏处理器 * * @author gaibu */ -public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { +public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler { @Override - String getRegex(Email annotation) { + String getRegex(EmailDesensitize annotation) { return annotation.regex(); } @Override - String getReplacer(Email annotation) { + String getReplacer(EmailDesensitize annotation) { return annotation.replacer(); } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java index 18f4faee2..400943833 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.framework.desensitize.core; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Email; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; import cn.iocoder.yudao.framework.desensitize.core.annotation.Address; import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; @@ -85,7 +85,7 @@ public class DesensitizeTest extends BaseMockitoUnitTest { private String slider2; @Slider(prefixKeep = 10) private String slider3; - @Email + @EmailDesensitize private String email; @Regex(regex = "芋道源码", replacer = "*") private String regex; From 729ec31dab4144ec70be764363213e4d50c0d8c2 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 19 Jan 2023 20:16:03 +0800 Subject: [PATCH 49/80] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=84=B1?= =?UTF-8?q?=E6=95=8F=E6=B3=A8=E8=A7=A3=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Regex.java => RegexDesensitize.java} | 2 +- .../DefaultRegexDesensitizationHandler.java | 10 ++--- ...BankCard.java => BankCardDesensitize.java} | 2 +- ...icense.java => CarLicenseDesensitize.java} | 2 +- ...eName.java => ChineseNameDesensitize.java} | 2 +- ...dPhone.java => FixedPhoneDesensitize.java} | 2 +- .../{IdCard.java => IdCardDesensitize.java} | 2 +- .../{Mobile.java => MobileDesensitize.java} | 2 +- ...Password.java => PasswordDesensitize.java} | 2 +- .../{Slider.java => SliderDesensitize.java} | 2 +- .../handler/BankCardDesensitization.java | 12 +++--- .../handler/CarLicenseDesensitization.java | 12 +++--- .../handler/ChineseNameDesensitization.java | 12 +++--- .../DefaultDesensitizationHandler.java | 12 +++--- .../handler/FixedPhoneDesensitization.java | 12 +++--- .../slider/handler/IdCardDesensitization.java | 12 +++--- .../slider/handler/MobileDesensitization.java | 12 +++--- .../handler/PasswordDesensitization.java | 12 +++--- .../desensitize/core/DesensitizeTest.java | 40 +++++++++---------- 19 files changed, 82 insertions(+), 82 deletions(-) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/{Regex.java => RegexDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{BankCard.java => BankCardDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{CarLicense.java => CarLicenseDesensitize.java} (95%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{ChineseName.java => ChineseNameDesensitize.java} (95%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{FixedPhone.java => FixedPhoneDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{IdCard.java => IdCardDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{Mobile.java => MobileDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{Password.java => PasswordDesensitize.java} (96%) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/{Slider.java => SliderDesensitize.java} (96%) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java index d0fddea6a..4ab7c7415 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/Regex.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = DefaultRegexDesensitizationHandler.class) -public @interface Regex { +public @interface RegexDesensitize { /** * 匹配的正则表达式(默认匹配所有) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java index 718380570..f92414e0c 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java @@ -1,21 +1,21 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; /** - * {@link Regex} 的正则脱敏处理器 + * {@link RegexDesensitize} 的正则脱敏处理器 * * @author gaibu */ -public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { +public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler { @Override - String getRegex(Regex annotation) { + String getRegex(RegexDesensitize annotation) { return annotation.regex(); } @Override - String getReplacer(Regex annotation) { + String getReplacer(RegexDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java index 762ce3118..ca04b2b13 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = BankCardDesensitization.class) -public @interface BankCard { +public @interface BankCardDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java similarity index 95% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java index d3d09ad42..82a99db20 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = CarLicenseDesensitization.class) -public @interface CarLicense { +public @interface CarLicenseDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseNameDesensitize.java similarity index 95% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseNameDesensitize.java index 92e46e594..73a0d0ee5 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseNameDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = ChineseNameDesensitization.class) -public @interface ChineseName { +public @interface ChineseNameDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java index 867552164..e847954ca 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = FixedPhoneDesensitization.class) -public @interface FixedPhone { +public @interface FixedPhoneDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java index 7b976bac6..05fb73ab9 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = IdCardDesensitization.class) -public @interface IdCard { +public @interface IdCardDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java index ca2f4f041..90dbcacc7 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Mobile.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = MobileDesensitization.class) -public @interface Mobile { +public @interface MobileDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java index f96e13b21..99ca5d12c 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = PasswordDesensitization.class) -public @interface Password { +public @interface PasswordDesensitize { /** * 前缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java index 4d3cac7a3..e13e9c47c 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java @@ -20,7 +20,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @DesensitizeBy(handler = DefaultDesensitizationHandler.class) -public @interface Slider { +public @interface SliderDesensitize { /** * 后缀保留长度 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java index ca2e00c89..1447f1a38 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java @@ -1,26 +1,26 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCardDesensitize; /** - * {@link BankCard} 的脱敏处理器 + * {@link BankCardDesensitize} 的脱敏处理器 * * @author gaibu */ -public class BankCardDesensitization extends AbstractDesensitizationHandler { +public class BankCardDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(BankCard annotation) { + Integer getPrefixKeep(BankCardDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(BankCard annotation) { + Integer getSuffixKeep(BankCardDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(BankCard annotation) { + String getReplacer(BankCardDesensitize annotation) { return annotation.replacer(); } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java index eafe634b7..3b10ef7ef 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java @@ -1,25 +1,25 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicenseDesensitize; /** - * {@link CarLicense} 的脱敏处理器 + * {@link CarLicenseDesensitize} 的脱敏处理器 * * @author gaibu */ -public class CarLicenseDesensitization extends AbstractDesensitizationHandler { +public class CarLicenseDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(CarLicense annotation) { + Integer getPrefixKeep(CarLicenseDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(CarLicense annotation) { + Integer getSuffixKeep(CarLicenseDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(CarLicense annotation) { + String getReplacer(CarLicenseDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java index 050843033..f75984dfa 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java @@ -1,26 +1,26 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseNameDesensitize; /** - * {@link ChineseName} 的脱敏处理器 + * {@link ChineseNameDesensitize} 的脱敏处理器 * * @author gaibu */ -public class ChineseNameDesensitization extends AbstractDesensitizationHandler { +public class ChineseNameDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(ChineseName annotation) { + Integer getPrefixKeep(ChineseNameDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(ChineseName annotation) { + Integer getSuffixKeep(ChineseNameDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(ChineseName annotation) { + String getReplacer(ChineseNameDesensitize annotation) { return annotation.replacer(); } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java index 187a22f11..1a114624b 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java @@ -1,25 +1,25 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.SliderDesensitize; /** - * {@link Slider} 的脱敏处理器 + * {@link SliderDesensitize} 的脱敏处理器 * * @author gaibu */ -public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { +public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(Slider annotation) { + Integer getPrefixKeep(SliderDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(Slider annotation) { + Integer getSuffixKeep(SliderDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(Slider annotation) { + String getReplacer(SliderDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java index 69b07cadf..c617e46d3 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java @@ -1,25 +1,25 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhoneDesensitize; /** - * {@link FixedPhone} 的脱敏处理器 + * {@link FixedPhoneDesensitize} 的脱敏处理器 * * @author gaibu */ -public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { +public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(FixedPhone annotation) { + Integer getPrefixKeep(FixedPhoneDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(FixedPhone annotation) { + Integer getSuffixKeep(FixedPhoneDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(FixedPhone annotation) { + String getReplacer(FixedPhoneDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java index dccf3e834..35db2ccd9 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java @@ -1,25 +1,25 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCardDesensitize; /** - * {@link IdCard} 的脱敏处理器 + * {@link IdCardDesensitize} 的脱敏处理器 * * @author gaibu */ -public class IdCardDesensitization extends AbstractDesensitizationHandler { +public class IdCardDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(IdCard annotation) { + Integer getPrefixKeep(IdCardDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(IdCard annotation) { + Integer getSuffixKeep(IdCardDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(IdCard annotation) { + String getReplacer(IdCardDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java index e5ddb49c2..6c31606c5 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java @@ -1,26 +1,26 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Mobile; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.MobileDesensitize; /** - * {@link Mobile} 的脱敏处理器 + * {@link MobileDesensitize} 的脱敏处理器 * * @author gaibu */ -public class MobileDesensitization extends AbstractDesensitizationHandler { +public class MobileDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(Mobile annotation) { + Integer getPrefixKeep(MobileDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(Mobile annotation) { + Integer getSuffixKeep(MobileDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(Mobile annotation) { + String getReplacer(MobileDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java index 26a7de496..16013f87b 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java @@ -1,25 +1,25 @@ package cn.iocoder.yudao.framework.desensitize.core.slider.handler; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PasswordDesensitize; /** - * {@link Password} 的码脱敏处理器 + * {@link PasswordDesensitize} 的码脱敏处理器 * * @author gaibu */ -public class PasswordDesensitization extends AbstractDesensitizationHandler { +public class PasswordDesensitization extends AbstractDesensitizationHandler { @Override - Integer getPrefixKeep(Password annotation) { + Integer getPrefixKeep(PasswordDesensitize annotation) { return annotation.prefixKeep(); } @Override - Integer getSuffixKeep(Password annotation) { + Integer getSuffixKeep(PasswordDesensitize annotation) { return annotation.suffixKeep(); } @Override - String getReplacer(Password annotation) { + String getReplacer(PasswordDesensitize annotation) { return annotation.replacer(); } } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java index 400943833..c308a0eb5 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/test/java/cn/iocoder/yudao/framework/desensitize/core/DesensitizeTest.java @@ -2,16 +2,16 @@ package cn.iocoder.yudao.framework.desensitize.core; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; -import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.Regex; +import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; import cn.iocoder.yudao.framework.desensitize.core.annotation.Address; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Mobile; -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCardDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicenseDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseNameDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhoneDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCardDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PasswordDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.MobileDesensitize; +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.SliderDesensitize; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import lombok.Data; import org.junit.jupiter.api.Test; @@ -65,29 +65,29 @@ public class DesensitizeTest extends BaseMockitoUnitTest { @Data public static class DesensitizeDemo { - @ChineseName + @ChineseNameDesensitize private String nickname; - @BankCard + @BankCardDesensitize private String bankCard; - @CarLicense + @CarLicenseDesensitize private String carLicense; - @FixedPhone + @FixedPhoneDesensitize private String fixedPhone; - @IdCard + @IdCardDesensitize private String idCard; - @Password + @PasswordDesensitize private String password; - @Mobile + @MobileDesensitize private String phoneNumber; - @Slider(prefixKeep = 6, suffixKeep = 1, replacer = "#") + @SliderDesensitize(prefixKeep = 6, suffixKeep = 1, replacer = "#") private String slider1; - @Slider(prefixKeep = 3, suffixKeep = 3) + @SliderDesensitize(prefixKeep = 3, suffixKeep = 3) private String slider2; - @Slider(prefixKeep = 10) + @SliderDesensitize(prefixKeep = 10) private String slider3; @EmailDesensitize private String email; - @Regex(regex = "芋道源码", replacer = "*") + @RegexDesensitize(regex = "芋道源码", replacer = "*") private String regex; @Address private String address; From 0763c720d2a5ba4f91cd3cbea6d8d8575eead5a4 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 21 Jan 2023 13:17:08 +0800 Subject: [PATCH 50/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../desensitize/core/regex/annotation/EmailDesensitize.java | 2 +- .../desensitize/core/slider/annotation/BankCardDesensitize.java | 2 +- .../core/slider/annotation/CarLicenseDesensitize.java | 2 +- .../core/slider/annotation/FixedPhoneDesensitize.java | 2 +- .../desensitize/core/slider/annotation/IdCardDesensitize.java | 2 +- .../desensitize/core/slider/annotation/MobileDesensitize.java | 2 +- .../desensitize/core/slider/annotation/PasswordDesensitize.java | 2 +- .../desensitize/core/slider/annotation/SliderDesensitize.java | 1 + ...onHandler.java => AbstractSliderDesensitizationHandler.java} | 2 +- .../core/slider/handler/BankCardDesensitization.java | 2 +- .../core/slider/handler/CarLicenseDesensitization.java | 2 +- .../core/slider/handler/ChineseNameDesensitization.java | 2 +- .../core/slider/handler/DefaultDesensitizationHandler.java | 2 +- .../core/slider/handler/FixedPhoneDesensitization.java | 2 +- .../desensitize/core/slider/handler/IdCardDesensitization.java | 2 +- .../desensitize/core/slider/handler/MobileDesensitization.java | 2 +- .../core/slider/handler/PasswordDesensitization.java | 2 +- 17 files changed, 17 insertions(+), 16 deletions(-) rename yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/{AbstractDesensitizationHandler.java => AbstractSliderDesensitizationHandler.java} (96%) diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java index 2e7ae3498..227f25499 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java @@ -30,7 +30,7 @@ public @interface EmailDesensitize { /** * 替换规则,邮箱; * - * 比如:example@gmail.com 脱敏之后 为e****@gmail.com + * 比如:example@gmail.com 脱敏之后为 e****@gmail.com */ String replacer() default "$1****$2"; } diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java index ca04b2b13..19ad54e25 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java @@ -33,7 +33,7 @@ public @interface BankCardDesensitize { int suffixKeep() default 2; /** - * 替换规则,银行卡号;比如:9988002866797031脱敏之后为998800********31 + * 替换规则,银行卡号; 比如:9988002866797031 脱敏之后为 998800********31 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java index 82a99db20..9000e1ec4 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java @@ -33,7 +33,7 @@ public @interface CarLicenseDesensitize { int suffixKeep() default 1; /** - * 替换规则,车牌号;比如:粤A66666脱敏之后为粤A6***6 + * 替换规则,车牌号;比如:粤A66666 脱敏之后为粤A6***6 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java index e847954ca..862235346 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java @@ -33,7 +33,7 @@ public @interface FixedPhoneDesensitize { int suffixKeep() default 2; /** - * 替换规则,固定电话;比如:01086551122脱敏之后为0108*****22 + * 替换规则,固定电话;比如:01086551122 脱敏之后为 0108*****22 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java index 05fb73ab9..8a654c915 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java @@ -33,7 +33,7 @@ public @interface IdCardDesensitize { int suffixKeep() default 2; /** - * 替换规则,身份证号码;比如:530321199204074611脱敏之后为530321**********11 + * 替换规则,身份证号码;比如:530321199204074611 脱敏之后为 530321**********11 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java index 90dbcacc7..f0c42f192 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java @@ -33,7 +33,7 @@ public @interface MobileDesensitize { int suffixKeep() default 4; /** - * 替换规则,手机号;比如:13248765917脱敏之后为132****5917 + * 替换规则,手机号;比如:13248765917 脱敏之后为 132****5917 */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java index 99ca5d12c..6a3b2694f 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java @@ -35,7 +35,7 @@ public @interface PasswordDesensitize { /** * 替换规则,密码; * - * 比如:123456脱敏之后为****** + * 比如:123456 脱敏之后为 ****** */ String replacer() default "*"; diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java index e13e9c47c..ec79635b9 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java @@ -29,6 +29,7 @@ public @interface SliderDesensitize { /** * 替换规则,会将前缀后缀保留后,全部替换成 replacer + * * 例如:prefixKeep = 1; suffixKeep = 2; replacer = "*"; * 原始字符串 123456 * 脱敏后 1***56 diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractSliderDesensitizationHandler.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java rename to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractSliderDesensitizationHandler.java index e41c57319..7dd2a7fd1 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractSliderDesensitizationHandler.java @@ -9,7 +9,7 @@ import java.lang.annotation.Annotation; * * @author gaibu */ -public abstract class AbstractDesensitizationHandler +public abstract class AbstractSliderDesensitizationHandler implements DesensitizationHandler { @Override diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java index 1447f1a38..e1d90ea6d 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCardDes * * @author gaibu */ -public class BankCardDesensitization extends AbstractDesensitizationHandler { +public class BankCardDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(BankCardDesensitize annotation) { diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java index 3b10ef7ef..34b3e9a69 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicenseD * * @author gaibu */ -public class CarLicenseDesensitization extends AbstractDesensitizationHandler { +public class CarLicenseDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(CarLicenseDesensitize annotation) { return annotation.prefixKeep(); diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java index f75984dfa..f71dac0e0 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName * * @author gaibu */ -public class ChineseNameDesensitization extends AbstractDesensitizationHandler { +public class ChineseNameDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(ChineseNameDesensitize annotation) { diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java index 1a114624b..8b0adaeab 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.SliderDesen * * @author gaibu */ -public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler { +public class DefaultDesensitizationHandler extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(SliderDesensitize annotation) { return annotation.prefixKeep(); diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java index c617e46d3..6e2326171 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhoneD * * @author gaibu */ -public class FixedPhoneDesensitization extends AbstractDesensitizationHandler { +public class FixedPhoneDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(FixedPhoneDesensitize annotation) { return annotation.prefixKeep(); diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java index 35db2ccd9..9d525b34c 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCardDesen * * @author gaibu */ -public class IdCardDesensitization extends AbstractDesensitizationHandler { +public class IdCardDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(IdCardDesensitize annotation) { return annotation.prefixKeep(); diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java index 6c31606c5..582900ad4 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.MobileDesen * * @author gaibu */ -public class MobileDesensitization extends AbstractDesensitizationHandler { +public class MobileDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(MobileDesensitize annotation) { diff --git a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java index 16013f87b..1bccaa2a4 100644 --- a/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java +++ b/yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PasswordDes * * @author gaibu */ -public class PasswordDesensitization extends AbstractDesensitizationHandler { +public class PasswordDesensitization extends AbstractSliderDesensitizationHandler { @Override Integer getPrefixKeep(PasswordDesensitize annotation) { return annotation.prefixKeep(); From c744e115e3c20af79c2f98b0d2080c7210f7cfa0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 10:11:16 +0800 Subject: [PATCH 51/80] =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E8=90=8C?= =?UTF-8?q?=E6=96=B0=E6=9B=B4=E5=AE=B9=E6=98=93=E7=9C=8B=E6=87=82=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 9 +-- .../dal/mysql/file/FileConfigMapper.java | 11 --- .../file/FileConfigRefreshConsumer.java | 2 +- .../infra/service/file/FileConfigService.java | 2 +- .../service/file/FileConfigServiceImpl.java | 48 +---------- .../file/FileConfigServiceImplTest.java | 6 +- .../dal/mysql/merchant/PayChannelMapper.java | 11 +-- .../merchant/PayChannelServiceImpl.java | 39 +-------- .../system/dal/mysql/dept/DeptMapper.java | 5 -- .../dal/mysql/oauth2/OAuth2ClientMapper.java | 6 -- .../dal/mysql/permission/MenuMapper.java | 5 -- .../dal/mysql/permission/RoleMapper.java | 5 -- .../permission/RoleMenuBatchInsertMapper.java | 14 ---- .../dal/mysql/permission/RoleMenuMapper.java | 18 ++--- .../permission/UserRoleBatchInsertMapper.java | 14 ---- .../dal/mysql/permission/UserRoleMapper.java | 23 ++---- .../sensitiveword/SensitiveWordMapper.java | 5 -- .../dal/mysql/sms/SmsChannelMapper.java | 6 -- .../dal/mysql/sms/SmsTemplateMapper.java | 5 -- .../system/dal/mysql/tenant/TenantMapper.java | 11 +-- .../system/service/dept/DeptServiceImpl.java | 47 ++--------- .../oauth2/OAuth2ClientServiceImpl.java | 43 +--------- .../service/permission/MenuServiceImpl.java | 46 ++--------- .../permission/PermissionServiceImpl.java | 79 +++---------------- .../service/permission/RoleServiceImpl.java | 44 +---------- .../SensitiveWordServiceImpl.java | 45 +---------- .../service/sms/SmsChannelServiceImpl.java | 45 +---------- .../service/sms/SmsTemplateServiceImpl.java | 58 +++----------- .../auth/AdminAuthServiceImplTest.java | 5 +- .../system/service/dept/DeptServiceTest.java | 20 ++--- .../oauth2/OAuth2ClientServiceImplTest.java | 3 - .../service/permission/MenuServiceTest.java | 24 ++---- .../permission/PermissionServiceTest.java | 32 +++----- .../service/permission/RoleServiceTest.java | 3 - .../SensitiveWordServiceImplTest.java | 2 - .../service/sms/SmsChannelServiceTest.java | 21 ++--- .../service/sms/SmsTemplateServiceTest.java | 6 +- 37 files changed, 111 insertions(+), 657 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuBatchInsertMapper.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleBatchInsertMapper.java diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index e0b5e4bb5..a831337e8 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -81,22 +81,19 @@ public interface BaseMapperX extends BaseMapper { } /** - * 逐条插入,适合少量数据插入,或者对性能要求不高的场景 - *

- * 如果大量,请使用 {@link com.baomidou.mybatisplus.extension.service.impl.ServiceImpl#saveBatch(Collection)} 方法 - * 使用示例,可见 RoleMenuBatchInsertMapper、UserRoleBatchInsertMapper 类 + * 批量插入,适合大量数据插入 * * @param entities 实体们 */ default void insertBatch(Collection entities) { - entities.forEach(this::insert); + Db.saveBatch(entities); } /** * 批量插入,适合大量数据插入 * * @param entities 实体们 - * @param size 插入数量 Db.saveBatch 默认为1000 + * @param size 插入数量 Db.saveBatch 默认为 1000 */ default void insertBatch(Collection entities, int size) { Db.saveBatch(entities, size); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileConfigMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileConfigMapper.java index e770dcafd..a2bf16be4 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileConfigMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileConfigMapper.java @@ -6,15 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; - -/** - * 文件配置 Mapper - * - * @author 芋道源码 - */ @Mapper public interface FileConfigMapper extends BaseMapperX { @@ -26,7 +18,4 @@ public interface FileConfigMapper extends BaseMapperX { .orderByDesc(FileConfigDO::getId)); } - @Select("SELECT COUNT(*) FROM infra_file_config WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/file/FileConfigRefreshConsumer.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/file/FileConfigRefreshConsumer.java index 671b41943..a3b41197f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/file/FileConfigRefreshConsumer.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/file/FileConfigRefreshConsumer.java @@ -23,7 +23,7 @@ public class FileConfigRefreshConsumer extends AbstractChannelMessageListener configs = fileConfigMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存文件配置,数量为:{}]", configs.size()); + log.info("[initLocalCache][缓存文件配置,数量为:{}]", configs.size()); - // 第二步:构建缓存。创建或更新文件 Client + // 第二步:构建缓存:创建或更新文件 Client configs.forEach(config -> { fileClientFactory.createOrUpdateFileClient(config.getId(), config.getStorage(), config.getConfig()); // 如果是 master,进行设置 @@ -114,9 +77,6 @@ public class FileConfigServiceImpl implements FileConfigService { masterFileClient = fileClientFactory.getFileClient(config.getId()); } }); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(configs, FileConfigDO::getUpdateTime); } @Override diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java index 33d0d1ad7..61c9827f6 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java @@ -30,7 +30,6 @@ import java.util.Map; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; @@ -74,16 +73,13 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { when(fileClientFactory.getFileClient(eq(1L))).thenReturn(masterFileClient); // 调用 - fileConfigService.initFileClients(); + fileConfigService.initLocalCache(); // 断言 fileClientFactory 调用 verify(fileClientFactory).createOrUpdateFileClient(eq(1L), eq(configDO1.getStorage()), eq(configDO1.getConfig())); verify(fileClientFactory).createOrUpdateFileClient(eq(2L), eq(configDO2.getStorage()), eq(configDO2.getConfig())); assertSame(masterFileClient, fileConfigService.getMasterFileClient()); - // 断言 maxUpdateTime 缓存 - assertEquals(max(configDO1.getUpdateTime(), configDO2.getUpdateTime()), - fileConfigService.getMaxUpdateTime()); } @Test diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/merchant/PayChannelMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/merchant/PayChannelMapper.java index 216cf689d..bea47f8ba 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/merchant/PayChannelMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/merchant/PayChannelMapper.java @@ -8,9 +8,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.channel.PayChann import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayChannelDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -21,9 +19,6 @@ public interface PayChannelMapper extends BaseMapperX { return selectOne(PayChannelDO::getAppId, appId, PayChannelDO::getCode, code); } - @Select("SELECT COUNT(*) FROM pay_channel WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - default PageResult selectPage(PayChannelPageReqVO reqVO) { return selectPage(reqVO, new QueryWrapperX() .eqIfPresent("code", reqVO.getCode()) @@ -67,14 +62,14 @@ public interface PayChannelMapper extends BaseMapperX { * 根据条件获取渠道 * * @param merchantId 商户编号 - * @param appid 应用编号 // TODO @aquan:appid =》appId + * @param appI 应用编号 * @param code 渠道编码 * @return 数量 */ - default PayChannelDO selectOne(Long merchantId, Long appid, String code) { + default PayChannelDO selectOne(Long merchantId, Long appI, String code) { return this.selectOne((new QueryWrapper().lambda() .eq(PayChannelDO::getMerchantId, merchantId) - .eq(PayChannelDO::getAppId, appid) + .eq(PayChannelDO::getAppId, appI) .eq(PayChannelDO::getCode, code) )); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java index e2fac7cad..d4869a414 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; @@ -19,7 +18,6 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayChannelDO; import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayChannelMapper; import cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -44,12 +42,6 @@ import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.CHANNEL_NOT_E @Validated public class PayChannelServiceImpl implements PayChannelService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 */ @@ -70,40 +62,15 @@ public class PayChannelServiceImpl implements PayChannelService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { // 注意:忽略自动多租户,因为要全局初始化缓存 TenantUtils.executeIgnore(() -> { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && channelMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List channels = channelMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存支付渠道,数量为:{}]", channels.size()); + log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size()); - // 第二步:构建缓存。创建或更新支付 Client + // 第二步:构建缓存:创建或更新支付 Client channels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(), payChannel.getCode(), payChannel.getConfig())); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(channels, PayChannelDO::getUpdateTime); }); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java index c8e6cf1f8..a7050a182 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java @@ -6,9 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqV import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.List; @Mapper @@ -30,7 +28,4 @@ public interface DeptMapper extends BaseMapperX { return selectCount(DeptDO::getParentId, parentId); } - @Select("SELECT COUNT(*) FROM system_dept WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/oauth2/OAuth2ClientMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/oauth2/OAuth2ClientMapper.java index 902fae7bb..e6012b0f0 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/oauth2/OAuth2ClientMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/oauth2/OAuth2ClientMapper.java @@ -6,9 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; /** @@ -30,7 +27,4 @@ public interface OAuth2ClientMapper extends BaseMapperX { return selectOne(OAuth2ClientDO::getClientId, clientId); } - @Select("SELECT COUNT(*) FROM system_oauth2_client WHERE update_time > #{maxUpdateTime}") - int selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java index 1334a6e15..cdab84b53 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java @@ -6,9 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuLi import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.List; @Mapper @@ -28,7 +26,4 @@ public interface MenuMapper extends BaseMapperX { .eqIfPresent(MenuDO::getStatus, reqVO.getStatus())); } - @Select("SELECT COUNT(*) FROM system_menu WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java index 1882236a3..55e853273 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java @@ -8,10 +8,8 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleEx import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; import org.springframework.lang.Nullable; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -47,7 +45,4 @@ public interface RoleMapper extends BaseMapperX { return selectList(RoleDO::getStatus, statuses); } - @Select("SELECT COUNT(*) FROM system_role WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuBatchInsertMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuBatchInsertMapper.java deleted file mode 100644 index 69ddfaf90..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuBatchInsertMapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.permission; - -import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleMenuDO; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Repository; - -/** - * 实体 {@link RoleMenuDO} 的批量插入 Mapper - * - * @author 芋道源码 - */ -@Repository -public class RoleMenuBatchInsertMapper extends ServiceImpl { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java index a07e87cc9..20f418676 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java @@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.system.dal.mysql.permission; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleMenuDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -20,23 +18,21 @@ public interface RoleMenuMapper extends BaseMapperX { } default List selectListByRoleId(Long roleId) { - return selectList(new QueryWrapper().eq("role_id", roleId)); + return selectList(RoleMenuDO::getRoleId, roleId); } default void deleteListByRoleIdAndMenuIds(Long roleId, Collection menuIds) { - delete(new QueryWrapper().eq("role_id", roleId) - .in("menu_id", menuIds)); + delete(new LambdaQueryWrapper() + .eq(RoleMenuDO::getRoleId, roleId) + .in(RoleMenuDO::getMenuId, menuIds)); } default void deleteListByMenuId(Long menuId) { - delete(new QueryWrapper().eq("menu_id", menuId)); + delete(new LambdaQueryWrapper().eq(RoleMenuDO::getMenuId, menuId)); } default void deleteListByRoleId(Long roleId) { - delete(new QueryWrapper().eq("role_id", roleId)); + delete(new LambdaQueryWrapper().eq(RoleMenuDO::getRoleId, roleId)); } - @Select("SELECT COUNT(*) FROM system_role_menu WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleBatchInsertMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleBatchInsertMapper.java deleted file mode 100644 index 474bdb2c1..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleBatchInsertMapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.permission; - -import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Repository; - -/** - * 实体 {@link UserRoleDO} 的批量插入 Mapper - * - * @author 芋道源码 - */ -@Repository -public class UserRoleBatchInsertMapper extends ServiceImpl { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java index e3700da92..12ff88a0f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java @@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.system.dal.mysql.permission; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -14,32 +12,25 @@ import java.util.List; public interface UserRoleMapper extends BaseMapperX { default List selectListByUserId(Long userId) { - return selectList(new QueryWrapper().eq("user_id", userId)); - } - - default List selectListByRoleId(Long roleId) { - return selectList(new QueryWrapper().eq("role_id", roleId)); + return selectList(UserRoleDO::getUserId, userId); } default void deleteListByUserIdAndRoleIdIds(Long userId, Collection roleIds) { - delete(new QueryWrapper().eq("user_id", userId) - .in("role_id", roleIds)); + delete(new LambdaQueryWrapper() + .eq(UserRoleDO::getUserId, userId) + .in(UserRoleDO::getRoleId, roleIds)); } default void deleteListByUserId(Long userId) { - delete(new QueryWrapper().eq("user_id", userId)); + delete(new LambdaQueryWrapper().eq(UserRoleDO::getUserId, userId)); } default void deleteListByRoleId(Long roleId) { - delete(new QueryWrapper().eq("role_id", roleId)); + delete(new LambdaQueryWrapper().eq(UserRoleDO::getRoleId, roleId)); } - default List selectListByRoleIds(Collection roleIds) { return selectList(UserRoleDO::getRoleId, roleIds); } - @Select("SELECT COUNT(*) FROM system_user_role WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java index 8e2788f09..831188761 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java @@ -7,9 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.Sensitiv import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.List; /** @@ -42,7 +40,4 @@ public interface SensitiveWordMapper extends BaseMapperX { return selectOne(SensitiveWordDO::getName, name); } - @Select("SELECT COUNT(*) FROM system_sensitive_word WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsChannelMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsChannelMapper.java index ec38e896e..4af731fc6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsChannelMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsChannelMapper.java @@ -6,9 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; @Mapper public interface SmsChannelMapper extends BaseMapperX { @@ -21,7 +18,4 @@ public interface SmsChannelMapper extends BaseMapperX { .orderByDesc(SmsChannelDO::getId)); } - @Select("SELECT COUNT(*) FROM system_sms_channel WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java index 08029f51b..ee6f54fef 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java @@ -7,17 +7,12 @@ import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTempla import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.List; @Mapper public interface SmsTemplateMapper extends BaseMapperX { - @Select("SELECT COUNT(*) FROM system_sms_template WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - default SmsTemplateDO selectByCode(String code) { return selectOne(SmsTemplateDO::getCode, code); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java index 6fe0e649a..8731e4628 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java @@ -1,15 +1,13 @@ package cn.iocoder.yudao.module.system.dal.mysql.tenant; -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; 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.tenant.vo.tenant.TenantExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.time.LocalDateTime; import java.util.List; /** @@ -52,7 +50,4 @@ public interface TenantMapper extends BaseMapperX { return selectList(TenantDO::getPackageId, packageId); } - @Select("SELECT COUNT(*) FROM system_tenant WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 049a6415a..6262eaf70 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.system.mq.producer.dept.DeptProducer; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -40,19 +41,13 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Slf4j public class DeptServiceImpl implements DeptService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 部门缓存 * key:部门编号 {@link DeptDO#getId()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - @SuppressWarnings("FieldCanBeLocal") + @Getter private volatile Map deptCache; /** * 父部门缓存 @@ -61,11 +56,8 @@ public class DeptServiceImpl implements DeptService { * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ + @Getter private volatile Multimap parentDeptCache; - /** - * 缓存部门的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile LocalDateTime maxUpdateTime; @Resource private DeptMapper deptMapper; @@ -79,48 +71,21 @@ public class DeptServiceImpl implements DeptService { @Override @PostConstruct public synchronized void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { // 注意:忽略自动多租户,因为要全局初始化缓存 TenantUtils.executeIgnore(() -> { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && deptMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List depts = deptMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存部门,数量为:{}]", depts.size()); + log.info("[initLocalCache][缓存部门,数量为:{}]", depts.size()); - // 第二步:构建缓存。创建或更新支付 Client - // 构建缓存 + // 第二步:构建缓存 ImmutableMap.Builder builder = ImmutableMap.builder(); ImmutableMultimap.Builder parentBuilder = ImmutableMultimap.builder(); depts.forEach(sysRoleDO -> { builder.put(sysRoleDO.getId(), sysRoleDO); parentBuilder.put(sysRoleDO.getParentId(), sysRoleDO); }); - // 设置缓存 deptCache = builder.build(); parentDeptCache = parentBuilder.build(); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(depts, DeptDO::getUpdateTime); }); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java index d9cadd1aa..970387bbb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java @@ -17,20 +17,17 @@ import com.google.common.annotations.VisibleForTesting; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -43,12 +40,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Slf4j public class OAuth2ClientServiceImpl implements OAuth2ClientService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 客户端缓存 * key:客户端编号 {@link OAuth2ClientDO#getClientId()} ()} @@ -58,11 +49,6 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { @Getter // 解决单测 @Setter // 解决单测 private volatile Map clientCache; - /** - * 缓存角色的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - @Getter - private volatile LocalDateTime maxUpdateTime; @Resource private OAuth2ClientMapper oauth2ClientMapper; @@ -76,37 +62,12 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && oauth2ClientMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List clients = oauth2ClientMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存 OAuth2 客户端,数量为:{}]", clients.size()); + log.info("[initLocalCache][缓存 OAuth2 客户端,数量为:{}]", clients.size()); // 第二步:构建缓存。 clientCache = convertMap(clients, OAuth2ClientDO::getClientId); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = getMaxValue(clients, OAuth2ClientDO::getUpdateTime); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java index 1f9fee802..32466d592 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java @@ -18,9 +18,9 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronization; @@ -28,7 +28,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -43,18 +42,13 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Slf4j public class MenuServiceImpl implements MenuService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 菜单缓存 * key:菜单编号 * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ + @Getter private volatile Map menuCache; /** * 权限与菜单缓存 @@ -63,11 +57,8 @@ public class MenuServiceImpl implements MenuService { * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ + @Getter private volatile Multimap permissionMenuCache; - /** - * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile LocalDateTime maxUpdateTime; @Resource private MenuMapper menuMapper; @@ -86,33 +77,11 @@ public class MenuServiceImpl implements MenuService { @Override @PostConstruct public synchronized void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && menuMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List menuList = menuMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存菜单,数量为:{}]", menuList.size()); + log.info("[initLocalCache][缓存菜单,数量为:{}]", menuList.size()); - // 第二步:构建缓存。 + // 第二步:构建缓存 ImmutableMap.Builder menuCacheBuilder = ImmutableMap.builder(); ImmutableMultimap.Builder permMenuCacheBuilder = ImmutableMultimap.builder(); menuList.forEach(menuDO -> { @@ -123,9 +92,6 @@ public class MenuServiceImpl implements MenuService { }); menuCache = menuCacheBuilder.build(); permissionMenuCache = permMenuCacheBuilder.build(); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(menuList, MenuDO::getUpdateTime); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java index bc4d51b8e..c40a8e31c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java @@ -16,9 +16,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleMenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; -import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMenuBatchInsertMapper; import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMenuMapper; -import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleBatchInsertMapper; import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper; import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; import cn.iocoder.yudao.module.system.mq.producer.permission.PermissionProducer; @@ -32,7 +30,6 @@ import com.google.common.collect.Sets; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronization; @@ -40,12 +37,10 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import java.util.function.Supplier; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; import static java.util.Collections.singleton; /** @@ -57,12 +52,6 @@ import static java.util.Collections.singleton; @Slf4j public class PermissionServiceImpl implements PermissionService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 角色编号与菜单编号的缓存映射 * key:角色编号 @@ -83,11 +72,6 @@ public class PermissionServiceImpl implements PermissionService { @Getter @Setter // 单元测试需要 private volatile Multimap menuRoleCache; - /** - * 缓存 RoleMenu 的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - @Getter - private volatile LocalDateTime roleMenuMaxUpdateTime; /** * 用户编号与角色编号的缓存映射 @@ -99,20 +83,11 @@ public class PermissionServiceImpl implements PermissionService { @Getter @Setter // 单元测试需要 private volatile Map> userRoleCache; - /** - * 缓存 UserRole 的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - @Getter - private volatile LocalDateTime userRoleMaxUpdateTime; @Resource private RoleMenuMapper roleMenuMapper; @Resource - private RoleMenuBatchInsertMapper roleMenuBatchInsertMapper; - @Resource private UserRoleMapper userRoleMapper; - @Resource - private UserRoleBatchInsertMapper userRoleBatchInsertMapper; @Resource private RoleService roleService; @@ -129,38 +104,22 @@ public class PermissionServiceImpl implements PermissionService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdateForRoleMenu(null); - initLocalCacheIfUpdateForUserRole(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdateForRoleMenu(this.roleMenuMaxUpdateTime); - initLocalCacheIfUpdateForUserRole(this.userRoleMaxUpdateTime); + initLocalCacheForRoleMenu(); + initLocalCacheForUserRole(); } /** * 刷新 RoleMenu 本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 */ @VisibleForTesting - void initLocalCacheIfUpdateForRoleMenu(LocalDateTime maxUpdateTime) { + void initLocalCacheForRoleMenu() { // 注意:忽略自动多租户,因为要全局初始化缓存 TenantUtils.executeIgnore(() -> { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && roleMenuMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdateForRoleMenu][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List roleMenus = roleMenuMapper.selectList(); - log.info("[initLocalCacheIfUpdateForRoleMenu][缓存角色与菜单,数量为:{}]", roleMenus.size()); + log.info("[initLocalCacheForRoleMenu][缓存角色与菜单,数量为:{}]", roleMenus.size()); - // 第二步:构建缓存。 + // 第二步:构建缓存 ImmutableMultimap.Builder roleMenuCacheBuilder = ImmutableMultimap.builder(); ImmutableMultimap.Builder menuRoleCacheBuilder = ImmutableMultimap.builder(); roleMenus.forEach(roleMenuDO -> { @@ -169,40 +128,24 @@ public class PermissionServiceImpl implements PermissionService { }); roleMenuCache = roleMenuCacheBuilder.build(); menuRoleCache = menuRoleCacheBuilder.build(); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.roleMenuMaxUpdateTime = getMaxValue(roleMenus, RoleMenuDO::getUpdateTime); }); } /** * 刷新 UserRole 本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 */ @VisibleForTesting - void initLocalCacheIfUpdateForUserRole(LocalDateTime maxUpdateTime) { + void initLocalCacheForUserRole() { // 注意:忽略自动多租户,因为要全局初始化缓存 TenantUtils.executeIgnore(() -> { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && userRoleMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdateForUserRole][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:加载数据 List userRoles = userRoleMapper.selectList(); - log.info("[initLocalCacheIfUpdateForUserRole][缓存用户与角色,数量为:{}]", userRoles.size()); + log.info("[initLocalCacheForUserRole][缓存用户与角色,数量为:{}]", userRoles.size()); // 第二步:构建缓存。 ImmutableMultimap.Builder userRoleCacheBuilder = ImmutableMultimap.builder(); userRoles.forEach(userRoleDO -> userRoleCacheBuilder.put(userRoleDO.getUserId(), userRoleDO.getRoleId())); userRoleCache = CollectionUtils.convertMultiMap2(userRoles, UserRoleDO::getUserId, UserRoleDO::getRoleId); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.userRoleMaxUpdateTime = getMaxValue(userRoles, UserRoleDO::getUpdateTime); }); } @@ -264,7 +207,7 @@ public class PermissionServiceImpl implements PermissionService { Collection deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIds); // 执行新增和删除。对于已经授权的菜单,不用做任何处理 if (!CollectionUtil.isEmpty(createMenuIds)) { - roleMenuBatchInsertMapper.saveBatch(CollectionUtils.convertList(createMenuIds, menuId -> { + roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> { RoleMenuDO entity = new RoleMenuDO(); entity.setRoleId(roleId); entity.setMenuId(menuId); @@ -308,7 +251,7 @@ public class PermissionServiceImpl implements PermissionService { Collection deleteMenuIds = CollUtil.subtract(dbRoleIds, roleIds); // 执行新增和删除。对于已经授权的角色,不用做任何处理 if (!CollectionUtil.isEmpty(createRoleIds)) { - userRoleBatchInsertMapper.saveBatch(CollectionUtils.convertList(createRoleIds, roleId -> { + userRoleMapper.insertBatch(CollectionUtils.convertList(createRoleIds, roleId -> { UserRoleDO entity = new UserRoleDO(); entity.setUserId(userId); entity.setRoleId(roleId); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java index f5569f855..3f9ee1351 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java @@ -22,7 +22,6 @@ import com.google.common.annotations.VisibleForTesting; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.lang.Nullable; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronization; @@ -31,7 +30,6 @@ import org.springframework.util.StringUtils; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -47,12 +45,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Slf4j public class RoleServiceImpl implements RoleService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 角色缓存 * key:角色编号 {@link RoleDO#getId()} @@ -61,11 +53,6 @@ public class RoleServiceImpl implements RoleService { */ @Getter private volatile Map roleCache; - /** - * 缓存角色的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - @Getter - private volatile LocalDateTime maxUpdateTime; @Resource private PermissionService permissionService; @@ -82,39 +69,14 @@ public class RoleServiceImpl implements RoleService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { // 注意:忽略自动多租户,因为要全局初始化缓存 TenantUtils.executeIgnore(() -> { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && roleMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List roleList = roleMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存角色,数量为:{}]", roleList.size()); + log.info("[initLocalCache][缓存角色,数量为:{}]", roleList.size()); - // 第二步:构建缓存。 + // 第二步:构建缓存 roleCache = CollectionUtils.convertMap(roleList, RoleDO::getId); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(roleList, RoleDO::getUpdateTime); }); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java index cc7975bfa..53357753f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java @@ -17,13 +17,11 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -40,12 +38,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_ @Validated public class SensitiveWordServiceImpl implements SensitiveWordService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 敏感词标签缓存 * key:敏感词编号 {@link SensitiveWordDO#getId()} @@ -55,12 +47,6 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { @Getter private volatile Set sensitiveWordTagsCache = Collections.emptySet(); - /** - * 缓存敏感词的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - @Getter - private volatile LocalDateTime maxUpdateTime; - @Resource private SensitiveWordMapper sensitiveWordMapper; @@ -84,42 +70,17 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && sensitiveWordMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List sensitiveWords = sensitiveWordMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存敏感词,数量为:{}]", sensitiveWords.size()); + log.info("[initLocalCache][缓存敏感词,数量为:{}]", sensitiveWords.size()); - // 第二步:构建缓存。 + // 第二步:构建缓存 // 写入 sensitiveWordTagsCache 缓存 Set tags = new HashSet<>(); sensitiveWords.forEach(word -> tags.addAll(word.getTags())); sensitiveWordTagsCache = tags; // 写入 defaultSensitiveWordTrie、tagSensitiveWordTries 缓存 initSensitiveWordTrie(sensitiveWords); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = CollectionUtils.getMaxValue(sensitiveWords, SensitiveWordDO::getUpdateTime); } private void initSensitiveWordTrie(List wordDOs) { 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 50eeb4910..592864651 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 @@ -11,17 +11,14 @@ import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; @@ -34,17 +31,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNE @Slf4j public class SmsChannelServiceImpl implements SmsChannelService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - - /** - * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile LocalDateTime maxUpdateTime; - @Resource private SmsClientFactory smsClientFactory; @@ -60,38 +46,13 @@ public class SmsChannelServiceImpl implements SmsChannelService { @Override @PostConstruct public void initLocalCache() { - initLocalCacheIfUpdate(null); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCacheIfUpdate(this.maxUpdateTime); - } - - /** - * 刷新本地缓存 - * - * @param maxUpdateTime 最大更新时间 - * 1. 如果 maxUpdateTime 为 null,则“强制”刷新缓存 - * 2. 如果 maxUpdateTime 不为 null,判断自 maxUpdateTime 是否有数据发生变化,有的情况下才刷新缓存 - */ - private void initLocalCacheIfUpdate(LocalDateTime maxUpdateTime) { - // 第一步:基于 maxUpdateTime 判断缓存是否刷新。 - // 如果没有增量的数据变化,则不进行本地缓存的刷新 - if (maxUpdateTime != null - && smsChannelMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - log.info("[initLocalCacheIfUpdate][数据未发生变化({}),本地缓存不刷新]", maxUpdateTime); - return; - } + // 第一步:查询数据 List channels = smsChannelMapper.selectList(); - log.info("[initLocalCacheIfUpdate][缓存短信渠道,数量为:{}]", channels.size()); + log.info("[initLocalCache][缓存短信渠道,数量为:{}]", channels.size()); - // 第二步:构建缓存。创建或更新短信 Client + // 第二步:构建缓存:创建或更新短信 Client List propertiesList = SmsChannelConvert.INSTANCE.convertList02(channels); propertiesList.forEach(properties -> smsClientFactory.createOrUpdateSmsClient(properties)); - - // 第三步:设置最新的 maxUpdateTime,用于下次的增量判断。 - this.maxUpdateTime = getMaxValue(channels, SmsChannelDO::getUpdateTime); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java index 9f3ad2dde..fd6a03f4f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; @@ -20,15 +19,17 @@ import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; import com.google.common.annotations.VisibleForTesting; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -44,12 +45,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Slf4j public class SmsTemplateServiceImpl implements SmsTemplateService { - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - /** * 正则表达式,匹配 {} 中的变量 */ @@ -73,51 +68,18 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ + @Getter // 为了方便测试,这里提供 getter 方法 private volatile Map smsTemplateCache; - /** - * 缓存短信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile LocalDateTime maxUpdateTime; @Override @PostConstruct public void initLocalCache() { - // 获取短信模板列表,如果有更新 - List smsTemplateList = this.loadSmsTemplateIfUpdate(maxUpdateTime); - if (CollUtil.isEmpty(smsTemplateList)) { - return; - } + // 第一步:查询数据 + List smsTemplateList = smsTemplateMapper.selectList(); + log.info("[initLocalCache][缓存短信模版,数量为:{}]", smsTemplateList.size()); - // 写入缓存 + // 第二步:构建缓存 smsTemplateCache = CollectionUtils.convertMap(smsTemplateList, SmsTemplateDO::getCode); - maxUpdateTime = CollectionUtils.getMaxValue(smsTemplateList, SmsTemplateDO::getUpdateTime); - log.info("[initLocalCache][初始化 SmsTemplate 数量为 {}]", smsTemplateList.size()); - } - - /** - * 如果短信模板发生变化,从数据库中获取最新的全量短信模板。 - * 如果未发生变化,则返回空 - * - * @param maxUpdateTime 当前短信模板的最大更新时间 - * @return 短信模板列表 - */ - private List loadSmsTemplateIfUpdate(LocalDateTime maxUpdateTime) { - // 第一步,判断是否要更新。 - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadSmsTemplateIfUpdate][首次加载全量短信模板]"); - } else { // 判断数据库中是否有更新的短信模板 - if (smsTemplateMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - return null; - } - log.info("[loadSmsTemplateIfUpdate][增量加载全量短信模板]"); - } - // 第二步,如果有更新,则从数据库加载所有短信模板 - return smsTemplateMapper.selectList(); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCache(); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java index 218778ac9..dc607b7ce 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java @@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.util.AssertUtils; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO; -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; @@ -16,7 +14,7 @@ import cn.iocoder.yudao.module.system.service.member.MemberService; import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; import cn.iocoder.yudao.module.system.service.social.SocialUserService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import com.anji.captcha.service.CaptchaService; +import com.xingyuv.captcha.service.CaptchaService; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -25,7 +23,6 @@ import javax.annotation.Resource; import javax.validation.Validator; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java index e17187ad6..6b4ff1028 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; @@ -9,9 +12,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; import cn.iocoder.yudao.module.system.enums.dept.DeptIdEnum; import cn.iocoder.yudao.module.system.mq.producer.dept.DeptProducer; -import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import com.google.common.collect.Multimap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,17 +19,15 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import static cn.hutool.core.bean.BeanUtil.getFieldValue; import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -56,8 +54,7 @@ public class DeptServiceTest extends BaseDbUnitTest { } @Test - @SuppressWarnings("unchecked") - void testInitLocalCache() { + public void testInitLocalCache() { // mock 数据 DeptDO deptDO1 = randomDeptDO(); deptMapper.insert(deptDO1); @@ -67,18 +64,15 @@ public class DeptServiceTest extends BaseDbUnitTest { // 调用 deptService.initLocalCache(); // 断言 deptCache 缓存 - Map deptCache = (Map) getFieldValue(deptService, "deptCache"); + Map deptCache = deptService.getDeptCache(); assertEquals(2, deptCache.size()); assertPojoEquals(deptDO1, deptCache.get(deptDO1.getId())); assertPojoEquals(deptDO2, deptCache.get(deptDO2.getId())); // 断言 parentDeptCache 缓存 - Multimap parentDeptCache = (Multimap) getFieldValue(deptService, "parentDeptCache"); + Multimap parentDeptCache = deptService.getParentDeptCache(); assertEquals(2, parentDeptCache.size()); assertPojoEquals(deptDO1, parentDeptCache.get(deptDO1.getParentId())); assertPojoEquals(deptDO2, parentDeptCache.get(deptDO2.getParentId())); - // 断言 maxUpdateTime 缓存 - LocalDateTime maxUpdateTime = (LocalDateTime) getFieldValue(deptService, "maxUpdateTime"); - assertEquals(ObjectUtils.max(deptDO1.getUpdateTime(), deptDO2.getUpdateTime()), maxUpdateTime); } @Test diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java index c7d4ce578..50401cf97 100755 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.Map; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; @@ -59,8 +58,6 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { assertEquals(2, clientCache.size()); assertPojoEquals(clientDO1, clientCache.get(clientDO1.getClientId())); assertPojoEquals(clientDO2, clientCache.get(clientDO2.getClientId())); - // 断言 maxUpdateTime 缓存 - assertEquals(max(clientDO1.getUpdateTime(), clientDO2.getUpdateTime()), oauth2ClientService.getMaxUpdateTime()); } @Test diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceTest.java index b5d21f031..eae4633b1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceTest.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.spring.SpringAopUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; @@ -20,7 +19,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; @@ -51,32 +49,24 @@ public class MenuServiceTest extends BaseDbUnitTest { private TenantService tenantService; @Test - public void testInitLocalCache_success() throws Exception { - MenuDO menuDO1 = createMenuDO(MenuTypeEnum.MENU, "xxxx", 0L); + public void testInitLocalCache_success() { + MenuDO menuDO1 = randomPojo(MenuDO.class); menuMapper.insert(menuDO1); - MenuDO menuDO2 = createMenuDO(MenuTypeEnum.MENU, "xxxx", 0L); + MenuDO menuDO2 = randomPojo(MenuDO.class); menuMapper.insert(menuDO2); // 调用 menuService.initLocalCache(); - - // 获取代理对象 - MenuServiceImpl target = (MenuServiceImpl) SpringAopUtils.getTarget(menuService); - - Map menuCache = - (Map) BeanUtil.getFieldValue(target, "menuCache"); + // 校验 menuCache 缓存 + Map menuCache = menuService.getMenuCache(); Assert.isTrue(menuCache.size() == 2); assertPojoEquals(menuDO1, menuCache.get(menuDO1.getId())); assertPojoEquals(menuDO2, menuCache.get(menuDO2.getId())); - - Multimap permissionMenuCache = - (Multimap) BeanUtil.getFieldValue(target, "permissionMenuCache"); + // 校验 permissionMenuCache 缓存 + Multimap permissionMenuCache = menuService.getPermissionMenuCache(); Assert.isTrue(permissionMenuCache.size() == 2); assertPojoEquals(menuDO1, permissionMenuCache.get(menuDO1.getPermission())); assertPojoEquals(menuDO2, permissionMenuCache.get(menuDO2.getPermission())); - - LocalDateTime maxUpdateTime = (LocalDateTime) BeanUtil.getFieldValue(target, "maxUpdateTime"); - assertEquals(ObjectUtils.max(menuDO1.getUpdateTime(), menuDO2.getUpdateTime()), maxUpdateTime); } @Test diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java index 6352c4593..afc4c0ced 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java @@ -3,18 +3,15 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleMenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; -import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMenuBatchInsertMapper; import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMenuMapper; -import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleBatchInsertMapper; import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper; import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; import cn.iocoder.yudao.module.system.mq.producer.permission.PermissionProducer; @@ -27,8 +24,10 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; @@ -42,8 +41,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@Import({PermissionServiceImpl.class, - RoleMenuBatchInsertMapper.class, UserRoleBatchInsertMapper.class}) +@Import({PermissionServiceImpl.class}) public class PermissionServiceTest extends BaseDbUnitTest { @Resource @@ -52,11 +50,7 @@ public class PermissionServiceTest extends BaseDbUnitTest { @Resource private RoleMenuMapper roleMenuMapper; @Resource - private RoleMenuBatchInsertMapper roleMenuBatchInsertMapper; - @Resource private UserRoleMapper userRoleMapper; - @Resource - private UserRoleBatchInsertMapper userRoleBatchInsertMapper; @MockBean private RoleService roleService; @@ -71,7 +65,7 @@ public class PermissionServiceTest extends BaseDbUnitTest { private PermissionProducer permissionProducer; @Test - public void testInitLocalCacheIfUpdateForRoleMenu() { + public void testInitLocalCacheForRoleMenu() { // mock 数据 RoleMenuDO roleMenuDO01 = randomPojo(RoleMenuDO.class, o -> o.setRoleId(1L).setMenuId(10L)); roleMenuMapper.insert(roleMenuDO01); @@ -79,7 +73,7 @@ public class PermissionServiceTest extends BaseDbUnitTest { roleMenuMapper.insert(roleMenuDO02); // 调用 - permissionService.initLocalCacheIfUpdateForRoleMenu(null); + permissionService.initLocalCacheForRoleMenu(); // 断言 roleMenuCache 缓存 assertEquals(1, permissionService.getRoleMenuCache().keySet().size()); assertEquals(asList(10L, 20L), permissionService.getRoleMenuCache().get(1L)); @@ -87,13 +81,10 @@ public class PermissionServiceTest extends BaseDbUnitTest { assertEquals(2, permissionService.getMenuRoleCache().size()); assertEquals(singletonList(1L), permissionService.getMenuRoleCache().get(10L)); assertEquals(singletonList(1L), permissionService.getMenuRoleCache().get(20L)); - // 断言 maxUpdateTime 缓存 - LocalDateTime maxUpdateTime = permissionService.getRoleMenuMaxUpdateTime(); - assertEquals(ObjectUtils.max(roleMenuDO01.getUpdateTime(), roleMenuDO02.getUpdateTime()), maxUpdateTime); } @Test - public void testInitLocalCacheIfUpdateForUserRole() { + public void testInitLocalCacheForUserRole() { // mock 数据 UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L)); userRoleMapper.insert(userRoleDO01); @@ -101,13 +92,10 @@ public class PermissionServiceTest extends BaseDbUnitTest { userRoleMapper.insert(roleMenuDO02); // 调用 - permissionService.initLocalCacheIfUpdateForUserRole(null); + permissionService.initLocalCacheForUserRole(); // 断言 roleMenuCache 缓存 assertEquals(1, permissionService.getUserRoleCache().size()); assertEquals(asSet(10L, 20L), permissionService.getUserRoleCache().get(1L)); - // 断言 maxUpdateTime 缓存 - LocalDateTime maxUpdateTime = permissionService.getUserRoleMaxUpdateTime(); - assertEquals(ObjectUtils.max(userRoleDO01.getUpdateTime(), roleMenuDO02.getUpdateTime()), maxUpdateTime); } @Test diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceTest.java index 37d3ba44e..a0d6c79a0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceTest.java @@ -23,7 +23,6 @@ import java.util.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; @@ -59,8 +58,6 @@ public class RoleServiceTest extends BaseDbUnitTest { Map roleCache = roleService.getRoleCache(); assertPojoEquals(roleDO1, roleCache.get(roleDO1.getId())); assertPojoEquals(roleDO2, roleCache.get(roleDO2.getId())); - // 断言 maxUpdateTime 缓存 - assertEquals(max(roleDO1.getUpdateTime(), roleDO2.getUpdateTime()), roleService.getMaxUpdateTime()); } @Test diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java index 447ea744c..273e74b4a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java @@ -60,8 +60,6 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { // 调用 sensitiveWordService.initLocalCache(); - // 断言 maxUpdateTime 缓存 - assertEquals(max(wordDO1.getUpdateTime(), wordDO2.getUpdateTime()), sensitiveWordService.getMaxUpdateTime()); // 断言 sensitiveWordTagsCache 缓存 assertEquals(SetUtils.asSet("论坛", "蔬菜"), sensitiveWordService.getSensitiveWordTags()); // 断言 tagSensitiveWordTries 缓存 diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java index 5dea2808f..4fe433d90 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java @@ -1,18 +1,17 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.hutool.core.bean.BeanUtil; -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.SmsChannelUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; -import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +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.SmsChannelUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; +import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; +import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -22,12 +21,11 @@ import java.time.LocalDateTime; import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -58,9 +56,6 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { // 调用 smsChannelService.initLocalCache(); - // 校验 maxUpdateTime 属性 - LocalDateTime maxUpdateTime = (LocalDateTime) BeanUtil.getFieldValue(smsChannelService, "maxUpdateTime"); - assertEquals(max(smsChannelDO01.getUpdateTime(), smsChannelDO02.getUpdateTime()), maxUpdateTime); // 校验调用 verify(smsClientFactory, times(1)).createOrUpdateSmsClient( argThat(properties -> isPojoEquals(smsChannelDO01, properties))); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java index 81e03f29c..a89d1b2e1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java @@ -61,7 +61,6 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { private SmsProducer smsProducer; @Test - @SuppressWarnings("unchecked") void testInitLocalCache() { // mock 数据 SmsTemplateDO smsTemplate01 = randomSmsTemplateDO(); @@ -72,13 +71,10 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { // 调用 smsTemplateService.initLocalCache(); // 断言 deptCache 缓存 - Map smsTemplateCache = (Map) getFieldValue(smsTemplateService, "smsTemplateCache"); + Map smsTemplateCache = smsTemplateService.getSmsTemplateCache(); assertEquals(2, smsTemplateCache.size()); assertPojoEquals(smsTemplate01, smsTemplateCache.get(smsTemplate01.getCode())); assertPojoEquals(smsTemplate02, smsTemplateCache.get(smsTemplate02.getCode())); - // 断言 maxUpdateTime 缓存 - LocalDateTime maxUpdateTime = (LocalDateTime) getFieldValue(smsTemplateService, "maxUpdateTime"); - assertEquals(max(smsTemplate01.getUpdateTime(), smsTemplate02.getUpdateTime()), maxUpdateTime); } @Test From 179fdc8464b2828650d94abf28322607a00c9576 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 11:17:52 +0800 Subject: [PATCH 52/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=20xss=20=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0=EF=BC=8C=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=20xss=20=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/YudaoWebAutoConfiguration.java | 48 +-------------- .../{web => xss}/config/XssProperties.java | 2 +- .../xss/config/YudaoXssAutoConfiguration.java | 60 +++++++++++++++++++ .../core/clean/JsoupXssCleaner.java | 20 +------ .../{web => xss}/core/clean/XssCleaner.java | 3 +- .../{web => xss}/core/filter/XssFilter.java | 8 +-- .../core/filter/XssRequestWrapper.java | 5 +- .../core/json/XssStringJsonDeserializer.java | 4 +- .../yudao/framework/xss/package-info.java | 6 ++ ...ot.autoconfigure.AutoConfiguration.imports | 3 +- 10 files changed, 83 insertions(+), 76 deletions(-) rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/config/XssProperties.java (92%) create mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/YudaoXssAutoConfiguration.java rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/core/clean/JsoupXssCleaner.java (84%) rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/core/clean/XssCleaner.java (83%) rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/core/filter/XssFilter.java (80%) rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/core/filter/XssRequestWrapper.java (95%) rename yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/{web => xss}/core/json/XssStringJsonDeserializer.java (94%) create mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/package-info.java diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java index 95955d5ee..b20565eca 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java @@ -2,27 +2,18 @@ package cn.iocoder.yudao.framework.web.config; import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; -import cn.iocoder.yudao.framework.web.core.clean.JsoupXssCleaner; -import cn.iocoder.yudao.framework.web.core.clean.XssCleaner; import cn.iocoder.yudao.framework.web.core.filter.CacheRequestBodyFilter; import cn.iocoder.yudao.framework.web.core.filter.DemoFilter; -import cn.iocoder.yudao.framework.web.core.filter.XssFilter; import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; import cn.iocoder.yudao.framework.web.core.handler.GlobalResponseBodyHandler; -import cn.iocoder.yudao.framework.web.core.json.XssStringJsonDeserializer; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; -import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.util.AntPathMatcher; -import org.springframework.util.PathMatcher; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -34,7 +25,7 @@ import javax.annotation.Resource; import javax.servlet.Filter; @AutoConfiguration -@EnableConfigurationProperties({WebProperties.class, XssProperties.class}) +@EnableConfigurationProperties(WebProperties.class) public class YudaoWebAutoConfiguration implements WebMvcConfigurer { @Resource @@ -107,15 +98,6 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { return createFilterBean(new CacheRequestBodyFilter(), WebFilterOrderEnum.REQUEST_BODY_CACHE_FILTER); } - /** - * 创建 XssFilter Bean,解决 Xss 安全问题 - */ - @Bean - @ConditionalOnBean(XssCleaner.class) - public FilterRegistrationBean xssFilter(XssProperties properties, PathMatcher pathMatcher, XssCleaner xssCleaner) { - return createFilterBean(new XssFilter(properties, pathMatcher, xssCleaner), WebFilterOrderEnum.XSS_FILTER); - } - /** * 创建 DemoFilter Bean,演示模式 */ @@ -125,33 +107,7 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { return createFilterBean(new DemoFilter(), WebFilterOrderEnum.DEMO_FILTER); } - - /** - * Xss 清理者 - * - * @return XssCleaner - */ - @Bean - @ConditionalOnMissingBean(XssCleaner.class) - public XssCleaner xssCleaner() { - return new JsoupXssCleaner(); - } - - /** - * 注册 Jackson 的序列化器,用于处理 json 类型参数的 xss 过滤 - * - * @return Jackson2ObjectMapperBuilderCustomizer - */ - @Bean - @ConditionalOnMissingBean(name = "xssJacksonCustomizer") - @ConditionalOnBean(ObjectMapper.class) - @ConditionalOnProperty(value = "yudao.xss.enable", havingValue = "true") - public Jackson2ObjectMapperBuilderCustomizer xssJacksonCustomizer(XssCleaner xssCleaner) { - // 在反序列化时进行 xss 过滤,可以替换使用 XssStringJsonSerializer,在序列化时进行处理 - return builder -> builder.deserializerByType(String.class, new XssStringJsonDeserializer(xssCleaner)); - } - - private static FilterRegistrationBean createFilterBean(T filter, Integer order) { + public static FilterRegistrationBean createFilterBean(T filter, Integer order) { FilterRegistrationBean bean = new FilterRegistrationBean<>(filter); bean.setOrder(order); return bean; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/XssProperties.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/XssProperties.java similarity index 92% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/XssProperties.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/XssProperties.java index e4d123089..c914b0465 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/XssProperties.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/XssProperties.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.web.config; +package cn.iocoder.yudao.framework.xss.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/YudaoXssAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/YudaoXssAutoConfiguration.java new file mode 100644 index 000000000..d5d892c07 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/config/YudaoXssAutoConfiguration.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.framework.xss.config; + +import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; +import cn.iocoder.yudao.framework.xss.core.clean.JsoupXssCleaner; +import cn.iocoder.yudao.framework.xss.core.clean.XssCleaner; +import cn.iocoder.yudao.framework.xss.core.filter.XssFilter; +import cn.iocoder.yudao.framework.xss.core.json.XssStringJsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.util.PathMatcher; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import static cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration.createFilterBean; + +@AutoConfiguration +@EnableConfigurationProperties(XssProperties.class) +public class YudaoXssAutoConfiguration implements WebMvcConfigurer { + + /** + * Xss 清理者 + * + * @return XssCleaner + */ + @Bean + @ConditionalOnMissingBean(XssCleaner.class) + public XssCleaner xssCleaner() { + return new JsoupXssCleaner(); + } + + /** + * 注册 Jackson 的序列化器,用于处理 json 类型参数的 xss 过滤 + * + * @return Jackson2ObjectMapperBuilderCustomizer + */ + @Bean + @ConditionalOnMissingBean(name = "xssJacksonCustomizer") + @ConditionalOnBean(ObjectMapper.class) + @ConditionalOnProperty(value = "yudao.xss.enable", havingValue = "true") + public Jackson2ObjectMapperBuilderCustomizer xssJacksonCustomizer(XssCleaner xssCleaner) { + // 在反序列化时进行 xss 过滤,可以替换使用 XssStringJsonSerializer,在序列化时进行处理 + return builder -> builder.deserializerByType(String.class, new XssStringJsonDeserializer(xssCleaner)); + } + + /** + * 创建 XssFilter Bean,解决 Xss 安全问题 + */ + @Bean + @ConditionalOnBean(XssCleaner.class) + public FilterRegistrationBean xssFilter(XssProperties properties, PathMatcher pathMatcher, XssCleaner xssCleaner) { + return createFilterBean(new XssFilter(properties, pathMatcher, xssCleaner), WebFilterOrderEnum.XSS_FILTER); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/JsoupXssCleaner.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/JsoupXssCleaner.java similarity index 84% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/JsoupXssCleaner.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/JsoupXssCleaner.java index 559267c3f..4cbc907b9 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/JsoupXssCleaner.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/JsoupXssCleaner.java @@ -1,11 +1,11 @@ -package cn.iocoder.yudao.framework.web.core.clean; +package cn.iocoder.yudao.framework.xss.core.clean; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.safety.Safelist; /** - * jsonp 过滤字符串 + * 基于 JSONP 实现 XSS 过滤字符串 */ public class JsoupXssCleaner implements XssCleaner { @@ -24,21 +24,6 @@ public class JsoupXssCleaner implements XssCleaner { this.baseUri = ""; } - public JsoupXssCleaner(Safelist safelist) { - this.safelist = safelist; - this.baseUri = ""; - } - - public JsoupXssCleaner(String baseUri) { - this.safelist = buildSafelist(); - this.baseUri = baseUri; - } - - public JsoupXssCleaner(Safelist safelist, String baseUri) { - this.safelist = safelist; - this.baseUri = baseUri; - } - /** * 构建一个 Xss 清理的 Safelist 规则。 * 基于 Safelist#relaxed() 的基础上: @@ -67,7 +52,6 @@ public class JsoupXssCleaner implements XssCleaner { // 虽然可以重写 WhiteList#isSafeAttribute 来处理,但是有隐患,所以暂时不支持相对路径 // WHITELIST.removeProtocols("a", "href", "ftp", "http", "https", "mailto"); // WHITELIST.removeProtocols("img", "src", "http", "https"); - return relaxedSafelist; } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/XssCleaner.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/XssCleaner.java similarity index 83% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/XssCleaner.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/XssCleaner.java index 433f7e775..529bc64a2 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/clean/XssCleaner.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/clean/XssCleaner.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.web.core.clean; +package cn.iocoder.yudao.framework.xss.core.clean; /** * 对 html 文本中的有 Xss 风险的数据进行清理 @@ -12,4 +12,5 @@ public interface XssCleaner { * @return 清理后的 html */ String clean(String html); + } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssFilter.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssFilter.java similarity index 80% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssFilter.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssFilter.java index 2da18768d..5f2ce6e3d 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssFilter.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssFilter.java @@ -1,7 +1,7 @@ -package cn.iocoder.yudao.framework.web.core.filter; +package cn.iocoder.yudao.framework.xss.core.filter; -import cn.iocoder.yudao.framework.web.config.XssProperties; -import cn.iocoder.yudao.framework.web.core.clean.XssCleaner; +import cn.iocoder.yudao.framework.xss.config.XssProperties; +import cn.iocoder.yudao.framework.xss.core.clean.XssCleaner; import lombok.AllArgsConstructor; import org.springframework.util.PathMatcher; import org.springframework.web.filter.OncePerRequestFilter; @@ -14,8 +14,6 @@ import java.io.IOException; /** * Xss 过滤器 - *

- * 对 Xss 不了解的胖友,可以看看 http://www.iocoder.cn/Fight/The-new-girl-asked-me-why-AJAX-requests-are-not-secure-I-did-not-answer/ * * @author 芋道源码 */ diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssRequestWrapper.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssRequestWrapper.java similarity index 95% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssRequestWrapper.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssRequestWrapper.java index 7beed46cc..35819f443 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/XssRequestWrapper.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/filter/XssRequestWrapper.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.framework.web.core.filter; +package cn.iocoder.yudao.framework.xss.core.filter; -import cn.iocoder.yudao.framework.web.core.clean.XssCleaner; +import cn.iocoder.yudao.framework.xss.core.clean.XssCleaner; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; @@ -13,6 +13,7 @@ import java.util.Map; * @author 芋道源码 */ public class XssRequestWrapper extends HttpServletRequestWrapper { + private final XssCleaner xssCleaner; public XssRequestWrapper(HttpServletRequest request, XssCleaner xssCleaner) { diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/json/XssStringJsonDeserializer.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/json/XssStringJsonDeserializer.java similarity index 94% rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/json/XssStringJsonDeserializer.java rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/json/XssStringJsonDeserializer.java index 7e1f631c7..2b1725d96 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/json/XssStringJsonDeserializer.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/core/json/XssStringJsonDeserializer.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.framework.web.core.json; +package cn.iocoder.yudao.framework.xss.core.json; -import cn.iocoder.yudao.framework.web.core.clean.XssCleaner; +import cn.iocoder.yudao.framework.xss.core.clean.XssCleaner; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/package-info.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/package-info.java new file mode 100644 index 000000000..c6e46f070 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/xss/package-info.java @@ -0,0 +1,6 @@ +/** + * 针对 XSS 的基础封装 + * + * XSS 说明:https://tech.meituan.com/2018/09/27/fe-security.html + */ +package cn.iocoder.yudao.framework.xss; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 2a422bfa2..818e33aa3 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,4 +1,5 @@ cn.iocoder.yudao.framework.apilog.config.YudaoApiLogAutoConfiguration cn.iocoder.yudao.framework.jackson.config.YudaoJacksonAutoConfiguration cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration -cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration +cn.iocoder.yudao.framework.xss.config.YudaoXssAutoConfiguration From 9b47dd4a678e0afa46c8b7dd630dfa78483c1784 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 12:25:34 +0800 Subject: [PATCH 53/80] =?UTF-8?q?b4bdd4f=EF=BC=9A=E5=BC=80=E5=90=AFTopNav?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=AD=90=E8=8F=9C=E5=8D=95=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/components/TopNav/index.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yudao-ui-admin/src/components/TopNav/index.vue b/yudao-ui-admin/src/components/TopNav/index.vue index 98c4afe84..02ca003d2 100644 --- a/yudao-ui-admin/src/components/TopNav/index.vue +++ b/yudao-ui-admin/src/components/TopNav/index.vue @@ -133,7 +133,9 @@ export default { } else { // 显示左侧联动菜单 this.activeRoutes(key); - this.$store.dispatch('app/toggleSideBarHide', false); + if (!this.$route.meta.link) { + this.$store.dispatch('app/toggleSideBarHide', false); + } } }, // 当前激活的路由 @@ -149,7 +151,7 @@ export default { if(routes.length > 0) { this.$store.commit("SET_SIDEBAR_ROUTERS", routes); } else { - this.$store.dispatch("app/toggleSideBarHide", true); + this.$store.dispatch('app/toggleSideBarHide', true); } }, ishttp(url) { From e9814b129bf46c79e727a10c1bd6b45449a2824a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 12:32:54 +0800 Subject: [PATCH 54/80] =?UTF-8?q?492919d=EF=BC=9A=E5=8D=87=E7=BA=A7element?= =?UTF-8?q?-ui=E5=88=B0=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC2.15.12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/package.json | 2 +- yudao-ui-admin/src/views/system/user/index.vue | 6 +++--- yudao-ui-admin/yarn.lock | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yudao-ui-admin/package.json b/yudao-ui-admin/package.json index c16997fc0..738ac509f 100644 --- a/yudao-ui-admin/package.json +++ b/yudao-ui-admin/package.json @@ -49,7 +49,7 @@ "core-js": "^3.26.0", "crypto-js": "^4.0.0", "echarts": "5.4.0", - "element-ui": "2.15.10", + "element-ui": "2.15.12", "file-saver": "2.0.5", "fuse.js": "6.6.2", "highlight.js": "9.18.5", diff --git a/yudao-ui-admin/src/views/system/user/index.vue b/yudao-ui-admin/src/views/system/user/index.vue index 064f0bcf1..5c3bb1655 100644 --- a/yudao-ui-admin/src/views/system/user/index.vue +++ b/yudao-ui-admin/src/views/system/user/index.vue @@ -364,9 +364,9 @@ export default { created() { this.getList(); this.getTreeselect(); - this.getConfigKey("sys.user.init-password").then(response => { - this.initPassword = response.msg; - }); + // this.getConfigKey("sys.user.init-password").then(response => { + // this.initPassword = response.msg; + // }); }, methods: { // 更多操作 diff --git a/yudao-ui-admin/yarn.lock b/yudao-ui-admin/yarn.lock index 73a3fce0f..0293cba48 100644 --- a/yudao-ui-admin/yarn.lock +++ b/yudao-ui-admin/yarn.lock @@ -3999,10 +3999,10 @@ electron-to-chromium@^1.4.251: resolved "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz" integrity sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA== -element-ui@2.15.10: - version "2.15.10" - resolved "https://registry.npmmirror.com/element-ui/-/element-ui-2.15.10.tgz" - integrity sha512-jmD++mU2wKXbisvx4fxOl2mHaU+HWHTAq/3Wf8x9Bwyu4GdDZPLABb+CGi3DWN6fPqdgRcd74aX39DO+YHObLw== +element-ui@2.15.12: + version "2.15.12" + resolved "https://registry.npmmirror.com/element-ui/-/element-ui-2.15.12.tgz#fdde927a54078b17a85541ff7c0f0dad32488b8e" + integrity sha512-Y5FMT2BPOindU2GkDEQ5ZKUVxDawKONRNMh2eL3uBx1FOtvUJ+L6IxXLVsNxq4WnaX/UnVNgWXebl7DobygZMg== dependencies: async-validator "~1.8.1" babel-helper-vue-jsx-merge-props "^2.0.0" From 0262fa5c153628e63c6c266026c7bb7a06d49f1a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 17:48:09 +0800 Subject: [PATCH 55/80] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20account=20=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/api/mail/MailSendApi.java | 30 +++ .../system/api/mail/dto/MailSendReqDTO.java | 38 --- .../mail/dto/MailSendSingleToUserReqDTO.java | 39 +++ .../system/enums/ErrorCodeConstants.java | 9 +- .../enums/mail/MailLogUserTypeEnum.java | 22 -- .../system/api/mail/MailSendApiImpl.java | 14 +- .../admin/mail/MailAccountController.java | 23 +- .../mail/vo/account/MailAccountBaseVO.java | 34 ++- .../vo/account/MailAccountCreateReqVO.java | 3 - .../mail/vo/account/MailAccountPageReqVO.java | 15 +- .../mail/vo/account/MailAccountRespVO.java | 25 ++ .../vo/account/MailAccountSimpleRespVO.java | 17 ++ .../vo/account/MailAccountUpdateReqVO.java | 3 - .../convert/mail/MailAccountConvert.java | 29 ++- .../dal/dataobject/mail/MailAccountDO.java | 9 +- .../system/dal/dataobject/mail/MailLogDO.java | 54 +++-- .../dal/dataobject/mail/MailTemplateDO.java | 7 +- .../dal/mysql/mail/MailAccountMapper.java | 28 +-- .../dal/mysql/mail/MailTemplateMapper.java | 8 +- .../system/mq/producer/mail/MailProducer.java | 2 +- .../service/mail/MailAccountService.java | 6 +- .../service/mail/MailTemplateService.java | 8 + .../mail/impl/MailAccountServiceImpl.java | 113 +++------ .../service/mail/impl/MailLogServiceImpl.java | 5 +- .../mail/impl/MailTemplateServiceImpl.java | 14 +- .../service/sms/SmsChannelServiceImpl.java | 2 +- yudao-ui-admin/src/api/system/mail/account.js | 44 ++++ .../src/views/system/mail/account/index.vue | 226 ++++++++++++++++++ 28 files changed, 555 insertions(+), 272 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java delete mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java create mode 100755 yudao-ui-admin/src/api/system/mail/account.js create mode 100755 yudao-ui-admin/src/views/system/mail/account/index.vue diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java index 2ffe0d7cb..3885259f2 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java @@ -1,4 +1,34 @@ package cn.iocoder.yudao.module.system.api.mail; +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO; + +import javax.validation.Valid; + +/** + * 邮箱发送 API 接口 + * + * @author 芋道源码 + */ public interface MailSendApi { + + /** + * 发送单条邮箱给 Admin 用户 + * + * 在 mail 为空时,使用 userId 加载对应 Admin 的邮箱 + * + * @param reqDTO 发送请求 + * @return 发送日志编号 + */ + Long sendSingleSmsToAdmin(@Valid MailSendSingleToUserReqDTO reqDTO); + + /** + * 发送单条邮箱给 Member 用户 + * + * 在 mail 为空时,使用 userId 加载对应 Member 的邮箱 + * + * @param reqDTO 发送请求 + * @return 发送日志编号 + */ + Long sendSingleSmsToMember(@Valid MailSendSingleToUserReqDTO reqDTO); + } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java deleted file mode 100644 index caa69678c..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.system.api.mail.dto; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Map; - -@ApiModel("管理后台 - 邮件发送 Req VO") -@Data -public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - - @ApiModelProperty(value = "用户编码",required = true) - @NotNull(message = "用户编码不能为空") - private String userId; - - @ApiModelProperty(value = "用户类型",required = true) - @NotNull(message = "用户类型不能为空") - private String userType; - - @ApiModelProperty(value = "邮箱模版id",example = "1024") - @NotNull(message = "邮箱模版编码不能为空") - private Integer templateCode; - - @ApiModelProperty(value = "邮箱参数") - @NotNull(message = "模版参数不能为空") - private Map templateParams; - - @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "收件人不能为空") - private List tos; - - - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java new file mode 100644 index 000000000..e2ede96ae --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendSingleToUserReqDTO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.api.mail.dto; + +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import java.util.Map; + +/** + * 邮件发送 Request DTO + * + * @author wangjingqi + */ +@Data +public class MailSendSingleToUserReqDTO { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private String userId; + /** + * 邮箱 + */ + @Email + private String mail; + + /** + * 邮件模板编号 + */ + @NotNull(message = "邮件模板编号不能为空") + private String templateCode; + /** + * 邮件模板参数 + */ + @NotNull(message = "邮件模板参数不能为空") + private Map templateParams; + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index ead06b204..135248867 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -141,16 +141,13 @@ public interface ErrorCodeConstants { ErrorCode OAUTH2_CODE_NOT_EXISTS = new ErrorCode(1002022000, "code 不存在"); ErrorCode OAUTH2_CODE_EXPIRE = new ErrorCode(1002022001, "code 已过期"); - // TODO @芋艿:需要重新搞下 mail 错误码 - - // ========== 邮箱账号 1002020000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + // ========== 邮箱账号 1002023000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002023000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002023001, "无法删除,该邮箱账号还有邮件模板"); // ========== 邮箱模版 1002021000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java deleted file mode 100644 index 4154c9bc1..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.system.enums.mail; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 邮件日志用户类型 - * - * @author wangjingyi - */ -@Getter -@AllArgsConstructor -public enum MailLogUserTypeEnum { - - COMMON (10), - VIP (20); - - /** - * 类型 - */ - private final int userType; -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java index cce0ed388..eaad0f8ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.api.mail; +import cn.iocoder.yudao.module.system.api.mail.dto.MailSendSingleToUserReqDTO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -10,5 +11,16 @@ import org.springframework.validation.annotation.Validated; */ @Service @Validated -public class MailSendApiImpl implements MailSendApi{ +public class MailSendApiImpl implements MailSendApi { + + @Override + public Long sendSingleSmsToAdmin(MailSendSingleToUserReqDTO reqDTO) { + return null; + } + + @Override + public Long sendSingleSmsToMember(MailSendSingleToUserReqDTO reqDTO) { + return null; + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 17a305c48..a18fb137b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -3,11 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -36,14 +32,14 @@ public class MailAccountController { @ApiOperation("创建邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:create')") public CommonResult createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) { - return success(mailAccountService.create(createReqVO)); + return success(mailAccountService.createMailAccount(createReqVO)); } @PutMapping("/update") @ApiOperation("修改邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:update')") public CommonResult updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) { - mailAccountService.update(updateReqVO); + mailAccountService.updateMailAccount(updateReqVO); return success(true); } @@ -52,18 +48,15 @@ public class MailAccountController { @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") public CommonResult deleteMailAccount(@RequestParam Long id) { - mailAccountService.delete(id); + mailAccountService.deleteMailAccount(id); return success(true); } - // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE - @GetMapping("/get") @ApiOperation("获得邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:get')") - public CommonResult getMailAccount(@RequestParam("id") Long id) { + public CommonResult getMailAccount(@RequestParam("id") Long id) { MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); } @@ -76,14 +69,10 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE - @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") - public CommonResult> getSimpleMailAccountList() { + public CommonResult> getSimpleMailAccountList() { List list = mailAccountService.getMailAccountList(); - // 排序后,返回给前端 - list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 8e392d476..7a3f2347f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -1,33 +1,41 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; -import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱账号基类 Base VO") +/** + * 邮箱账号 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ @Data public class MailAccountBaseVO { - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "邮箱必填") - @Email(message = "必须是Email格式") - private String fromAddress; + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱不能为空") + @Email(message = "必须是 Email 格式") + private String mail; - @ApiModelProperty(value = "用户名",required = true,example = "yudao") - @NotNull(message = "用户名必填") + @ApiModelProperty(value = "用户名", required = true, example = "yudao") + @NotNull(message = "用户名不能为空") private String username; - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") - @NotNull(message = "网站必填") + @ApiModelProperty(value = "密码", required = true, example = "123456") + @NotNull(message = "密码必填") + private String password; + + @ApiModelProperty(value = "网站", required = true, example = "www.iocoder.cn") + @NotNull(message = "网站不能为空") private String host; - @ApiModelProperty(value = "端口",required = true,example = "80") + @ApiModelProperty(value = "端口", required = true, example = "80") + @NotNull(message = "端口不能为空") private Integer port; - @ApiModelProperty(value = "是否开启ssl",required = true,example = "2") - @NotNull(message = "是否开启ssl必填") + @ApiModelProperty(value = "是否开启 ssl", required = true, example = "true") + @NotNull(message = "是否开启 ssl 必填") private Boolean sslEnable; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 476a3077a..2bcca7850 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -14,7 +14,4 @@ import javax.validation.constraints.NotNull; @ToString(callSuper = true) public class MailAccountCreateReqVO extends MailAccountBaseVO { - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 327c8465d..9e5869172 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -13,21 +13,10 @@ import lombok.ToString; @ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") - private String fromAddress; + @ApiModelProperty(value = "邮箱", required = true, example = "yudaoyuanma@123.com") + private String mail; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") private String username; - @ApiModelProperty(value = "密码" , required = true , example = "123456") - private String password; - - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") - private String host; - - @ApiModelProperty(value = "端口" , required = true , example = "80") - private String port; - - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") - private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java new file mode 100644 index 000000000..9eef7281a --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +@ApiModel("管理后台 - 邮箱账号 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailAccountRespVO extends MailAccountBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private LocalDateTime createTime; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java new file mode 100644 index 000000000..93118388e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("管理后台 - 邮箱账号的精简 Response VO") +@Data +public class MailAccountSimpleRespVO { + + @ApiModelProperty(value = "邮箱比那好", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "邮箱", required = true, example = "768541388@qq.com") + private String mail; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 4544e95b5..43a13ad18 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -18,7 +18,4 @@ public class MailAccountUpdateReqVO extends MailAccountBaseVO { @NotNull(message = "编号不能为空") private Long id; - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index b60ac088f..daadbfe5a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import org.mapstruct.Mapper; @@ -14,30 +16,33 @@ import java.util.Map; @Mapper public interface MailAccountConvert { + MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class); - MailAccountDO convert (MailAccountBaseVO mailAccountBaseVO); + MailAccountDO convert(MailAccountBaseVO bean); - MailAccountBaseVO convert (MailAccountDO mailAccountDO); + MailAccountRespVO convert(MailAccountDO bean); - PageResult convertPage(PageResult pageResult); + PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); - default MailAccount convertAccount(MailSendMessage mailAccountDO){ + // TODO 芋艿:改下 + default MailAccount convertAccount(MailSendMessage bean) { return new MailAccount() - .setHost(mailAccountDO.getHost()) - .setPort(mailAccountDO.getPort()) + .setHost(bean.getHost()) + .setPort(bean.getPort()) .setAuth(true) - .setFrom(mailAccountDO.getFromAddress()) - .setUser(mailAccountDO.getUsername()) - .setPass(mailAccountDO.getPassword()) - .setSslEnable(mailAccountDO.getSslEnable()); + .setFrom(bean.getFromAddress()) + .setUser(bean.getUsername()) + .setPass(bean.getPassword()) + .setSslEnable(bean.getSslEnable()); } + // TODO 芋艿:改下 default Map convertToMap(MailAccountDO mailAccountDO , String content) { Map map = new HashMap<>(); - map.put("from_address" , mailAccountDO.getFromAddress()); + map.put("from_address" , mailAccountDO.getMail()); map.put("username" , mailAccountDO.getUsername()); map.put("content" , content); return map; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 910440df7..33e6859e2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; /** - * 邮箱账号 - * 配置发送邮箱的账号 + * 邮箱账号 DO + * + * 用途:配置发送邮箱的账号 * * @author wangjingyi * @since 2022-03-21 @@ -25,7 +25,8 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ - private String fromAddress; + private String mail; + /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index d4b0e5f81..598b52cfc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -13,7 +13,7 @@ import java.util.Date; import java.util.Map; /** - * 邮箱日志 + * 邮箱日志 DO * 记录每一次邮件的发送 * * @author wangjingyi @@ -29,7 +29,7 @@ import java.util.Map; public class MailLogDO extends BaseDO implements Serializable { /** - * 主键 + * 日志编号,自增 */ private Long id; @@ -37,62 +37,74 @@ public class MailLogDO extends BaseDO implements Serializable { * 用户编码 */ private Long userId; - /** * 用户类型 * - * 冗余 {@link MailLogUserTypeEnum#getUserType} + * 枚举 {@link UserTypeEnum} */ private Integer userType; + /** + * 接收邮箱地址 + */ + private String toMail; - // TODO @wangjingyi:accountId /** * 邮箱账号编号 + * + * 关联 {@link MailAccountDO#getId()} */ private Long accountId; - - // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE /** - * 邮箱账号 + * 发送邮箱地址 * - * 冗余 {@link MailAccountDO} + * 冗余 {@link MailAccountDO#getMail()} */ - private String fromAddress; + private String fromMail; + // ========= 模板相关字段 ========= /** - * 模版主键 + * 模版编号 + * + * 关联 {@link MailTemplateDO#getId()} */ private Long templateId; - + /** + * 末班编码 + * + * 冗余 {@link MailTemplateDO#getCode()} + */ + private String templateCode; /** * 模版内容 + * + * 基于 {@link MailTemplateDO#getContent()} 格式化后的内容 */ private String templateContent; - /** + * 模版参数 + * * 基于 {@link MailTemplateDO#getParams()} 输入后的参数 */ @TableField(typeHandler = JacksonTypeHandler.class) private Map templateParams; - /** - * 发送时间 - */ - private Date sendTime; - - //=========接收相关字段========= + // ========= 发送相关字段 ========= /** * 发送状态 * * 枚举 {@link MailSendStatusEnum} */ private Integer sendStatus; + /** + * 发送时间 + */ + private Date sendTime; + // ========= 接收相关字段 ========= /** * 发送结果 */ private String sendResult; - /** * 消息ID */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index c4708657f..c3c1cae83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode; import java.util.List; /** - * 邮箱模版 + * 邮箱模版 DO * * @author wangjingyi * @since 2022-03-21 @@ -34,9 +34,12 @@ public class MailTemplateDO extends BaseDO { */ private String code; /** - * 邮箱账号主键 + * 发送的邮箱账号编号 + * + * 关联 {@link MailAccountDO#getId()} */ private Long accountId; + /** * 标题 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 1e4f263ac..24ce1ef06 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -2,37 +2,19 @@ package cn.iocoder.yudao.module.system.dal.mysql.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.util.Date; @Mapper public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { - return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("from_address" , pageReqVO.getFromAddress()) - .likeIfPresent("host" , pageReqVO.getHost()) - .likeIfPresent("username" , pageReqVO.getUsername()) - .eqIfPresent("password" , pageReqVO.getPassword()) - .eqIfPresent("port" , pageReqVO.getPort()) - ); - } - - default MailAccountDO selectByUserName(String userName){ - return selectOne(new QueryWrapperX() - .eqIfPresent("username" , userName)); - } - - default MailAccountDO selectByUserNameAndId(String userName,Long id){ - return selectOne(new QueryWrapperX() - .eqIfPresent("username" , userName) - .neIfPresent("id" , id)); + return selectPage(pageReqVO, new LambdaQueryWrapperX() + .likeIfPresent(MailAccountDO::getMail, pageReqVO.getMail()) + .likeIfPresent(MailAccountDO::getUsername , pageReqVO.getUsername())); } default MailAccountDO selectOneByFrom(String from){ @@ -40,6 +22,4 @@ public interface MailAccountMapper extends BaseMapperX { .eqIfPresent("from_address" , from)); } - @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index d7d1cd73c..86bb5e8f5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -36,5 +37,10 @@ public interface MailTemplateMapper extends BaseMapperX { default MailTemplateDO selectOneByAccountId(Long accountId){ return selectOne(new QueryWrapperX() .eqIfPresent("account_id" , accountId)); - }; + } + + default Long selectCountByAccountId(Long accountId) { + return selectCount(MailTemplateDO::getAccountId, accountId); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index 50c505512..8b92ee953 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -55,7 +55,7 @@ public class MailProducer { public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List> templateParams,String to) { MailSendMessage message = new MailSendMessage(); message.setContent(content) - .setFromAddress(mailAccountDO.getFromAddress()) + .setFromAddress(mailAccountDO.getMail()) .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) .setPassword(mailAccountDO.getPassword()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index fe0615f4f..2c90a9121 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -28,21 +28,21 @@ public interface MailAccountService { * @param createReqVO 邮箱账号信息 * @return 编号 */ - Long create(@Valid MailAccountCreateReqVO createReqVO); + Long createMailAccount(@Valid MailAccountCreateReqVO createReqVO); /** * 修改邮箱账号 * * @param updateReqVO 邮箱账号信息 */ - void update(@Valid MailAccountUpdateReqVO updateReqVO); + void updateMailAccount(@Valid MailAccountUpdateReqVO updateReqVO); /** * 删除邮箱账号 * * @param id 编号 */ - void delete(Long id); + void deleteMailAccount(Long id); /** * 获取邮箱账号信息 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 16d65b4f9..662d77623 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -85,4 +85,12 @@ public interface MailTemplateService { */ String formatMailTemplateContent(String content, Map params); + /** + * 获得指定邮箱账号下的邮件模板数量 + * + * @param accountId 账号编号 + * @return 数量 + */ + long countByAccountId(Long accountId); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 3ae44693b..2da58091b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,32 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.util.Date; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; - +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS; /** * 邮箱账号 Service 实现类 @@ -43,7 +39,7 @@ public class MailAccountServiceImpl implements MailAccountService { private MailAccountMapper mailAccountMapper; @Resource - private MailTemplateMapper mailTemplateMapper; + private MailTemplateService mailTemplateService; @Resource private MailProducer mailProducer; @@ -56,75 +52,61 @@ public class MailAccountServiceImpl implements MailAccountService { */ private volatile Map mailAccountCache; - /** - * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile Date maxUpdateTime; - @Override @PostConstruct public void initLocalCache() { - List mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime); - if (CollUtil.isEmpty(mailAccountDOList)) { - return; - } + // 第一步:查询数据 + List accounts = mailAccountMapper.selectList(); + log.info("[initLocalCache][缓存邮箱账号,数量:{}]", accounts.size()); - // 写入缓存 - mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId); - maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime); - log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size()); - } - - private List loadMailAccountIfUpdate(Date maxUpdateTime) { - //第一步 判断是否需要更新 - if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]"); - }else{ // 判断数据库中是否有更新的账号信息 - if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { - return null; - } - log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]"); - } - return mailAccountMapper.selectList(); + // 第二步:构建缓存 + mailAccountCache = convertMap(accounts, MailAccountDO::getId); } @Override - public Long create(MailAccountCreateReqVO createReqVO) { - // username 要校验唯一 - this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); - mailAccountMapper.insert(mailAccountDO); + public Long createMailAccount(MailAccountCreateReqVO createReqVO) { + // 插入 + MailAccountDO account = MailAccountConvert.INSTANCE.convert(createReqVO); + mailAccountMapper.insert(account); - // 更新 + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); - return mailAccountDO.getId(); + return account.getId(); } @Override - public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE - this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId()); - MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); + public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) { // 校验是否存在 - validateMailAccountExists(mailAccountDO.getId()); + validateMailAccountExists(updateReqVO.getId()); // 更新 + MailAccountDO updateObj = MailAccountConvert.INSTANCE.convert(updateReqVO); + mailAccountMapper.updateById(updateObj); + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); - mailAccountMapper.updateById(mailAccountDO); } @Override - public void delete(Long id) { + public void deleteMailAccount(Long id) { // 校验是否存在账号 validateMailAccountExists(id); // 校验是否存在关联模版 - validateMailTemplateByAccountId(id); + if (mailTemplateService.countByAccountId(id) > 0) { + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); + } + // 删除 mailAccountMapper.deleteById(id); - // 更新 + // 发送刷新消息 mailProducer.sendMailAccountRefreshMessage(); } + private void validateMailAccountExists(Long id) { + if (mailAccountMapper.selectById(id) == null) { + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + } + @Override public MailAccountDO getMailAccount(Long id) { return mailAccountMapper.selectById(id); @@ -140,33 +122,4 @@ public class MailAccountServiceImpl implements MailAccountService { return mailAccountMapper.selectList(); } - private void validateMailAccountExists(Long id) { - if (mailAccountMapper.selectById(id) == null) { - throw exception(MAIL_ACCOUNT_NOT_EXISTS); - } - } - - private void validateMailAccountOnlyByUserName(String userName){ - mailAccountCache.forEach((key,value)->{ - if(value.getUsername().equals(userName)){ - throw exception(MAIL_ACCOUNT_EXISTS); - } - }); - } - private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){ - mailAccountCache.forEach((key , value)->{ - if (value.getUsername().equals(userName)){ - if (!key.equals(id)){ - throw exception(MAIL_ACCOUNT_EXISTS); - } - } - }); - } - private void validateMailTemplateByAccountId(Long accountId){ - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); - if (mailTemplateDO != null) { - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE - throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); - } - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index a7bf04fc7..c489ad9bb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -51,7 +50,7 @@ public class MailLogServiceImpl implements MailLogService { logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() : MailSendStatusEnum.IGNORE.getStatus()) // 设置邮箱相关字段 - .fromAddress(mailAccountDO.getFromAddress()) + .fromMail(mailAccountDO.getMail()) .accountId(mailAccountDO.getId()) // TODO @wangjingyi:userId、userType //用户信息 @@ -60,7 +59,7 @@ public class MailLogServiceImpl implements MailLogService { .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent); - logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); + logDOBuilder.fromMail(mailAccountDO.getMail()); logDOBuilder.accountId(mailAccountDO.getId()); // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE // 设置模板相关字段 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 3fcac8b9e..9ae635cee 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -53,19 +53,19 @@ public class MailTemplateServiceImpl implements MailTemplateService { */ private volatile Map mailTemplateCache; - private volatile Date maxUpdateTime; - @Override @PostConstruct public void initLocalCache() { - List mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime); + if (true) { + return; + } + List mailTemplateDOList = this.loadMailTemplateIfUpdate(null); if (CollUtil.isEmpty(mailTemplateDOList)) { return; } // 写入缓存 mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); - maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); } @@ -156,4 +156,10 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 第二步,如果有更新,则从数据库加载所有邮件模板 return mailTemplateMapper.selectList(); } + + @Override + public long countByAccountId(Long accountId) { + return mailTemplateMapper.selectCountByAccountId(accountId); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java index 592864651..d126fbf0f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java @@ -81,7 +81,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { public void deleteSmsChannel(Long id) { // 校验存在 this.validateSmsChannelExists(id); - // 校验是否有字典数据 + // 校验是否有在使用该账号的模版 if (smsTemplateService.countByChannelId(id) > 0) { throw exception(SMS_CHANNEL_HAS_CHILDREN); } diff --git a/yudao-ui-admin/src/api/system/mail/account.js b/yudao-ui-admin/src/api/system/mail/account.js new file mode 100755 index 000000000..171fe553f --- /dev/null +++ b/yudao-ui-admin/src/api/system/mail/account.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 创建邮箱账号 +export function createMailAccount(data) { + return request({ + url: '/system/mail-account/create', + method: 'post', + data: data + }) +} + +// 更新邮箱账号 +export function updateMailAccount(data) { + return request({ + url: '/system/mail-account/update', + method: 'put', + data: data + }) +} + +// 删除邮箱账号 +export function deleteMailAccount(id) { + return request({ + url: '/system/mail-account/delete?id=' + id, + method: 'delete' + }) +} + +// 获得邮箱账号 +export function getMailAccount(id) { + return request({ + url: '/system/mail-account/get?id=' + id, + method: 'get' + }) +} + +// 获得邮箱账号分页 +export function getMailAccountPage(query) { + return request({ + url: '/system/mail-account/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/views/system/mail/account/index.vue b/yudao-ui-admin/src/views/system/mail/account/index.vue new file mode 100755 index 000000000..f3821d8bc --- /dev/null +++ b/yudao-ui-admin/src/views/system/mail/account/index.vue @@ -0,0 +1,226 @@ + + + From ea39dcc5c803ffd0a569243cb2a678ebc0d04b1b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 25 Jan 2023 20:44:48 +0800 Subject: [PATCH 56/80] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20template=20=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 8 +- .../admin/mail/MailTemplateController.java | 35 +-- .../mail/vo/account/MailAccountBaseVO.java | 8 +- .../vo/account/MailAccountSimpleRespVO.java | 2 +- .../mail/vo/template/MailTemplateBaseVO.java | 41 +-- .../vo/template/MailTemplateCreateReqVO.java | 3 +- .../vo/template/MailTemplatePageReqVO.java | 41 ++- .../mail/vo/template/MailTemplateRespVO.java | 25 +- .../vo/template/MailTemplateSimpleRespVO.java | 17 ++ .../vo/template/MailTemplateUpdateReqVO.java | 3 +- .../convert/mail/MailTemplateConvert.java | 11 +- .../dal/dataobject/mail/MailAccountDO.java | 4 +- .../system/dal/dataobject/mail/MailLogDO.java | 12 +- .../dal/dataobject/mail/MailTemplateDO.java | 6 +- .../dal/mysql/mail/MailTemplateMapper.java | 33 +-- .../service/mail/MailTemplateService.java | 36 +-- .../mail/impl/MailTemplateServiceImpl.java | 120 ++++---- .../src/main/resources/application.yaml | 3 + yudao-ui-admin/src/api/system/mail/account.js | 8 + .../src/api/system/mail/template.js | 44 +++ .../src/views/system/mail/account/index.vue | 20 +- .../src/views/system/mail/template/index.vue | 269 ++++++++++++++++++ 22 files changed, 550 insertions(+), 199 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java create mode 100755 yudao-ui-admin/src/api/system/mail/template.js create mode 100755 yudao-ui-admin/src/views/system/mail/template/index.vue diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 135248867..577fcb2ad 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -145,9 +145,9 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002023000, "邮箱账号不存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002023001, "无法删除,该邮箱账号还有邮件模板"); - // ========== 邮箱模版 1002021000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); + // ========== 邮箱模版 1002024000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002024000, "邮件模版不存在"); + ErrorCode MAIL_TEMPLATE_CODE_EXISTS = new ErrorCode(1002024001, "邮件模版 code({}) 已存在"); + ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); // TODO 优化 } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index 2fae6164b..741462c95 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; @@ -10,13 +9,11 @@ import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; - -import java.util.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -26,37 +23,35 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { - // TODO @wangjingyi:private DONE - @Autowired + @Resource private MailTemplateService mailTempleService; @PostMapping("/create") - @ApiOperation("创建邮箱模版") + @ApiOperation("创建邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:create')") public CommonResult createMailTemplate(@Valid @RequestBody MailTemplateCreateReqVO createReqVO){ - return success(mailTempleService.create(createReqVO)); + return success(mailTempleService.createMailTemplate(createReqVO)); } @PutMapping("/update") - @ApiOperation("修改邮箱模版") + @ApiOperation("修改邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:update')") public CommonResult updateMailTemplate(@Valid @RequestBody MailTemplateUpdateReqVO updateReqVO){ - mailTempleService.update(updateReqVO); + mailTempleService.updateMailTemplate(updateReqVO); return success(true); } @DeleteMapping("/delete") - @ApiOperation("删除邮箱模版") + @ApiOperation("删除邮件模版") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:delete')") - public CommonResult deleteMailTemplate(@Valid @RequestBody Long id) { - mailTempleService.delete(id); + public CommonResult deleteMailTemplate(@RequestParam("id") Long id) { + mailTempleService.deleteMailTemplate(id); return success(true); } - // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 DONE RespVO中需要BaseVO 中哪些字段 - @GetMapping("/get") - @ApiOperation("获得邮箱模版") + @ApiOperation("获得邮件模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:get')") public CommonResult getMailTemplate(@RequestParam("id") Long id) { @@ -65,7 +60,7 @@ public class MailTemplateController { } @GetMapping("/page") - @ApiOperation("获得邮箱模版分页") + @ApiOperation("获得邮件模版分页") @PreAuthorize("@ss.hasPermission('system:mail-template:query')") public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); @@ -73,11 +68,9 @@ public class MailTemplateController { } @GetMapping("/list-all-simple") - @ApiOperation(value = "获得邮箱模版精简列表") - public CommonResult> getSimpleTemplateList() { + @ApiOperation(value = "获得邮件模版精简列表") + public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); - // 排序后,返回给前端 - list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 7a3f2347f..ef18cb6ac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -26,12 +26,12 @@ public class MailAccountBaseVO { @NotNull(message = "密码必填") private String password; - @ApiModelProperty(value = "网站", required = true, example = "www.iocoder.cn") - @NotNull(message = "网站不能为空") + @ApiModelProperty(value = "SMTP 服务器域名", required = true, example = "www.iocoder.cn") + @NotNull(message = "SMTP 服务器域名不能为空") private String host; - @ApiModelProperty(value = "端口", required = true, example = "80") - @NotNull(message = "端口不能为空") + @ApiModelProperty(value = "SMTP 服务器端口", required = true, example = "80") + @NotNull(message = "SMTP 服务器端口不能为空") private Integer port; @ApiModelProperty(value = "是否开启 ssl", required = true, example = "true") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java index 93118388e..96916a715 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSimpleRespVO.java @@ -8,7 +8,7 @@ import lombok.Data; @Data public class MailAccountSimpleRespVO { - @ApiModelProperty(value = "邮箱比那好", required = true, example = "1024") + @ApiModelProperty(value = "邮箱编号", required = true, example = "1024") private Long id; @ApiModelProperty(value = "邮箱", required = true, example = "768541388@qq.com") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index 1e44336aa..e2835debd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -1,44 +1,47 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; -import io.swagger.annotations.ApiModel; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱模版基类 Base VO") +/** + * 邮件模版 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ @Data public class MailTemplateBaseVO { - @ApiModelProperty("主键") - @NotNull(message = "主键不能为空") - private Long id; - @ApiModelProperty("名称") + @ApiModelProperty(value = "模版名称", required = true, example = "测试名字") @NotNull(message = "名称不能为空") private String name; - @ApiModelProperty("标识") - @NotNull(message = "邮箱模版code不能为空") + @ApiModelProperty(value = "模版编号", required = true, example = "test") + @NotNull(message = "模版编号不能为空") private String code; - @ApiModelProperty("发件人") - @NotNull(message = "发件人不能为空") - @Email(message = "发件人格式有误") - private String username; + @ApiModelProperty(value = "发送的邮箱账号编号", required = true, example = "1") + @NotNull(message = "发送的邮箱账号编号不能为空") + private Long accountId; - @ApiModelProperty("标题") - @NotNull(message = "标题不能为空") + @ApiModelProperty(value = "发送人名称", example = "芋头") + private String nickname; + + @ApiModelProperty(value = "标题", required = true, example = "注册成功") + @NotEmpty(message = "标题不能为空") private String title; - @ApiModelProperty("内容") - @NotNull(message = "内容不能为空") + @ApiModelProperty(value = "内容", required = true, example = "你好,注册成功啦") + @NotEmpty(message = "内容不能为空") private String content; - @ApiModelProperty("状态") + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") @NotNull(message = "状态不能为空") private Integer status; - @ApiModelProperty("备注") + @ApiModelProperty(value = "备注", example = "奥特曼") private String remark; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java index 2311cb087..6eab6e9ab 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java @@ -5,11 +5,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -@ApiModel("管理后台 - 邮箱模版创建 Request VO") +@ApiModel("管理后台 - 邮件模版创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailTemplateCreateReqVO extends MailTemplateBaseVO { - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index a48c5a91a..f3cec08f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -6,33 +6,32 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; -@ApiModel("管理后台 - 邮箱模版分页 Request VO") +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 邮件模版分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailTemplatePageReqVO extends PageParam { - @ApiModelProperty("主键") - private Long id; - @ApiModelProperty("名称") - private String name; - - @ApiModelProperty("标识") - private String code; - - @ApiModelProperty("发件人") - private String username; - - @ApiModelProperty("标题") - private String title; - - @ApiModelProperty("内容") - private String content; - - @ApiModelProperty("状态") + @ApiModelProperty(value = "状态", example = "1", notes = "参见 CommonStatusEnum 枚举") private Integer status; - @ApiModelProperty("备注") - private String remark; + @ApiModelProperty(value = "标识", example = "code_1024", notes = "模糊匹配") + private String code; + + @ApiModelProperty(value = "名称", example = "芋头", notes = "模糊匹配") + private String name; + + @ApiModelProperty(value = "账号编号", example = "2048") + private Long accountId; + + @ApiModelProperty(value = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java index 33683b1c5..a2153f9cd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -1,4 +1,27 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; -public class MailTemplateRespVO extends MailTemplateBaseVO{ +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; +import java.util.List; + +@ApiModel("管理后台 - 邮件末班 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailTemplateRespVO extends MailTemplateBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "参数数组", example = "name,code") + private List params; + + @ApiModelProperty(value = "创建时间", required = true) + private LocalDateTime createTime; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java new file mode 100644 index 000000000..2ff488036 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSimpleRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("管理后台 - 邮件模版的精简 Response VO") +@Data +public class MailTemplateSimpleRespVO { + + @ApiModelProperty(value = "模版编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "模版名字", required = true, example = "哒哒哒") + private String name; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java index 82d9997be..5dfa377a2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java @@ -8,7 +8,7 @@ import lombok.ToString; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 邮箱模版修改 Request VO") +@ApiModel("管理后台 - 邮件模版修改 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -17,4 +17,5 @@ public class MailTemplateUpdateReqVO extends MailTemplateBaseVO { @ApiModelProperty(value = "编号", required = true, example = "1024") @NotNull(message = "编号不能为空") private Long id; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 46a25b9e2..4430ffb05 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,12 +13,14 @@ public interface MailTemplateConvert { MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); - MailTemplateDO convert(MailTemplateBaseVO baseVO); + MailTemplateDO convert(MailTemplateUpdateReqVO bean); - MailTemplateRespVO convert(MailTemplateDO mailTemplateDO); + MailTemplateDO convert(MailTemplateCreateReqVO bean); + + MailTemplateRespVO convert(MailTemplateDO bean); PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 33e6859e2..b5d349439 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -36,11 +36,11 @@ public class MailAccountDO extends BaseDO { */ private String password; /** - * 主机 + * SMTP 服务器域名 */ private String host; /** - * 端口 + * SMTP 服务器端口 */ private Integer port; /** diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 598b52cfc..ddd0f7158 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -69,11 +69,21 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long templateId; /** - * 末班编码 + * 模版编码 * * 冗余 {@link MailTemplateDO#getCode()} */ private String templateCode; + /** + * 模版发送人名称 + * + * 冗余 {@link MailTemplateDO#getNickname()} + */ + private String templateNickname; + /** + * 模版标题 + */ + private String templateTitle; /** * 模版内容 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index c3c1cae83..f669b455f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode; import java.util.List; /** - * 邮箱模版 DO + * 邮件模版 DO * * @author wangjingyi * @since 2022-03-21 @@ -40,6 +40,10 @@ public class MailTemplateDO extends BaseDO { */ private Long accountId; + /** + * 发送人名称 + */ + private String nickname; /** * 标题 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 86bb5e8f5..f03aa4ae9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; @@ -11,36 +12,24 @@ import org.apache.ibatis.annotations.Select; import java.util.Date; - @Mapper public interface MailTemplateMapper extends BaseMapperX { default PageResult selectPage(MailTemplatePageReqVO pageReqVO){ - return selectPage(pageReqVO , new QueryWrapperX() - .likeIfPresent("name" , pageReqVO.getName()) - .likeIfPresent("username" , pageReqVO.getUsername()) - .likeIfPresent("title" , pageReqVO.getTitle()) - .likeIfPresent("content" , pageReqVO.getContent()) - .eqIfPresent("status" , pageReqVO.getStatus()) - .likeIfPresent("remark" , pageReqVO.getRemark()) - ); - } - - default MailTemplateDO selectOneByCode(String code){ - return selectOne(new QueryWrapperX() - .eqIfPresent("code" , code)); - }; - - @Select("SELECT COUNT(*) FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") - Long selectByMaxUpdateTime(Date maxUpdateTime); - - default MailTemplateDO selectOneByAccountId(Long accountId){ - return selectOne(new QueryWrapperX() - .eqIfPresent("account_id" , accountId)); + return selectPage(pageReqVO , new LambdaQueryWrapperX() + .eqIfPresent(MailTemplateDO::getStatus, pageReqVO.getStatus()) + .likeIfPresent(MailTemplateDO::getCode, pageReqVO.getCode()) + .likeIfPresent(MailTemplateDO::getName, pageReqVO.getName()) + .eqIfPresent(MailTemplateDO::getAccountId, pageReqVO.getAccountId()) + .betweenIfPresent(MailTemplateDO::getCreateTime, pageReqVO.getCreateTime())); } default Long selectCountByAccountId(Long accountId) { return selectCount(MailTemplateDO::getAccountId, accountId); } + default MailTemplateDO selectByCode(String code) { + return selectOne(MailTemplateDO::getCode, code); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 662d77623..704f7d653 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; /** - * 邮箱模版服务类 + * 邮件模版 Service 接口 * * @author wangjingyi * @since 2022-03-21 @@ -19,34 +19,34 @@ import java.util.Map; public interface MailTemplateService { /** - * 初始化邮箱模版的本地缓存 + * 初始化邮件模版的本地缓存 */ void initLocalCache(); /** - * 邮箱模版创建 + * 邮件模版创建 * - * @param createReqVO 邮箱信息 + * @param createReqVO 邮件信息 * @return 编号 */ - Long create(@Valid MailTemplateCreateReqVO createReqVO); + Long createMailTemplate(@Valid MailTemplateCreateReqVO createReqVO); /** - * 邮箱模版修改 + * 邮件模版修改 * - * @param updateReqVO 邮箱信息 + * @param updateReqVO 邮件信息 */ - void update(@Valid MailTemplateUpdateReqVO updateReqVO); + void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO); /** - * 邮箱模版删除 + * 邮件模版删除 * * @param id 编号 */ - void delete(Long id); + void deleteMailTemplate(Long id); /** - * 获取邮箱模版 + * 获取邮件模版 * * @param id 编号 * @return 邮件模版 @@ -54,39 +54,39 @@ public interface MailTemplateService { MailTemplateDO getMailTemplate(Long id); /** - * 获取邮箱模版分页 + * 获取邮件模版分页 * * @param pageReqVO 模版信息 - * @return 邮箱模版分页信息 + * @return 邮件模版分页信息 */ PageResult getMailTemplatePage(MailTemplatePageReqVO pageReqVO); /** - * 获取邮箱模板数组 + * 获取邮件模板数组 * * @return 模版数组 */ List getMailTemplateList(); /** - * 从缓存中获取邮箱模版 + * 从缓存中获取邮件模版 * * @param code 模板编码 - * @return 邮箱模板 + * @return 邮件模板 */ MailTemplateDO getMailTemplateByCodeFromCache(String code); /** * 邮件模版内容合成 * - * @param content 邮箱模版 + * @param content 邮件模版 * @param params 合成参数 * @return 格式化后的内容 */ String formatMailTemplateContent(String content, Map params); /** - * 获得指定邮箱账号下的邮件模板数量 + * 获得指定邮件账号下的邮件模板数量 * * @param accountId 账号编号 * @return 数量 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9ae635cee..753614683 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; @@ -13,6 +15,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -25,8 +28,8 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 邮箱模版 Service 实现类 @@ -47,56 +50,71 @@ public class MailTemplateServiceImpl implements MailTemplateService { /** * 邮件模板缓存 - * key:邮箱模板编码 {@link MailTemplateDO#getId()} + * key:邮件模版标识 {@link MailTemplateDO#getCode()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - private volatile Map mailTemplateCache; + private volatile Map mailTemplateCache; @Override @PostConstruct public void initLocalCache() { - if (true) { - return; - } - List mailTemplateDOList = this.loadMailTemplateIfUpdate(null); - if (CollUtil.isEmpty(mailTemplateDOList)) { - return; - } + // 第一步:查询数据 + List templates = mailTemplateMapper.selectList(); + log.info("[initLocalCache][缓存邮件模版,数量:{}]", templates.size()); - // 写入缓存 - mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); - log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); + // 第二步:构建缓存 + mailTemplateCache = convertMap(templates, MailTemplateDO::getCode); } @Override - public Long create(MailTemplateCreateReqVO createReqVO) { - // 要校验存在 - validateMailTemplateExists(createReqVO.getId()); - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); - mailTemplateMapper.insert(mailTemplateDO); - // TODO @wangjingyi:mq 更新 DONE + public Long createMailTemplate(MailTemplateCreateReqVO createReqVO) { + // 校验 code 是否唯一 + validateCodeUnique(null, createReqVO.getCode()); + + // 插入 + MailTemplateDO template = MailTemplateConvert.INSTANCE.convert(createReqVO); + mailTemplateMapper.insert(template); + // 发送刷新消息 mailProducer.sendMailTemplateRefreshMessage(); - return mailTemplateDO.getId(); + return template.getId(); } @Override - public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // 校验是否唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。DONE - this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); - mailTemplateMapper.updateById(mailTemplateDO); - // TODO @wangjingyi:mq 更新 DONE - mailProducer.sendMailTemplateRefreshMessage(); - } - - @Override - public void delete(Long id) { + public void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO) { // 校验是否存在 - this.validateMailTemplateExists(id); + validateMailTemplateExists(updateReqVO.getId()); + // 校验 code 是否唯一 + validateCodeUnique(updateReqVO.getId(),updateReqVO.getCode()); + + // 更新 + MailTemplateDO updateObj = MailTemplateConvert.INSTANCE.convert(updateReqVO); + mailTemplateMapper.updateById(updateObj); + // 发送刷新消息 + mailProducer.sendMailTemplateRefreshMessage(); + } + + @VisibleForTesting + public void validateCodeUnique(Long id, String code) { + MailTemplateDO template = mailTemplateMapper.selectByCode(code); + if (template == null) { + return; + } + // 存在 template 记录的情况下 + if (id == null // 新增时,说明重复 + || ObjUtil.notEqual(id, template.getId())) { // 更新时,如果 id 不一致,说明重复 + throw exception(MAIL_TEMPLATE_CODE_EXISTS); + } + } + + @Override + public void deleteMailTemplate(Long id) { + // 校验是否存在 + validateMailTemplateExists(id); + + // 删除 mailTemplateMapper.deleteById(id); - // TODO @wangjingyi:mq 更新 DONE + // 发送刷新消息 mailProducer.sendMailTemplateRefreshMessage(); } @@ -122,41 +140,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { } private void validateMailTemplateExists(Long id) { - if (mailTemplateCache.get(id) == null) { + if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnlyByCode(Long id ,String code){ - mailTemplateCache.forEach((key,value)->{ - if (value.getCode().equals(code)){ - if (!key.equals(id)){ - throw exception(MAIL_TEMPLATE_EXISTS); - } - } - }); - } - /** - * 如果邮件模板发生变化,从数据库中获取最新的全量邮件模板。 - * 如果未发生变化,则返回空 - * - * @param maxUpdateTime 当前邮件模板的最大更新时间 - * @return 邮件模板列表 - */ - private List loadMailTemplateIfUpdate(Date maxUpdateTime) { - // 第一步,判断是否要更新。 - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadMailTemplateIfUpdate][首次加载全量邮件模板]"); - } else { // 判断数据库中是否有更新的邮件模板 - if (mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime) == 0) { - return null; - } - log.info("[loadSmsTemplateIfUpdate][增量加载全量邮件模板]"); - } - // 第二步,如果有更新,则从数据库加载所有邮件模板 - return mailTemplateMapper.selectList(); - } - @Override public long countByAccountId(Long accountId) { return mailTemplateMapper.selectCountByAccountId(accountId); diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 325e88f42..e1bcb137e 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -138,6 +138,9 @@ yudao: - system_sms_log - system_sensitive_word - system_oauth2_client + - system_mail_account + - system_mail_template + - system_mail_log - infra_codegen_column - infra_codegen_table - infra_test_demo diff --git a/yudao-ui-admin/src/api/system/mail/account.js b/yudao-ui-admin/src/api/system/mail/account.js index 171fe553f..0868e4f37 100755 --- a/yudao-ui-admin/src/api/system/mail/account.js +++ b/yudao-ui-admin/src/api/system/mail/account.js @@ -42,3 +42,11 @@ export function getMailAccountPage(query) { params: query }) } + +// 获取邮箱账号的精简信息列表 +export function getSimpleMailAccountList() { + return request({ + url: '/system/mail-account/list-all-simple', + method: 'get', + }) +} diff --git a/yudao-ui-admin/src/api/system/mail/template.js b/yudao-ui-admin/src/api/system/mail/template.js new file mode 100755 index 000000000..ee5d8d454 --- /dev/null +++ b/yudao-ui-admin/src/api/system/mail/template.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 创建邮件模版 +export function createMailTemplate(data) { + return request({ + url: '/system/mail-template/create', + method: 'post', + data: data + }) +} + +// 更新邮件模版 +export function updateMailTemplate(data) { + return request({ + url: '/system/mail-template/update', + method: 'put', + data: data + }) +} + +// 删除邮件模版 +export function deleteMailTemplate(id) { + return request({ + url: '/system/mail-template/delete?id=' + id, + method: 'delete' + }) +} + +// 获得邮件模版 +export function getMailTemplate(id) { + return request({ + url: '/system/mail-template/get?id=' + id, + method: 'get' + }) +} + +// 获得邮件模版分页 +export function getMailTemplatePage(query) { + return request({ + url: '/system/mail-template/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/views/system/mail/account/index.vue b/yudao-ui-admin/src/views/system/mail/account/index.vue index f3821d8bc..96e3cc461 100755 --- a/yudao-ui-admin/src/views/system/mail/account/index.vue +++ b/yudao-ui-admin/src/views/system/mail/account/index.vue @@ -29,8 +29,8 @@ - - + +