diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/LeaveAllocationDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/LeaveAllocationDTO.java index ff76ca0..7cb8ca9 100644 --- a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/LeaveAllocationDTO.java +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/LeaveAllocationDTO.java @@ -3,7 +3,11 @@ package cn.fw.valhalla.domain.dto; import cn.fw.valhalla.common.enums.AllocationTypeEnum; import lombok.Data; +import javax.validation.Valid; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.util.List; /** * @author : kurisu @@ -15,26 +19,70 @@ import javax.validation.constraints.NotNull; public class LeaveAllocationDTO { @NotNull(message = "记录id不能为空") private Long id; - - @NotNull(message = "分配方式不能为空") - private Integer allocationType; - /** - * 指定人员id + * 分配规则 */ - private Long userId; + @Valid + @NotEmpty(message = "分配规则不能为空") + private List ruleList; - /** - * 门店id (前端无关) - */ - private Long shopId; /** - * 分配方式 (前端无关) - */ - private AllocationTypeEnum type; - /** - * 顾问id (前端无关) + * 原始顾问id (前端无关) */ private Long adviserId; + + public static class Allocation { + /** + * 指定人员id + */ + @NotNull(message = "人员id不能为空") + private Long userId; + /** + * 人员名称 + */ + private String userName; + /** + * 指定人员id + */ + @Min(value = 1, message = "保有客数量必须大于0") + private Integer num; + + /** + * 门店id (前端无关) + */ + private Long shopId; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + public Long getShopId() { + return shopId; + } + + public void setShopId(Long shopId) { + this.shopId = shopId; + } + } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/LeaveNeedDoBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/LeaveNeedDoBizService.java index 672cf53..db5d176 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/LeaveNeedDoBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/LeaveNeedDoBizService.java @@ -213,25 +213,20 @@ public class LeaveNeedDoBizService { } private void prepareAllocation(LeaveAllocationDTO dto) { - AllocationTypeEnum typeEnum = AllocationTypeEnum.ofValue(dto.getAllocationType()); - BV.notNull(typeEnum, () -> "分配方式不正确,请重试"); - dto.setType(typeEnum); LeaveNeedDo needDo = leaveNeedDoService.queryProcessableById(dto.getId()); BV.notNull(needDo, () -> "该条记录已处理或不存在,请刷新后重试"); - dto.setAdviserId(needDo.getUserId()); - if (AllocationTypeEnum.ONE.equals(typeEnum)) { - BV.notNull(dto.getUserId(), () -> "指定人员不能为空"); - List dataRange = userService.getUserRoleDataRange(dto.getUserId(), RoleCode.FWGW); + + List ruleList = dto.getRuleList(); + BV.notNull(ruleList, () -> "分配规则不能为空"); + + for (LeaveAllocationDTO.Allocation rule : ruleList) { + List dataRange = userService.getUserRoleDataRange(rule.getUserId(), RoleCode.FWGW); List shopIdList = dataRange.stream().map(UserRoleDataRangeDTO::getRangeValue).collect(Collectors.toList()); - BV.isNotEmpty(shopIdList, () -> "指定人员非服务顾问角色,请核对"); Long shopId = shopIdList.get(0); - BV.isTrue(needDo.getShopId().equals(shopId), () -> "指定人员所属门店与档案归属门店不符"); - dto.setShopId(shopId); - } - - if (AllocationTypeEnum.ALL.equals(dto.getType())) { - dto.setShopId(needDo.getShopId()); + BV.isNotEmpty(shopIdList, () -> String.format("[%s]无服务接待角色,请核对", rule.getUserName())); + BV.isTrue(needDo.getShopId().equals(shopId), () -> String.format("[%s]所属门店与离职人员门店不符", rule.getUserName())); + rule.setShopId(shopId); } } @@ -246,63 +241,34 @@ public class LeaveNeedDoBizService { if (CollectionUtils.isEmpty(customerList)) { return null; } - if (AllocationTypeEnum.ONE.equals(dto.getType())) { - allocation(key, customerList, dto); - } - if (AllocationTypeEnum.ALL.equals(dto.getType())) { - allocation(key, customerList, dto.getShopId()); - } - return customerList; - } + List ruleList = dto.getRuleList(); - /** - * 分配给指定人员 - * - * @param list - * @param dto - */ - private void allocation(String key, List list, LeaveAllocationDTO dto) { - List spl = new ArrayList<>(list.size()); - final String userName = Optional.ofNullable(userService.user(dto.getUserId())).map(UserInfoDTO::getUserName).orElse(""); - for (Customer customer : list) { - customer.setShopId(dto.getShopId()); - customer.setAdviserId(dto.getUserId()); - spl.add(createPool(customer, userName)); - rejectPool(customer.getId(), dto.getShopId(), userName, dto.getUserId(), customer.getGroupId()); - } - customerService.updateBatchById(list); - stammkundePoolService.saveBatch(spl); - setToCache(key, new UserInfo(dto.getUserId(), "", list.size())); - } + final List list = new ArrayList<>(); + final List spl = new ArrayList<>(); + final LinkedList queue = new LinkedList<>(); - /** - * 门店内平均分配 - * - * @param list - * @param shopId - */ - private void allocation(String key, List list, Long shopId) { - List users = userService.getUserByRole(shopId, RoleCode.FWGW); - BV.isNotEmpty(users, () -> "该门店没有服务顾问,请检查配置是否正确"); - List spl = new ArrayList<>(list.size()); - LinkedList queue = new LinkedList<>(); - for (PostUserDTO user : users) { - queue.offer(new UserInfo(user.getUserId(), user.getUserName())); - } - for (Customer customer : list) { - UserInfo info = queue.poll(); - customer.setShopId(shopId); - customer.setAdviserId(Objects.requireNonNull(info, "服务顾问信息获取异常,请重试").getUserId()); - info.setCount(info.getCount() + 1); - rejectPool(customer.getId(), shopId, info.getUserName(), info.getUserId(), customer.getGroupId()); - spl.add(createPool(customer, info.getUserName())); - queue.offer(info); + for (LeaveAllocationDTO.Allocation rule : ruleList) { + List subList = customerList.subList(0, rule.getNum()); + if (CollectionUtils.isEmpty(subList)) { + continue; + } + for (Customer customer : subList) { + customer.setShopId(rule.getShopId()); + customer.setAdviserId(rule.getUserId()); + rejectPool(customer.getId(), rule.getShopId(), rule.getUserName(), rule.getUserId(), customer.getGroupId()); + spl.add(createPool(customer, rule.getUserName())); + list.add(customer); + } + queue.add(new UserInfo(rule.getUserId(), rule.getUserName(), subList.size())); + subList.clear(); } customerService.updateBatchById(list); stammkundePoolService.saveBatch(spl); setToCache(key, queue); + return list; } + /** * 完成分配的后续处理逻辑 *