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,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping; | ||
10 | import org.springframework.web.bind.annotation.RequestBody; | 10 | import org.springframework.web.bind.annotation.RequestBody; |
11 | 11 | ||
12 | import javax.validation.Valid; | 12 | import javax.validation.Valid; |
13 | -import javax.validation.constraints.NotEmpty; | ||
14 | import javax.validation.constraints.NotNull; | 13 | import javax.validation.constraints.NotNull; |
15 | import java.util.List; | 14 | import java.util.List; |
16 | 15 | ||
@@ -39,7 +38,7 @@ public interface IMessageCenterService { | @@ -39,7 +38,7 @@ public interface IMessageCenterService { | ||
39 | * @return | 38 | * @return |
40 | */ | 39 | */ |
41 | @PostMapping("/sendBatch") | 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,13 +2,16 @@ package cn.fw.hestia.server.controller.api; | ||
2 | 2 | ||
3 | import cn.fw.common.web.annotation.ControllerMethod; | 3 | 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.common.utils.MessageFormatUtil; | ||
5 | import cn.fw.hestia.sdk.api.IMessageCenterService; | 6 | import cn.fw.hestia.sdk.api.IMessageCenterService; |
6 | import cn.fw.hestia.sdk.params.TemplateMessageParam; | 7 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
7 | import cn.fw.hestia.sdk.params.ValidList; | 8 | import cn.fw.hestia.sdk.params.ValidList; |
8 | import cn.fw.hestia.sdk.result.SendResult; | 9 | import cn.fw.hestia.sdk.result.SendResult; |
9 | import cn.fw.hestia.service.buz.MessageCenterBizService; | 10 | import cn.fw.hestia.service.buz.MessageCenterBizService; |
11 | +import lombok.Getter; | ||
10 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
14 | +import org.springframework.beans.factory.annotation.Value; | ||
12 | import org.springframework.web.bind.annotation.*; | 15 | import org.springframework.web.bind.annotation.*; |
13 | 16 | ||
14 | import javax.validation.Valid; | 17 | import javax.validation.Valid; |
@@ -30,6 +33,10 @@ import static cn.fw.common.web.util.ResultBuilder.success; | @@ -30,6 +33,10 @@ import static cn.fw.common.web.util.ResultBuilder.success; | ||
30 | public class MessageCenterServiceImpl implements IMessageCenterService { | 33 | public class MessageCenterServiceImpl implements IMessageCenterService { |
31 | private final MessageCenterBizService messageCenterBizService; | 34 | private final MessageCenterBizService messageCenterBizService; |
32 | 35 | ||
36 | + @Value("${task.max-size}") | ||
37 | + @Getter | ||
38 | + private int maxSize; | ||
39 | + | ||
33 | @Autowired | 40 | @Autowired |
34 | public MessageCenterServiceImpl(final MessageCenterBizService messageCenterBizService) { | 41 | public MessageCenterServiceImpl(final MessageCenterBizService messageCenterBizService) { |
35 | this.messageCenterBizService = messageCenterBizService; | 42 | this.messageCenterBizService = messageCenterBizService; |
@@ -47,6 +54,7 @@ public class MessageCenterServiceImpl implements IMessageCenterService { | @@ -47,6 +54,7 @@ public class MessageCenterServiceImpl implements IMessageCenterService { | ||
47 | @ControllerMethod("批量发送模板消息") | 54 | @ControllerMethod("批量发送模板消息") |
48 | public Message<List<SendResult>> sendBatch(@RequestBody @Valid ValidList<TemplateMessageParam> paramList) { | 55 | public Message<List<SendResult>> sendBatch(@RequestBody @Valid ValidList<TemplateMessageParam> paramList) { |
49 | BV.isNotEmpty(paramList, () -> "消息列表不能为空"); | 56 | BV.isNotEmpty(paramList, () -> "消息列表不能为空"); |
57 | + BV.isTrue(paramList.size() <= getMaxSize(), () -> MessageFormatUtil.MessageFormatTransfer("最多支持一次性发送{0}条", getMaxSize())); | ||
50 | return success(messageCenterBizService.saveBatchMessage(paramList)); | 58 | return success(messageCenterBizService.saveBatchMessage(paramList)); |
51 | } | 59 | } |
52 | 60 |
fw-hestia-server/src/main/resources/application.yml
@@ -122,4 +122,5 @@ logbook: | @@ -122,4 +122,5 @@ logbook: | ||
122 | style: http | 122 | style: http |
123 | 123 | ||
124 | task: | 124 | task: |
125 | - switch: 'on' | ||
126 | \ No newline at end of file | 125 | \ No newline at end of file |
126 | + switch: 'on' | ||
127 | + max-size: 1000 | ||
127 | \ No newline at end of file | 128 | \ No newline at end of file |