mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	【代码评审】SYSTEM:订阅消息
This commit is contained in:
		| @@ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV