Commit 512d68f79317290ba565b0a15080201823c7f73c

Authored by YunaiV
1 parent 008b544f

【代码评审】SYSTEM:订阅消息

yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
1 package cn.iocoder.yudao.module.trade.enums; 1 package cn.iocoder.yudao.module.trade.enums;
2 2
3 -// TODO @芋艿:枚举  
4 /** 3 /**
5 * 通知模板枚举类 4 * 通知模板枚举类
6 * 5 *
@@ -8,6 +7,8 @@ package cn.iocoder.yudao.module.trade.enums; @@ -8,6 +7,8 @@ package cn.iocoder.yudao.module.trade.enums;
8 */ 7 */
9 public interface MessageTemplateConstants { 8 public interface MessageTemplateConstants {
10 9
  10 + //======================= 短信消息模版 =======================
  11 +
11 String ORDER_DELIVERY = "order_delivery"; // 短信模版编号 12 String ORDER_DELIVERY = "order_delivery"; // 短信模版编号
12 13
13 String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) 14 String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过)
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
1 package cn.iocoder.yudao.module.pay.enums; 1 package cn.iocoder.yudao.module.pay.enums;
2 2
3 -// TODO @芋艿:枚举  
4 /** 3 /**
5 * 通知模板枚举类 4 * 通知模板枚举类
6 * 5 *
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.api.social.dto; @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.api.social.dto;
3 import jakarta.validation.constraints.NotNull; 3 import jakarta.validation.constraints.NotNull;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 -import java.util.HashMap;  
7 import java.util.Map; 6 import java.util.Map;
8 7
9 /** 8 /**
@@ -15,6 +14,7 @@ import java.util.Map; @@ -15,6 +14,7 @@ import java.util.Map;
15 @Data 14 @Data
16 public class SocialWxSubscribeMessageSendReqDTO { 15 public class SocialWxSubscribeMessageSendReqDTO {
17 16
  17 + // TODO @puhui999:貌似使用 userId + userType 会不会更合理哈。这样,后端进行查询三方用户的绑定表~
18 /** 18 /**
19 * 接收者(用户)的 openid. 19 * 接收者(用户)的 openid.
20 * <pre> 20 * <pre>
@@ -27,58 +27,43 @@ public class SocialWxSubscribeMessageSendReqDTO { @@ -27,58 +27,43 @@ public class SocialWxSubscribeMessageSendReqDTO {
27 private String toUser; 27 private String toUser;
28 28
29 /** 29 /**
30 - * 所需下发的模板消息的id.  
31 - * <pre>  
32 - * 参数:template_id  
33 - * 是否必填: 是  
34 - * 描述: 所需下发的模板消息的id  
35 - * </pre> 30 + * 模版消息编号
36 */ 31 */
37 - @NotNull(message = "模板消息的id不能为空") 32 + @NotNull(message = "模版消息编号不能为空")
38 private String templateId; 33 private String templateId;
39 34
40 /** 35 /**
41 - * 点击模板卡片后的跳转页面,仅限本小程序内的页面.  
42 - * <pre>  
43 - * 参数:page  
44 - * 是否必填: 否  
45 - * 描述: 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。  
46 - * </pre> 36 + * 点击模板卡片后的跳转页面,仅限本小程序内的页面
  37 + *
  38 + * 支持带参数,(示例 index?foo=bar )。该字段不填则模板无跳转。
47 */ 39 */
48 private String page; 40 private String page;
49 41
50 /** 42 /**
51 - * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版 43 + * 跳转小程序类型
  44 + *
  45 + * developer 为开发版;trial 为体验版;formal 为正式版【默认】
52 * 46 *
53 * 枚举 WxMaConstants.MiniProgramState 47 * 枚举 WxMaConstants.MiniProgramState
54 */ 48 */
  49 + // TODO @puhui999:这个非必填。如果没有,代码里去默认下;
55 @NotNull(message = "跳转小程序类型不能为空") 50 @NotNull(message = "跳转小程序类型不能为空")
56 private String miniprogramState; 51 private String miniprogramState;
57 52
58 /** 53 /**
59 - * 进入小程序查看的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN 54 + * 进入小程序查看的语言类型
  55 + *
  56 + * zh_CN(简体中文)【默认】、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文)
60 * 57 *
61 * 枚举 WxMaConstants.MiniProgramLang 58 * 枚举 WxMaConstants.MiniProgramLang
62 */ 59 */
  60 + // TODO @puhui999:这个非必填。如果没有,代码里去默认下;
63 @NotNull(message = "进入小程序查看的语言类型不能为空") 61 @NotNull(message = "进入小程序查看的语言类型不能为空")
64 private String lang; 62 private String lang;
65 63
66 /** 64 /**
67 - * 模板内容,不填则下发空模板.  
68 - * <pre>  
69 - * 参数:data  
70 - * 是否必填: 是  
71 - * 描述: 模板内容,不填则下发空模板  
72 - * </pre> 65 + * 模板内容的参数
73 */ 66 */
74 private Map<String, String> messages; 67 private Map<String, String> messages;
75 68
76 - public SocialWxSubscribeMessageSendReqDTO addData(String key, String value) {  
77 - if (messages == null) {  
78 - messages = new HashMap<>();  
79 - }  
80 - messages.put(key, value);  
81 - return this;  
82 - }  
83 -  
84 } 69 }
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java
@@ -12,7 +12,7 @@ import lombok.Data; @@ -12,7 +12,7 @@ import lombok.Data;
12 public class SocialWxSubscribeTemplateRespDTO { 12 public class SocialWxSubscribeTemplateRespDTO {
13 13
14 /** 14 /**
15 - * 添加至账号下的模板 id,发送小程序订阅消息时所需 15 + * 模版编号
16 */ 16 */
17 private String id; 17 private String id;
18 18
@@ -31,12 +31,11 @@ public class SocialWxSubscribeTemplateRespDTO { @@ -31,12 +31,11 @@ public class SocialWxSubscribeTemplateRespDTO {
31 */ 31 */
32 private String example; 32 private String example;
33 33
34 - // TODO @puhui999:这个在 wxjava 里面,有枚举字段么?没得🤣  
35 /** 34 /**
36 * 模版类型 35 * 模版类型
37 * 36 *
38 - * 2 为一次性订阅  
39 - * 3 为长期订阅 37 + * 2:为一次性订阅
  38 + * 3:为长期订阅
40 */ 39 */
41 private Integer type; 40 private Integer type;
42 41
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java
@@ -71,10 +71,10 @@ public class SocialClientController { @@ -71,10 +71,10 @@ public class SocialClientController {
71 return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class)); 71 return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class));
72 } 72 }
73 73
74 - //======================= TODO 测试发送订阅消息 =======================  
75 -  
76 @PostMapping("/send-subscribe-message") 74 @PostMapping("/send-subscribe-message")
77 - public void testSendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) { 75 + @Operation(summary = "发送订阅消息") // 用于测试
  76 + @PreAuthorize("@ss.hasPermission('system:social-client:query')")
  77 + public void sendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) {
78 socialClientService.sendSubscribeMessage(reqDTO, UserTypeEnum.MEMBER.getValue()); 78 socialClientService.sendSubscribeMessage(reqDTO, UserTypeEnum.MEMBER.getValue());
79 } 79 }
80 80
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java
@@ -26,20 +26,21 @@ public interface SocialUserConvert { @@ -26,20 +26,21 @@ public interface SocialUserConvert {
26 @Mapping(source = "reqVO.type", target = "socialType") 26 @Mapping(source = "reqVO.type", target = "socialType")
27 SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); 27 SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO);
28 28
  29 + // TODO @puhui999:要不 convert 直接放到 service 里。
29 default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) { 30 default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) {
30 WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); 31 WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
31 Map<String, String> messages = reqDTO.getMessages(); 32 Map<String, String> messages = reqDTO.getMessages();
32 if (CollUtil.isNotEmpty(messages)) { 33 if (CollUtil.isNotEmpty(messages)) {
33 - messages.keySet().forEach(key -> {  
34 - findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value)));  
35 - }); 34 + messages.keySet().forEach(key -> findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value))));
36 } 35 }
37 return message; 36 return message;
38 } 37 }
39 38
  39 + // TODO @puhui999:要不 convert 直接放到 service 里。其实可以 BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class) 来搞的呀。
40 @Mapping(target = "id", source = "priTmplId") 40 @Mapping(target = "id", source = "priTmplId")
41 SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo); 41 SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo);
42 42
  43 + // TODO @puhui999:是不是用 CollectionUtils.convertList 就 ok 啦。
43 default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) { 44 default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) {
44 List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>(); 45 List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>();
45 subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo))); 46 subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo)));