mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	【代码评审】SYSTEM:订阅消息
This commit is contained in:
		| @@ -1,6 +1,5 @@ | |||||||
| package cn.iocoder.yudao.module.trade.enums; | package cn.iocoder.yudao.module.trade.enums; | ||||||
|  |  | ||||||
| // TODO @芋艿:枚举 |  | ||||||
| /** | /** | ||||||
|  * 通知模板枚举类 |  * 通知模板枚举类 | ||||||
|  * |  * | ||||||
| @@ -8,6 +7,8 @@ package cn.iocoder.yudao.module.trade.enums; | |||||||
|  */ |  */ | ||||||
| public interface MessageTemplateConstants { | public interface MessageTemplateConstants { | ||||||
|  |  | ||||||
|  |     //======================= 短信消息模版 ======================= | ||||||
|  |  | ||||||
|     String ORDER_DELIVERY = "order_delivery"; // 短信模版编号 |     String ORDER_DELIVERY = "order_delivery"; // 短信模版编号 | ||||||
|  |  | ||||||
|     String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) |     String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| package cn.iocoder.yudao.module.pay.enums; | package cn.iocoder.yudao.module.pay.enums; | ||||||
|  |  | ||||||
| // TODO @芋艿:枚举 |  | ||||||
| /** | /** | ||||||
|  * 通知模板枚举类 |  * 通知模板枚举类 | ||||||
|  * |  * | ||||||
|   | |||||||
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.api.social.dto; | |||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
|  |  | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -15,6 +14,7 @@ import java.util.Map; | |||||||
| @Data | @Data | ||||||
| public class SocialWxSubscribeMessageSendReqDTO { | public class SocialWxSubscribeMessageSendReqDTO { | ||||||
|  |  | ||||||
|  |     // TODO @puhui999:貌似使用 userId + userType 会不会更合理哈。这样,后端进行查询三方用户的绑定表~ | ||||||
|     /** |     /** | ||||||
|      * 接收者(用户)的 openid. |      * 接收者(用户)的 openid. | ||||||
|      * <pre> |      * <pre> | ||||||
| @@ -27,58 +27,43 @@ public class SocialWxSubscribeMessageSendReqDTO { | |||||||
|     private String toUser; |     private String toUser; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 所需下发的模板消息的id. |      * 模版消息编号 | ||||||
|      * <pre> |  | ||||||
|      * 参数:template_id |  | ||||||
|      * 是否必填: 是 |  | ||||||
|      * 描述: 所需下发的模板消息的id |  | ||||||
|      * </pre> |  | ||||||
|      */ |      */ | ||||||
|     @NotNull(message = "模板消息的id不能为空") |     @NotNull(message = "模版消息编号不能为空") | ||||||
|     private String templateId; |     private String templateId; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 点击模板卡片后的跳转页面,仅限本小程序内的页面. |      * 点击模板卡片后的跳转页面,仅限本小程序内的页面 | ||||||
|      * <pre> |      * | ||||||
|      * 参数:page |      * 支持带参数,(示例 index?foo=bar )。该字段不填则模板无跳转。 | ||||||
|      * 是否必填: 否 |  | ||||||
|      * 描述: 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。 |  | ||||||
|      * </pre> |  | ||||||
|      */ |      */ | ||||||
|     private String page; |     private String page; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版 |      * 跳转小程序类型 | ||||||
|  |      * | ||||||
|  |      * developer 为开发版;trial 为体验版;formal 为正式版【默认】 | ||||||
|      * |      * | ||||||
|      * 枚举 WxMaConstants.MiniProgramState |      * 枚举 WxMaConstants.MiniProgramState | ||||||
|      */ |      */ | ||||||
|  |     // TODO @puhui999:这个非必填。如果没有,代码里去默认下; | ||||||
|     @NotNull(message = "跳转小程序类型不能为空") |     @NotNull(message = "跳转小程序类型不能为空") | ||||||
|     private String miniprogramState; |     private String miniprogramState; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 进入小程序查看的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN |      * 进入小程序查看的语言类型 | ||||||
|  |      * | ||||||
|  |      * zh_CN(简体中文)【默认】、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文) | ||||||
|      * |      * | ||||||
|      * 枚举 WxMaConstants.MiniProgramLang |      * 枚举 WxMaConstants.MiniProgramLang | ||||||
|      */ |      */ | ||||||
|  |     // TODO @puhui999:这个非必填。如果没有,代码里去默认下; | ||||||
|     @NotNull(message = "进入小程序查看的语言类型不能为空") |     @NotNull(message = "进入小程序查看的语言类型不能为空") | ||||||
|     private String lang; |     private String lang; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 模板内容,不填则下发空模板. |      * 模板内容的参数 | ||||||
|      * <pre> |  | ||||||
|      * 参数:data |  | ||||||
|      * 是否必填: 是 |  | ||||||
|      * 描述: 模板内容,不填则下发空模板 |  | ||||||
|      * </pre> |  | ||||||
|      */ |      */ | ||||||
|     private Map<String, String> messages; |     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 { | public class SocialWxSubscribeTemplateRespDTO { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 添加至账号下的模板 id,发送小程序订阅消息时所需 |      * 模版编号 | ||||||
|      */ |      */ | ||||||
|     private String id; |     private String id; | ||||||
|  |  | ||||||
| @@ -31,12 +31,11 @@ public class SocialWxSubscribeTemplateRespDTO { | |||||||
|      */ |      */ | ||||||
|     private String example; |     private String example; | ||||||
|  |  | ||||||
|     // TODO @puhui999:这个在 wxjava 里面,有枚举字段么?没得🤣 |  | ||||||
|     /** |     /** | ||||||
|      * 模版类型 |      * 模版类型 | ||||||
|      * |      * | ||||||
|      * 2 为一次性订阅 |      * 2:为一次性订阅 | ||||||
|      * 3 为长期订阅 |      * 3:为长期订阅 | ||||||
|      */ |      */ | ||||||
|     private Integer type; |     private Integer type; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -71,10 +71,10 @@ public class SocialClientController { | |||||||
|         return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class)); |         return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     //======================= TODO 测试发送订阅消息 ======================= |  | ||||||
|  |  | ||||||
|     @PostMapping("/send-subscribe-message") |     @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()); |         socialClientService.sendSubscribeMessage(reqDTO, UserTypeEnum.MEMBER.getValue()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,20 +26,21 @@ public interface SocialUserConvert { | |||||||
|     @Mapping(source = "reqVO.type", target = "socialType") |     @Mapping(source = "reqVO.type", target = "socialType") | ||||||
|     SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); |     SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); | ||||||
|  |  | ||||||
|  |     // TODO @puhui999:要不 convert 直接放到 service 里。 | ||||||
|     default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) { |     default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) { | ||||||
|         WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); |         WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); | ||||||
|         Map<String, String> messages = reqDTO.getMessages(); |         Map<String, String> messages = reqDTO.getMessages(); | ||||||
|         if (CollUtil.isNotEmpty(messages)) { |         if (CollUtil.isNotEmpty(messages)) { | ||||||
|             messages.keySet().forEach(key -> { |             messages.keySet().forEach(key -> findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value)))); | ||||||
|                 findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value))); |  | ||||||
|             }); |  | ||||||
|         } |         } | ||||||
|         return message; |         return message; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO @puhui999:要不 convert 直接放到 service 里。其实可以 BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class) 来搞的呀。 | ||||||
|     @Mapping(target = "id", source = "priTmplId") |     @Mapping(target = "id", source = "priTmplId") | ||||||
|     SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo); |     SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo); | ||||||
|  |  | ||||||
|  |     // TODO @puhui999:是不是用 CollectionUtils.convertList 就 ok 啦。 | ||||||
|     default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) { |     default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) { | ||||||
|         List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>(); |         List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>(); | ||||||
|         subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo))); |         subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo))); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV