Commit 9aed06af5d8de23657f60c701e6a1a51e8743b33

Authored by YunaiV
1 parent 5eb5472d

🔧 简化 notify 模块的 VO

Showing 15 changed files with 94 additions and 199 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java
... ... @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.system.controller.admin.notify;
3 3 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO;
7 8 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
8 9 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
9   -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert;
10 10 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
11 11 import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
12 12 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -39,8 +39,8 @@ public class NotifyMessageController {
39 39 @Parameter(name = "id", description = "编号", required = true, example = "1024")
40 40 @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
41 41 public CommonResult<NotifyMessageRespVO> getNotifyMessage(@RequestParam("id") Long id) {
42   - NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id);
43   - return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage));
  42 + NotifyMessageDO message = notifyMessageService.getNotifyMessage(id);
  43 + return success(BeanUtils.toBean(message, NotifyMessageRespVO.class));
44 44 }
45 45  
46 46 @GetMapping("/page")
... ... @@ -48,7 +48,7 @@ public class NotifyMessageController {
48 48 @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
49 49 public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
50 50 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
51   - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
  51 + return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
52 52 }
53 53  
54 54 // ========== 查看自己的站内信 ==========
... ... @@ -58,7 +58,7 @@ public class NotifyMessageController {
58 58 public CommonResult<PageResult<NotifyMessageRespVO>> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) {
59 59 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO,
60 60 getLoginUserId(), UserTypeEnum.ADMIN.getValue());
61   - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
  61 + return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
62 62 }
63 63  
64 64 @PutMapping("/update-read")
... ... @@ -83,13 +83,14 @@ public class NotifyMessageController {
83 83 @RequestParam(name = "size", defaultValue = "10") Integer size) {
84 84 List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(
85 85 getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size);
86   - return success(NotifyMessageConvert.INSTANCE.convertList(list));
  86 + return success(BeanUtils.toBean(list, NotifyMessageRespVO.class));
87 87 }
88 88  
89 89 @GetMapping("/get-unread-count")
90 90 @Operation(summary = "获得当前用户的未读站内信数量")
91 91 public CommonResult<Long> getUnreadNotifyMessageCount() {
92   - return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
  92 + return success(notifyMessageService.getUnreadNotifyMessageCount(
  93 + getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
93 94 }
94 95  
95 96 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java
... ... @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.system.controller.admin.notify;
3 3 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*;
7   -import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert;
8 8 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
9 9 import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
10 10 import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService;
... ... @@ -35,14 +35,14 @@ public class NotifyTemplateController {
35 35 @PostMapping("/create")
36 36 @Operation(summary = "创建站内信模版")
37 37 @PreAuthorize("@ss.hasPermission('system:notify-template:create')")
38   - public CommonResult<Long> createNotifyTemplate(@Valid @RequestBody NotifyTemplateCreateReqVO createReqVO) {
  38 + public CommonResult<Long> createNotifyTemplate(@Valid @RequestBody NotifyTemplateSaveReqVO createReqVO) {
39 39 return success(notifyTemplateService.createNotifyTemplate(createReqVO));
40 40 }
41 41  
42 42 @PutMapping("/update")
43 43 @Operation(summary = "更新站内信模版")
44 44 @PreAuthorize("@ss.hasPermission('system:notify-template:update')")
45   - public CommonResult<Boolean> updateNotifyTemplate(@Valid @RequestBody NotifyTemplateUpdateReqVO updateReqVO) {
  45 + public CommonResult<Boolean> updateNotifyTemplate(@Valid @RequestBody NotifyTemplateSaveReqVO updateReqVO) {
46 46 notifyTemplateService.updateNotifyTemplate(updateReqVO);
47 47 return success(true);
48 48 }
... ... @@ -61,8 +61,8 @@ public class NotifyTemplateController {
61 61 @Parameter(name = "id", description = "编号", required = true, example = "1024")
62 62 @PreAuthorize("@ss.hasPermission('system:notify-template:query')")
63 63 public CommonResult<NotifyTemplateRespVO> getNotifyTemplate(@RequestParam("id") Long id) {
64   - NotifyTemplateDO notifyTemplate = notifyTemplateService.getNotifyTemplate(id);
65   - return success(NotifyTemplateConvert.INSTANCE.convert(notifyTemplate));
  64 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(id);
  65 + return success(BeanUtils.toBean(template, NotifyTemplateRespVO.class));
66 66 }
67 67  
68 68 @GetMapping("/page")
... ... @@ -70,7 +70,7 @@ public class NotifyTemplateController {
70 70 @PreAuthorize("@ss.hasPermission('system:notify-template:query')")
71 71 public CommonResult<PageResult<NotifyTemplateRespVO>> getNotifyTemplatePage(@Valid NotifyTemplatePageReqVO pageVO) {
72 72 PageResult<NotifyTemplateDO> pageResult = notifyTemplateService.getNotifyTemplatePage(pageVO);
73   - return success(NotifyTemplateConvert.INSTANCE.convertPage(pageResult));
  73 + return success(BeanUtils.toBean(pageResult, NotifyTemplateRespVO.class));
74 74 }
75 75  
76 76 @PostMapping("/send-notify")
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import org.springframework.format.annotation.DateTimeFormat;
6   -
7   -import javax.validation.constraints.NotNull;
8   -import java.time.LocalDateTime;
9   -import java.util.Map;
10   -
11   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
12   -
13   -/**
14   - * 站内信消息 Base VO,提供给添加、修改、详细的子 VO 使用
15   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
16   - */
17   -@Data
18   -public class NotifyMessageBaseVO {
19   -
20   - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25025")
21   - @NotNull(message = "用户编号不能为空")
22   - private Long userId;
23   -
24   - @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
25   - @NotNull(message = "用户类型不能为空")
26   - private Byte userType;
27   -
28   - @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13013")
29   - @NotNull(message = "模版编号不能为空")
30   - private Long templateId;
31   -
32   - @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
33   - @NotNull(message = "模板编码不能为空")
34   - private String templateCode;
35   -
36   - @Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
37   - @NotNull(message = "模版发送人名称不能为空")
38   - private String templateNickname;
39   -
40   - @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
41   - @NotNull(message = "模版内容不能为空")
42   - private String templateContent;
43   -
44   - @Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
45   - @NotNull(message = "模版类型不能为空")
46   - private Integer templateType;
47   -
48   - @Schema(description = "模版参数", requiredMode = Schema.RequiredMode.REQUIRED)
49   - @NotNull(message = "模版参数不能为空")
50   - private Map<String, Object> templateParams;
51   -
52   - @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
53   - @NotNull(message = "是否已读不能为空")
54   - private Boolean readStatus;
55   -
56   - @Schema(description = "阅读时间")
57   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
58   - private LocalDateTime readTime;
59   -
60   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java
... ... @@ -2,20 +2,47 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7 5  
8 6 import java.time.LocalDateTime;
  7 +import java.util.Map;
9 8  
10 9 @Schema(description = "管理后台 - 站内信 Response VO")
11 10 @Data
12   -@EqualsAndHashCode(callSuper = true)
13   -@ToString(callSuper = true)
14   -public class NotifyMessageRespVO extends NotifyMessageBaseVO {
  11 +public class NotifyMessageRespVO {
15 12  
16 13 @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
17 14 private Long id;
18 15  
  16 + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25025")
  17 + private Long userId;
  18 +
  19 + @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  20 + private Byte userType;
  21 +
  22 + @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13013")
  23 + private Long templateId;
  24 +
  25 + @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01")
  26 + private String templateCode;
  27 +
  28 + @Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  29 + private String templateNickname;
  30 +
  31 + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容")
  32 + private String templateContent;
  33 +
  34 + @Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  35 + private Integer templateType;
  36 +
  37 + @Schema(description = "模版参数", requiredMode = Schema.RequiredMode.REQUIRED)
  38 + private Map<String, Object> templateParams;
  39 +
  40 + @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  41 + private Boolean readStatus;
  42 +
  43 + @Schema(description = "阅读时间")
  44 + private LocalDateTime readTime;
  45 +
19 46 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
20 47 private LocalDateTime createTime;
21 48  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.*;
5   -
6   -@Schema(description = "管理后台 - 站内信模版创建 Request VO")
7   -@Data
8   -@EqualsAndHashCode(callSuper = true)
9   -@ToString(callSuper = true)
10   -public class NotifyTemplateCreateReqVO extends NotifyTemplateBaseVO {
11   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java
1 1 package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.*;
  4 +import lombok.Data;
5 5  
6 6 import java.time.LocalDateTime;
7   -import java.util.*;
  7 +import java.util.List;
8 8  
9 9 @Schema(description = "管理后台 - 站内信模版 Response VO")
10 10 @Data
11   -@EqualsAndHashCode(callSuper = true)
12   -@ToString(callSuper = true)
13   -public class NotifyTemplateRespVO extends NotifyTemplateBaseVO {
  11 +public class NotifyTemplateRespVO {
14 12  
15 13 @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
16 14 private Long id;
17 15  
  16 + @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试模版")
  17 + private String name;
  18 +
  19 + @Schema(description = "模版编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "SEND_TEST")
  20 + private String code;
  21 +
  22 + @Schema(description = "模版类型,对应 system_notify_template_type 字典", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + private Integer type;
  24 +
  25 + @Schema(description = "发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆")
  26 + private String nickname;
  27 +
  28 + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是模版内容")
  29 + private String content;
  30 +
18 31 @Schema(description = "参数数组", example = "name,code")
19 32 private List<String> params;
20 33  
  34 + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  35 + private Integer status;
  36 +
  37 + @Schema(description = "备注", example = "我是备注")
  38 + private String remark;
  39 +
21 40 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
22 41 private LocalDateTime createTime;
23 42  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSaveReqVO.java
... ... @@ -3,17 +3,17 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.common.validation.InEnum;
5 5 import io.swagger.v3.oas.annotations.media.Schema;
6   -import lombok.Data;
  6 +import lombok.*;
7 7  
8 8 import javax.validation.constraints.NotEmpty;
9 9 import javax.validation.constraints.NotNull;
10 10  
11   -/**
12   - * 站内信模版 Base VO,提供给添加、修改、详细的子 VO 使用
13   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
14   - */
  11 +@Schema(description = "管理后台 - 站内信模版创建/修改 Request VO")
15 12 @Data
16   -public class NotifyTemplateBaseVO {
  13 +public class NotifyTemplateSaveReqVO {
  14 +
  15 + @Schema(description = "ID", example = "1024")
  16 + private Long id;
17 17  
18 18 @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试模版")
19 19 @NotEmpty(message = "模版名称不能为空")
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java
... ... @@ -25,4 +25,5 @@ public class NotifyTemplateSendReqVO {
25 25  
26 26 @Schema(description = "模板参数")
27 27 private Map<String, Object> templateParams;
  28 +
28 29 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.*;
5   -import javax.validation.constraints.*;
6   -
7   -@Schema(description = "管理后台 - 站内信模版更新 Request VO")
8   -@Data
9   -@EqualsAndHashCode(callSuper = true)
10   -@ToString(callSuper = true)
11   -public class NotifyTemplateUpdateReqVO extends NotifyTemplateBaseVO {
12   -
13   - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
14   - @NotNull(message = "ID 不能为空")
15   - private Long id;
16   -
17   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java deleted
1   -package cn.iocoder.yudao.module.system.convert.notify;
2   -
3   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
5   -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
6   -import org.mapstruct.Mapper;
7   -import org.mapstruct.factory.Mappers;
8   -
9   -import java.util.List;
10   -
11   -/**
12   - * 站内信 Convert
13   - *
14   - * @author xrcoder
15   - */
16   -@Mapper
17   -public interface NotifyMessageConvert {
18   -
19   - NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class);
20   -
21   - NotifyMessageRespVO convert(NotifyMessageDO bean);
22   -
23   - List<NotifyMessageRespVO> convertList(List<NotifyMessageDO> list);
24   -
25   - PageResult<NotifyMessageRespVO> convertPage(PageResult<NotifyMessageDO> page);
26   -
27   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java deleted
1   -package cn.iocoder.yudao.module.system.convert.notify;
2   -
3   -import java.util.*;
4   -
5   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -
7   -import cn.iocoder.yudao.framework.common.util.date.DateUtils;
8   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO;
9   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO;
10   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO;
11   -import org.mapstruct.Mapper;
12   -import org.mapstruct.factory.Mappers;
13   -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
14   -
15   -/**
16   - * 站内信模版 Convert
17   - *
18   - * @author xrcoder
19   - */
20   -@Mapper(uses = DateUtils.class)
21   -public interface NotifyTemplateConvert {
22   -
23   - NotifyTemplateConvert INSTANCE = Mappers.getMapper(NotifyTemplateConvert.class);
24   -
25   - NotifyTemplateDO convert(NotifyTemplateCreateReqVO bean);
26   -
27   - NotifyTemplateDO convert(NotifyTemplateUpdateReqVO bean);
28   -
29   - NotifyTemplateRespVO convert(NotifyTemplateDO bean);
30   -
31   - List<NotifyTemplateRespVO> convertList(List<NotifyTemplateDO> list);
32   -
33   - PageResult<NotifyTemplateRespVO> convertPage(PageResult<NotifyTemplateDO> page);
34   -
35   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java
... ... @@ -14,8 +14,6 @@ import java.util.Collection;
14 14 import java.util.List;
15 15 import java.util.Map;
16 16  
17   -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
18   -
19 17 /**
20 18 * 站内信 Service 实现类
21 19 *
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java
1 1 package cn.iocoder.yudao.module.system.service.notify;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO;
5 4 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO;
6   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO;
  5 +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO;
7 6 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
8 7  
9 8 import javax.validation.Valid;
... ... @@ -22,14 +21,14 @@ public interface NotifyTemplateService {
22 21 * @param createReqVO 创建信息
23 22 * @return 编号
24 23 */
25   - Long createNotifyTemplate(@Valid NotifyTemplateCreateReqVO createReqVO);
  24 + Long createNotifyTemplate(@Valid NotifyTemplateSaveReqVO createReqVO);
26 25  
27 26 /**
28 27 * 更新站内信模版
29 28 *
30 29 * @param updateReqVO 更新信息
31 30 */
32   - void updateNotifyTemplate(@Valid NotifyTemplateUpdateReqVO updateReqVO);
  31 + void updateNotifyTemplate(@Valid NotifyTemplateSaveReqVO updateReqVO);
33 32  
34 33 /**
35 34 * 删除站内信模版
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java
... ... @@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.system.service.notify;
3 3 import cn.hutool.core.util.ReUtil;
4 4 import cn.hutool.core.util.StrUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO;
8   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO;
9   -import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert;
  8 +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO;
10 9 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
11 10 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper;
12 11 import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
... ... @@ -45,12 +44,12 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
45 44 private NotifyTemplateMapper notifyTemplateMapper;
46 45  
47 46 @Override
48   - public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) {
  47 + public Long createNotifyTemplate(NotifyTemplateSaveReqVO createReqVO) {
49 48 // 校验站内信编码是否重复
50 49 validateNotifyTemplateCodeDuplicate(null, createReqVO.getCode());
51 50  
52 51 // 插入
53   - NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO);
  52 + NotifyTemplateDO notifyTemplate = BeanUtils.toBean(createReqVO, NotifyTemplateDO.class);
54 53 notifyTemplate.setParams(parseTemplateContentParams(notifyTemplate.getContent()));
55 54 notifyTemplateMapper.insert(notifyTemplate);
56 55 return notifyTemplate.getId();
... ... @@ -59,14 +58,14 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
59 58 @Override
60 59 @CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE,
61 60 allEntries = true) // allEntries 清空所有缓存,因为可能修改到 code 字段,不好清理
62   - public void updateNotifyTemplate(NotifyTemplateUpdateReqVO updateReqVO) {
  61 + public void updateNotifyTemplate(NotifyTemplateSaveReqVO updateReqVO) {
63 62 // 校验存在
64 63 validateNotifyTemplateExists(updateReqVO.getId());
65 64 // 校验站内信编码是否重复
66 65 validateNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
67 66  
68 67 // 更新
69   - NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO);
  68 + NotifyTemplateDO updateObj = BeanUtils.toBean(updateReqVO, NotifyTemplateDO.class);
70 69 updateObj.setParams(parseTemplateContentParams(updateObj.getContent()));
71 70 notifyTemplateMapper.updateById(updateObj);
72 71 }
... ... @@ -135,4 +134,5 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
135 134 public String formatNotifyTemplateContent(String content, Map<String, Object> params) {
136 135 return StrUtil.format(content, params);
137 136 }
  137 +
138 138 }
... ...
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImplTest.java
... ... @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.notify;
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
6   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO;
7 6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO;
8   -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO;
  7 +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO;
9 8 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
10 9 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper;
11 10 import org.junit.jupiter.api.Test;
... ... @@ -41,8 +40,9 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
41 40 @Test
42 41 public void testCreateNotifyTemplate_success() {
43 42 // 准备参数
44   - NotifyTemplateCreateReqVO reqVO = randomPojo(NotifyTemplateCreateReqVO.class,
45   - o -> o.setStatus(randomCommonStatus()));
  43 + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class,
  44 + o -> o.setStatus(randomCommonStatus()))
  45 + .setId(null); // 防止 id 被赋值
46 46  
47 47 // 调用
48 48 Long notifyTemplateId = notifyTemplateService.createNotifyTemplate(reqVO);
... ... @@ -50,7 +50,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
50 50 assertNotNull(notifyTemplateId);
51 51 // 校验记录的属性是否正确
52 52 NotifyTemplateDO notifyTemplate = notifyTemplateMapper.selectById(notifyTemplateId);
53   - assertPojoEquals(reqVO, notifyTemplate);
  53 + assertPojoEquals(reqVO, notifyTemplate, "id");
54 54 }
55 55  
56 56 @Test
... ... @@ -59,7 +59,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
59 59 NotifyTemplateDO dbNotifyTemplate = randomPojo(NotifyTemplateDO.class);
60 60 notifyTemplateMapper.insert(dbNotifyTemplate);// @Sql: 先插入出一条存在的数据
61 61 // 准备参数
62   - NotifyTemplateUpdateReqVO reqVO = randomPojo(NotifyTemplateUpdateReqVO.class, o -> {
  62 + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class, o -> {
63 63 o.setId(dbNotifyTemplate.getId()); // 设置更新的 ID
64 64 o.setStatus(randomCommonStatus());
65 65 });
... ... @@ -74,7 +74,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
74 74 @Test
75 75 public void testUpdateNotifyTemplate_notExists() {
76 76 // 准备参数
77   - NotifyTemplateUpdateReqVO reqVO = randomPojo(NotifyTemplateUpdateReqVO.class);
  77 + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class);
78 78  
79 79 // 调用, 并断言异常
80 80 assertServiceException(() -> notifyTemplateService.updateNotifyTemplate(reqVO), NOTIFY_TEMPLATE_NOT_EXISTS);
... ...