ClueApiBizService.java
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package cn.fw.valhalla.service.bus.follow;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.common.utils.StringUtils;
import cn.fw.valhalla.common.utils.ThreadPoolUtil;
import cn.fw.valhalla.domain.db.follow.FollowClue;
import cn.fw.valhalla.domain.db.pub.PubCluePool;
import cn.fw.valhalla.domain.enums.ClueStatusEnum;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.enums.PublicClueStateEnum;
import cn.fw.valhalla.domain.enums.SettingTypeEnum;
import cn.fw.valhalla.domain.vo.setting.SettingVO;
import cn.fw.valhalla.sdk.result.CustomerClueDeadline;
import cn.fw.valhalla.service.bus.setting.strategy.impl.GeneralSetting;
import cn.fw.valhalla.service.data.FollowClueService;
import cn.fw.valhalla.service.data.PubCluePoolService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
/**
* 线索api查询
*
* @author : kurisu
* @version : 2.0
* @className : ClueApiBizService
* @description : 线索查询
* @date : 2023-04-27 17:07
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class ClueApiBizService {
private final FollowClueService followClueService;
private final GeneralSetting generalSetting;
private final PubCluePoolService pubCluePoolService;
/**
* 查询线索最快到期的时间
*
* @param vin
* @param groupId
* @return
*/
public CustomerClueDeadline queryClueDeadline(final String vin, final Long groupId) {
final CustomerClueDeadline customerClueDeadline = new CustomerClueDeadline();
customerClueDeadline.setVin(vin);
SettingVO bySettingType = generalSetting.getBySettingType(SettingTypeEnum.EFFECTIVE_TIME, groupId, generalSetting.COMMON_BRAND_ID);
int hours = Optional.ofNullable(bySettingType).map(SettingVO::getDetailValue).orElse(36);
Duration duration = Duration.ofHours(hours);
customerClueDeadline.setFollowDuration(duration);
FollowClue followClue = followClueService.getOne(Wrappers.<FollowClue>lambdaQuery()
.eq(FollowClue::getVin, vin)
.eq(FollowClue::getGroupId, groupId)
.eq(FollowClue::getClueState, ClueStatusEnum.ONGOING)
.ne(FollowClue::getClueType, FollowTypeEnum.AC)
.orderByAsc(FollowClue::getEndTime)
.last(" limit 1")
);
LocalDateTime deadline = null;
if (Objects.nonNull(followClue)) {
deadline = followClue.getEndTime();
}
PubCluePool pubCluePool = pubCluePoolService.getOne(Wrappers.<PubCluePool>lambdaQuery()
.eq(PubCluePool::getVin, vin)
.eq(PubCluePool::getGroupId, groupId)
.eq(PubCluePool::getState, PublicClueStateEnum.ONGOING)
.orderByAsc(PubCluePool::getDeadline)
.last(" limit 1")
);
if (Objects.nonNull(pubCluePool)) {
LocalDateTime pubClueDeadline = pubCluePool.getDeadline().atStartOfDay();
if (Objects.isNull(deadline)) {
deadline = pubClueDeadline;
} else {
if (pubClueDeadline.isBefore(deadline)) {
deadline = pubClueDeadline;
}
}
}
if (Objects.nonNull(deadline)) {
customerClueDeadline.setDeadline(DateUtil.localDateTime2Date(deadline));
}
return customerClueDeadline;
}
/**
* 批量查询档案最快到期线索的截止时间
*
* @param vinList
* @param groupId
* @return
*/
public List<CustomerClueDeadline> queryClueDeadlineBatch(final List<String> vinList, final Long groupId) {
HashSet<String> vinSet = new HashSet<>();
for (String vin : vinList) {
if (StringUtils.isValid(vin)) {
vinSet.add(vin);
}
}
final List<CustomerClueDeadline> list = new ArrayList<>();
CompletableFuture<Void>[] futureArr = vinSet.stream()
.map(vin -> CompletableFuture.runAsync(() -> list.add(queryClueDeadline(vin, groupId)), ThreadPoolUtil.getInstance().getExecutor()))
.<CompletableFuture<Void>>toArray(CompletableFuture[]::new);
try {
CompletableFuture.allOf(futureArr).get();
} catch (Exception e) {
log.error("Failed to query clue deadline", e);
}
return list;
}
}