Commit f5051c10349da628c546a7e0f90cb68eb7a08894
1 parent
94c87aab
保有客分配,新增指定人员数量
Showing
2 changed files
with
92 additions
and
78 deletions
fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/LeaveAllocationDTO.java
... | ... | @@ -3,7 +3,11 @@ package cn.fw.valhalla.domain.dto; |
3 | 3 | import cn.fw.valhalla.common.enums.AllocationTypeEnum; |
4 | 4 | import lombok.Data; |
5 | 5 | |
6 | +import javax.validation.Valid; | |
7 | +import javax.validation.constraints.Min; | |
8 | +import javax.validation.constraints.NotEmpty; | |
6 | 9 | import javax.validation.constraints.NotNull; |
10 | +import java.util.List; | |
7 | 11 | |
8 | 12 | /** |
9 | 13 | * @author : kurisu |
... | ... | @@ -15,26 +19,70 @@ import javax.validation.constraints.NotNull; |
15 | 19 | public class LeaveAllocationDTO { |
16 | 20 | @NotNull(message = "记录id不能为空") |
17 | 21 | private Long id; |
18 | - | |
19 | - @NotNull(message = "分配方式不能为空") | |
20 | - private Integer allocationType; | |
21 | - | |
22 | 22 | /** |
23 | - * 指定人员id | |
23 | + * 分配规则 | |
24 | 24 | */ |
25 | - private Long userId; | |
25 | + @Valid | |
26 | + @NotEmpty(message = "分配规则不能为空") | |
27 | + private List<Allocation> ruleList; | |
26 | 28 | |
27 | - /** | |
28 | - * 门店id (前端无关) | |
29 | - */ | |
30 | - private Long shopId; | |
31 | 29 | |
32 | 30 | /** |
33 | - * 分配方式 (前端无关) | |
34 | - */ | |
35 | - private AllocationTypeEnum type; | |
36 | - /** | |
37 | - * 顾问id (前端无关) | |
31 | + * 原始顾问id (前端无关) | |
38 | 32 | */ |
39 | 33 | private Long adviserId; |
34 | + | |
35 | + public static class Allocation { | |
36 | + /** | |
37 | + * 指定人员id | |
38 | + */ | |
39 | + @NotNull(message = "人员id不能为空") | |
40 | + private Long userId; | |
41 | + /** | |
42 | + * 人员名称 | |
43 | + */ | |
44 | + private String userName; | |
45 | + /** | |
46 | + * 指定人员id | |
47 | + */ | |
48 | + @Min(value = 1, message = "保有客数量必须大于0") | |
49 | + private Integer num; | |
50 | + | |
51 | + /** | |
52 | + * 门店id (前端无关) | |
53 | + */ | |
54 | + private Long shopId; | |
55 | + | |
56 | + public Long getUserId() { | |
57 | + return userId; | |
58 | + } | |
59 | + | |
60 | + public void setUserId(Long userId) { | |
61 | + this.userId = userId; | |
62 | + } | |
63 | + | |
64 | + public String getUserName() { | |
65 | + return userName; | |
66 | + } | |
67 | + | |
68 | + public void setUserName(String userName) { | |
69 | + this.userName = userName; | |
70 | + } | |
71 | + | |
72 | + public Integer getNum() { | |
73 | + return num; | |
74 | + } | |
75 | + | |
76 | + public void setNum(Integer num) { | |
77 | + this.num = num; | |
78 | + } | |
79 | + | |
80 | + public Long getShopId() { | |
81 | + return shopId; | |
82 | + } | |
83 | + | |
84 | + public void setShopId(Long shopId) { | |
85 | + this.shopId = shopId; | |
86 | + } | |
87 | + } | |
40 | 88 | } | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/LeaveNeedDoBizService.java
... | ... | @@ -213,25 +213,20 @@ public class LeaveNeedDoBizService { |
213 | 213 | } |
214 | 214 | |
215 | 215 | private void prepareAllocation(LeaveAllocationDTO dto) { |
216 | - AllocationTypeEnum typeEnum = AllocationTypeEnum.ofValue(dto.getAllocationType()); | |
217 | - BV.notNull(typeEnum, () -> "分配方式不正确,请重试"); | |
218 | - dto.setType(typeEnum); | |
219 | 216 | LeaveNeedDo needDo = leaveNeedDoService.queryProcessableById(dto.getId()); |
220 | 217 | BV.notNull(needDo, () -> "该条记录已处理或不存在,请刷新后重试"); |
221 | - | |
222 | 218 | dto.setAdviserId(needDo.getUserId()); |
223 | - if (AllocationTypeEnum.ONE.equals(typeEnum)) { | |
224 | - BV.notNull(dto.getUserId(), () -> "指定人员不能为空"); | |
225 | - List<UserRoleDataRangeDTO> dataRange = userService.getUserRoleDataRange(dto.getUserId(), RoleCode.FWGW); | |
219 | + | |
220 | + List<LeaveAllocationDTO.Allocation> ruleList = dto.getRuleList(); | |
221 | + BV.notNull(ruleList, () -> "分配规则不能为空"); | |
222 | + | |
223 | + for (LeaveAllocationDTO.Allocation rule : ruleList) { | |
224 | + List<UserRoleDataRangeDTO> dataRange = userService.getUserRoleDataRange(rule.getUserId(), RoleCode.FWGW); | |
226 | 225 | List<Long> shopIdList = dataRange.stream().map(UserRoleDataRangeDTO::getRangeValue).collect(Collectors.toList()); |
227 | - BV.isNotEmpty(shopIdList, () -> "指定人员非服务顾问角色,请核对"); | |
228 | 226 | Long shopId = shopIdList.get(0); |
229 | - BV.isTrue(needDo.getShopId().equals(shopId), () -> "指定人员所属门店与档案归属门店不符"); | |
230 | - dto.setShopId(shopId); | |
231 | - } | |
232 | - | |
233 | - if (AllocationTypeEnum.ALL.equals(dto.getType())) { | |
234 | - dto.setShopId(needDo.getShopId()); | |
227 | + BV.isNotEmpty(shopIdList, () -> String.format("[%s]无服务接待角色,请核对", rule.getUserName())); | |
228 | + BV.isTrue(needDo.getShopId().equals(shopId), () -> String.format("[%s]所属门店与离职人员门店不符", rule.getUserName())); | |
229 | + rule.setShopId(shopId); | |
235 | 230 | } |
236 | 231 | } |
237 | 232 | |
... | ... | @@ -246,63 +241,34 @@ public class LeaveNeedDoBizService { |
246 | 241 | if (CollectionUtils.isEmpty(customerList)) { |
247 | 242 | return null; |
248 | 243 | } |
249 | - if (AllocationTypeEnum.ONE.equals(dto.getType())) { | |
250 | - allocation(key, customerList, dto); | |
251 | - } | |
252 | - if (AllocationTypeEnum.ALL.equals(dto.getType())) { | |
253 | - allocation(key, customerList, dto.getShopId()); | |
254 | - } | |
255 | - return customerList; | |
256 | - } | |
244 | + List<LeaveAllocationDTO.Allocation> ruleList = dto.getRuleList(); | |
257 | 245 | |
258 | - /** | |
259 | - * 分配给指定人员 | |
260 | - * | |
261 | - * @param list | |
262 | - * @param dto | |
263 | - */ | |
264 | - private void allocation(String key, List<Customer> list, LeaveAllocationDTO dto) { | |
265 | - List<StammkundePool> spl = new ArrayList<>(list.size()); | |
266 | - final String userName = Optional.ofNullable(userService.user(dto.getUserId())).map(UserInfoDTO::getUserName).orElse(""); | |
267 | - for (Customer customer : list) { | |
268 | - customer.setShopId(dto.getShopId()); | |
269 | - customer.setAdviserId(dto.getUserId()); | |
270 | - spl.add(createPool(customer, userName)); | |
271 | - rejectPool(customer.getId(), dto.getShopId(), userName, dto.getUserId(), customer.getGroupId()); | |
272 | - } | |
273 | - customerService.updateBatchById(list); | |
274 | - stammkundePoolService.saveBatch(spl); | |
275 | - setToCache(key, new UserInfo(dto.getUserId(), "", list.size())); | |
276 | - } | |
246 | + final List<Customer> list = new ArrayList<>(); | |
247 | + final List<StammkundePool> spl = new ArrayList<>(); | |
248 | + final LinkedList<UserInfo> queue = new LinkedList<>(); | |
277 | 249 | |
278 | - /** | |
279 | - * 门店内平均分配 | |
280 | - * | |
281 | - * @param list | |
282 | - * @param shopId | |
283 | - */ | |
284 | - private void allocation(String key, List<Customer> list, Long shopId) { | |
285 | - List<PostUserDTO> users = userService.getUserByRole(shopId, RoleCode.FWGW); | |
286 | - BV.isNotEmpty(users, () -> "该门店没有服务顾问,请检查配置是否正确"); | |
287 | - List<StammkundePool> spl = new ArrayList<>(list.size()); | |
288 | - LinkedList<UserInfo> queue = new LinkedList<>(); | |
289 | - for (PostUserDTO user : users) { | |
290 | - queue.offer(new UserInfo(user.getUserId(), user.getUserName())); | |
291 | - } | |
292 | - for (Customer customer : list) { | |
293 | - UserInfo info = queue.poll(); | |
294 | - customer.setShopId(shopId); | |
295 | - customer.setAdviserId(Objects.requireNonNull(info, "服务顾问信息获取异常,请重试").getUserId()); | |
296 | - info.setCount(info.getCount() + 1); | |
297 | - rejectPool(customer.getId(), shopId, info.getUserName(), info.getUserId(), customer.getGroupId()); | |
298 | - spl.add(createPool(customer, info.getUserName())); | |
299 | - queue.offer(info); | |
250 | + for (LeaveAllocationDTO.Allocation rule : ruleList) { | |
251 | + List<Customer> subList = customerList.subList(0, rule.getNum()); | |
252 | + if (CollectionUtils.isEmpty(subList)) { | |
253 | + continue; | |
254 | + } | |
255 | + for (Customer customer : subList) { | |
256 | + customer.setShopId(rule.getShopId()); | |
257 | + customer.setAdviserId(rule.getUserId()); | |
258 | + rejectPool(customer.getId(), rule.getShopId(), rule.getUserName(), rule.getUserId(), customer.getGroupId()); | |
259 | + spl.add(createPool(customer, rule.getUserName())); | |
260 | + list.add(customer); | |
261 | + } | |
262 | + queue.add(new UserInfo(rule.getUserId(), rule.getUserName(), subList.size())); | |
263 | + subList.clear(); | |
300 | 264 | } |
301 | 265 | customerService.updateBatchById(list); |
302 | 266 | stammkundePoolService.saveBatch(spl); |
303 | 267 | setToCache(key, queue); |
268 | + return list; | |
304 | 269 | } |
305 | 270 | |
271 | + | |
306 | 272 | /** |
307 | 273 | * 完成分配的后续处理逻辑 |
308 | 274 | * | ... | ... |