PubFollowBizService.java
7.74 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package cn.fw.valhalla.service.bus.pub;
import cn.fw.valhalla.domain.db.customer.Customer;
import cn.fw.valhalla.domain.db.customer.CustomerBaseInfo;
import cn.fw.valhalla.domain.db.follow.ClueTask;
import cn.fw.valhalla.domain.db.pool.PublicPool;
import cn.fw.valhalla.domain.db.pub.PubCluePool;
import cn.fw.valhalla.domain.enums.*;
import cn.fw.valhalla.rpc.oop.OopService;
import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
import cn.fw.valhalla.service.bus.follow.strategy.impl.PubFollowStrategy;
import cn.fw.valhalla.service.bus.setting.SettingBizService;
import cn.fw.valhalla.service.data.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* 公共池跟进处理
*
* @author : kurisu
* @version : 1.0
* @className : PubFollowBizService
* @description : 公共池跟进处理
* @date : 2023-03-17 17:23
*/
@Slf4j
@Service
public class PubFollowBizService {
private final PubCluePoolService pubCluePoolService;
private final PublicPoolService publicPoolService;
private final StammkundePoolService stammkundePoolService;
private final CustomerService customerService;
private final CustomerBaseInfoService customerBaseInfoService;
private final SettingBizService settingBizService;
private final ClueTaskService clueTaskService;
private final StringRedisTemplate stringRedisTemplate;
private final OopService oopService;
private final PubFollowStrategy pubFollowStrategy;
@Value("${follow.todo.PubFollowCode}")
@Getter(AccessLevel.PRIVATE)
private String pubFollowCode;
@Value("${spring.cache.custom.global-prefix}:role-change-need-close:clue")
@Getter(AccessLevel.PRIVATE)
private String roleChangeNeedCloseClueKey;
@Autowired
public PubFollowBizService(final PubCluePoolService pubCluePoolService,
final PublicPoolService publicPoolService,
final StammkundePoolService stammkundePoolService,
final CustomerService customerService,
final CustomerBaseInfoService customerBaseInfoService,
final SettingBizService settingBizService,
final ClueTaskService clueTaskService,
final StringRedisTemplate stringRedisTemplate,
final OopService oopService,
final PubFollowStrategy pubFollowStrategy) {
this.pubCluePoolService = pubCluePoolService;
this.publicPoolService = publicPoolService;
this.stammkundePoolService = stammkundePoolService;
this.customerService = customerService;
this.customerBaseInfoService = customerBaseInfoService;
this.settingBizService = settingBizService;
this.clueTaskService = clueTaskService;
this.stringRedisTemplate = stringRedisTemplate;
this.oopService = oopService;
this.pubFollowStrategy = pubFollowStrategy;
}
/**
* 人员角色变动或缓存需要战败的vin
*
* @param userId
* @param shopId
*/
public void onRoleChange(Long userId, Long shopId) {
List<PubCluePool> list = pubCluePoolService.list(Wrappers.<PubCluePool>lambdaQuery()
.eq(PubCluePool::getAdviserId, userId)
.eq(PubCluePool::getState, PublicClueStateEnum.ONGOING)
);
if (CollectionUtils.isEmpty(list)) {
return;
}
BoundSetOperations<String, String> setOps = stringRedisTemplate.boundSetOps(getRoleChangeNeedCloseClueKey());
for (PubCluePool pool : list) {
setOps.add(String.valueOf(pool.getId()));
}
}
/**
* 开始线索
* @param pool
*/
@Transactional(rollbackFor = Exception.class)
public void startClue(PubCluePool pool) {
pubFollowStrategy.startClue(pool);
pool.setBegun(Boolean.TRUE);
pubCluePoolService.updateById(pool);
}
/**
* 角色变动结束线索
*
* @param id
*/
@Transactional(rollbackFor = Exception.class)
public void roleChangeDefeatClue(String id) {
PubCluePool pool = pubCluePoolService.getById(Long.valueOf(id));
if (Objects.isNull(pool)) {
return;
}
Customer customer = customerService.queryByFrameNo(pool.getVin(), pool.getGroupId());
endClue(pool);
if (Objects.nonNull(customer)) {
customerRemoval(customer);
}
}
/**
* 结束线索
*
* @param pool
*/
@Transactional(rollbackFor = Exception.class)
public void endClue(PubCluePool pool) {
ClueTask task = clueTaskService.getOne(Wrappers.<ClueTask>lambdaQuery()
.eq(ClueTask::getClueId, pool.getId())
.eq(ClueTask::getType, FollowTypeEnum.PL)
.eq(ClueTask::getState, TaskStateEnum.ONGOING)
, Boolean.FALSE);
if (Objects.nonNull(task)) {
pubFollowStrategy.onRoleChangeCloseTask(task);
}
pool.setState(PublicClueStateEnum.DEFEAT);
pool.setCloseTime(LocalDateTime.now());
pool.setDefeatReason(TaskDefeatTypeEnum.D);
pubCluePoolService.updateById(pool);
}
/**
* 移除档案到公共池
*
* @param customer
*/
private void customerRemoval(Customer customer) {
PublicPool publicPool = createPublicPool(customer);
publicPoolService.save(publicPool);
stammkundePoolService.reject(customer.getId(), customer.getGroupId(), DefeatReasonEnum.RC);
customer.setAdviserId(null);
customer.setShopId(null);
customerService.updateById(customer);
}
private PublicPool createPublicPool(Customer customer) {
final Long shopId = Optional.ofNullable(customer.getLastArrivalShop()).orElse(customer.getShopId());
ShopDTO shop = oopService.shop(shopId);
BV.notNull(shop, () -> String.format("门店[%s]信息获取失败", shopId));
String shopName = shop.getShortName();
final Long baseId = customer.getBaseId();
CustomerBaseInfo baseInfo = customerBaseInfoService.getById(baseId);
BV.notNull(baseInfo, () -> String.format("档案车主信息获取失败[%s]", baseId));
PublicPool pool = new PublicPool();
pool.setCustomerId(customer.getId());
pool.setCustomerName(baseInfo.getName());
pool.setPlateNo(customer.getPlateNo());
pool.setFrameNo(customer.getFrameNo());
pool.setBrandId(customer.getBrandId());
pool.setBrandName(customer.getBrandName());
pool.setSeriesId(customer.getSeriesId());
pool.setSeriesName(customer.getSeriesName());
pool.setSpecId(customer.getSpecId());
pool.setSpecName(customer.getSpecName());
pool.setAddress(baseInfo.getAddress());
pool.setCompany(baseInfo.getCompanyName());
pool.setType(PublicPoolTypeEnum.RC);
pool.setShopId(shopId);
pool.setShopName(shopName);
pool.setTimes(customer.getArrivalCount());
pool.setReason(PublicPoolTypeEnum.RC.getName());
pool.setGroupId(customer.getGroupId());
return pool;
}
}