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

+ * 前端控制器 + *

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

+ * 前端控制器 + *

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

+ * 前端控制器 + *

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

+ * + *

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

+ * + *

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

+ * + *

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

+ * Mapper 接口 + *

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

+ * Mapper 接口 + *

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

+ * Mapper 接口 + *

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

+ * 服务类 + *

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

+ * 服务类 + *

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

+ * 服务类 + *

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

+ * 服务实现类 + *

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

+ * 服务实现类 + *

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

+ * 服务实现类 + *

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

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

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

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

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

- * 前端控制器 - *

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

+ * 前端控制器 + *

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

- * 前端控制器 - *

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

+ * 前端控制器 + *

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

- * 前端控制器 - *

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

- * - *

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

- * - *

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

+ * + *

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

- * - *

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

+ * 邮箱账号 + *

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

- * Mapper 接口 - *

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

+ * Mapper 接口 + *

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

- * Mapper 接口 - *

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

+ * Mapper 接口 + *

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

- * Mapper 接口 - *

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

+ * 邮箱账号 Service 接口 + *

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

- * 服务类 - *

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

+ * 服务类 + *

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

- * 服务类 - *

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

+ * 服务类 + *

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

- * 服务类 - *

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

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

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

- * 服务实现类 - *

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

+ * 服务实现类 + *

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

- * 服务实现类 - *

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

+ * 服务实现类 + *

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

- * 服务实现类 - *

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

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

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

- * Mapper 接口 - *

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

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

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

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

- * 邮箱日志功能 - *

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

- * 前端控制器 - *

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

- * + * 邮箱日志 *

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

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

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

- * Mapper 接口 - *

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

+ * 服务类 + *

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

- * 服务类 - *

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

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

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

- * 服务实现类 - *

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

* 邮箱账号 Service 接口 - *

+ *

// TODO wangjingyi:不用

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

* 邮箱账号 Service 接口 - *

// TODO wangjingyi:不用

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

- * 服务类 - *

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

- * 服务类 - *

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

* 邮箱日志实现类 - *

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

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

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

* 邮箱账号 Service 实现类 - *

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

* 邮箱日志 - *

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

* 邮箱模版 - *

* * @author wangjingyi * @since 2022-03-21 @@ -24,48 +15,42 @@ import lombok.experimental.Accessors; @TableName(value = "system_mail_template", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class MailTemplateDO extends BaseDO implements Serializable { +public class MailTemplateDO extends BaseDO { /** * 主键 */ private Long id; - /** * 模版名称 */ private String name; - /** * 模版编号 */ private String code; - + // TODO @wangjingyi:应该使用 accountId 呀 /** * 用户名 */ private String username; - /** * 标题 */ private String title; - /** * 内容 */ private String content; - /** * 状态 + * + * 枚举 {@link CommonStatusEnum} */ - private String status; - + private String status; // TODO @wangjingyi:Integer /** * 备注 */ private String remark; - } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index d0a43e6796..8697b21514 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,8 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import org.apache.ibatis.annotations.Mapper; -import java.util.Map; - @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -23,7 +21,8 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - QueryWrapperX queryWrapperX = new QueryWrapperX(); + // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); + QueryWrapperX queryWrapperX = new QueryWrapperX<>(); queryWrapperX.eqIfPresent("username", userName); return this.selectOne(queryWrapperX); }; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index 635a2bf907..d65887e54a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -23,6 +23,7 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ + // TODO @wangjingyi:优先使用 lambada 查询 return selectOne("code" , code); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 9792c6cc5e..c1289154f8 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; @@ -19,10 +18,8 @@ import java.util.List; */ public interface MailAccountService { - // TODO @wangjingyi:注释,完整;参数校验还是要做的; - /** - * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 + * 创建邮箱账号 * * @param createReqVO 邮箱账号信息 * @return 编号 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1511309eb9..1071eae5d2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ public interface MailTemplateService { /** * 邮箱模版创建 + * * @param createReqVO 邮箱信息 * @return 编号 */ @@ -27,12 +28,14 @@ public interface MailTemplateService { /** * 邮箱模版修改 + * * @param updateReqVO 邮箱信息 */ void update(@Valid MailTemplateUpdateReqVO updateReqVO); /** * 邮箱模版删除 + * * @param id 编号 */ void delete(Long id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index fa2f8879ee..aa1fb1d467 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.module.system.service.mail.impl; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -18,9 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; @@ -54,7 +47,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 + // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 @@ -64,6 +57,7 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { + // TODO @wangjingyi:删除时,要判断是否有使用的模板 // 校验是否存在 this.validateMailAccountExists(id); mailAccountMapper.deleteById(id); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 7ce118303d..2bd74ac4cc 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -15,15 +15,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; -import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +55,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); + this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailTemplateExists(mailTemplateDO.getId()); @@ -85,6 +82,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void sendMail(MailReqVO mailReqVO) { + // TODO @@wangjingyi:发送的时候,参考下短信; MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); //查询账号信息 MailAccountDO mailAccountDO = mailAccountMapper.selectOne( From d7305739d3fcef6efe25c12d33c02b903c181308 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Sat, 30 Apr 2022 21:31:55 +0800 Subject: [PATCH 16/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 + .../pom.xml | 65 +++++++++++ .../config/YudaoMailAutoConfiguration.java | 21 ++++ .../mail/core/client/MailClient.java | 23 ++++ .../mail/core/client/MailClientFactory.java | 5 + .../mail/core/client/MailCodeMapping.java | 17 +++ .../mail/core/client/MailCommonResult.java | 68 +++++++++++ .../core/client/dto/MailReceiveRespDTO.java | 48 ++++++++ .../mail/core/client/dto/MailSendRespDTO.java | 18 +++ .../core/client/dto/MailTemplateRespDTO.java | 31 +++++ .../core/client/impl/AbstractMailClient.java | 14 +++ .../client/impl/MailClientFactoryImpl.java | 39 +++++++ .../client/impl/hutool/HutoolMailClient.java | 29 +++++ .../impl/hutool/HutoolMailCodeMapping.java | 20 ++++ .../mail/core/enums/MailChannelEnum.java | 32 ++++++ .../MailFrameworkErrorCodeConstants.java | 47 ++++++++ .../enums/MailTemplateAuditStatusEnum.java | 21 ++++ .../core/property/MailChannelProperties.java | 52 +++++++++ .../module/system/api/mail/MailSendApi.java | 4 + .../system/api/mail/dto/MailSendReqDTO.java | 38 +++++++ .../system/enums/ErrorCodeConstants.java | 1 + .../system/enums/mail/MailSendStatusEnum.java | 24 ++++ .../yudao-module-system-impl/pom.xml | 5 + .../system/api/mail/MailSendApiImpl.java | 14 +++ .../mail/vo/account/MailAccountBaseVO.java | 22 ++-- .../admin/mail/vo/log/MailLogExcelVO.java | 5 +- .../admin/mail/vo/log/MailLogRespVO.java | 2 +- .../admin/mail/vo/send/MailReqVO.java | 14 ++- .../mail/vo/template/MailTemplateBaseVO.java | 12 +- .../vo/template/MailTemplatePageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailLogDO.java | 22 ++-- .../dal/dataobject/mail/MailTemplateDO.java | 9 +- .../dal/mysql/mail/MailAccountMapper.java | 7 +- .../dal/mysql/mail/MailTemplateMapper.java | 15 ++- .../mq/consumer/mail/MailSendConsumer.java | 8 +- .../mq/message/mail/MailSendMessage.java | 26 +++-- .../system/mq/producer/mail/MailProducer.java | 65 +++++++++++ .../system/service/mail/MailLogService.java | 16 +++ .../system/service/mail/MailSendService.java | 41 +++++++ .../service/mail/MailTemplateService.java | 17 +++ .../mail/impl/MailAccountServiceImpl.java | 20 +++- .../service/mail/impl/MailLogServiceImpl.java | 42 +++++++ .../mail/impl/MailSendServiceImpl.java | 107 ++++++++++++++++++ .../mail/impl/MailTemplateServiceImpl.java | 55 ++++++++- 44 files changed, 1085 insertions(+), 59 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 73bb614cd7..42c887c561 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,6 +30,7 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms + yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml new file mode 100644 index 0000000000..8cca217789 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml @@ -0,0 +1,65 @@ + + + + cn.iocoder.boot + yudao-framework + ${revision} + + 4.0.0 + yudao-spring-boot-starter-biz-mail + jar + + + + cn.iocoder.boot + yudao-common + + + + + org.springframework.boot + spring-boot-starter + + + + + io.opentracing + opentracing-util + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + + + + + com.google.guava + guava + true + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + + jakarta.validation + jakarta.validation-api + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java new file mode 100644 index 0000000000..c83b1e5f1e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.config; + +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 邮箱配置类 + * + * @author 芋道源码 + */ +@Configuration +public class YudaoMailAutoConfiguration { + + @Bean + public MailClientFactory mailClientFactory() { + return new MailClientFactoryImpl(); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java new file mode 100644 index 0000000000..a17260410a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import java.util.List; + +/** + * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 + * + * @author wangjingyi + * @date 2021/4/19 19:21 + */ +public interface MailClient { + + /** + * 发送邮件 + * + * @param from 邮箱账号 + * @param content 内容 + * @param title 标题 + * @param tos 收件人 + * @return 邮件发送结果 + */ + String sendMail(String from, String content, String title, List tos); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java new file mode 100644 index 0000000000..3244dfe761 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java @@ -0,0 +1,5 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +public interface MailClientFactory { + MailClient getMailClient(); +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java new file mode 100644 index 0000000000..c33b4be3e3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +import java.util.function.Function; + +/** + * 将 API 的错误码,转换为通用的错误码 + * + * @see MailCommonResult + * @see MailFrameworkErrorCodeConstants + * + * @author 芋道源码 + */ +public interface MailCodeMapping extends Function { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java new file mode 100644 index 0000000000..a53a3b9897 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.framework.mail.core.client; + +import cn.hutool.core.exceptions.ExceptionUtil; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; + +/** + * 短信的 CommonResult 拓展类 + * + * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 + * + * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 + * + * @author 芋道源码 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MailCommonResult extends CommonResult { + + /** + * API 返回错误码 + * + * 由于第三方的错误码可能是字符串,所以使用 String 类型 + */ + private String apiCode; + /** + * API 返回提示 + */ + private String apiMsg; + + /** + * API 请求编号 + */ + private String apiRequestId; + + private MailCommonResult() { + } + + public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, + T data, MailCodeMapping codeMapping) { + Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); + MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); + result.setData(data); + // 翻译错误码 + if (codeMapping != null) { + ErrorCode errorCode = codeMapping.apply(apiCode); + if (errorCode == null) { + errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; + } + result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); + } + return result; + } + + public static MailCommonResult error(Throwable ex) { + MailCommonResult result = new MailCommonResult<>(); + result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); + result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); + return result; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java new file mode 100644 index 0000000000..11f27f58a6 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * 消息接收 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailReceiveRespDTO { + + /** + * 是否接收成功 + */ + private Boolean success; + /** + * API 接收结果的编码 + */ + private String errorCode; + /** + * API 接收结果的说明 + */ + private String errorMsg; + + /** + * 手机号 + */ + private String mobile; + /** + * 用户接收时间 + */ + private Date receiveTime; + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + /** + * 短信日志编号 + * + * 对应 SysSmsLogDO 的编号 + */ + private Long logId; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java new file mode 100644 index 0000000000..b4a94a6347 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信发送 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailSendRespDTO { + + /** + * 短信 API 发送返回的序号 + */ + private String serialNo; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java new file mode 100644 index 0000000000..14bdeacd89 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.framework.mail.core.client.dto; + +import lombok.Data; + +/** + * 短信模板 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MailTemplateRespDTO { + + /** + * 模板编号 + */ + private String id; + /** + * 短信内容 + */ + private String content; + /** + * 审核状态 + * + */ + private Integer auditStatus; + /** + * 审核未通过的理由 + */ + private String auditReason; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java new file mode 100644 index 0000000000..097c8e095f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +/** + * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 + * + * @author zzf + * @date 2021/2/1 9:28 + */ +@Slf4j +public abstract class AbstractMailClient implements MailClient { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java new file mode 100644 index 0000000000..9923bd3df4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl; + +import cn.iocoder.yudao.framework.mail.core.client.MailClient; +import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +@Validated +@Slf4j +public class MailClientFactoryImpl implements MailClientFactory { + + private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); + + public MailClientFactoryImpl (){ + Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { + AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); + channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); + }); + } + + private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { + switch (mailChannelEnum){ + case HUTOOL: return new HutoolMailClient(); + } + // 创建失败,错误日志 + 抛出异常 + log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); + throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); + } + + @Override + public MailClient getMailClient() { + return channelCodeClients.get("HUTOOL"); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java new file mode 100644 index 0000000000..457ad7e370 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + + +/** + * 邮件客户端实现 + * + * @author wangjingyi + * @date 2021/4/25 14:25 + */ +@Slf4j +public class HutoolMailClient extends AbstractMailClient { + + @Override + public String sendMail(String from, String content, String title, List tos) { + try{ + return MailUtil.send(from , title , content , false , null); + }catch (Exception e){ + log.error(e.getMessage()); + } + return ""; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java new file mode 100644 index 0000000000..711d369502 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; + +/** + * 阿里云的 SmsCodeMapping 实现类 + * + * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 + * + * @author 芋道源码 + */ +public class HutoolMailCodeMapping implements MailCodeMapping { + + @Override + public ErrorCode apply(String apiCode) { + return null; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java new file mode 100644 index 0000000000..51d2f1fcae --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.hutool.core.util.ArrayUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信渠道枚举 + * + * @author zzf + * @date 2021/1/25 10:56 + */ +@Getter +@AllArgsConstructor +public enum MailChannelEnum { + HUTOOL("HUTOOL" , "HUTOOL"), + ; + + /** + * 编码 + */ + private final String code; + /** + * 名字 + */ + private final String name; + + public static MailChannelEnum getByCode(String code) { + return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java new file mode 100644 index 0000000000..e5ef74cf33 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * 短信框架的错误码枚举 + * + * 短信框架,使用 2-001-000-000 段 + * + * @author 芋道源码 + */ +public interface MailFrameworkErrorCodeConstants { + + ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); + + // ========== 权限 / 限流等相关 2001000100 ========== + + ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); + // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 + ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); + + // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 + ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); + // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 + ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); + + ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); + + // ========== 模板相关 2001000200 ========== + ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 + ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); + + // ========== 签名相关 2001000300 ========== + ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); + + // ========== 账户相关 2001000400 ========== + ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); + ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); + + // ========== 其它相关 2001000900 开头 ========== + ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); + ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); + ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); + + ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java new file mode 100644 index 0000000000..95c3c31a3e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.mail.core.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信模板的审核状态枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum MailTemplateAuditStatusEnum { + + CHECKING(1), + SUCCESS(2), + FAIL(3); + + private final Integer status; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java new file mode 100644 index 0000000000..1f19ac12bd --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.framework.mail.core.property; + +import lombok.Data; +import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 短信渠道配置类 + * + * @author zzf + * @date 2021/1/25 17:01 + */ +@Data +@Validated +public class MailChannelProperties { + + /** + * 渠道编号 + */ + @NotNull(message = "短信渠道 ID 不能为空") + private Long id; + /** + * 短信签名 + */ + @NotEmpty(message = "短信签名不能为空") + private String signature; + /** + * 渠道编码 + * + * 枚举 {@link MailChannelEnum} + */ + @NotEmpty(message = "渠道编码不能为空") + private String code; + /** + * 短信 API 的账号 + */ + @NotEmpty(message = "短信 API 的账号不能为空") + private String apiKey; + /** + * 短信 API 的秘钥 + */ + @NotEmpty(message = "短信 API 的秘钥不能为空") + private String apiSecret; + /** + * 短信发送回调 URL + */ + private String callbackUrl; + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java new file mode 100644 index 0000000000..2ffe0d7cb7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApi.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.api.mail; + +public interface MailSendApi { +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java new file mode 100644 index 0000000000..a3b0f2e354 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.system.api.mail.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel("管理后台 - 邮件发送 Req VO") +@Data +public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 + + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") + private String from; + + @ApiModelProperty(value = "标题",example = "标题") + private String title; + + @ApiModelProperty(value = "内容",example = "内容") + private String content; + + @ApiModelProperty(value = "邮箱模版id",example = "1024") + @NotNull(message = "邮箱模版id不能为空") + private Integer templateId; + + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "收件人不能为空") + private List tos; + + @ApiModelProperty(value = "附件",example = "附件编码") + private List fileIds; + + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 8520cb1155..07322ccd72 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -126,5 +126,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002020000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java new file mode 100644 index 0000000000..8936ea9c79 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailSendStatusEnum.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件的发送状态枚举 + * + * @author wangjingyi + * @date 2022/4/10 13:39 + */ +@Getter +@AllArgsConstructor +public enum MailSendStatusEnum { + + INIT(0), // 初始化 + SUCCESS(10), // 发送成功 + FAILURE(20), // 发送失败 + IGNORE(30), // 忽略,即不发送 + ; + + private final int status; + +} diff --git a/yudao-module-system/yudao-module-system-impl/pom.xml b/yudao-module-system/yudao-module-system-impl/pom.xml index b297830b5a..65dc74d03e 100644 --- a/yudao-module-system/yudao-module-system-impl/pom.xml +++ b/yudao-module-system/yudao-module-system-impl/pom.xml @@ -47,6 +47,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict + + cn.iocoder.boot + yudao-spring-boot-starter-biz-mail + cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission @@ -102,6 +106,7 @@ yudao-spring-boot-starter-excel + diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java new file mode 100644 index 0000000000..cce0ed3883 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/api/mail/MailSendApiImpl.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.system.api.mail; + +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +/** + * 邮件发送 API 接口 + * + * @author wangjingyi + */ +@Service +@Validated +public class MailSendApiImpl implements MailSendApi{ +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index 67cf9ba3a3..d8650b52e8 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -4,28 +4,34 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱账号基类 Base VO") @Data -public class MailAccountBaseVO { // TODO @wangjingqi:1), 不用空格;2)from、username、password、host、sslEnable 都要参数校验,非空;3)username 要 Email 格式;port Integer; +public class MailAccountBaseVO { - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") + @NotNull(message = "邮箱必填") private String from; - @ApiModelProperty(value = "用户名" , required = true , example = "yudao") + @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") + @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码" , required = true , example = "123456") + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") private String password; - @ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn") + @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") + @NotNull(message = "网站必填") private String host; - @ApiModelProperty(value = "端口" , required = true , example = "80") - private String port; + @ApiModelProperty(value = "端口",required = true,example = "80") + private Integer port; - @ApiModelProperty(value = "是否开启ssl" , required = true , example = "2") + @ApiModelProperty(value = "是否开启ssl",required = true,example = "2") + @NotNull(message = "是否开启ssl必填") private Boolean sslEnable; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java index 442a101a30..d341ce6789 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogExcelVO.java @@ -6,6 +6,7 @@ import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; +import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -30,10 +31,10 @@ public class MailLogExcelVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @ExcelProperty(value = "发送时间" ) - private Timestamp sendTime; + private Date sendTime; @ExcelProperty(value = "发送状态") - private Boolean sendStatus; + private Integer sendStatus; @ExcelProperty(value = "发送结果") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index af8e81698d..024e075f44 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -36,7 +36,7 @@ public class MailLogRespVO { private Timestamp sendTime; @ApiModelProperty(value = "发送状态" , required = false , example = "1") - private Boolean sendStatus; + private Integer sendStatus; @ApiModelProperty(value = "发送结果" , required = false , example = "yudaoyuanma@123.com") private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 4ce06a718f..65142ee3fa 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; @@ -11,25 +12,26 @@ import java.util.List; @Data public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱账号不能为空") + @Email(message = "邮箱账号格式错误") private String from; - @ApiModelProperty(value = "标题" , example = "标题") + @ApiModelProperty(value = "标题",example = "标题") private String title; - @ApiModelProperty(value = "内容" , example = "内容") + @ApiModelProperty(value = "内容",example = "内容") private String content; - @ApiModelProperty(value = "邮箱模版id" , example = "1024") + @ApiModelProperty(value = "邮箱模版id",example = "1024") @NotNull(message = "邮箱模版id不能为空") private Integer templateId; - @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件" , example = "附件编码") + @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java index e3c9797ab7..1e44336aac 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java @@ -4,15 +4,18 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; @ApiModel("管理后台 - 邮箱模版基类 Base VO") @Data -public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不完善;2)id、name、code、username、title、content、status 是不是要参数校验呀 +public class MailTemplateBaseVO { @ApiModelProperty("主键") + @NotNull(message = "主键不能为空") private Long id; @ApiModelProperty("名称") + @NotNull(message = "名称不能为空") private String name; @ApiModelProperty("标识") @@ -20,16 +23,21 @@ public class MailTemplateBaseVO { // TODO @wangjingqi:1)swagger 注解不 private String code; @ApiModelProperty("发件人") + @NotNull(message = "发件人不能为空") + @Email(message = "发件人格式有误") private String username; @ApiModelProperty("标题") + @NotNull(message = "标题不能为空") private String title; @ApiModelProperty("内容") + @NotNull(message = "内容不能为空") private String content; @ApiModelProperty("状态") - private String status; + @NotNull(message = "状态不能为空") + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java index 398e6ac03b..a48c5a91af 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplatePageReqVO.java @@ -31,7 +31,7 @@ public class MailTemplatePageReqVO extends PageParam { private String content; @ApiModelProperty("状态") - private String status; + private Integer status; @ApiModelProperty("备注") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index f6b9e689c4..7454d2acb3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import java.io.Serializable; -import java.sql.Timestamp; +import java.util.Date; /** * 邮箱日志 @@ -18,6 +18,10 @@ import java.sql.Timestamp; @TableName(value = "system_mail_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@AllArgsConstructor +@NoArgsConstructor public class MailLogDO extends BaseDO implements Serializable { /** @@ -29,7 +33,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号编号 */ - private String accountCode; + private Long accountId; // TODO @wangjingyi:如果是冗余字段,记得 @ 下; /** @@ -40,7 +44,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 模版主键 */ - private String templateId; + private Long templateId; /** * 模版编号 @@ -65,16 +69,18 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送时间 */ - private Timestamp sendTime; + private Date sendTime; /** * 发送状态 + * + * 枚举 {@link MailSendStatusEnum} */ - // TODO @wangjingyi:四个状态,参考短信模块 - private Boolean sendStatus; + private Integer sendStatus; /** * 发送结果 + * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index b86e39e95e..96f9ba4ab0 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Date; + /** * 邮箱模版 * @@ -29,11 +31,10 @@ public class MailTemplateDO extends BaseDO { * 模版编号 */ private String code; - // TODO @wangjingyi:应该使用 accountId 呀 /** - * 用户名 + * 邮箱账号主键 */ - private String username; + private Long accountId; /** * 标题 */ @@ -47,7 +48,7 @@ public class MailTemplateDO extends BaseDO { * * 枚举 {@link CommonStatusEnum} */ - private String status; // TODO @wangjingyi:Integer + private Integer status; /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 8697b21514..651f5c75fd 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -21,9 +22,7 @@ public interface MailAccountMapper extends BaseMapperX { } default MailAccountDO selectByUserName(String userName){ - // TODO @wangjingyi:selectOne 有封装的方法;然后,编码一定要学会使用泛型呀。例如说 QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - queryWrapperX.eqIfPresent("username", userName); - return this.selectOne(queryWrapperX); + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index d65887e54a..a5cbf0b2a3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -6,6 +6,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper @@ -23,7 +26,15 @@ public interface MailTemplateMapper extends BaseMapperX { } default MailTemplateDO selectOneByCode(String code){ - // TODO @wangjingyi:优先使用 lambada 查询 - return selectOne("code" , code); + return selectOne(new QueryWrapperX() + .eqIfPresent("code" , code)); + }; + + @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectByMaxUpdateTime(Date maxUpdateTime); + + default MailTemplateDO selectOneByAccountId(Long accountId){ + return selectOne(new QueryWrapperX() + .eqIfPresent("account_id" , accountId)); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java index 4b02f760ea..978ea59973 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailSendConsumer.java @@ -2,17 +2,23 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -// TODO 芋艿:这个暂未实现 +import javax.annotation.Resource; + + @Component @Slf4j public class MailSendConsumer extends AbstractStreamMessageListener { + @Resource + private MailSendService mailSendService; @Override public void onMessage(MailSendMessage message) { log.info("[onMessage][消息内容({})]", message); + mailSendService.doSendMail(message); } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index aee02c76e9..275a458250 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; +import java.util.List; import java.util.Map; /** @@ -16,29 +17,34 @@ import java.util.Map; @EqualsAndHashCode(callSuper = true) public class MailSendMessage extends AbstractStreamMessage { + /** + * 日志id + */ + @NotNull(message = "邮箱日志id不能为空") + private Long logId; /** * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String address; + private String from; /** - * 短信模板编号 + * 邮箱模板编号 */ - @NotNull(message = "短信模板编号不能为空") + @NotNull(message = "邮箱模板编号不能为空") private String templateCode; /** - * 短信模板参数 + * 收件人 */ - private Map templateParams; - + @NotNull(message = "收件人不能为空") + private List tos; /** - * 用户编号,允许空 + * 标题 */ - private Integer userId; + private String title; /** - * 用户类型,允许空 + * 内容 */ - private Integer userType; + private String content; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java new file mode 100644 index 0000000000..ed82c24a4d --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.system.mq.producer.mail; + +import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Mail 邮件相关消息的 Producer + * + * @author wangjingyi + * @date 2021/4/19 13:33 + */ +@Slf4j +@Component +public class MailProducer { + + @Resource + private RedisMQTemplate redisMQTemplate; + + /** + * 发送 {@link SmsChannelRefreshMessage} 消息 + */ + public void sendMailChannelRefreshMessage() { + SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link SmsTemplateRefreshMessage} 消息 + */ + public void sendMailTemplateRefreshMessage() { + SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + redisMQTemplate.send(message); + } + + /** + * 发送 {@link MailSendMessage} 消息 + * + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 邮箱模版信息 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + MailSendMessage message = new MailSendMessage(); + message.setContent(content); + message.setFrom(mailAccountDO.getFrom()); + message.setTemplateCode(mailTemplateDO.getCode()); + message.setTitle(title); + message.setTos(tos); + message.setLogId(sendLogId); + redisMQTemplate.send(message); + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index fa195259bf..0a5d25ba2c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -4,7 +4,9 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; @@ -28,4 +30,18 @@ public interface MailLogService { * @return */ List getMailLogList(MailLogExportReqVO exportReqVO); + + /** + * 创建邮箱日志 + * @param mailAccountDO 邮箱账号信息 + * @param mailTemplateDO 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 + */ + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + + Long updateSmsSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java new file mode 100644 index 0000000000..31f6a3f3e7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.system.service.mail; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * 邮箱模版服务类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +public interface MailSendService { + + /** + * 发送邮件 + * + * @param templateCode 邮件模版编码 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + */ + void sendMail(String templateCode, String from , String content , List tos , String title); + + /** + * 执行真正的邮件发送 + * 注意,该方法仅仅提供给 MQ Consumer 使用 + * + * @param message 邮件 + */ + void doSendMail(MailSendMessage message); +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 1071eae5d2..b8101f0af7 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import javax.validation.Valid; import java.util.List; +import java.util.Map; /** * 邮箱模版服务类 @@ -18,6 +19,7 @@ import java.util.List; */ public interface MailTemplateService { + void initLocalCache(); /** * 邮箱模版创建 * @@ -62,6 +64,13 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** + *从缓存中获取邮箱模版 + * + * @param code 模板编码 + * @return 邮箱模板 + */ + MailTemplateDO getMailTemplateByCodeFromCache(String code); /** * 发送邮件 @@ -69,4 +78,12 @@ public interface MailTemplateService { * @param mailReqVO 邮件发送信息 */ void sendMail(MailReqVO mailReqVO); + + /** + * 邮件模版内容合成 + * @param content 邮箱模版 + * @param params 合成参数 + * @return + */ + String formateMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index aa1fb1d467..36ca05213f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -16,8 +17,7 @@ import javax.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -47,8 +47,8 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 // TODO @wangjingyi:更新的就是自己,username 这样写,会重复呀。 - this.validateMailAccountOnlyByUserName(updateReqVO.getUsername()); + // username 要校验唯一 + this.validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 this.validateMailAccountExists(mailAccountDO.getId()); @@ -57,9 +57,10 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void delete(Long id) { - // TODO @wangjingyi:删除时,要判断是否有使用的模板 - // 校验是否存在 + // 校验是否存在账号 this.validateMailAccountExists(id); + // 校验是否存在关联模版 + this.validateMailTemplateByAccountId(id); mailAccountMapper.deleteById(id); } @@ -90,4 +91,11 @@ public class MailAccountServiceImpl implements MailAccountService { throw exception(MAIL_ACCOUNT_EXISTS); } } + + private void validateMailTemplateByAccountId(Long accountId){ + MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); + if (mailTemplateDO != null) { + throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + } + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index c6b492498b..bdceb0d727 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -4,14 +4,21 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; +import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.sql.Timestamp; +import java.util.Date; import java.util.List; +import java.util.Objects; /** * 邮箱日志实现类 @@ -35,4 +42,39 @@ public class MailLogServiceImpl implements MailLogService { public List getMailLogList(MailLogExportReqVO exportReqVO) { return mailLogMapper.selectList(exportReqVO); } + + @Override + public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.accountId(mailAccountDO.getId()); + logDOBuilder.content(content); + logDOBuilder.title(title); + logDOBuilder.templateCode(mailTemplateDO.getCode()); + logDOBuilder.templateId(mailTemplateDO.getId()); + logDOBuilder.to(tos.toString()); + logDOBuilder.sendTime(new Date()); + logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() + : MailSendStatusEnum.IGNORE.getStatus()); + + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } + + @Override + public Long updateSmsSendResult(Long logId, String result) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId); + logDOBuilder.sendResult(result); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + return logId; + } + + public Long create(){ + MailLogDO mailLogDO = new MailLogDO(); + mailLogMapper.insert(mailLogDO); + return mailLogDO.getId(); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java new file mode 100644 index 0000000000..61e428048d --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -0,0 +1,107 @@ +package cn.iocoder.yudao.module.system.service.mail.impl; + + +import cn.hutool.extra.mail.MailAccount; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; +import cn.iocoder.yudao.module.system.service.mail.MailLogService; +import cn.iocoder.yudao.module.system.service.mail.MailSendService; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import cn.iocoder.yudao.framework.mail.core.client.MailClient; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; + +/** + * 邮箱模版 服务实现类 + * + * @author wangjingyi + * @since 2022-03-21 + */ +@Service +@Validated +@Slf4j +public class MailSendServiceImpl implements MailSendService { + + @Resource + private MailTemplateMapper mailTemplateMapper; + @Resource + private MailAccountMapper mailAccountMapper; + @Resource + private MailTemplateService mailTemplateService; + @Resource + private MailLogService mailLogService; + @Resource + private MailClientFactory mailClientFactory; + @Resource + private MailProducer mailProducer; + + + @Override + public void sendMail(String templateCode, String from , String content , List tos , String title) { + // TODO @@wangjingyi:发送的时候,参考下短信; + MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); + // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 + Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from", from + ); + Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); + content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); + + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); + + // 发送 MQ 消息,异步执行发送短信 + if (isSend) { + mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + } + } + + @Override + public void doSendMail(MailSendMessage message) { + MailClient mailClient = mailClientFactory.getMailClient(); + String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + mailLogService.updateSmsSendResult(message.getLogId() , result); + } + + private MailTemplateDO checkMailTemplateValid(String templateCode) { + MailTemplateDO mailTemplateDO = mailTemplateService.getMailTemplateByCodeFromCache(templateCode); + if (mailTemplateDO == null){ + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + return mailTemplateDO; + } + + private void validateMailTemplateExists(Long id) { + if (mailTemplateMapper.selectById(id) == null) { + throw exception(MAIL_TEMPLATE_NOT_EXISTS); + } + } + + private void validateMailTemplateOnlyByCode(String code){ + if (mailTemplateMapper.selectOneByCode(code) != null) { + throw exception(MAIL_TEMPLATE_EXISTS); + } + } +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 2bd74ac4cc..e1d2121863 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; @@ -13,14 +15,18 @@ import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Date; import java.util.List; import java.util.Map; @@ -36,6 +42,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL */ @Service @Validated +@Slf4j public class MailTemplateServiceImpl implements MailTemplateService { @Resource @@ -43,6 +50,38 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailAccountMapper mailAccountMapper; + private volatile List mailTemplateDOList; + + /** + * 邮件模板缓存 + * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailTemplateCache; + + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + if(maxUpdateTime == null){ + mailTemplateDOList = mailTemplateMapper.selectList(); + }else{ + if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ + return; + } + } + if (CollUtil.isEmpty(mailTemplateDOList)) { + return; + } + + // 写入缓存 + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); + log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); + } + @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 @@ -54,11 +93,9 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // code 要校验唯一 - this.validateMailTemplateOnlyByCode(updateReqVO.getCode()); // TODO @wangjingyi:code 这样写,修改自己会有问题 - MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailTemplateExists(mailTemplateDO.getId()); + this.validateMailTemplateExists(updateReqVO.getId()); + MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); } @@ -80,6 +117,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public List getMailTemplateList() {return mailTemplateMapper.selectList();} + @Override + public MailTemplateDO getMailTemplateByCodeFromCache(String code) { + return mailTemplateCache.get(code); + } + @Override public void sendMail(MailReqVO mailReqVO) { // TODO @@wangjingyi:发送的时候,参考下短信; @@ -102,6 +144,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + @Override + public String formateMailTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + private void validateMailTemplateExists(Long id) { if (mailTemplateMapper.selectById(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); From 0b0e37a3d50f05b6518acdaed2f761a81f9bfd17 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 2 May 2022 23:21:45 +0800 Subject: [PATCH 17/65] =?UTF-8?q?code=20review=20=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 6 +++++- .../admin/mail/MailTemplateController.java | 3 +++ .../mail/vo/account/MailAccountPageReqVO.java | 1 + .../service/mail/MailAccountService.java | 1 - .../system/service/mail/MailLogService.java | 19 ++++++++++------- .../service/mail/MailTemplateService.java | 1 + .../mail/impl/MailAccountServiceImpl.java | 21 ++++++++++++------- .../service/mail/impl/MailLogServiceImpl.java | 3 ++- .../mail/impl/MailSendServiceImpl.java | 2 +- .../mail/impl/MailTemplateServiceImpl.java | 6 ++++++ 10 files changed, 44 insertions(+), 19 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index c16c7a60ba..864c106d63 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -24,7 +24,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - @Api(tags = "管理后台 - 邮件账号") @RestController @RequestMapping("/system/mail-account") @@ -57,6 +56,9 @@ public class MailAccountController { return success(true); } + // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + @GetMapping("/get") @ApiOperation("获得邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -74,6 +76,8 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") public CommonResult> getSimpleMailAccountList() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index cffd7f980d..f75c8daadd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -29,6 +29,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { + // TODO @wangjingyi:private @Autowired MailTemplateService mailTempleService; @@ -55,6 +56,8 @@ public class MailTemplateController { return success(true); } + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 520f319982..2ae2ad1624 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -12,6 +12,7 @@ import lombok.ToString; @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountPageReqVO extends PageParam { + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index c1289154f8..e8937d9730 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; import java.util.List; - /** * 邮箱账号 Service 接口 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 0a5d25ba2c..f5d4174111 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail; - import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -11,14 +10,16 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; /** - * 邮箱日志服务类 + * 邮箱日志服务类 * * @author wangjingyi * @since 2022-03-21 */ public interface MailLogService { + /** * 邮箱日志分页 + * * @param pageVO * @return */ @@ -26,6 +27,7 @@ public interface MailLogService { /** * 邮箱日志数组信息 + * * @param exportReqVO * @return */ @@ -33,13 +35,14 @@ public interface MailLogService { /** * 创建邮箱日志 - * @param mailAccountDO 邮箱账号信息 + * + * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index b8101f0af7..99b8fafeff 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -20,6 +20,7 @@ import java.util.Map; public interface MailTemplateService { void initLocalCache(); + /** * 邮箱模版创建 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 36ca05213f..06945127cf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** - * 邮箱账号 Service 实现类 + * 邮箱账号 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -39,28 +39,34 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); + validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); + + // 更新 return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 - this.validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 + validateMailAccountExists(updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); + validateMailAccountExists(mailAccountDO.getId()); + + // 更新 mailAccountMapper.updateById(mailAccountDO); } @Override public void delete(Long id) { // 校验是否存在账号 - this.validateMailAccountExists(id); + validateMailAccountExists(id); // 校验是否存在关联模版 - this.validateMailTemplateByAccountId(id); + validateMailTemplateByAccountId(id); + + // 删除 mailAccountMapper.deleteById(id); } @@ -95,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService { private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS throw exception(MAIL_RELATE_TEMPLATE_EXISTS); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index bdceb0d727..7c1b277da0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; @@ -62,6 +61,7 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } + // TODO @wangjingyi:不需要返回 id 呀 @Override public Long updateSmsSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); @@ -72,6 +72,7 @@ public class MailLogServiceImpl implements MailLogService { return logId; } + // TODO @wangjingyi:无用的方法,需要进行删除 public Long create(){ MailLogDO mailLogDO = new MailLogDO(); mailLogMapper.insert(mailLogDO); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 61e428048d..f2146f0270 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail.impl; - import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; @@ -80,6 +79,7 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 MailClient mailClient = mailClientFactory.getMailClient(); String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); mailLogService.updateSmsSendResult(message.getLogId() , result); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index e1d2121863..f3d85841ef 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -62,6 +62,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 @Override @PostConstruct public void initLocalCache() { @@ -85,9 +86,11 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { // code 要校验唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 this.validateMailTemplateOnlyByCode(createReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); + // TODO @wangjingyi:mq 更新 return mailTemplateDO.getId(); } @@ -97,6 +100,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { this.validateMailTemplateExists(updateReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); + // TODO @wangjingyi:mq 更新 } @Override @@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); + // TODO @wangjingyi:mq 更新 } @Override @@ -144,6 +149,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); } + // TODO @@wangjingyi:单词拼写错误 @Override public String formateMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From ea92b8412173b0ef0c65e30e9cbebcd56e029ed6 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Wed, 4 May 2022 22:31:12 +0800 Subject: [PATCH 18/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4mail-module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-framework/pom.xml | 1 - .../pom.xml | 65 ------------------ .../config/YudaoMailAutoConfiguration.java | 21 ------ .../mail/core/client/MailClient.java | 23 ------- .../mail/core/client/MailClientFactory.java | 5 -- .../mail/core/client/MailCodeMapping.java | 17 ----- .../mail/core/client/MailCommonResult.java | 68 ------------------- .../core/client/dto/MailReceiveRespDTO.java | 48 ------------- .../mail/core/client/dto/MailSendRespDTO.java | 18 ----- .../core/client/dto/MailTemplateRespDTO.java | 31 --------- .../core/client/impl/AbstractMailClient.java | 14 ---- .../client/impl/MailClientFactoryImpl.java | 39 ----------- .../client/impl/hutool/HutoolMailClient.java | 29 -------- .../impl/hutool/HutoolMailCodeMapping.java | 20 ------ .../mail/core/enums/MailChannelEnum.java | 32 --------- .../MailFrameworkErrorCodeConstants.java | 47 ------------- .../enums/MailTemplateAuditStatusEnum.java | 21 ------ .../core/property/MailChannelProperties.java | 52 -------------- .../system/enums/ErrorCodeConstants.java | 18 +++-- .../yudao-module-system-biz/pom.xml | 4 -- .../convert/mail/MailTemplateConvert.java | 4 -- .../mail/impl/MailSendServiceImpl.java | 10 +-- 22 files changed, 14 insertions(+), 573 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 42c887c561..73bb614cd7 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -30,7 +30,6 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms - yudao-spring-boot-starter-biz-mail yudao-spring-boot-starter-activiti yudao-spring-boot-starter-biz-pay yudao-spring-boot-starter-biz-weixin diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml deleted file mode 100644 index 8cca217789..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - cn.iocoder.boot - yudao-framework - ${revision} - - 4.0.0 - yudao-spring-boot-starter-biz-mail - jar - - - - cn.iocoder.boot - yudao-common - - - - - org.springframework.boot - spring-boot-starter - - - - - io.opentracing - opentracing-util - - - - - cn.iocoder.boot - yudao-spring-boot-starter-test - test - - - - - com.google.guava - guava - true - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - - - - jakarta.validation - jakarta.validation-api - - - org.projectlombok - lombok - - - - \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java deleted file mode 100644 index c83b1e5f1e..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/config/YudaoMailAutoConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.config; - -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.client.impl.MailClientFactoryImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * 邮箱配置类 - * - * @author 芋道源码 - */ -@Configuration -public class YudaoMailAutoConfiguration { - - @Bean - public MailClientFactory mailClientFactory() { - return new MailClientFactoryImpl(); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java deleted file mode 100644 index a17260410a..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClient.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import java.util.List; - -/** - * 邮件客户端,用于对接各邮箱平台的 SDK,实现邮件发送等功能 - * - * @author wangjingyi - * @date 2021/4/19 19:21 - */ -public interface MailClient { - - /** - * 发送邮件 - * - * @param from 邮箱账号 - * @param content 内容 - * @param title 标题 - * @param tos 收件人 - * @return 邮件发送结果 - */ - String sendMail(String from, String content, String title, List tos); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java deleted file mode 100644 index 3244dfe761..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailClientFactory.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -public interface MailClientFactory { - MailClient getMailClient(); -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java deleted file mode 100644 index c33b4be3e3..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCodeMapping.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -import java.util.function.Function; - -/** - * 将 API 的错误码,转换为通用的错误码 - * - * @see MailCommonResult - * @see MailFrameworkErrorCodeConstants - * - * @author 芋道源码 - */ -public interface MailCodeMapping extends Function { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java deleted file mode 100644 index a53a3b9897..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/MailCommonResult.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client; - -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import cn.iocoder.yudao.framework.mail.core.enums.MailFrameworkErrorCodeConstants; - -/** - * 短信的 CommonResult 拓展类 - * - * 考虑到不同的平台,返回的 code 和 msg 是不同的,所以统一额外返回 {@link #apiCode} 和 {@link #apiMsg} 字段 - * - * 另外,一些短信平台(例如说阿里云、腾讯云)会返回一个请求编号,用于排查请求失败的问题,我们设置到 {@link #apiRequestId} 字段 - * - * @author 芋道源码 - */ -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailCommonResult extends CommonResult { - - /** - * API 返回错误码 - * - * 由于第三方的错误码可能是字符串,所以使用 String 类型 - */ - private String apiCode; - /** - * API 返回提示 - */ - private String apiMsg; - - /** - * API 请求编号 - */ - private String apiRequestId; - - private MailCommonResult() { - } - - public static MailCommonResult build(String apiCode, String apiMsg, String apiRequestId, - T data, MailCodeMapping codeMapping) { - Assert.notNull(codeMapping, "参数 codeMapping 不能为空"); - MailCommonResult result = new MailCommonResult().setApiCode(apiCode).setApiMsg(apiMsg).setApiRequestId(apiRequestId); - result.setData(data); - // 翻译错误码 - if (codeMapping != null) { - ErrorCode errorCode = codeMapping.apply(apiCode); - if (errorCode == null) { - errorCode = MailFrameworkErrorCodeConstants.MAIL_UNKNOWN; - } - result.setCode(errorCode.getCode()).setMsg(errorCode.getMsg()); - } - return result; - } - - public static MailCommonResult error(Throwable ex) { - MailCommonResult result = new MailCommonResult<>(); - result.setCode(MailFrameworkErrorCodeConstants.EXCEPTION.getCode()); - result.setMsg(ExceptionUtil.getRootCauseMessage(ex)); - return result; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java deleted file mode 100644 index 11f27f58a6..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailReceiveRespDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -import java.util.Date; - -/** - * 消息接收 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailReceiveRespDTO { - - /** - * 是否接收成功 - */ - private Boolean success; - /** - * API 接收结果的编码 - */ - private String errorCode; - /** - * API 接收结果的说明 - */ - private String errorMsg; - - /** - * 手机号 - */ - private String mobile; - /** - * 用户接收时间 - */ - private Date receiveTime; - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - /** - * 短信日志编号 - * - * 对应 SysSmsLogDO 的编号 - */ - private Long logId; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java deleted file mode 100644 index b4a94a6347..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailSendRespDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信发送 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailSendRespDTO { - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java deleted file mode 100644 index 14bdeacd89..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/dto/MailTemplateRespDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.dto; - -import lombok.Data; - -/** - * 短信模板 Response DTO - * - * @author 芋道源码 - */ -@Data -public class MailTemplateRespDTO { - - /** - * 模板编号 - */ - private String id; - /** - * 短信内容 - */ - private String content; - /** - * 审核状态 - * - */ - private Integer auditStatus; - /** - * 审核未通过的理由 - */ - private String auditReason; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java deleted file mode 100644 index 097c8e095f..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/AbstractMailClient.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; - -/** - * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 - * - * @author zzf - * @date 2021/2/1 9:28 - */ -@Slf4j -public abstract class AbstractMailClient implements MailClient { -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java deleted file mode 100644 index 9923bd3df4..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/MailClientFactoryImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl; - -import cn.iocoder.yudao.framework.mail.core.client.MailClient; -import cn.iocoder.yudao.framework.mail.core.client.impl.hutool.HutoolMailClient; -import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -@Validated -@Slf4j -public class MailClientFactoryImpl implements MailClientFactory { - - private final ConcurrentMap channelCodeClients = new ConcurrentHashMap<>(); - - public MailClientFactoryImpl (){ - Arrays.stream(MailChannelEnum.values()).forEach(mailChannelEnum -> { - AbstractMailClient abstractMailClient = createMailClient(mailChannelEnum); - channelCodeClients.put(mailChannelEnum.getCode() , abstractMailClient); - }); - } - - private AbstractMailClient createMailClient(MailChannelEnum mailChannelEnum) { - switch (mailChannelEnum){ - case HUTOOL: return new HutoolMailClient(); - } - // 创建失败,错误日志 + 抛出异常 - log.error("[createMailClient][配置({}) 找不到合适的客户端实现]" , mailChannelEnum); - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", mailChannelEnum)); - } - - @Override - public MailClient getMailClient() { - return channelCodeClients.get("HUTOOL"); - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java deleted file mode 100644 index 457ad7e370..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailClient.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.hutool.extra.mail.MailUtil; -import cn.iocoder.yudao.framework.mail.core.client.impl.AbstractMailClient; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; - - -/** - * 邮件客户端实现 - * - * @author wangjingyi - * @date 2021/4/25 14:25 - */ -@Slf4j -public class HutoolMailClient extends AbstractMailClient { - - @Override - public String sendMail(String from, String content, String title, List tos) { - try{ - return MailUtil.send(from , title , content , false , null); - }catch (Exception e){ - log.error(e.getMessage()); - } - return ""; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java deleted file mode 100644 index 711d369502..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/client/impl/hutool/HutoolMailCodeMapping.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.client.impl.hutool; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.framework.mail.core.client.MailCodeMapping; - -/** - * 阿里云的 SmsCodeMapping 实现类 - * - * 参见 https://help.aliyun.com/document_detail/101346.htm 文档 - * - * @author 芋道源码 - */ -public class HutoolMailCodeMapping implements MailCodeMapping { - - @Override - public ErrorCode apply(String apiCode) { - return null; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java deleted file mode 100644 index 51d2f1fcae..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailChannelEnum.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.hutool.core.util.ArrayUtil; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信渠道枚举 - * - * @author zzf - * @date 2021/1/25 10:56 - */ -@Getter -@AllArgsConstructor -public enum MailChannelEnum { - HUTOOL("HUTOOL" , "HUTOOL"), - ; - - /** - * 编码 - */ - private final String code; - /** - * 名字 - */ - private final String name; - - public static MailChannelEnum getByCode(String code) { - return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java deleted file mode 100644 index e5ef74cf33..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailFrameworkErrorCodeConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; - -/** - * 短信框架的错误码枚举 - * - * 短信框架,使用 2-001-000-000 段 - * - * @author 芋道源码 - */ -public interface MailFrameworkErrorCodeConstants { - - ErrorCode MAIL_UNKNOWN = new ErrorCode(2001000000, "未知错误,需要解析"); - - // ========== 权限 / 限流等相关 2001000100 ========== - - ErrorCode SMS_PERMISSION_DENY = new ErrorCode(2001000100, "没有发送短信的权限"); - // 云片:可以配置 IP 白名单,只有在白名单中才可以发送短信 - ErrorCode SMS_IP_DENY = new ErrorCode(2001000100, "IP 不允许发送短信"); - - // 阿里云:将短信发送频率限制在正常的业务限流范围内。默认短信验证码:使用同一签名,对同一个手机号验证码,支持 1 条 / 分钟,5 条 / 小时,累计 10 条 / 天。 - ErrorCode SMS_SEND_BUSINESS_LIMIT_CONTROL = new ErrorCode(2001000102, "指定手机的发送限流"); - // 阿里云:已经达到您在控制台设置的短信日发送量限额值。在国内消息设置 > 安全设置,修改发送总量阈值。 - ErrorCode SMS_SEND_DAY_LIMIT_CONTROL = new ErrorCode(2001000103, "每天的发送限流"); - - ErrorCode SMS_SEND_CONTENT_INVALID = new ErrorCode(2001000104, "短信内容有敏感词"); - - // ========== 模板相关 2001000200 ========== - ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000200, "短信模板不合法"); // 包括短信模板不存在 - ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000201, "模板参数不正确"); - - // ========== 签名相关 2001000300 ========== - ErrorCode SMS_SIGN_INVALID = new ErrorCode(2001000300, "短信签名不可用"); - - // ========== 账户相关 2001000400 ========== - ErrorCode SMS_ACCOUNT_MONEY_NOT_ENOUGH = new ErrorCode(2001000400, "账户余额不足"); - ErrorCode SMS_ACCOUNT_INVALID = new ErrorCode(2001000401, "apiKey 不存在"); - - // ========== 其它相关 2001000900 开头 ========== - ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失"); - ErrorCode SMS_MOBILE_INVALID = new ErrorCode(2001000901, "手机格式不正确"); - ErrorCode SMS_MOBILE_BLACK = new ErrorCode(2001000902, "手机号在黑名单中"); - - ErrorCode EXCEPTION = new ErrorCode(2001000999, "调用异常"); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java deleted file mode 100644 index 95c3c31a3e..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/enums/MailTemplateAuditStatusEnum.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信模板的审核状态枚举 - * - * @author 芋道源码 - */ -@AllArgsConstructor -@Getter -public enum MailTemplateAuditStatusEnum { - - CHECKING(1), - SUCCESS(2), - FAIL(3); - - private final Integer status; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java deleted file mode 100644 index 1f19ac12bd..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-mail/src/main/java/cn/iocoder/yudao/framework/mail/core/property/MailChannelProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.framework.mail.core.property; - -import lombok.Data; -import cn.iocoder.yudao.framework.mail.core.enums.MailChannelEnum; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 短信渠道配置类 - * - * @author zzf - * @date 2021/1/25 17:01 - */ -@Data -@Validated -public class MailChannelProperties { - - /** - * 渠道编号 - */ - @NotNull(message = "短信渠道 ID 不能为空") - private Long id; - /** - * 短信签名 - */ - @NotEmpty(message = "短信签名不能为空") - private String signature; - /** - * 渠道编码 - * - * 枚举 {@link MailChannelEnum} - */ - @NotEmpty(message = "渠道编码不能为空") - private String code; - /** - * 短信 API 的账号 - */ - @NotEmpty(message = "短信 API 的账号不能为空") - private String apiKey; - /** - * 短信 API 的秘钥 - */ - @NotEmpty(message = "短信 API 的秘钥不能为空") - private String apiSecret; - /** - * 短信发送回调 URL - */ - private String callbackUrl; - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 07322ccd72..d514345dab 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -119,13 +119,17 @@ public interface ErrorCodeConstants { ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002018001, "社交解绑失败,非当前用户绑定"); ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002018002, "社交授权失败,找不到对应的用户"); - // ========== 邮箱账号 1002019000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002019000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002019001, "邮箱账号存在"); + // ========== 系统铭感词 1002019000 ========= + ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1002019000, "系统敏感词在所有标签中都不存在"); + ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1002019001, "系统敏感词已在标签中存在"); - // ========== 邮箱模版 1002020000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002020000 , "邮箱模版不存在"); - ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002020001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002020002, "存在关联邮箱模版"); + // ========== 邮箱账号 1002020000 ========== + ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1002020000, "邮箱账号不存在"); + ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); + + // ========== 邮箱模版 1002021000 ========== + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); + ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml index 2240f3b955..e23ba8ab86 100644 --- a/yudao-module-system/yudao-module-system-biz/pom.xml +++ b/yudao-module-system/yudao-module-system-biz/pom.xml @@ -42,10 +42,6 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-dict - - cn.iocoder.boot - yudao-spring-boot-starter-biz-mail - cn.iocoder.boot yudao-spring-boot-starter-biz-data-permission diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 3f4693bcb0..35c6c0a9bc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -1,11 +1,7 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvertImpl; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index f2146f0270..bc4b496f1e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -13,10 +13,8 @@ import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; -import cn.iocoder.yudao.framework.mail.core.client.MailClientFactory; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import cn.iocoder.yudao.framework.mail.core.client.MailClient; import javax.annotation.Resource; import java.util.List; @@ -46,8 +44,6 @@ public class MailSendServiceImpl implements MailSendService { @Resource private MailLogService mailLogService; @Resource - private MailClientFactory mailClientFactory; - @Resource private MailProducer mailProducer; @@ -80,9 +76,9 @@ public class MailSendServiceImpl implements MailSendService { @Override public void doSendMail(MailSendMessage message) { // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - MailClient mailClient = mailClientFactory.getMailClient(); - String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - mailLogService.updateSmsSendResult(message.getLogId() , result); + //MailClient mailClient = mailClientFactory.getMailClient(); + //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); + //mailLogService.updateSmsSendResult(message.getLogId() , result); } private MailTemplateDO checkMailTemplateValid(String templateCode) { From 8bc5254e308ab0d774635f0629bc508f58c8041a Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 03:06:00 +0800 Subject: [PATCH 19/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E7=AE=B1=E8=B4=A6=E5=8F=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=20=E4=BF=AE=E6=94=B9=E6=A0=A1=E9=AA=8C=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/MailAccountController.java | 4 +- .../admin/mail/MailTemplateController.java | 25 ++--- .../mail/vo/account/MailAccountBaseVO.java | 4 - .../vo/account/MailAccountCreateReqVO.java | 6 ++ .../vo/account/MailAccountUpdateReqVO.java | 3 + .../mail/vo/template/MailTemplateRespVO.java | 4 + .../convert/mail/MailAccountConvert.java | 3 +- .../convert/mail/MailTemplateConvert.java | 7 +- .../dal/mysql/mail/MailAccountMapper.java | 17 ++++ .../dal/mysql/mail/MailTemplateMapper.java | 2 +- .../mail/MailTemplateRefreshConsumer.java | 29 ++++++ .../mail/MailAccountRefreshMessage.java | 19 ++++ .../mq/message/mail/MailSendMessage.java | 24 +++++ .../mail/MailTemplateRefreshMessage.java | 19 ++++ .../system/mq/producer/mail/MailProducer.java | 19 ++-- .../service/mail/MailAccountService.java | 5 + .../system/service/mail/MailLogService.java | 8 +- .../service/mail/MailTemplateService.java | 12 +-- .../mail/impl/MailAccountServiceImpl.java | 86 +++++++++++++--- .../service/mail/impl/MailLogServiceImpl.java | 13 +-- .../mail/impl/MailSendServiceImpl.java | 41 +++++--- .../mail/impl/MailTemplateServiceImpl.java | 98 +++++++++---------- 23 files changed, 318 insertions(+), 132 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index d514345dab..32ba7181eb 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -130,6 +130,6 @@ public interface ErrorCodeConstants { // ========== 邮箱模版 1002021000 ========== ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); - ErrorCode MAIL_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 864c106d63..17a305c481 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -57,7 +57,7 @@ public class MailAccountController { } // TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。 - // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 + // 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段 DONE @GetMapping("/get") @ApiOperation("获得邮箱账号") @@ -76,7 +76,7 @@ public class MailAccountController { return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); } - // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 + // TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回 DONE @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱账号精简列表") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index f75c8daadd..2fae6164b8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -29,9 +26,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { - // TODO @wangjingyi:private + // TODO @wangjingyi:private DONE @Autowired - MailTemplateService mailTempleService; + private MailTemplateService mailTempleService; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -56,13 +53,13 @@ public class MailTemplateController { return success(true); } - // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 + // TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议 DONE RespVO中需要BaseVO 中哪些字段 @GetMapping("/get") @ApiOperation("获得邮箱模版") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-template:get')") - public CommonResult getMailTemplate(@RequestParam("id") Long id) { + public CommonResult getMailTemplate(@RequestParam("id") Long id) { MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id); return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); } @@ -70,25 +67,17 @@ public class MailTemplateController { @GetMapping("/page") @ApiOperation("获得邮箱模版分页") @PreAuthorize("@ss.hasPermission('system:mail-template:query')") - public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { + public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); } @GetMapping("/list-all-simple") @ApiOperation(value = "获得邮箱模版精简列表") - public CommonResult> getSimpleTemplateList() { + public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); // 排序后,返回给前端 list.sort(Comparator.comparing(MailTemplateDO::getId)); return success(MailTemplateConvert.INSTANCE.convertList02(list)); } - - @PostMapping("/send") - @ApiOperation("发送邮件") - @PreAuthorize("@ss.hasPermission('system:mail-template:send')") - public CommonResult sendMail(@Valid @RequestBody MailReqVO mailReqVO){ - mailTempleService.sendMail(mailReqVO); - return success(true); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index d8650b52e8..b785b74cc0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -20,10 +20,6 @@ public class MailAccountBaseVO { @Email(message = "必须是Email格式") private String username; - @ApiModelProperty(value = "密码",required = true,example = "123456") - @NotNull(message = "密码必填") - private String password; - @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") @NotNull(message = "网站必填") private String host; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java index 8585e9d75c..476a3077aa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java @@ -1,14 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 邮箱账号创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailAccountCreateReqVO extends MailAccountBaseVO { + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java index 43a13ad18b..4544e95b55 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java @@ -18,4 +18,7 @@ public class MailAccountUpdateReqVO extends MailAccountBaseVO { @NotNull(message = "编号不能为空") private Long id; + @ApiModelProperty(value = "密码",required = true,example = "123456") + @NotNull(message = "密码必填") + private String password; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java new file mode 100644 index 0000000000..33683b1c58 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; + +public class MailTemplateRespVO extends MailTemplateBaseVO{ +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index 8dbfbc58d9..f2228e1702 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -4,6 +4,7 @@ import cn.hutool.extra.mail.MailAccount; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,7 +24,7 @@ public interface MailAccountConvert { List convertList02(List list); - default MailAccount convertAccount(MailAccountDO mailAccountDO){ + default MailAccount convertAccount(MailSendMessage mailAccountDO){ return new MailAccount() .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 35c6c0a9bc..87fd8efe7a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,9 +15,9 @@ public interface MailTemplateConvert { MailTemplateDO convert(MailTemplateBaseVO baseVO); - MailTemplateBaseVO convert(MailTemplateDO mailTemplateDO); + MailTemplateRespVO convert(MailTemplateDO mailTemplateDO); - PageResult convertPage(PageResult pageResult); + PageResult convertPage(PageResult pageResult); - List convertList02(List list); + List convertList02(List list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 651f5c75fd..420b24eeb2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -7,6 +7,9 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; @Mapper public interface MailAccountMapper extends BaseMapperX { @@ -25,4 +28,18 @@ public interface MailAccountMapper extends BaseMapperX { return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); }; + + default MailAccountDO selectByUserNameAndId(String userName,Long id){ + return selectOne(new QueryWrapperX() + .eqIfPresent("username" , userName) + .neIfPresent("id" , id)); + }; + + default MailAccountDO selectOneByFrom(String from){ + return selectOne(new QueryWrapperX() + .eqIfPresent("from" , from)); + }; + + @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") + Long selectCountByUpdateTimeGt(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java index a5cbf0b2a3..d7d1cd73c9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailTemplateMapper.java @@ -30,7 +30,7 @@ public interface MailTemplateMapper extends BaseMapperX { .eqIfPresent("code" , code)); }; - @Select("SELECT id FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + @Select("SELECT COUNT(*) FROM system_mail_template WHERE update_time > #{maxUpdateTime} LIMIT 1") Long selectByMaxUpdateTime(Date maxUpdateTime); default MailTemplateDO selectOneByAccountId(Long accountId){ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java new file mode 100644 index 0000000000..b4eac0165e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.system.mq.consumer.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; +import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 针对 {@link MailTemplateRefreshMessage} 的消费者 + * + * @author wangjingyi + */ +@Component +@Slf4j +public class MailTemplateRefreshConsumer extends AbstractChannelMessageListener { + + @Resource + private MailTemplateService mailTemplateService; + + @Override + public void onMessage(MailTemplateRefreshMessage message) { + log.info("[onMessage][收到 MailTemplate 刷新信息]"); + mailTemplateService.initLocalCache(); + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java new file mode 100644 index 0000000000..d5eafb04d9 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailAccountRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱账号的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailAccountRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-account.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 275a458250..3df7c6dcff 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -27,6 +27,16 @@ public class MailSendMessage extends AbstractStreamMessage { */ @NotNull(message = "邮箱地址不能为空") private String from; + /** + * 用户名 + */ + @NotNull(message = "用户名不能为空") + private String username; + /** + * 密码 + */ + @NotNull(message = "密码不能为空") + private String password; /** * 邮箱模板编号 */ @@ -45,6 +55,20 @@ public class MailSendMessage extends AbstractStreamMessage { * 内容 */ private String content; + /** + * 主机 + */ + @NotNull(message = "host不能为空") + private String host; + /** + * 端口 + */ + @NotNull(message = "端口号不能为空") + private Integer port; + /** + * 是否开启 SSL + */ + private Boolean sslEnable; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java new file mode 100644 index 0000000000..476411ca1b --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailTemplateRefreshMessage.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.mq.message.mail; + +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 邮箱模板的数据刷新 Message + * + * @author wangjingyi + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MailTemplateRefreshMessage extends AbstractChannelMessage { + @Override + public String getChannel() { + return "system.mail-template.refresh"; + } +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index ed82c24a4d..db8bbebf64 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -4,7 +4,9 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; +import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; @@ -28,18 +30,18 @@ public class MailProducer { private RedisMQTemplate redisMQTemplate; /** - * 发送 {@link SmsChannelRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailChannelRefreshMessage() { - SmsChannelRefreshMessage message = new SmsChannelRefreshMessage(); + public void sendMailTemplateRefreshMessage() { + MailTemplateRefreshMessage message = new MailTemplateRefreshMessage(); redisMQTemplate.send(message); } /** - * 发送 {@link SmsTemplateRefreshMessage} 消息 + * 发送 {@link MailTemplateRefreshMessage} 消息 */ - public void sendMailTemplateRefreshMessage() { - SmsTemplateRefreshMessage message = new SmsTemplateRefreshMessage(); + public void sendMailAccountRefreshMessage() { + MailAccountRefreshMessage message = new MailAccountRefreshMessage(); redisMQTemplate.send(message); } @@ -56,6 +58,11 @@ public class MailProducer { MailSendMessage message = new MailSendMessage(); message.setContent(content); message.setFrom(mailAccountDO.getFrom()); + message.setHost(mailAccountDO.getHost()); + message.setPort(mailAccountDO.getPort()); + message.setPassword(mailAccountDO.getPassword()); + message.setUsername(mailAccountDO.getUsername()); + message.setSslEnable(mailAccountDO.getSslEnable()); message.setTemplateCode(mailTemplateDO.getCode()); message.setTitle(title); message.setTos(tos); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index e8937d9730..fe0615f4f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -17,6 +17,11 @@ import java.util.List; */ public interface MailAccountService { + /** + * 初始化邮箱账号的本地缓存 + */ + void initLocalCache(); + /** * 创建邮箱账号 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index f5d4174111..da35012e25 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -46,5 +46,11 @@ public interface MailLogService { */ Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); - Long updateSmsSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId + */ + void updateMailSendResult(Long logId, String result); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 99b8fafeff..873d337f4a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -19,6 +19,9 @@ import java.util.Map; */ public interface MailTemplateService { + /** + * 初始化邮箱模版的本地缓存 + */ void initLocalCache(); /** @@ -73,18 +76,11 @@ public interface MailTemplateService { */ MailTemplateDO getMailTemplateByCodeFromCache(String code); - /** - * 发送邮件 - * - * @param mailReqVO 邮件发送信息 - */ - void sendMail(MailReqVO mailReqVO); - /** * 邮件模版内容合成 * @param content 邮箱模版 * @param params 合成参数 * @return */ - String formateMailTemplateContent(String content, Map params); + String formatMailTemplateContent(String content, Map params); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 06945127cf..3ae44693ba 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,20 +1,28 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.util.Date; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -28,6 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; */ @Service @Validated +@Slf4j public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -36,26 +45,71 @@ public class MailAccountServiceImpl implements MailAccountService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource + private MailProducer mailProducer; + + /** + * 邮箱账号缓存 + * key:邮箱账号编码 {@link MailAccountDO#getId()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map mailAccountCache; + + /** + * 缓存菜单的最大更新时间,用于后续的增量轮询,判断是否有更新 + */ + private volatile Date maxUpdateTime; + + @Override + @PostConstruct + public void initLocalCache() { + List mailAccountDOList = this.loadMailAccountIfUpdate(maxUpdateTime); + if (CollUtil.isEmpty(mailAccountDOList)) { + return; + } + + // 写入缓存 + mailAccountCache = CollectionUtils.convertMap(mailAccountDOList, MailAccountDO::getId); + maxUpdateTime = CollectionUtils.getMaxValue(mailAccountDOList, MailAccountDO::getUpdateTime); + log.info("[initLocalCache][初始化 MailAccount 数量为 {}]", mailAccountDOList.size()); + } + + private List loadMailAccountIfUpdate(Date maxUpdateTime) { + //第一步 判断是否需要更新 + if(null == maxUpdateTime){ // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailAccountIfUpdate][首次加载全量账号信息]"); + }else{ // 判断数据库中是否有更新的账号信息 + if (mailAccountMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { + return null; + } + log.info("[loadMailAccountIfUpdate][增量加载全量账号信息]"); + } + return mailAccountMapper.selectList(); + } + @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 - validateMailAccountOnlyByUserName(createReqVO.getUsername()); + this.validateMailAccountOnlyByUserName(createReqVO.getUsername()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO); mailAccountMapper.insert(mailAccountDO); // 更新 + mailProducer.sendMailAccountRefreshMessage(); return mailAccountDO.getId(); } @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 - validateMailAccountExists(updateReqVO.getId()); + // username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己 DONE + this.validateMailAccountOnlyByUserNameAndId(updateReqVO.getUsername(),updateReqVO.getId()); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 validateMailAccountExists(mailAccountDO.getId()); // 更新 + mailProducer.sendMailAccountRefreshMessage(); mailAccountMapper.updateById(mailAccountDO); } @@ -65,9 +119,10 @@ public class MailAccountServiceImpl implements MailAccountService { validateMailAccountExists(id); // 校验是否存在关联模版 validateMailTemplateByAccountId(id); - // 删除 mailAccountMapper.deleteById(id); + // 更新 + mailProducer.sendMailAccountRefreshMessage(); } @Override @@ -92,17 +147,26 @@ public class MailAccountServiceImpl implements MailAccountService { } private void validateMailAccountOnlyByUserName(String userName){ - MailAccountDO mailAccountDO = mailAccountMapper.selectByUserName(userName); - if (mailAccountDO != null) { - throw exception(MAIL_ACCOUNT_EXISTS); - } + mailAccountCache.forEach((key,value)->{ + if(value.getUsername().equals(userName)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + }); + } + private void validateMailAccountOnlyByUserNameAndId(String userName,Long id){ + mailAccountCache.forEach((key , value)->{ + if (value.getUsername().equals(userName)){ + if (!key.equals(id)){ + throw exception(MAIL_ACCOUNT_EXISTS); + } + } + }); } - private void validateMailTemplateByAccountId(Long accountId){ MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId); if (mailTemplateDO != null) { - // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS - throw exception(MAIL_RELATE_TEMPLATE_EXISTS); + // TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS DONE + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); } } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 7c1b277da0..76a7198aba 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -8,13 +8,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailLogMapper; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; -import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.Objects; @@ -61,21 +59,14 @@ public class MailLogServiceImpl implements MailLogService { return mailLogDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 + // TODO @wangjingyi:不需要返回 id 呀 DONE @Override - public Long updateSmsSendResult(Long logId, String result) { + public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); logDOBuilder.id(logId); logDOBuilder.sendResult(result); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); - return logId; } - // TODO @wangjingyi:无用的方法,需要进行删除 - public Long create(){ - MailLogDO mailLogDO = new MailLogDO(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index bc4b496f1e..6b0cccd832 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; @@ -21,8 +22,7 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** * 邮箱模版 服务实现类 @@ -49,36 +49,47 @@ public class MailSendServiceImpl implements MailSendService { @Override public void sendMail(String templateCode, String from , String content , List tos , String title) { - // TODO @@wangjingyi:发送的时候,参考下短信; + // TODO @@wangjingyi:发送的时候,参考下短信;DONE + //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(mailTemplateDO.getStatus()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", from - ); + //校验账号信息是否合法 + MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = mailTemplateService.formateMailTemplateContent(mailTemplateDO.getContent(), params); + content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); // 后续功能 TODO :附件查询 //List fileIds = mailSendVO.getFileIds(); - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - // 发送 MQ 消息,异步执行发送短信 if (isSend) { mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); } } + private MailAccountDO checkMailAccountValid(String from) { + MailAccountDO mailAccountDO = mailAccountMapper.selectOneByFrom(from); + if(null == mailAccountDO){ + throw exception(MAIL_ACCOUNT_NOT_EXISTS); + } + return mailAccountDO; + } + @Override public void doSendMail(MailSendMessage message) { - // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 - //MailClient mailClient = mailClientFactory.getMailClient(); - //String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos()); - //mailLogService.updateSmsSendResult(message.getLogId() , result); + // TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的 DONE + //装载账号信息 + MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); + //发送邮件 + try{ + String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + mailLogService.updateMailSendResult(message.getLogId() , messageId); + }catch (Exception e){ + mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + } + } private MailTemplateDO checkMailTemplateValid(String templateCode) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index f3d85841ef..89a0b43eae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; +import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -48,59 +49,53 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; @Resource - private MailAccountMapper mailAccountMapper; - - private volatile List mailTemplateDOList; + private MailProducer mailProducer; /** * 邮件模板缓存 - * key:邮箱模板编码 {@link MailTemplateDO#getCode()} + * key:邮箱模板编码 {@link MailTemplateDO#getId()} * * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 */ - private volatile Map mailTemplateCache; + private volatile Map mailTemplateCache; private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 + // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { - if(maxUpdateTime == null){ - mailTemplateDOList = mailTemplateMapper.selectList(); - }else{ - if(mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime)<=0){ - return; - } - } + List mailTemplateDOList = this.loadMailTemplateIfUpdate(maxUpdateTime); if (CollUtil.isEmpty(mailTemplateDOList)) { return; } // 写入缓存 - mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getCode); + mailTemplateCache = CollectionUtils.convertMap(mailTemplateDOList, MailTemplateDO::getId); maxUpdateTime = CollectionUtils.getMaxValue(mailTemplateDOList, MailTemplateDO::getUpdateTime); log.info("[initLocalCache][初始化 mailTemplate 数量为 {}]", mailTemplateDOList.size()); } @Override public Long create(MailTemplateCreateReqVO createReqVO) { - // code 要校验唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 - this.validateMailTemplateOnlyByCode(createReqVO.getCode()); + //要校验存在 + this.validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); return mailTemplateDO.getId(); } @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { - // 校验是否存在 - this.validateMailTemplateExists(updateReqVO.getId()); + // 校验是否唯一 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -108,7 +103,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { // 校验是否存在 this.validateMailTemplateExists(id); mailTemplateMapper.deleteById(id); - // TODO @wangjingyi:mq 更新 + // TODO @wangjingyi:mq 更新 DONE + mailProducer.sendMailTemplateRefreshMessage(); } @Override @@ -127,43 +123,45 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } + // TODO @@wangjingyi:单词拼写错误 DONE @Override - public void sendMail(MailReqVO mailReqVO) { - // TODO @@wangjingyi:发送的时候,参考下短信; - MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId()); - //查询账号信息 - MailAccountDO mailAccountDO = mailAccountMapper.selectOne( - "from", mailReqVO.getFrom() - ); - String content = mailReqVO.getContent(); - Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); - content = StrUtil.format(mailTemplateDO.getContent(), params); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - - //装载账号信息 - MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); - - //发送 - MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false); - } - - // TODO @@wangjingyi:单词拼写错误 - @Override - public String formateMailTemplateContent(String content, Map params) { + public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); } private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { + if (mailTemplateCache.get(id) == null) { throw exception(MAIL_TEMPLATE_NOT_EXISTS); } } - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); + private void validateMailTemplateOnlyByCode(Long id ,String code){ + mailTemplateCache.forEach((key,value)->{ + if (value.getCode().equals(code)){ + if (!key.equals(id)){ + throw exception(MAIL_TEMPLATE_EXISTS); + } + } + }); + } + /** + * 如果邮件模板发生变化,从数据库中获取最新的全量邮件模板。 + * 如果未发生变化,则返回空 + * + * @param maxUpdateTime 当前邮件模板的最大更新时间 + * @return 邮件模板列表 + */ + private List loadMailTemplateIfUpdate(Date maxUpdateTime) { + // 第一步,判断是否要更新。 + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadMailTemplateIfUpdate][首次加载全量邮件模板]"); + } else { // 判断数据库中是否有更新的邮件模板 + if (mailTemplateMapper.selectByMaxUpdateTime(maxUpdateTime) == 0) { + return null; + } + log.info("[loadSmsTemplateIfUpdate][增量加载全量邮件模板]"); } + // 第二步,如果有更新,则从数据库加载所有邮件模板 + return mailTemplateMapper.selectList(); } } From 8d6a4d40a08a6f265a848d412ad53c3278578f39 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 04:36:32 +0800 Subject: [PATCH 20/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/dataobject/mail/MailAccountDO.java | 2 ++ .../yudao/module/system/dal/mysql/mail/MailAccountMapper.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index d285adec5b..7b17104ec1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -24,6 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ + @TableField("`from`") private String from; /** * 用户名 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index 420b24eeb2..e869ecf227 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("form" , pageReqVO.getFrom()) + .likeIfPresent("from" , pageReqVO.getFrom()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) From c3335ba2cacf436b14da2dbe95994fd29b7dc514 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:41:11 +0800 Subject: [PATCH 21/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/vo/account/MailAccountBaseVO.java | 4 ++-- .../admin/mail/vo/account/MailAccountPageReqVO.java | 2 +- .../system/dal/dataobject/mail/MailAccountDO.java | 3 +-- .../system/dal/mysql/mail/MailAccountMapper.java | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java index b785b74cc0..8e392d4766 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java @@ -13,11 +13,11 @@ public class MailAccountBaseVO { @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "邮箱必填") - private String from; + @Email(message = "必须是Email格式") + private String fromAddress; @ApiModelProperty(value = "用户名",required = true,example = "yudao") @NotNull(message = "用户名必填") - @Email(message = "必须是Email格式") private String username; @ApiModelProperty(value = "网站",required = true,example = "www.iocoder.cn") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java index 2ae2ad1624..327c8465de 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountPageReqVO.java @@ -14,7 +14,7 @@ import lombok.ToString; public class MailAccountPageReqVO extends PageParam { @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") - private String from; + private String fromAddress; @ApiModelProperty(value = "用户名" , required = true , example = "yudao") private String username; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 7b17104ec1..910440df7a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -25,8 +25,7 @@ public class MailAccountDO extends BaseDO { /** * 邮箱 */ - @TableField("`from`") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index e869ecf227..1e4f263acd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -16,7 +16,7 @@ public interface MailAccountMapper extends BaseMapperX { default PageResult selectPage(MailAccountPageReqVO pageReqVO) { return selectPage(pageReqVO, new QueryWrapperX() - .likeIfPresent("from" , pageReqVO.getFrom()) + .likeIfPresent("from_address" , pageReqVO.getFromAddress()) .likeIfPresent("host" , pageReqVO.getHost()) .likeIfPresent("username" , pageReqVO.getUsername()) .eqIfPresent("password" , pageReqVO.getPassword()) @@ -27,18 +27,18 @@ public interface MailAccountMapper extends BaseMapperX { default MailAccountDO selectByUserName(String userName){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName)); - }; + } default MailAccountDO selectByUserNameAndId(String userName,Long id){ return selectOne(new QueryWrapperX() .eqIfPresent("username" , userName) .neIfPresent("id" , id)); - }; + } default MailAccountDO selectOneByFrom(String from){ return selectOne(new QueryWrapperX() - .eqIfPresent("from" , from)); - }; + .eqIfPresent("from_address" , from)); + } @Select("SELECT COUNT(*) FROM system_mail_account WHERE update_time > #{maxUpdateTime}") Long selectCountByUpdateTimeGt(Date maxUpdateTime); From 63983bbab3d48b22847c22a589f51dc520795f11 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Thu, 5 May 2022 18:52:34 +0800 Subject: [PATCH 22/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20bu?= =?UTF-8?q?g=20-=E4=BF=AE=E6=94=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/convert/mail/MailAccountConvert.java | 8 ++++---- .../module/system/dal/dataobject/mail/MailLogDO.java | 2 +- .../module/system/mq/message/mail/MailSendMessage.java | 2 +- .../module/system/mq/producer/mail/MailProducer.java | 2 +- .../system/service/mail/impl/MailLogServiceImpl.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index f2228e1702..b60ac088ff 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -29,18 +29,18 @@ public interface MailAccountConvert { .setHost(mailAccountDO.getHost()) .setPort(mailAccountDO.getPort()) .setAuth(true) - .setFrom(mailAccountDO.getFrom()) + .setFrom(mailAccountDO.getFromAddress()) .setUser(mailAccountDO.getUsername()) .setPass(mailAccountDO.getPassword()) .setSslEnable(mailAccountDO.getSslEnable()); - }; + } default Map convertToMap(MailAccountDO mailAccountDO , String content) { Map map = new HashMap<>(); - map.put("from" , mailAccountDO.getFrom()); + map.put("from_address" , mailAccountDO.getFromAddress()); map.put("username" , mailAccountDO.getUsername()); map.put("content" , content); return map; - }; + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 7454d2acb3..97cc51f4ca 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -39,7 +39,7 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 邮箱账号 */ - private String from; + private String fromAddress; /** * 模版主键 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index 3df7c6dcff..fd1d68f6f1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -26,7 +26,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 邮箱地址 */ @NotNull(message = "邮箱地址不能为空") - private String from; + private String fromAddress; /** * 用户名 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index db8bbebf64..3b6745c26b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -57,7 +57,7 @@ public class MailProducer { public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { MailSendMessage message = new MailSendMessage(); message.setContent(content); - message.setFrom(mailAccountDO.getFrom()); + message.setFromAddress(mailAccountDO.getFromAddress()); message.setHost(mailAccountDO.getHost()); message.setPort(mailAccountDO.getPort()); message.setPassword(mailAccountDO.getPassword()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index 76a7198aba..e251cc82ed 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -43,7 +43,7 @@ public class MailLogServiceImpl implements MailLogService { @Override public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.from(mailAccountDO.getFrom()); + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); logDOBuilder.content(content); logDOBuilder.title(title); From 1464f7d399de68de75a6fb84aef8b58783982a16 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 17 May 2022 20:07:50 +0800 Subject: [PATCH 23/65] =?UTF-8?q?code=20review=20=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/test/TestDemoServiceImpl.java | 2 +- .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/mail/vo/log/MailLogPageReqVO.java | 3 ++ .../admin/mail/vo/send/MailReqVO.java | 1 - .../convert/mail/MailTemplateConvert.java | 2 ++ .../system/dal/dataobject/mail/MailLogDO.java | 1 - .../system/service/mail/MailLogService.java | 29 +++++++-------- .../service/mail/MailTemplateService.java | 8 +++-- .../service/mail/impl/MailLogServiceImpl.java | 36 ++++++++++++------- .../mail/impl/MailTemplateServiceImpl.java | 16 +++------ 10 files changed, 54 insertions(+), 46 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java index 92153b0226..731a29cccf 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java @@ -79,7 +79,7 @@ public class TestDemoServiceImpl implements TestDemoService { @Override public PageResult getTestDemoPage(TestDemoPageReqVO pageReqVO) { -// testDemoMapper.selectList2(); + testDemoMapper.selectList2(); return testDemoMapper.selectPage(pageReqVO); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 32ba7181eb..cb6db27e1d 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -128,7 +128,7 @@ public interface ErrorCodeConstants { ErrorCode MAIL_ACCOUNT_EXISTS = new ErrorCode(1002020001, "邮箱账号存在"); // ========== 邮箱模版 1002021000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000 , "邮箱模版不存在"); + ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 9928a77469..67f91735b1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -17,6 +17,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { + + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") private String from; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java index 65142ee3fa..560c3bf424 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailReqVO.java @@ -34,5 +34,4 @@ public class MailReqVO { // TODO @wangjingqi:1), 不用空格;2)应该 @ApiModelProperty(value = "附件",example = "附件编码") private List fileIds; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java index 87fd8efe7a..46a25b9e2a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java @@ -11,6 +11,7 @@ import java.util.List; @Mapper public interface MailTemplateConvert { + MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); MailTemplateDO convert(MailTemplateBaseVO baseVO); @@ -20,4 +21,5 @@ public interface MailTemplateConvert { PageResult convertPage(PageResult pageResult); List convertList02(List list); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 97cc51f4ca..2472cd95fa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -80,7 +80,6 @@ public class MailLogDO extends BaseDO implements Serializable { /** * 发送结果 - * */ private String sendResult; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index da35012e25..98a445c8ae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -20,37 +20,38 @@ public interface MailLogService { /** * 邮箱日志分页 * - * @param pageVO - * @return + * @param pageVO 分页参数 + * @return 分页结果 */ PageResult getMailLogPage(MailLogPageReqVO pageVO); /** * 邮箱日志数组信息 * - * @param exportReqVO - * @return + * @param exportReqVO 导出筛选请求 + * @return 导出的日志数据 */ List getMailLogList(MailLogExportReqVO exportReqVO); /** * 创建邮箱日志 * - * @param mailAccountDO 邮箱账号信息 - * @param mailTemplateDO 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 - * @param isSend 是否发送成功 + * @param mailAccountDO 邮箱账号信息 + * @param template 模版信息 + * @param from 邮箱 + * @param content 内容 + * @param tos 收件人 + * @param title 标题 + * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); /** * 更新邮件发送结果 * - * @param logId 发送日志Id - * @param result 发送结果 默认返回messageId + * @param logId 发送日志Id + * @param result 发送结果 默认返回messageId */ void updateMailSendResult(Long logId, String result); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 873d337f4a..16d65b4f9c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; @@ -68,8 +67,9 @@ public interface MailTemplateService { * @return 模版数组 */ List getMailTemplateList(); + /** - *从缓存中获取邮箱模版 + * 从缓存中获取邮箱模版 * * @param code 模板编码 * @return 邮箱模板 @@ -78,9 +78,11 @@ public interface MailTemplateService { /** * 邮件模版内容合成 + * * @param content 邮箱模版 * @param params 合成参数 - * @return + * @return 格式化后的内容 */ String formatMailTemplateContent(String content, Map params); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index e251cc82ed..afc7dcb938 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -27,6 +27,7 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { + // TODO @wangjingyi:private,然后使用 @Resource @Autowired MailLogMapper mailLogMapper; @@ -41,25 +42,34 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); - logDOBuilder.accountId(mailAccountDO.getId()); - logDOBuilder.content(content); - logDOBuilder.title(title); - logDOBuilder.templateCode(mailTemplateDO.getCode()); - logDOBuilder.templateId(mailTemplateDO.getId()); - logDOBuilder.to(tos.toString()); - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() : MailSendStatusEnum.IGNORE.getStatus()); + // 设置邮箱相关字段 + // TODO @wangjingyi:userId、userType + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); + logDOBuilder.accountId(mailAccountDO.getId()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 + logDOBuilder.to(tos.toString()); + // 设置模板相关字段 + // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams + logDOBuilder.templateId(template.getId()); + logDOBuilder.templateCode(template.getCode()); + logDOBuilder.title(title); + logDOBuilder.content(content); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 + logDOBuilder.sendTime(new Date()); - MailLogDO mailLogDO = logDOBuilder.build(); - mailLogMapper.insert(mailLogDO); - return mailLogDO.getId(); + // 插入数据库 + MailLogDO logDO = logDOBuilder.build(); + mailLogMapper.insert(logDO); + return logDO.getId(); } - // TODO @wangjingyi:不需要返回 id 呀 DONE + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 89a0b43eae..9f8315458c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -3,20 +3,13 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -36,7 +29,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; /** - * 邮箱模版 服务实现类 + * 邮箱模版 Service 实现类 * * @author wangjingyi * @since 2022-03-21 @@ -48,6 +41,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Resource private MailTemplateMapper mailTemplateMapper; + @Resource private MailProducer mailProducer; @@ -61,7 +55,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { private volatile Date maxUpdateTime; - // TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现 DONE @Override @PostConstruct public void initLocalCache() { @@ -78,8 +71,8 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public Long create(MailTemplateCreateReqVO createReqVO) { - //要校验存在 - this.validateMailTemplateExists(createReqVO.getId()); + // 要校验存在 + validateMailTemplateExists(createReqVO.getId()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); // TODO @wangjingyi:mq 更新 DONE @@ -123,7 +116,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { return mailTemplateCache.get(code); } - // TODO @@wangjingyi:单词拼写错误 DONE @Override public String formatMailTemplateContent(String content, Map params) { return StrUtil.format(content, params); From 0ddb50be579f87bafe1c577e485646b1c56994f7 Mon Sep 17 00:00:00 2001 From: wangjingyi Date: Mon, 11 Jul 2022 15:02:06 +0800 Subject: [PATCH 24/65] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E7=A0=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/mail/dto/MailSendReqDTO.java | 26 +++++----- .../system/enums/ErrorCodeConstants.java | 1 + .../enums/mail/MailLogUserTypeEnum.java | 22 ++++++++ .../admin/mail/vo/log/MailLogPageReqVO.java | 4 +- .../system/dal/dataobject/mail/MailLogDO.java | 45 +++++++++++------ .../dal/dataobject/mail/MailTemplateDO.java | 9 +++- .../mail/MailTemplateRefreshConsumer.java | 1 - .../mq/message/mail/MailSendMessage.java | 7 ++- .../system/mq/producer/mail/MailProducer.java | 33 ++++++------ .../system/service/mail/MailLogService.java | 20 ++++++-- .../system/service/mail/MailSendService.java | 8 +-- .../service/mail/impl/MailLogServiceImpl.java | 49 +++++++++++------- .../mail/impl/MailSendServiceImpl.java | 50 ++++++++++--------- .../mail/impl/MailTemplateServiceImpl.java | 2 +- 14 files changed, 175 insertions(+), 102 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java index a3b0f2e354..caa69678c2 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/mail/dto/MailSendReqDTO.java @@ -7,32 +7,32 @@ import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.Map; @ApiModel("管理后台 - 邮件发送 Req VO") @Data public class MailSendReqDTO { // TODO @wangjingqi:1), 不用空格;2)应该只要传递 templateCode、参数就好,title、from、content、附件应该都是参数里的 - @ApiModelProperty(value = "邮箱",required = true,example = "yudaoyuanma@123.com") - @NotNull(message = "邮箱账号不能为空") - @Email(message = "邮箱账号格式错误") - private String from; + @ApiModelProperty(value = "用户编码",required = true) + @NotNull(message = "用户编码不能为空") + private String userId; - @ApiModelProperty(value = "标题",example = "标题") - private String title; - - @ApiModelProperty(value = "内容",example = "内容") - private String content; + @ApiModelProperty(value = "用户类型",required = true) + @NotNull(message = "用户类型不能为空") + private String userType; @ApiModelProperty(value = "邮箱模版id",example = "1024") - @NotNull(message = "邮箱模版id不能为空") - private Integer templateId; + @NotNull(message = "邮箱模版编码不能为空") + private Integer templateCode; + + @ApiModelProperty(value = "邮箱参数") + @NotNull(message = "模版参数不能为空") + private Map templateParams; @ApiModelProperty(value = "收件人",required = true,example = "yudaoyuanma@123.com") @NotNull(message = "收件人不能为空") private List tos; - @ApiModelProperty(value = "附件",example = "附件编码") - private List fileIds; } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index cb6db27e1d..4147383ae5 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -131,5 +131,6 @@ public interface ErrorCodeConstants { ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1002021000, "邮箱模版不存在"); ErrorCode MAIL_TEMPLATE_EXISTS = new ErrorCode(1002021001, "邮箱模版存在"); ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1002021002, "存在关联邮箱模版"); + ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002021003, "模板参数({})缺失"); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java new file mode 100644 index 0000000000..4154c9bc1c --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/mail/MailLogUserTypeEnum.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.system.enums.mail; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 邮件日志用户类型 + * + * @author wangjingyi + */ +@Getter +@AllArgsConstructor +public enum MailLogUserTypeEnum { + + COMMON (10), + VIP (20); + + /** + * 类型 + */ + private final int userType; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java index 67f91735b1..680fe6d1f6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogPageReqVO.java @@ -18,9 +18,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @ToString(callSuper = true) public class MailLogPageReqVO extends PageParam { - // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 + // TODO @wangjingyi:required 为 false 时,它是默认值,所以不用谢 DONE - @ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com") + @ApiModelProperty(value = "邮箱" , example = "yudaoyuanma@123.com") private String from; @ApiModelProperty(value = "模版编号" , required = false , example = "templeId") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java index 2472cd95fa..d4b0e5f811 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailLogDO.java @@ -1,12 +1,16 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.system.enums.mail.MailLogUserTypeEnum; import cn.iocoder.yudao.module.system.enums.mail.MailSendStatusEnum; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; import java.io.Serializable; import java.util.Date; +import java.util.Map; /** * 邮箱日志 @@ -29,15 +33,29 @@ public class MailLogDO extends BaseDO implements Serializable { */ private Long id; + /** + * 用户编码 + */ + private Long userId; + + /** + * 用户类型 + * + * 冗余 {@link MailLogUserTypeEnum#getUserType} + */ + private Integer userType; + // TODO @wangjingyi:accountId /** * 邮箱账号编号 */ private Long accountId; - // TODO @wangjingyi:如果是冗余字段,记得 @ 下; + // TODO @wangjingyi:如果是冗余字段,记得 @ 下;DONE /** * 邮箱账号 + * + * 冗余 {@link MailAccountDO} */ private String fromAddress; @@ -47,30 +65,22 @@ public class MailLogDO extends BaseDO implements Serializable { private Long templateId; /** - * 模版编号 + * 模版内容 */ - private String templateCode; + private String templateContent; /** - * 标题 + * 基于 {@link MailTemplateDO#getParams()} 输入后的参数 */ - private String title; - - /** - * 内容 - */ - private String content; - - /** - * 收件人 - */ - private String to; + @TableField(typeHandler = JacksonTypeHandler.class) + private Map templateParams; /** * 发送时间 */ private Date sendTime; + //=========接收相关字段========= /** * 发送状态 * @@ -83,5 +93,10 @@ public class MailLogDO extends BaseDO implements Serializable { */ private String sendResult; + /** + * 消息ID + */ + private String messageId; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java index 96f9ba4ab0..c4708657f5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; +import java.util.List; /** * 邮箱模版 @@ -43,6 +45,11 @@ public class MailTemplateDO extends BaseDO { * 内容 */ private String content; + /** + * 参数数组(自动根据内容生成) + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List params; /** * 状态 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java index b4eac0165e..199b147c80 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/mail/MailTemplateRefreshConsumer.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.mq.consumer.mail; import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java index fd1d68f6f1..6e8c46668e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/mail/MailSendMessage.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.mq.message.mail; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage; import lombok.Data; import lombok.EqualsAndHashCode; @@ -46,7 +47,7 @@ public class MailSendMessage extends AbstractStreamMessage { * 收件人 */ @NotNull(message = "收件人不能为空") - private List tos; + private String to; /** * 标题 */ @@ -69,6 +70,10 @@ public class MailSendMessage extends AbstractStreamMessage { * 是否开启 SSL */ private Boolean sslEnable; + /** + * 邮箱模板参数 + */ + private List> templateParams; @Override public String getStreamKey() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java index 3b6745c26b..50c5055123 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/mail/MailProducer.java @@ -7,9 +7,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.mq.message.mail.MailAccountRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.message.mail.MailTemplateRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -48,25 +45,27 @@ public class MailProducer { /** * 发送 {@link MailSendMessage} 消息 * + * @param sendLogId 发送日志编码 * @param mailAccountDO 邮箱账号信息 * @param mailTemplateDO 邮箱模版信息 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 邮箱模版参数 + * @param to 收件人 */ - public void sendMailSendMessage(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content, List tos, String title , Long sendLogId) { + public void sendMailSendMessage(Long sendLogId,MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String content,List> templateParams,String to) { MailSendMessage message = new MailSendMessage(); - message.setContent(content); - message.setFromAddress(mailAccountDO.getFromAddress()); - message.setHost(mailAccountDO.getHost()); - message.setPort(mailAccountDO.getPort()); - message.setPassword(mailAccountDO.getPassword()); - message.setUsername(mailAccountDO.getUsername()); - message.setSslEnable(mailAccountDO.getSslEnable()); - message.setTemplateCode(mailTemplateDO.getCode()); - message.setTitle(title); - message.setTos(tos); - message.setLogId(sendLogId); + message.setContent(content) + .setFromAddress(mailAccountDO.getFromAddress()) + .setHost(mailAccountDO.getHost()) + .setPort(mailAccountDO.getPort()) + .setPassword(mailAccountDO.getPassword()) + .setUsername(mailAccountDO.getUsername()) + .setSslEnable(mailAccountDO.getSslEnable()) + .setTemplateCode(mailTemplateDO.getCode()) + .setTitle(mailTemplateDO.getTitle()) + .setTo(to) + .setLogId(sendLogId) + .setTemplateParams(templateParams); redisMQTemplate.send(message); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java index 98a445c8ae..6b04f7a74f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogService.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import java.util.List; +import java.util.Map; /** * 邮箱日志服务类 @@ -36,15 +37,16 @@ public interface MailLogService { /** * 创建邮箱日志 * + * @param userId 用户编码 + * @param userType 用户类型 + * @param to 收件人 * @param mailAccountDO 邮箱账号信息 * @param template 模版信息 - * @param from 邮箱 - * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateContent 模版内容 + * @param templateParams 模版参数 * @param isSend 是否发送成功 */ - Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend); + Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend); /** * 更新邮件发送结果 @@ -54,4 +56,12 @@ public interface MailLogService { */ void updateMailSendResult(Long logId, String result); + /** + * 更新邮件发送结果 + * + * @param logId 发送日志Id + * @param exception 发送结果 + */ + void updateFailMailSendResult(Long logId, String exception); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java index 31f6a3f3e7..615b34fcf9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendService.java @@ -26,10 +26,12 @@ public interface MailSendService { * @param templateCode 邮件模版编码 * @param from 邮箱 * @param content 内容 - * @param tos 收件人 - * @param title 标题 + * @param templateParams 模版参数 + * @param to 收件人 + * @param userId 用户编码 + * @param userType 用户类型 */ - void sendMail(String templateCode, String from , String content , List tos , String title); + void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams); /** * 执行真正的邮件发送 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java index afc7dcb938..a7bf04fc76 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailLogServiceImpl.java @@ -13,8 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -27,9 +29,9 @@ import java.util.Objects; @Validated public class MailLogServiceImpl implements MailLogService { - // TODO @wangjingyi:private,然后使用 @Resource - @Autowired - MailLogMapper mailLogMapper; + // TODO @wangjingyi:private,然后使用 @Resource DONE + @Resource + private MailLogMapper mailLogMapper; @Override public PageResult getMailLogPage(MailLogPageReqVO pageVO) { @@ -42,26 +44,29 @@ public class MailLogServiceImpl implements MailLogService { } @Override - public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List tos, String title, Boolean isSend) { + public Long createMailLog(Long userId,Integer userType,String to,MailAccountDO mailAccountDO, MailTemplateDO template , String templateContent, Map templateParams, Boolean isSend) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。 + // TODO @wangjingyi:使用 builder 的时候,不用每个 set 是一行。DONE // 根据是否要发送,设置状态 logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus() - : MailSendStatusEnum.IGNORE.getStatus()); - // 设置邮箱相关字段 - // TODO @wangjingyi:userId、userType + : MailSendStatusEnum.IGNORE.getStatus()) + // 设置邮箱相关字段 + .fromAddress(mailAccountDO.getFromAddress()) + .accountId(mailAccountDO.getId()) + // TODO @wangjingyi:userId、userType + //用户信息 + .userId(userId).userType(userType) + //模版信息 + .templateId(template.getId()).templateParams(templateParams).templateContent(templateContent); + + logDOBuilder.fromAddress(mailAccountDO.getFromAddress()); logDOBuilder.accountId(mailAccountDO.getId()); - // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 - logDOBuilder.to(tos.toString()); + // TODO @wangjingyi:每个接收人一条日志。发送多个人,就调用多次,业务方。因为某个邮箱有问题,会导致所有都发送失败。 DONE // 设置模板相关字段 // TODO @wangjingyi:可以参考下 sms 短信的逻辑,templateContent、templateParams - logDOBuilder.templateId(template.getId()); - logDOBuilder.templateCode(template.getCode()); - logDOBuilder.title(title); - logDOBuilder.content(content); - // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 - logDOBuilder.sendTime(new Date()); + // TODO @wangjingyi:有结果的时候,才是 sendTime 哈 DONE + //logDOBuilder.sendTime(new Date()); // 插入数据库 MailLogDO logDO = logDOBuilder.build(); @@ -69,14 +74,20 @@ public class MailLogServiceImpl implements MailLogService { return logDO.getId(); } - // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。 + // TODO @wangjingyi:还是加几个字段哈,日志上。sendStatus,成功、失败;messageId 消息标号。sendException 记录发送的异常。这样界面才好筛选邮件的发送结果。DONE @Override public void updateMailSendResult(Long logId, String result) { MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); - logDOBuilder.id(logId); - logDOBuilder.sendResult(result); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(result).messageId(result).sendStatus(MailSendStatusEnum.SUCCESS.getStatus()); MailLogDO mailLogDO = logDOBuilder.build(); mailLogMapper.updateById(mailLogDO); } + @Override + public void updateFailMailSendResult(Long logId, String exception) { + MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder(); + logDOBuilder.id(logId).sendTime(new Date()).sendResult(exception).sendStatus(MailSendStatusEnum.FAILURE.getStatus()); + MailLogDO mailLogDO = logDOBuilder.build(); + mailLogMapper.updateById(mailLogDO); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java index 6b0cccd832..9a9e9fe50c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailSendServiceImpl.java @@ -2,17 +2,18 @@ package cn.iocoder.yudao.module.system.service.mail.impl; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; -import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -34,9 +36,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @Validated @Slf4j public class MailSendServiceImpl implements MailSendService { - - @Resource - private MailTemplateMapper mailTemplateMapper; + @Resource private MailAccountMapper mailAccountMapper; @Resource @@ -48,7 +48,7 @@ public class MailSendServiceImpl implements MailSendService { @Override - public void sendMail(String templateCode, String from , String content , List tos , String title) { + public void sendMail(Long userId, Integer userType, String templateCode, String from,String to, String content, Map templateParams) { // TODO @@wangjingyi:发送的时候,参考下短信;DONE //校验邮箱模版是否合法 MailTemplateDO mailTemplateDO = this.checkMailTemplateValid(templateCode); @@ -58,14 +58,11 @@ public class MailSendServiceImpl implements MailSendService { MailAccountDO mailAccountDO = this.checkMailAccountValid(from); Map params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content); content = mailTemplateService.formatMailTemplateContent(mailTemplateDO.getContent(), params); - Long sendLogId = mailLogService.createMailLog(mailAccountDO , mailTemplateDO , from , content , tos , title , isSend); - - // 后续功能 TODO :附件查询 - //List fileIds = mailSendVO.getFileIds(); - + Long sendLogId = mailLogService.createMailLog(userId,userType,to,mailAccountDO , mailTemplateDO , content, templateParams, isSend); + List> newTemplateParams = buildTemplateParams(mailTemplateDO,templateParams); // 发送 MQ 消息,异步执行发送短信 if (isSend) { - mailProducer.sendMailSendMessage(mailAccountDO , mailTemplateDO ,content , tos , title , sendLogId); + mailProducer.sendMailSendMessage(sendLogId,mailAccountDO , mailTemplateDO ,content, newTemplateParams,to); } } @@ -84,10 +81,10 @@ public class MailSendServiceImpl implements MailSendService { MailAccount account = MailAccountConvert.INSTANCE.convertAccount(message); //发送邮件 try{ - String messageId = MailUtil.send(account,message.getTos(),message.getTitle(),message.getContent(),false,null); + String messageId = MailUtil.send(account,message.getTo(),message.getTitle(),message.getContent(),false,null); mailLogService.updateMailSendResult(message.getLogId() , messageId); }catch (Exception e){ - mailLogService.updateMailSendResult(message.getLogId() , e.getMessage()); + mailLogService.updateFailMailSendResult(message.getLogId() , e.getMessage()); } } @@ -99,16 +96,21 @@ public class MailSendServiceImpl implements MailSendService { } return mailTemplateDO; } - - private void validateMailTemplateExists(Long id) { - if (mailTemplateMapper.selectById(id) == null) { - throw exception(MAIL_TEMPLATE_NOT_EXISTS); - } - } - - private void validateMailTemplateOnlyByCode(String code){ - if (mailTemplateMapper.selectOneByCode(code) != null) { - throw exception(MAIL_TEMPLATE_EXISTS); - } + /** + * 将参数模板,处理成有序的 KeyValue 数组 + * + * @param template 邮箱模板 + * @param templateParams 原始参数 + * @return 处理后的参数 + */ + @VisibleForTesting + public List> buildTemplateParams(MailTemplateDO template, Map templateParams) { + return template.getParams().stream().map(key -> { + Object value = templateParams.get(key); + if (value == null) { + throw exception(MAIL_SEND_TEMPLATE_PARAM_MISS, key); + } + return new KeyValue<>(key, value); + }).collect(Collectors.toList()); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 9f8315458c..3fcac8b9e5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -83,7 +83,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override public void update(@Valid MailTemplateUpdateReqVO updateReqVO) { // 校验是否唯一 - // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。 + // TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。DONE this.validateMailTemplateOnlyByCode(updateReqVO.getId(),updateReqVO.getCode()); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); mailTemplateMapper.updateById(mailTemplateDO); From e637bff8cdc7071a04489fcbe3ffa60dd5b7c344 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 10 Jan 2023 15:10:16 +0800 Subject: [PATCH 25/65] =?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 3bfc020ba6..0f20b1a788 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 0000000000..4119f8ea7a --- /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 0000000000..bf0f585c42 --- /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 0000000000..f883173c30 --- /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 0000000000..89a1f63c82 --- /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 0000000000..4f8883c507 --- /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 0000000000..d718aae1b7 --- /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 26/65] =?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 4119f8ea7a..7f15d0d4c7 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 bf0f585c42..65dd2108d0 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 0000000000..c2df586c43 --- /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 0000000000..ebafaa9bc0 --- /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 0000000000..8fa73169a8 --- /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 0000000000..11f1f58141 --- /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 0000000000..97d2698ed8 --- /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 0000000000..142e7c0f6e --- /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 0000000000..f91988735c --- /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 0000000000..921019c5de --- /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 0000000000..8d823a139c --- /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 0000000000..0829c6a455 --- /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 f883173c30..0000000000 --- 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 89a1f63c82..0000000000 --- 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 4f8883c507..0000000000 --- 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 d718aae1b7..a5d06feb1b 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 0000000000..23336b0cf4 --- /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 0000000000..1846156d46 --- /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 0000000000..81b9ccc500 --- /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 0000000000..a43b3e28eb --- /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 0000000000..63b4eaabfc --- /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 27/65] =?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 7b056c46b0..be2f14dd65 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 a43b3e28eb..f90475d6d3 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 28/65] =?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 a5d06feb1b..ba5a63bfb5 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 23336b0cf4..456d2b920c 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 1846156d46..63089054fb 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 81b9ccc500..2d8336d1f8 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 29/65] =?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 ba5a63bfb5..74870e7716 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 63089054fb..57fc711787 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 2d8336d1f8..47887da39f 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 f90475d6d3..956be23f33 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 b8c728aef8a8f94938d49c4a5ff90e8632ec1e37 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 13:10:02 +0800 Subject: [PATCH 30/65] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/codegen/CodegenServiceImpl.java | 4 -- .../service/db/DatabaseTableServiceImpl.java | 47 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index d531d237b5..3b693eb505 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -237,10 +237,6 @@ public class CodegenServiceImpl implements CodegenService { @Override public List getDatabaseTableList(Long dataSourceConfigId, String name, String comment) { List tables = databaseTableService.getTableList(dataSourceConfigId, name, comment); - // 移除置顶前缀的表名 // TODO 未来做成可配置 - tables.removeIf(table -> table.getName().toUpperCase().startsWith("QRTZ_")); - tables.removeIf(table -> table.getName().toUpperCase().startsWith("ACT_")); - tables.removeIf(table -> table.getName().toUpperCase().startsWith("FLW_")); // 移除已经生成的表 // 移除在 Codegen 中,已经存在的 Set existsTables = CollectionUtils.convertSet( diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java index 6b8346cf0d..77ff2409fb 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java @@ -12,9 +12,12 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.DateType; import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -28,6 +31,26 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { @Resource private DataSourceConfigService dataSourceConfigService; + private final Map ConfigBuilderMap = new HashMap<>(); + + @PostConstruct + public void initConfigBuilderMap() { + for (DataSourceConfigDO config : dataSourceConfigService.getDataSourceConfigList()) { + // 使用 MyBatis Plus Generator 解析表结构 + DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), + config.getPassword()).build(); + StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); + // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 + strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); + + GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate + ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), + null, globalConfig, null); + + ConfigBuilderMap.put(config.getId(), builder); + } + } + @Override public List getTableList(Long dataSourceConfigId, String nameLike, String commentLike) { List tables = getTableList0(dataSourceConfigId, null); @@ -42,24 +65,16 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { } public List getTableList0(Long dataSourceConfigId, String name) { - // 获得数据源配置 - DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); - Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); + ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); + Assert.notNull(builder, "数据源({}) 不存在!", dataSourceConfigId); - // 使用 MyBatis Plus Generator 解析表结构 - DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), - config.getPassword()).build(); - StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); - if (StrUtil.isNotEmpty(name)) { - strategyConfig.addInclude(name); - } - GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate - ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), - null, globalConfig, null); // 按照名字排序 List tables = builder.getTableInfoList(); - tables.sort(Comparator.comparing(TableInfo::getName)); - return tables; + if (StrUtil.isBlank(name)) { + tables.sort(Comparator.comparing(TableInfo::getName)); + return tables; + } else { + return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name)); + } } - } From 4f5dbb2288912f74500cdc902382a5d28d040d78 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 16:35:58 +0800 Subject: [PATCH 31/65] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/db/DatabaseTableServiceImpl.java | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java index 77ff2409fb..55f56a5dc7 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java @@ -12,12 +12,9 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.DateType; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -31,26 +28,6 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { @Resource private DataSourceConfigService dataSourceConfigService; - private final Map ConfigBuilderMap = new HashMap<>(); - - @PostConstruct - public void initConfigBuilderMap() { - for (DataSourceConfigDO config : dataSourceConfigService.getDataSourceConfigList()) { - // 使用 MyBatis Plus Generator 解析表结构 - DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), - config.getPassword()).build(); - StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); - // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 - strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); - - GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate - ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), - null, globalConfig, null); - - ConfigBuilderMap.put(config.getId(), builder); - } - } - @Override public List getTableList(Long dataSourceConfigId, String nameLike, String commentLike) { List tables = getTableList0(dataSourceConfigId, null); @@ -65,16 +42,28 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { } public List getTableList0(Long dataSourceConfigId, String name) { - ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); - Assert.notNull(builder, "数据源({}) 不存在!", dataSourceConfigId); + // 获得数据源配置 + DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); + Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); + // 使用 MyBatis Plus Generator 解析表结构 + DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), + config.getPassword()).build(); + StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); + if (StrUtil.isNotEmpty(name)) { + strategyConfig.addInclude(name); + }else{ + // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 + strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); + } + + GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate + ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), + null, globalConfig, null); // 按照名字排序 List tables = builder.getTableInfoList(); - if (StrUtil.isBlank(name)) { - tables.sort(Comparator.comparing(TableInfo::getName)); - return tables; - } else { - return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name)); - } + tables.sort(Comparator.comparing(TableInfo::getName)); + return tables; } + } 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 32/65] =?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 8fa73169a8..0000000000 --- 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 11f1f58141..0000000000 --- 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 97d2698ed8..0000000000 --- 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 142e7c0f6e..0000000000 --- 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 f91988735c..0000000000 --- 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 921019c5de..0000000000 --- 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 8d823a139c..0000000000 --- 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 0829c6a455..0000000000 --- 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 456d2b920c..5787eae569 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 65dd2108d0..888330ebe1 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 0000000000..9c10fb0ac6 --- /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 0000000000..746e5503b7 --- /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 c2df586c43..7ee6fadd51 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 0000000000..17c86055ea --- /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 0000000000..a21734909c --- /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 0000000000..9336351dab --- /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 0000000000..4402ab7d68 --- /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 0000000000..898c9d4a79 --- /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 0000000000..5b7e7e638e --- /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 0000000000..7833377c40 --- /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 0000000000..1f8c7a4894 --- /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 0000000000..148189ffe3 --- /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 0000000000..2ad620c0e0 --- /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 ebafaa9bc0..c752df310d 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 47887da39f..92b8c0d6c9 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 0000000000..d7cef7d2ff --- /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 0000000000..ba0a6607bb --- /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 0000000000..3be33a0b8a --- /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 0000000000..8fb71289f1 --- /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 0000000000..ce76b357e3 --- /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 0000000000..35a656c3db --- /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 0000000000..0525cb874c --- /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 74870e7716..0000000000 --- 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 57fc711787..0000000000 --- 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 956be23f33..0fbdb04f11 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 63b4eaabfc..0000000000 --- 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 33/65] =?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 746e5503b7..ebd754b1ed 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 4402ab7d68..4c41569e88 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 898c9d4a79..fb89ddb084 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 5b7e7e638e..3b4a1a5302 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 7833377c40..663388d892 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 1f8c7a4894..ac2ba9cd39 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 148189ffe3..c4bb6e1eb2 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 2ad620c0e0..c78354d153 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 34/65] =?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 7f15d0d4c7..1afb387b82 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 5787eae569..95c193f6b0 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 888330ebe1..b95ccd68d5 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 9c10fb0ac6..a4dd246659 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 17c86055ea..a9d495adfb 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 92b8c0d6c9..0b25cdbe5d 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 0fbdb04f11..accfa77dd2 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 35/65] =?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 be2f14dd65..f57f7a944b 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 0f20b1a788..12244f5ce6 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 a9d495adfb..0000000000 --- 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 942ca258fc..0000000000 --- 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 d7cef7d2ff..0000000000 --- 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 ba0a6607bb..0000000000 --- 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 3be33a0b8a..0000000000 --- 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 8fb71289f1..0000000000 --- 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 ce76b357e3..0000000000 --- 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 35a656c3db..0000000000 --- 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 0525cb874c..0000000000 --- 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 1afb387b82..53879bd0f2 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 95c193f6b0..abd756ef23 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 b95ccd68d5..d06e633a6a 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 a4dd246659..e59d96cec6 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 accfa77dd2..85dee2f53f 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 ebd754b1ed..303320b70a 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 7ee6fadd51..6c457fd0c6 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 0000000000..158c6de3de --- /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 a21734909c..b3a788aa96 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 9336351dab..5313381c30 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 4c41569e88..762ce3118b 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 fb89ddb084..d3d09ad42d 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 3b4a1a5302..92e46e594b 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 663388d892..8675521647 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 ac2ba9cd39..7b976bac6c 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 c4bb6e1eb2..bbe067ab79 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 c78354d153..87d7893fe9 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 c752df310d..4d3cac7a38 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 0b25cdbe5d..bd5ca926da 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 0000000000..76e63a6b11 --- /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 0000000000..742851a31d --- /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 0000000000..f7314867d1 --- /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 0000000000..0c498b071b --- /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 0000000000..50672ce352 --- /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 0000000000..657a191298 --- /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 0000000000..d3561ce5da --- /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 0000000000..e6c11bd445 --- /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 36/65] =?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 303320b70a..02d7043fe5 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 6c457fd0c6..e5d2558fa2 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 b3a788aa96..9fa5d80d77 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 5313381c30..b6692d448b 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 0000000000..03db9cb720 --- /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 0000000000..0cd338e1f5 --- /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 0000000000..ef1a2bbf9a --- /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 fcbcb28304a335970c281f34c3f2f958f907cc9b Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 17 Jan 2023 11:35:22 +0800 Subject: [PATCH 37/65] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/infra/service/db/DatabaseTableServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java index 55f56a5dc7..d0c80ba61e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java @@ -52,7 +52,7 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); if (StrUtil.isNotEmpty(name)) { strategyConfig.addInclude(name); - }else{ + } else { // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); } From 6593ec4214ba27b87e890b759cc1b0a4db2e4236 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 19 Jan 2023 10:25:43 +0800 Subject: [PATCH 38/65] =?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 53879bd0f2..c4a96ebe1e 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 abd756ef23..4c75cd9576 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 d06e633a6a..0166cb6ef2 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 e59d96cec6..470a0becf5 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 85dee2f53f..3f85f88bd4 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 0000000000..d56282535e --- /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 02d7043fe5..686367c2f7 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 e5d2558fa2..d0fddea6a4 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 158c6de3de..f43431b1d0 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 9fa5d80d77..718380570c 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 b6692d448b..ff77755e9a 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 87d7893fe9..ca2f4f041d 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 bbe067ab79..f96e13b21e 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 bd5ca926da..e41c57319a 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 76e63a6b11..ca2e00c899 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 d3561ce5da..26a7de496f 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 03db9cb720..18f4faee20 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 0cd338e1f5..735d25b346 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 ef1a2bbf9a..7a8455f8d1 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 8c69219d02..2dc5316920 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 39/65] =?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 4c75cd9576..0000000000 --- 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 3f85f88bd4..2c15a747d1 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 686367c2f7..2e7ae34987 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 ff77755e9a..8d1867a64c 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 18f4faee20..4009438333 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 372de7a4d5c98f20bfbeadfe53c1421af233fab8 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 19 Jan 2023 11:15:41 +0800 Subject: [PATCH 40/65] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E8=BF=9B=E5=85=A5=E5=8A=A0=E8=BD=BD=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin-vue3/.env.base | 2 ++ yudao-ui-admin-vue3/.env.dev | 2 ++ yudao-ui-admin-vue3/.env.pro | 2 ++ yudao-ui-admin-vue3/.env.test | 2 ++ yudao-ui-admin-vue3/src/main.ts | 7 +++++++ yudao-ui-admin-vue3/src/types/auto-components.d.ts | 6 ++++++ yudao-ui-admin-vue3/src/utils/env.ts | 8 ++++++++ yudao-ui-admin-vue3/src/views/infra/swagger/index.vue | 3 ++- yudao-ui-admin-vue3/types/env.d.ts | 1 + 9 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 yudao-ui-admin-vue3/src/utils/env.ts diff --git a/yudao-ui-admin-vue3/.env.base b/yudao-ui-admin-vue3/.env.base index 7a2f2a0ff6..fdb26d8501 100644 --- a/yudao-ui-admin-vue3/.env.base +++ b/yudao-ui-admin-vue3/.env.base @@ -1,6 +1,8 @@ # 本地开发环境 NODE_ENV=development +VITE_DEV=true + # 请求路径 VITE_BASE_URL='http://localhost:48080' diff --git a/yudao-ui-admin-vue3/.env.dev b/yudao-ui-admin-vue3/.env.dev index a67cdc6864..3b85e4819f 100644 --- a/yudao-ui-admin-vue3/.env.dev +++ b/yudao-ui-admin-vue3/.env.dev @@ -1,6 +1,8 @@ # 开发环境 NODE_ENV=production +VITE_DEV=false + # 请求路径 VITE_BASE_URL='http://localhost:48080' diff --git a/yudao-ui-admin-vue3/.env.pro b/yudao-ui-admin-vue3/.env.pro index 4b47737e10..8348e02e3c 100644 --- a/yudao-ui-admin-vue3/.env.pro +++ b/yudao-ui-admin-vue3/.env.pro @@ -1,6 +1,8 @@ # 生产环境 NODE_ENV=production +VITE_DEV=false + # 请求路径 VITE_BASE_URL='http://localhost:48080' diff --git a/yudao-ui-admin-vue3/.env.test b/yudao-ui-admin-vue3/.env.test index 6166840fa0..85e2cf5450 100644 --- a/yudao-ui-admin-vue3/.env.test +++ b/yudao-ui-admin-vue3/.env.test @@ -1,6 +1,8 @@ # 测试环境 NODE_ENV=production +VITE_DEV=false + # 请求路径 VITE_BASE_URL='http://localhost:48080' diff --git a/yudao-ui-admin-vue3/src/main.ts b/yudao-ui-admin-vue3/src/main.ts index e4511d9b1e..f5e3c024e8 100644 --- a/yudao-ui-admin-vue3/src/main.ts +++ b/yudao-ui-admin-vue3/src/main.ts @@ -37,6 +37,13 @@ import App from './App.vue' import './permission' +import { isDevMode } from '@/utils/env' + +if (isDevMode()) { + console.info(isDevMode()) + import('element-plus/dist/index.css') +} + // 创建实例 const setupAll = async () => { const app = createApp(App) diff --git a/yudao-ui-admin-vue3/src/types/auto-components.d.ts b/yudao-ui-admin-vue3/src/types/auto-components.d.ts index 0a56908aad..a35bc2a301 100644 --- a/yudao-ui-admin-vue3/src/types/auto-components.d.ts +++ b/yudao-ui-admin-vue3/src/types/auto-components.d.ts @@ -21,6 +21,7 @@ declare module '@vue/runtime-core' { DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default'] Echart: typeof import('./../components/Echart/src/Echart.vue')['default'] Editor: typeof import('./../components/Editor/src/Editor.vue')['default'] + ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElBadge: typeof import('element-plus/es')['ElBadge'] ElButton: typeof import('element-plus/es')['ElButton'] ElCard: typeof import('element-plus/es')['ElCard'] @@ -30,6 +31,7 @@ declare module '@vue/runtime-core' { ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] ElDescriptions: typeof import('element-plus/es')['ElDescriptions'] ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem'] + ElDialog: typeof import('element-plus/es')['ElDialog'] ElDivider: typeof import('element-plus/es')['ElDivider'] ElDrawer: typeof import('element-plus/es')['ElDrawer'] ElDropdown: typeof import('element-plus/es')['ElDropdown'] @@ -38,6 +40,7 @@ declare module '@vue/runtime-core' { ElForm: typeof import('element-plus/es')['ElForm'] ElFormItem: typeof import('element-plus/es')['ElFormItem'] ElIcon: typeof import('element-plus/es')['ElIcon'] + ElImage: typeof import('element-plus/es')['ElImage'] ElImageViewer: typeof import('element-plus/es')['ElImageViewer'] ElInput: typeof import('element-plus/es')['ElInput'] ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] @@ -51,7 +54,10 @@ declare module '@vue/runtime-core' { ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSkeleton: typeof import('element-plus/es')['ElSkeleton'] + ElSpace: typeof import('element-plus/es')['ElSpace'] ElSwitch: typeof import('element-plus/es')['ElSwitch'] + ElTable: typeof import('element-plus/es')['ElTable'] + ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] ElTag: typeof import('element-plus/es')['ElTag'] diff --git a/yudao-ui-admin-vue3/src/utils/env.ts b/yudao-ui-admin-vue3/src/utils/env.ts new file mode 100644 index 0000000000..4a45f62236 --- /dev/null +++ b/yudao-ui-admin-vue3/src/utils/env.ts @@ -0,0 +1,8 @@ +export const isDevMode = () => { + const dev = import.meta.env.VITE_DEV + if (dev && dev === true) { + return true + } else { + return false + } +} diff --git a/yudao-ui-admin-vue3/src/views/infra/swagger/index.vue b/yudao-ui-admin-vue3/src/views/infra/swagger/index.vue index 72a826e619..dce8122eee 100644 --- a/yudao-ui-admin-vue3/src/views/infra/swagger/index.vue +++ b/yudao-ui-admin-vue3/src/views/infra/swagger/index.vue @@ -5,5 +5,6 @@ diff --git a/yudao-ui-admin-vue3/types/env.d.ts b/yudao-ui-admin-vue3/types/env.d.ts index 33e1f40b8b..81469b76d9 100644 --- a/yudao-ui-admin-vue3/types/env.d.ts +++ b/yudao-ui-admin-vue3/types/env.d.ts @@ -11,6 +11,7 @@ interface ImportMetaEnv { readonly VITE_APP_TITLE: string readonly VITE_PORT: number readonly VITE_OPEN: string + readonly VITE_DEV: boolean readonly VITE_ROUTE_ALWAYSSHOW_ENABLE: string readonly VITE_APP_CAPTCHA_ENABLE: string readonly VITE_APP_TENANT_ENABLE: string From fbb154f93dadbb029c6e92146214a37b12ee51f6 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 19 Jan 2023 13:36:21 +0800 Subject: [PATCH 41/65] =?UTF-8?q?perf:=20=E7=94=A8=E6=88=B7=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=A0=91=E8=B6=85=E5=87=BA=E9=AB=98=E5=BA=A6=E5=90=8E?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BB=9A=E5=8A=A8=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/types/auto-components.d.ts | 1 + .../src/views/system/user/index.vue | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/yudao-ui-admin-vue3/src/types/auto-components.d.ts b/yudao-ui-admin-vue3/src/types/auto-components.d.ts index a35bc2a301..46a1ae56c5 100644 --- a/yudao-ui-admin-vue3/src/types/auto-components.d.ts +++ b/yudao-ui-admin-vue3/src/types/auto-components.d.ts @@ -51,6 +51,7 @@ declare module '@vue/runtime-core' { ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] ElRow: typeof import('element-plus/es')['ElRow'] + ElScroll: typeof import('element-plus/es')['ElScroll'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSkeleton: typeof import('element-plus/es')['ElSkeleton'] diff --git a/yudao-ui-admin-vue3/src/views/system/user/index.vue b/yudao-ui-admin-vue3/src/views/system/user/index.vue index 971db66dc6..d125112de7 100644 --- a/yudao-ui-admin-vue3/src/views/system/user/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/user/index.vue @@ -8,17 +8,19 @@ - + + +