浏览代码

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

YunaiV 10 月之前
父节点
当前提交
512d68f793

+ 2 - 1
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java

@@ -1,6 +1,5 @@
 package cn.iocoder.yudao.module.trade.enums;
 
-// TODO @芋艿:枚举
 /**
  * 通知模板枚举类
  *
@@ -8,6 +7,8 @@ package cn.iocoder.yudao.module.trade.enums;
  */
 public interface MessageTemplateConstants {
 
+    //======================= 短信消息模版 =======================
+
     String ORDER_DELIVERY = "order_delivery"; // 短信模版编号
 
     String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过)

+ 0 - 1
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java

@@ -1,6 +1,5 @@
 package cn.iocoder.yudao.module.pay.enums;
 
-// TODO @芋艿:枚举
 /**
  * 通知模板枚举类
  *

+ 15 - 30
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;
 import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 
-import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -15,6 +14,7 @@ import java.util.Map;
 @Data
 public class SocialWxSubscribeMessageSendReqDTO {
 
+    // TODO @puhui999:貌似使用 userId + userType 会不会更合理哈。这样,后端进行查询三方用户的绑定表~
     /**
      * 接收者(用户)的 openid.
      * <pre>
@@ -27,58 +27,43 @@ public class SocialWxSubscribeMessageSendReqDTO {
     private String toUser;
 
     /**
-     * 所需下发的模板消息的id.
-     * <pre>
-     * 参数:template_id
-     * 是否必填: 是
-     * 描述: 所需下发的模板消息的id
-     * </pre>
+     * 模版消息编号
      */
-    @NotNull(message = "模板消息的id不能为空")
+    @NotNull(message = "模版消息编号不能为空")
     private String templateId;
 
     /**
-     * 点击模板卡片后的跳转页面,仅限本小程序内的页面.
-     * <pre>
-     * 参数:page
-     * 是否必填: 否
-     * 描述: 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
-     * </pre>
+     * 点击模板卡片后的跳转页面,仅限本小程序内的页面
+     *
+     * 支持带参数,(示例 index?foo=bar )。该字段不填则模板无跳转。
      */
     private String page;
 
     /**
-     * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
+     * 跳转小程序类型
+     *
+     * developer 为开发版;trial 为体验版;formal 为正式版【默认】
      *
      * 枚举 WxMaConstants.MiniProgramState
      */
+    // TODO @puhui999:这个非必填。如果没有,代码里去默认下;
     @NotNull(message = "跳转小程序类型不能为空")
     private String miniprogramState;
 
     /**
-     * 进入小程序查看的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
+     * 进入小程序查看的语言类型
+     *
+     * zh_CN(简体中文)【默认】、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文)
      *
      * 枚举 WxMaConstants.MiniProgramLang
      */
+    // TODO @puhui999:这个非必填。如果没有,代码里去默认下;
     @NotNull(message = "进入小程序查看的语言类型不能为空")
     private String lang;
 
     /**
-     * 模板内容,不填则下发空模板.
-     * <pre>
-     * 参数:data
-     * 是否必填: 是
-     * 描述: 模板内容,不填则下发空模板
-     * </pre>
+     * 模板内容的参数
      */
     private Map<String, String> messages;
 
-    public SocialWxSubscribeMessageSendReqDTO addData(String key, String value) {
-        if (messages == null) {
-            messages = new HashMap<>();
-        }
-        messages.put(key, value);
-        return this;
-    }
-
 }

+ 3 - 4
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;
 public class SocialWxSubscribeTemplateRespDTO {
 
     /**
-     * 添加至账号下的模板 id,发送小程序订阅消息时所需
+     * 模版编号
      */
     private String id;
 
@@ -31,12 +31,11 @@ public class SocialWxSubscribeTemplateRespDTO {
      */
     private String example;
 
-    // TODO @puhui999:这个在 wxjava 里面,有枚举字段么?没得🤣
     /**
      * 模版类型
      *
-     * 2 为一次性订阅
-     * 3 为长期订阅
+     * 2为一次性订阅
+     * 3为长期订阅
      */
     private Integer type;
 

+ 3 - 3
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 {
         return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class));
     }
 
-    //======================= TODO 测试发送订阅消息 =======================
-
     @PostMapping("/send-subscribe-message")
-    public void testSendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) {
+    @Operation(summary = "发送订阅消息") // 用于测试
+    @PreAuthorize("@ss.hasPermission('system:social-client:query')")
+    public void sendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) {
         socialClientService.sendSubscribeMessage(reqDTO, UserTypeEnum.MEMBER.getValue());
     }
 

+ 4 - 3
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 {
     @Mapping(source = "reqVO.type", target = "socialType")
     SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO);
 
+    // TODO @puhui999:要不 convert 直接放到 service 里。
     default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) {
         WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
         Map<String, String> messages = reqDTO.getMessages();
         if (CollUtil.isNotEmpty(messages)) {
-            messages.keySet().forEach(key -> {
-                findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value)));
-            });
+            messages.keySet().forEach(key -> findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value))));
         }
         return message;
     }
 
+    // TODO @puhui999:要不 convert 直接放到 service 里。其实可以 BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class) 来搞的呀。
     @Mapping(target = "id", source = "priTmplId")
     SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo);
 
+    // TODO @puhui999:是不是用 CollectionUtils.convertList 就 ok 啦。
     default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) {
         List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>();
         subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo)));