Commit 666de3c5946595613d6cfe38e1c7ddad44ec8a48
1 parent
da5641c7
feature(*): 优化查询线索到期时间的api接口
- 优化查询线索到期时间的api接口
Showing
6 changed files
with
80 additions
and
44 deletions
fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java
... | ... | @@ -22,7 +22,7 @@ public class ThreadPoolUtil { |
22 | 22 | private ThreadPoolUtil() { |
23 | 23 | this.executor = ExecutorBuilder.create() |
24 | 24 | .setCorePoolSize(20) |
25 | - .setMaxPoolSize(500) | |
25 | + .setMaxPoolSize(200) | |
26 | 26 | .setThreadFactory(new ThreadFactoryBuilder().setNameFormat("valhalla-custom-%d").build()) |
27 | 27 | .setAllowCoreThreadTimeOut(true) |
28 | 28 | .setWorkQueue(new LinkedBlockingQueue<>(4096)) | ... | ... |
fw-valhalla-sdk/src/main/java/cn/fw/valhalla/sdk/api/ValhallaGeneralApiService.java
1 | 1 | package cn.fw.valhalla.sdk.api; |
2 | 2 | |
3 | 3 | import cn.fw.data.base.domain.common.Message; |
4 | +import cn.fw.valhalla.sdk.param.ClueDeadlineParams; | |
4 | 5 | import cn.fw.valhalla.sdk.param.CustomerQueryReq; |
5 | 6 | import cn.fw.valhalla.sdk.param.ReachLogReq; |
6 | 7 | import cn.fw.valhalla.sdk.result.AccidentFollowerResult; |
... | ... | @@ -54,12 +55,11 @@ public interface ValhallaGeneralApiService { |
54 | 55 | /** |
55 | 56 | * 查询车辆最短的一个跟进的截止日期(不包含事故车) |
56 | 57 | * |
57 | - * @param vinList maxLength 1000 | |
58 | - * @param groupId | |
58 | + * @param params | |
59 | 59 | * @return |
60 | 60 | */ |
61 | - @GetMapping("/query/customer/clue/batch/deadline") | |
62 | - Message<List<CustomerClueDeadline>> queryClueDeadlineBatch(@RequestParam("vinList") List<String> vinList, @RequestParam("groupId") Long groupId); | |
61 | + @PostMapping("/query/customer/clue/batch/deadline") | |
62 | + Message<List<CustomerClueDeadline>> queryClueDeadlineBatch(@Valid @RequestBody ClueDeadlineParams params); | |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * 根据车牌号查询事故车跟进人员 | ... | ... |
fw-valhalla-sdk/src/main/java/cn/fw/valhalla/sdk/param/ClueDeadlineParams.java
0 → 100644
1 | +package cn.fw.valhalla.sdk.param; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +import javax.validation.constraints.NotEmpty; | |
6 | +import javax.validation.constraints.NotNull; | |
7 | +import javax.validation.constraints.Size; | |
8 | +import java.util.Collections; | |
9 | +import java.util.List; | |
10 | + | |
11 | +/** | |
12 | + * 查询线索截止日期参数 | |
13 | + * | |
14 | + * @author : kurisu | |
15 | + * @version : 2.0 | |
16 | + * @className : ClueDeadlineParams | |
17 | + * @description : 查询线索截止日期参数 | |
18 | + * @date : 2023-04-28 16:40 | |
19 | + */ | |
20 | +@Data | |
21 | +public class ClueDeadlineParams { | |
22 | + @NotNull(message = "集团id不能为空") | |
23 | + private Long groupId; | |
24 | + @NotEmpty(message = "vin不能为空") | |
25 | + @Size(min = 1, max = 1000, message = "最大支持一次性查询1000条数据") | |
26 | + private List<String> vinList; | |
27 | + | |
28 | + public void setVinList(final List<String> vinList) { | |
29 | + this.vinList = vinList; | |
30 | + } | |
31 | + | |
32 | + public void setVin(final String vin) { | |
33 | + this.vinList = Collections.singletonList(vin); | |
34 | + } | |
35 | +} | ... | ... |
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/api/ValhallaGeneralApiServiceImpl.java
... | ... | @@ -5,6 +5,7 @@ import cn.fw.data.base.domain.common.Message; |
5 | 5 | import cn.fw.valhalla.domain.db.follow.ClueTask; |
6 | 6 | import cn.fw.valhalla.domain.dto.CustomerDetailDto; |
7 | 7 | import cn.fw.valhalla.sdk.api.ValhallaGeneralApiService; |
8 | +import cn.fw.valhalla.sdk.param.ClueDeadlineParams; | |
8 | 9 | import cn.fw.valhalla.sdk.param.CustomerQueryReq; |
9 | 10 | import cn.fw.valhalla.sdk.param.ReachLogReq; |
10 | 11 | import cn.fw.valhalla.sdk.result.AccidentFollowerResult; |
... | ... | @@ -97,17 +98,14 @@ public class ValhallaGeneralApiServiceImpl implements ValhallaGeneralApiService |
97 | 98 | /** |
98 | 99 | * 查询车辆最短的一个跟进的截止日期(不包含事故车) |
99 | 100 | * |
100 | - * @param vinList | |
101 | + * @param params | |
101 | 102 | * @return |
102 | 103 | */ |
103 | - @GetMapping("/query/customer/clue/batch/deadline") | |
104 | + @PostMapping("/query/customer/clue/batch/deadline") | |
104 | 105 | @Override |
105 | 106 | @ControllerMethod("查询车辆最短的一个跟进的截止日期[批量]") |
106 | - public Message<List<CustomerClueDeadline>> queryClueDeadlineBatch(@RequestParam("vinList") final List<String> vinList, @RequestParam("groupId") final Long groupId) { | |
107 | - BV.isNotEmpty(vinList, () -> "车辆vin不能为空"); | |
108 | - int size = vinList.size(); | |
109 | - BV.isTrue(size <= 1000, () -> "已经超过可查询的最大查询数量[1000]"); | |
110 | - return success(clueApiBizService.queryClueDeadlineBatch(vinList, groupId)); | |
107 | + public Message<List<CustomerClueDeadline>> queryClueDeadlineBatch(@Valid @RequestBody ClueDeadlineParams params) { | |
108 | + return success(clueApiBizService.queryClueDeadlineBatch(params.getVinList(), params.getGroupId())); | |
111 | 109 | } |
112 | 110 | |
113 | 111 | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/ClueApiBizService.java
... | ... | @@ -51,6 +51,40 @@ public class ClueApiBizService { |
51 | 51 | public CustomerClueDeadline queryClueDeadline(final String vin, final Long groupId) { |
52 | 52 | final CustomerClueDeadline customerClueDeadline = new CustomerClueDeadline(); |
53 | 53 | customerClueDeadline.setVin(vin); |
54 | + fillClueDeadline(customerClueDeadline, groupId); | |
55 | + return customerClueDeadline; | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * 批量查询档案最快到期线索的截止时间 | |
60 | + * | |
61 | + * @param vinList | |
62 | + * @param groupId | |
63 | + * @return | |
64 | + */ | |
65 | + public List<CustomerClueDeadline> queryClueDeadlineBatch(final List<String> vinList, final Long groupId) { | |
66 | + HashSet<String> vinSet = new HashSet<>(); | |
67 | + for (String vin : vinList) { | |
68 | + if (StringUtils.isValid(vin)) { | |
69 | + vinSet.add(vin); | |
70 | + } | |
71 | + } | |
72 | + final List<CustomerClueDeadline> list = new ArrayList<>(vinSet.size()); | |
73 | + for (String vin : vinSet) { | |
74 | + CustomerClueDeadline clue = new CustomerClueDeadline(); | |
75 | + clue.setVin(vin); | |
76 | + list.add(clue); | |
77 | + } | |
78 | + CompletableFuture<Void>[] futureArr = list.stream() | |
79 | + .map(r -> CompletableFuture.runAsync(() -> fillClueDeadline(r, groupId), ThreadPoolUtil.getInstance().getExecutor())) | |
80 | + .<CompletableFuture<Void>>toArray(CompletableFuture[]::new); | |
81 | + CompletableFuture.allOf(futureArr).join(); | |
82 | + return list; | |
83 | + } | |
84 | + | |
85 | + private void fillClueDeadline(CustomerClueDeadline customerClueDeadline, Long groupId) { | |
86 | + String vin = customerClueDeadline.getVin(); | |
87 | + customerClueDeadline.setVin(vin); | |
54 | 88 | SettingVO bySettingType = generalSetting.getBySettingType(SettingTypeEnum.EFFECTIVE_TIME, groupId, generalSetting.COMMON_BRAND_ID); |
55 | 89 | int hours = Optional.ofNullable(bySettingType).map(SettingVO::getDetailValue).orElse(36); |
56 | 90 | Duration duration = Duration.ofHours(hours); |
... | ... | @@ -87,32 +121,5 @@ public class ClueApiBizService { |
87 | 121 | if (Objects.nonNull(deadline)) { |
88 | 122 | customerClueDeadline.setDeadline(DateUtil.localDateTime2Date(deadline)); |
89 | 123 | } |
90 | - return customerClueDeadline; | |
91 | - } | |
92 | - | |
93 | - /** | |
94 | - * 批量查询档案最快到期线索的截止时间 | |
95 | - * | |
96 | - * @param vinList | |
97 | - * @param groupId | |
98 | - * @return | |
99 | - */ | |
100 | - public List<CustomerClueDeadline> queryClueDeadlineBatch(final List<String> vinList, final Long groupId) { | |
101 | - HashSet<String> vinSet = new HashSet<>(); | |
102 | - for (String vin : vinList) { | |
103 | - if (StringUtils.isValid(vin)) { | |
104 | - vinSet.add(vin); | |
105 | - } | |
106 | - } | |
107 | - final List<CustomerClueDeadline> list = new ArrayList<>(); | |
108 | - CompletableFuture<Void>[] futureArr = vinSet.stream() | |
109 | - .map(vin -> CompletableFuture.runAsync(() -> list.add(queryClueDeadline(vin, groupId)), ThreadPoolUtil.getInstance().getExecutor())) | |
110 | - .<CompletableFuture<Void>>toArray(CompletableFuture[]::new); | |
111 | - try { | |
112 | - CompletableFuture.allOf(futureArr).join(); | |
113 | - } catch (Exception e) { | |
114 | - log.error("Failed to query clue deadline", e); | |
115 | - } | |
116 | - return list; | |
117 | 124 | } |
118 | 125 | } | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/pub/PubFollowBizService.java
... | ... | @@ -186,11 +186,7 @@ public class PubFollowBizService { |
186 | 186 | } |
187 | 187 | }, ThreadPoolUtil.getInstance().getExecutor())).<CompletableFuture<Void>>toArray(CompletableFuture[]::new); |
188 | 188 | |
189 | - try { | |
190 | - CompletableFuture.allOf(futureArr).get(); | |
191 | - } catch (Exception e) { | |
192 | - log.error("数据查询失败", e); | |
193 | - } | |
189 | + CompletableFuture.allOf(futureArr).join(); | |
194 | 190 | return simpleList; |
195 | 191 | } |
196 | 192 | ... | ... |