Commit 00e8ae34b9badd75ee5fd307a71c9e1b0675a8a8
1 parent
bbb0ab04
优化发送接口
Showing
6 changed files
with
63 additions
and
19 deletions
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/api/IMessageCenterService.java
@@ -2,6 +2,7 @@ package cn.fw.hestia.sdk.api; | @@ -2,6 +2,7 @@ package cn.fw.hestia.sdk.api; | ||
2 | 2 | ||
3 | import cn.fw.data.base.domain.common.Message; | 3 | import cn.fw.data.base.domain.common.Message; |
4 | import cn.fw.hestia.sdk.params.TemplateMessageParam; | 4 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
5 | +import cn.fw.hestia.sdk.result.SendResult; | ||
5 | import org.springframework.cloud.openfeign.FeignClient; | 6 | import org.springframework.cloud.openfeign.FeignClient; |
6 | import org.springframework.web.bind.annotation.DeleteMapping; | 7 | import org.springframework.web.bind.annotation.DeleteMapping; |
7 | import org.springframework.web.bind.annotation.PostMapping; | 8 | import org.springframework.web.bind.annotation.PostMapping; |
@@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody; | @@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody; | ||
9 | 10 | ||
10 | import javax.validation.Valid; | 11 | import javax.validation.Valid; |
11 | import javax.validation.constraints.NotNull; | 12 | import javax.validation.constraints.NotNull; |
13 | +import java.util.List; | ||
12 | 14 | ||
13 | /** | 15 | /** |
14 | * @author : kurisu | 16 | * @author : kurisu |
@@ -26,7 +28,7 @@ public interface IMessageCenterService { | @@ -26,7 +28,7 @@ public interface IMessageCenterService { | ||
26 | * @return | 28 | * @return |
27 | */ | 29 | */ |
28 | @PostMapping("/send") | 30 | @PostMapping("/send") |
29 | - Message<Long> send(@Valid @RequestBody TemplateMessageParam templateMessageParam); | 31 | + Message<List<SendResult>> send(@Valid @RequestBody TemplateMessageParam templateMessageParam); |
30 | 32 | ||
31 | /** | 33 | /** |
32 | * 撤回消息 | 34 | * 撤回消息 |
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/params/TemplateMessageParam.java
@@ -3,11 +3,11 @@ package cn.fw.hestia.sdk.params; | @@ -3,11 +3,11 @@ package cn.fw.hestia.sdk.params; | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | import lombok.ToString; | 4 | import lombok.ToString; |
5 | 5 | ||
6 | -import javax.validation.constraints.Max; | ||
7 | import javax.validation.constraints.NotBlank; | 6 | import javax.validation.constraints.NotBlank; |
8 | import javax.validation.constraints.NotNull; | 7 | import javax.validation.constraints.NotNull; |
9 | import javax.validation.constraints.Size; | 8 | import javax.validation.constraints.Size; |
10 | import java.util.Map; | 9 | import java.util.Map; |
10 | +import java.util.Set; | ||
11 | 11 | ||
12 | /** | 12 | /** |
13 | * 模板消息param | 13 | * 模板消息param |
@@ -19,12 +19,6 @@ import java.util.Map; | @@ -19,12 +19,6 @@ import java.util.Map; | ||
19 | * 变更结果:{{keyword2.DATA}} | 19 | * 变更结果:{{keyword2.DATA}} |
20 | * {{remark.DATA}} | 20 | * {{remark.DATA}} |
21 | * | 21 | * |
22 | - * 示例: | ||
23 | - * 尊敬的客户,您的业务状态已经发生变更 变更详情如下: | ||
24 | - * 变更类型:组局地点 | ||
25 | - * 变更结果:由清水河改为滨江 | ||
26 | - * 如有疑问,请拨打客服电话 | ||
27 | - * | ||
28 | * @author kurisu | 22 | * @author kurisu |
29 | */ | 23 | */ |
30 | @Data | 24 | @Data |
@@ -33,8 +27,8 @@ public class TemplateMessageParam { | @@ -33,8 +27,8 @@ public class TemplateMessageParam { | ||
33 | /** | 27 | /** |
34 | * 会员id | 28 | * 会员id |
35 | */ | 29 | */ |
36 | - @NotNull(message = "会员id不能为空") | ||
37 | - private Long memberId; | 30 | + @Size(min = 1, message = "会员id不能为空") |
31 | + private Set<Long> memberIdSet; | ||
38 | /** | 32 | /** |
39 | * 标题 小程序展示用 | 33 | * 标题 小程序展示用 |
40 | * maxLength 32 | 34 | * maxLength 32 |
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/result/MessageSendMq.java
@@ -22,6 +22,10 @@ public class MessageSendMq { | @@ -22,6 +22,10 @@ public class MessageSendMq { | ||
22 | */ | 22 | */ |
23 | private Long sceneToken; | 23 | private Long sceneToken; |
24 | /** | 24 | /** |
25 | + * 用户id | ||
26 | + */ | ||
27 | + private Long memberId; | ||
28 | + /** | ||
25 | * 发送时间 | 29 | * 发送时间 |
26 | */ | 30 | */ |
27 | private Date sendTime; | 31 | private Date sendTime; |
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/result/SendResult.java
0 → 100644
1 | +package cn.fw.hestia.sdk.result; | ||
2 | + | ||
3 | +import lombok.AllArgsConstructor; | ||
4 | +import lombok.Data; | ||
5 | +import lombok.NoArgsConstructor; | ||
6 | + | ||
7 | +/** | ||
8 | + * @author : kurisu | ||
9 | + * @className : SendResult | ||
10 | + * @description : 消息发送返回结果 | ||
11 | + * @date: 2021-09-28 11:00 | ||
12 | + */ | ||
13 | +@Data | ||
14 | +@AllArgsConstructor | ||
15 | +@NoArgsConstructor | ||
16 | +public class SendResult { | ||
17 | + /** | ||
18 | + * 唯一标识 | ||
19 | + */ | ||
20 | + private Long sceneToken; | ||
21 | + /** | ||
22 | + * 用户id | ||
23 | + */ | ||
24 | + private Long memberId; | ||
25 | +} |
fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/api/MessageCenterServiceImpl.java
@@ -4,6 +4,7 @@ import cn.fw.common.web.annotation.ControllerMethod; | @@ -4,6 +4,7 @@ import cn.fw.common.web.annotation.ControllerMethod; | ||
4 | import cn.fw.data.base.domain.common.Message; | 4 | import cn.fw.data.base.domain.common.Message; |
5 | import cn.fw.hestia.sdk.api.IMessageCenterService; | 5 | import cn.fw.hestia.sdk.api.IMessageCenterService; |
6 | import cn.fw.hestia.sdk.params.TemplateMessageParam; | 6 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
7 | +import cn.fw.hestia.sdk.result.SendResult; | ||
7 | import cn.fw.hestia.service.buz.MessageCenterBizService; | 8 | import cn.fw.hestia.service.buz.MessageCenterBizService; |
8 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.*; | @@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.*; | ||
12 | import javax.validation.Valid; | 13 | import javax.validation.Valid; |
13 | import javax.validation.constraints.NotNull; | 14 | import javax.validation.constraints.NotNull; |
14 | 15 | ||
16 | +import java.util.List; | ||
17 | + | ||
15 | import static cn.fw.common.web.util.ResultBuilder.success; | 18 | import static cn.fw.common.web.util.ResultBuilder.success; |
16 | 19 | ||
17 | /** | 20 | /** |
@@ -34,7 +37,7 @@ public class MessageCenterServiceImpl implements IMessageCenterService { | @@ -34,7 +37,7 @@ public class MessageCenterServiceImpl implements IMessageCenterService { | ||
34 | @PostMapping("/send") | 37 | @PostMapping("/send") |
35 | @Override | 38 | @Override |
36 | @ControllerMethod("发送模板消息") | 39 | @ControllerMethod("发送模板消息") |
37 | - public Message<Long> send(@Valid @RequestBody TemplateMessageParam templateMessageParam) { | 40 | + public Message<List<SendResult>> send(@Valid @RequestBody TemplateMessageParam templateMessageParam) { |
38 | return success(messageCenterBizService.saveMessage(templateMessageParam)); | 41 | return success(messageCenterBizService.saveMessage(templateMessageParam)); |
39 | } | 42 | } |
40 | 43 |
fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java
@@ -15,6 +15,7 @@ import cn.fw.hestia.rpc.passport.TemplateMessageService; | @@ -15,6 +15,7 @@ import cn.fw.hestia.rpc.passport.TemplateMessageService; | ||
15 | import cn.fw.hestia.rpc.passport.dto.TMParam; | 15 | import cn.fw.hestia.rpc.passport.dto.TMParam; |
16 | import cn.fw.hestia.sdk.params.TemplateMessageParam; | 16 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
17 | import cn.fw.hestia.sdk.result.MessageSendMq; | 17 | import cn.fw.hestia.sdk.result.MessageSendMq; |
18 | +import cn.fw.hestia.sdk.result.SendResult; | ||
18 | import cn.fw.hestia.service.data.MessageHistoryService; | 19 | import cn.fw.hestia.service.data.MessageHistoryService; |
19 | import cn.fw.hestia.service.data.SendLogService; | 20 | import cn.fw.hestia.service.data.SendLogService; |
20 | import cn.fw.passport.sdk.api.param.WxMpTempMessageData; | 21 | import cn.fw.passport.sdk.api.param.WxMpTempMessageData; |
@@ -63,10 +64,14 @@ public class MessageCenterBizService { | @@ -63,10 +64,14 @@ public class MessageCenterBizService { | ||
63 | * @return token | 64 | * @return token |
64 | */ | 65 | */ |
65 | @Transactional(rollbackFor = Exception.class) | 66 | @Transactional(rollbackFor = Exception.class) |
66 | - public Long saveMessage(TemplateMessageParam templateMessageParam) { | ||
67 | - MessageHistory messageHistory = createBean(templateMessageParam); | ||
68 | - messageHistoryService.save(messageHistory); | ||
69 | - return messageHistory.getId(); | 67 | + public List<SendResult> saveMessage(TemplateMessageParam templateMessageParam) { |
68 | + List<MessageHistory> messageHistory = createBeans(templateMessageParam); | ||
69 | + messageHistoryService.saveBatch(messageHistory); | ||
70 | + List<SendResult> list = new ArrayList<>(); | ||
71 | + for (MessageHistory history : messageHistory) { | ||
72 | + list.add(new SendResult(history.getId(), history.getMemberId())); | ||
73 | + } | ||
74 | + return list; | ||
70 | } | 75 | } |
71 | 76 | ||
72 | 77 | ||
@@ -84,7 +89,7 @@ public class MessageCenterBizService { | @@ -84,7 +89,7 @@ public class MessageCenterBizService { | ||
84 | if (succeed) { | 89 | if (succeed) { |
85 | history.setState(MessageStateEnum.SUMI); | 90 | history.setState(MessageStateEnum.SUMI); |
86 | //发送成功发送mq | 91 | //发送成功发送mq |
87 | - sendMsgProducer.send(new MessageSendMq(history.getId(), new Date())); | 92 | + sendMsgProducer.send(new MessageSendMq(history.getId(), history.getMemberId(), new Date())); |
88 | } else { | 93 | } else { |
89 | history.setSendTime(DateUtil.getExpired(history.getSendTime(), 1 << frequency, Calendar.MINUTE)); | 94 | history.setSendTime(DateUtil.getExpired(history.getSendTime(), 1 << frequency, Calendar.MINUTE)); |
90 | } | 95 | } |
@@ -204,7 +209,7 @@ public class MessageCenterBizService { | @@ -204,7 +209,7 @@ public class MessageCenterBizService { | ||
204 | boolean succeed = MessageConstant.SUCCEED_STR.equals(result); | 209 | boolean succeed = MessageConstant.SUCCEED_STR.equals(result); |
205 | if (succeed) { | 210 | if (succeed) { |
206 | messageHistory.setState(MessageStateEnum.SUMI); | 211 | messageHistory.setState(MessageStateEnum.SUMI); |
207 | - sendMsgProducer.send(new MessageSendMq(messageHistory.getId(), new Date())); | 212 | + sendMsgProducer.send(new MessageSendMq(messageHistory.getId(), messageHistory.getMemberId(), new Date())); |
208 | } | 213 | } |
209 | messageHistoryService.updateById(messageHistory); | 214 | messageHistoryService.updateById(messageHistory); |
210 | return result; | 215 | return result; |
@@ -223,9 +228,20 @@ public class MessageCenterBizService { | @@ -223,9 +228,20 @@ public class MessageCenterBizService { | ||
223 | return result; | 228 | return result; |
224 | } | 229 | } |
225 | 230 | ||
226 | - private MessageHistory createBean(TemplateMessageParam param) { | 231 | + private List<MessageHistory> createBeans(TemplateMessageParam param) { |
232 | + List<MessageHistory> list = new ArrayList<>(); | ||
233 | + Set<Long> idSet = param.getMemberIdSet(); | ||
234 | + BV.isNotEmpty(idSet, () -> "发送的目标用户不能为空"); | ||
235 | + for (Long memberId : idSet) { | ||
236 | + createBeans(param, memberId); | ||
237 | + list.add(createBeans(param, memberId)); | ||
238 | + } | ||
239 | + return list; | ||
240 | + } | ||
241 | + | ||
242 | + private MessageHistory createBeans(TemplateMessageParam param, Long memberId) { | ||
227 | MessageHistory messageHistory = new MessageHistory(); | 243 | MessageHistory messageHistory = new MessageHistory(); |
228 | - messageHistory.setMemberId(param.getMemberId()); | 244 | + messageHistory.setMemberId(memberId); |
229 | messageHistory.setTemplateCode(getTemplateCode()); | 245 | messageHistory.setTemplateCode(getTemplateCode()); |
230 | messageHistory.setTitle(param.getTitle()); | 246 | messageHistory.setTitle(param.getTitle()); |
231 | messageHistory.setContent(param.getContent()); | 247 | messageHistory.setContent(param.getContent()); |