Commit 0de79f3b47bf1affba9f57bfb0c2441d8e15a582
1 parent
cc5087e0
优化批量发送接口
Showing
3 changed files
with
11 additions
and
3 deletions
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/api/IMessageCenterService.java
... | ... | @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping; |
10 | 10 | import org.springframework.web.bind.annotation.RequestBody; |
11 | 11 | |
12 | 12 | import javax.validation.Valid; |
13 | -import javax.validation.constraints.NotEmpty; | |
14 | 13 | import javax.validation.constraints.NotNull; |
15 | 14 | import java.util.List; |
16 | 15 | |
... | ... | @@ -39,7 +38,7 @@ public interface IMessageCenterService { |
39 | 38 | * @return |
40 | 39 | */ |
41 | 40 | @PostMapping("/sendBatch") |
42 | - Message<List<SendResult>> sendBatch(@RequestBody @NotEmpty(message = "消息列表不能为空") @Valid ValidList<TemplateMessageParam> paramList); | |
41 | + Message<List<SendResult>> sendBatch(@RequestBody @Valid ValidList<TemplateMessageParam> paramList); | |
43 | 42 | |
44 | 43 | /** |
45 | 44 | * 撤回消息 | ... | ... |
fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/api/MessageCenterServiceImpl.java
... | ... | @@ -2,13 +2,16 @@ package cn.fw.hestia.server.controller.api; |
2 | 2 | |
3 | 3 | import cn.fw.common.web.annotation.ControllerMethod; |
4 | 4 | import cn.fw.data.base.domain.common.Message; |
5 | +import cn.fw.hestia.common.utils.MessageFormatUtil; | |
5 | 6 | import cn.fw.hestia.sdk.api.IMessageCenterService; |
6 | 7 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
7 | 8 | import cn.fw.hestia.sdk.params.ValidList; |
8 | 9 | import cn.fw.hestia.sdk.result.SendResult; |
9 | 10 | import cn.fw.hestia.service.buz.MessageCenterBizService; |
11 | +import lombok.Getter; | |
10 | 12 | import lombok.extern.slf4j.Slf4j; |
11 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
14 | +import org.springframework.beans.factory.annotation.Value; | |
12 | 15 | import org.springframework.web.bind.annotation.*; |
13 | 16 | |
14 | 17 | import javax.validation.Valid; |
... | ... | @@ -30,6 +33,10 @@ import static cn.fw.common.web.util.ResultBuilder.success; |
30 | 33 | public class MessageCenterServiceImpl implements IMessageCenterService { |
31 | 34 | private final MessageCenterBizService messageCenterBizService; |
32 | 35 | |
36 | + @Value("${task.max-size}") | |
37 | + @Getter | |
38 | + private int maxSize; | |
39 | + | |
33 | 40 | @Autowired |
34 | 41 | public MessageCenterServiceImpl(final MessageCenterBizService messageCenterBizService) { |
35 | 42 | this.messageCenterBizService = messageCenterBizService; |
... | ... | @@ -47,6 +54,7 @@ public class MessageCenterServiceImpl implements IMessageCenterService { |
47 | 54 | @ControllerMethod("批量发送模板消息") |
48 | 55 | public Message<List<SendResult>> sendBatch(@RequestBody @Valid ValidList<TemplateMessageParam> paramList) { |
49 | 56 | BV.isNotEmpty(paramList, () -> "消息列表不能为空"); |
57 | + BV.isTrue(paramList.size() <= getMaxSize(), () -> MessageFormatUtil.MessageFormatTransfer("最多支持一次性发送{0}条", getMaxSize())); | |
50 | 58 | return success(messageCenterBizService.saveBatchMessage(paramList)); |
51 | 59 | } |
52 | 60 | ... | ... |