|
@@ -1,7 +1,6 @@
|
|
package com.qmth.sop.business.service.impl;
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -17,7 +16,6 @@ import com.qmth.sop.business.bean.result.*;
|
|
import com.qmth.sop.business.entity.*;
|
|
import com.qmth.sop.business.entity.*;
|
|
import com.qmth.sop.business.mapper.TBUserArchivesAllocationMapper;
|
|
import com.qmth.sop.business.mapper.TBUserArchivesAllocationMapper;
|
|
import com.qmth.sop.business.service.*;
|
|
import com.qmth.sop.business.service.*;
|
|
-import com.qmth.sop.common.base.BaseEntity;
|
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.enums.*;
|
|
import com.qmth.sop.common.enums.*;
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
@@ -26,7 +24,9 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@@ -43,18 +43,12 @@ public class TBUserArchivesAllocationServiceImpl
|
|
extends ServiceImpl<TBUserArchivesAllocationMapper, TBUserArchivesAllocation>
|
|
extends ServiceImpl<TBUserArchivesAllocationMapper, TBUserArchivesAllocation>
|
|
implements TBUserArchivesAllocationService {
|
|
implements TBUserArchivesAllocationService {
|
|
|
|
|
|
- @Resource
|
|
|
|
- private TBServiceService tbServiceService;
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private TBCrmService tbCrmService;
|
|
private TBCrmService tbCrmService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private SysRoleService sysRoleService;
|
|
private SysRoleService sysRoleService;
|
|
|
|
|
|
- @Resource
|
|
|
|
- private SysUserRoleService sysUserRoleService;
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private TBUserArchivesService tbUserArchivesService;
|
|
private TBUserArchivesService tbUserArchivesService;
|
|
|
|
|
|
@@ -73,6 +67,9 @@ public class TBUserArchivesAllocationServiceImpl
|
|
@Resource
|
|
@Resource
|
|
private TBUserArchivesAllocationLogService tbUserArchivesAllocationLogService;
|
|
private TBUserArchivesAllocationLogService tbUserArchivesAllocationLogService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private TBCrmDetailService tbCrmDetailService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public IPage<UserArchivesAllocationResult> findCrmAllocationPage(Long serviceUnitId, String province, String city,
|
|
public IPage<UserArchivesAllocationResult> findCrmAllocationPage(Long serviceUnitId, String province, String city,
|
|
String area, String customName, Integer gap, Long regionId, Integer pageNumber, Integer pageSize) {
|
|
String area, String customName, Integer gap, Long regionId, Integer pageNumber, Integer pageSize) {
|
|
@@ -130,113 +127,77 @@ public class TBUserArchivesAllocationServiceImpl
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam) {
|
|
|
|
- Long serviceUnitId = userArchivesAllocationParam.getServiceUnitId();
|
|
|
|
- TBService tbService = tbServiceService.getById(serviceUnitId);
|
|
|
|
- if (Objects.isNull(tbService)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("服务单元不存在");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String crmNo = userArchivesAllocationParam.getCrmNo();
|
|
|
|
- Long regionUserId = userArchivesAllocationParam.getRegionUserId();
|
|
|
|
-
|
|
|
|
- List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, crmNo));
|
|
|
|
- if (CollectionUtils.isEmpty(tbCrmList)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("派单不存在");
|
|
|
|
- }
|
|
|
|
- if (tbCrmList.size() > 1) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("存在多个相同派单号的派单[" + crmNo + "]");
|
|
|
|
- }
|
|
|
|
- TBCrm tbCrm = tbCrmList.get(0);
|
|
|
|
-
|
|
|
|
- List<TBUserArchivesAllocation> dbList = this.list(
|
|
|
|
- new QueryWrapper<TBUserArchivesAllocation>().lambda().eq(TBUserArchivesAllocation::getCrmNo, crmNo));
|
|
|
|
-
|
|
|
|
- // if (dbList.stream().anyMatch(e -> Objects.nonNull(e.getSopNo()))) {
|
|
|
|
- // throw ExceptionResultEnum.ERROR.exception("已发布的派单不能调配");
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // 新增关系
|
|
|
|
|
|
+ public void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam) throws InterruptedException {
|
|
|
|
+ SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
List<AllocationParam> allocationParamList = userArchivesAllocationParam.getAllocationParams();
|
|
List<AllocationParam> allocationParamList = userArchivesAllocationParam.getAllocationParams();
|
|
|
|
+ Long crmDetailId = userArchivesAllocationParam.getCrmDetailId();
|
|
|
|
+ TBCrmDetail crmDetail = tbCrmDetailService.getById(crmDetailId);
|
|
|
|
+ if (Objects.isNull(crmDetail)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到派单详情");
|
|
|
|
+ }
|
|
|
|
|
|
- List<TBUserArchivesAllocation> tbUserArchivesAllocationList = new ArrayList<>();
|
|
|
|
- // 处理实施工程师或助理工程师
|
|
|
|
- if (CollectionUtils.isNotEmpty(allocationParamList)) {
|
|
|
|
- for (AllocationParam allocationParam : allocationParamList) {
|
|
|
|
- Long roleId = allocationParam.getRoleId();
|
|
|
|
- List<Long> userIdList = allocationParam.getUserIdList();
|
|
|
|
- SysRole role = sysRoleService.getById(roleId);
|
|
|
|
- if (Objects.isNull(role)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("认证角色不存在");
|
|
|
|
- } else {
|
|
|
|
- if (!RoleTypeEnum.EFFECT_ENGINEER.equals(role.getType()) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(
|
|
|
|
- role.getType())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(
|
|
|
|
- String.format("认证角色类型为[%s]不属于[%s]或[%s]", role.getType().getDesc(),
|
|
|
|
- RoleTypeEnum.EFFECT_ENGINEER.getDesc(),
|
|
|
|
- RoleTypeEnum.ASSISTANT_ENGINEER.getDesc()));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ String crmNo = crmDetail.getCrmNo();
|
|
|
|
+ TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
|
|
|
|
|
|
- for (Long userId : userIdList) {
|
|
|
|
- List<Long> sysRoleIdList = sysUserRoleService.listRoleByUserId(userId).stream()
|
|
|
|
- .map(BaseEntity::getId).distinct().collect(Collectors.toList());
|
|
|
|
- if (!sysRoleIdList.contains(roleId)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("所选用户不包含认证角色[" + role.getType().getDesc() + "]");
|
|
|
|
- }
|
|
|
|
- TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
|
|
|
|
- if (!UserArchivesStatusEnum.FREE.equals(tbUserArchives.getStatus())) {
|
|
|
|
- List<TBCrm> occupiedCrm = tbCrmService.findOccupiedCrm(userId, null);
|
|
|
|
- if (CollectionUtils.isEmpty(occupiedCrm)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("人员占用状态异常");
|
|
|
|
- }
|
|
|
|
- if (!occupiedCrm.stream().map(TBCrm::getCrmNo).collect(Collectors.toList()).contains(crmNo)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(
|
|
|
|
- String.format("工程师[%s]已经被派单号为[%s]的派单占用,请先将工程师从派单中移出", tbUserArchives.getName(),
|
|
|
|
- occupiedCrm.stream().map(TBCrm::getCrmNo).collect(Collectors.joining())));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
|
|
|
|
- tbUserArchivesAllocation.setCrmNo(crmNo);
|
|
|
|
- tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
|
|
|
|
- tbUserArchivesAllocation.setServiceId(serviceUnitId);
|
|
|
|
- tbUserArchivesAllocation.setUserId(userId);
|
|
|
|
- tbUserArchivesAllocationList.add(tbUserArchivesAllocation);
|
|
|
|
|
|
+ // 该派单详情全部的人员分配关系
|
|
|
|
+ List<TBUserArchivesAllocation> allocatedDatasource = this.list(
|
|
|
|
+ new QueryWrapper<TBUserArchivesAllocation>().lambda().eq(TBUserArchivesAllocation::getCrmDetailId, crmDetailId));
|
|
|
|
+
|
|
|
|
+ for (AllocationParam allocationParam : allocationParamList) {
|
|
|
|
+ SopRoleTypeEnum sopRoleType = allocationParam.getSopRoleType();
|
|
|
|
+ String remark = allocationParam.getRemark();
|
|
|
|
+ // 本次要分配的人员档案id集合
|
|
|
|
+ List<Long> archivesIdList = allocationParam.getArchivesIdList();
|
|
|
|
+
|
|
|
|
+ List<TBUserArchivesAllocation> allocatedList = allocatedDatasource.stream()
|
|
|
|
+ .filter(e -> e.getSopRoleType().equals(sopRoleType)).collect(Collectors.toList());
|
|
|
|
+ // 之前已分配的人员档案id集合
|
|
|
|
+ List<Long> allocatedIdList = allocatedList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 经过对比要删除的人员档案id集合
|
|
|
|
+ List<Long> removeList = allocatedIdList.stream().filter(e -> !archivesIdList.contains(e)).distinct().collect(Collectors.toList());
|
|
|
|
+ // 对删除的档案人员添加历史记录
|
|
|
|
+ List<TBUserArchivesAllocationLog> historicList = removeList.stream().flatMap(e -> {
|
|
|
|
+ UserArchivesResult userArchivesResult = tbUserArchivesService.findUserArchivesByArchivesIdORUserId(e,
|
|
|
|
+ null);
|
|
|
|
+ TBUserArchivesAllocationLog historic = new TBUserArchivesAllocationLog();
|
|
|
|
+ historic.setCrmDetailId(crmDetailId);
|
|
|
|
+ historic.setSopRoleType(sopRoleType);
|
|
|
|
+ historic.setUserId(userArchivesResult.getUserId());
|
|
|
|
+ historic.setArchivesId(e);
|
|
|
|
+ historic.setArchivesName(userArchivesResult.getName());
|
|
|
|
+ historic.setSupplierName(userArchivesResult.getSupplierName());
|
|
|
|
+ historic.setCity(userArchivesResult.getCity());
|
|
|
|
+ historic.insertInfo(requestUser.getId());
|
|
|
|
+ return Stream.of(historic);
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ tbUserArchivesAllocationLogService.saveBatch(historicList);
|
|
|
|
+ this.remove(new QueryWrapper<TBUserArchivesAllocation>().lambda()
|
|
|
|
+ .eq(TBUserArchivesAllocation::getArchivesId, removeList)
|
|
|
|
+ .eq(TBUserArchivesAllocation::getCrmDetailId, crmDetailId));
|
|
|
|
+
|
|
|
|
+ // 经过对比要新增的人员档案id集合
|
|
|
|
+ List<Long> addList = archivesIdList.stream().filter(e -> !allocatedIdList.contains(e)).distinct().collect(Collectors.toList());
|
|
|
|
+ List<TBUserArchivesAllocation> addListData = addList.stream().flatMap(e -> {
|
|
|
|
+ TBUserArchivesAllocation allocation = new TBUserArchivesAllocation();
|
|
|
|
+ allocation.setCrmDetailId(crmDetailId);
|
|
|
|
+ allocation.setArchivesId(e);
|
|
|
|
+ // TODO: 2024/5/20 服务单元id有可能要去掉(感觉调配和划定没有关系) - czx
|
|
|
|
+
|
|
|
|
+ allocation.setServiceId(tbCrm.getServiceId());
|
|
|
|
+ allocation.setCrmNo(crmNo);
|
|
|
|
+ allocation.setSopRoleType(sopRoleType);
|
|
|
|
+ allocation.setUserId(sysUserService.findByArchivesId(e).getId());
|
|
|
|
+ allocation.setArchivesId(e);
|
|
|
|
+ if (remark != null && remark.length() > 0) {
|
|
|
|
+ allocation.setRemark(remark);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 更新区域负责人
|
|
|
|
- UpdateWrapper<TBCrm> coordinatorUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- coordinatorUpdateWrapper.lambda().set(TBCrm::getRegionCoordinatorId, regionUserId)
|
|
|
|
- .eq(TBCrm::getId, tbCrm.getId());
|
|
|
|
- tbCrmService.update(coordinatorUpdateWrapper);
|
|
|
|
-
|
|
|
|
- // 新增前删除派单关系
|
|
|
|
- if (CollectionUtils.isNotEmpty(dbList)) {
|
|
|
|
- // 删除关系前先将工程师状态更改为空闲
|
|
|
|
- List<Long> engineerDbIdList = dbList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct()
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- archivesUpdateWrapper.lambda().set(TBUserArchives::getStatus, UserArchivesStatusEnum.FREE)
|
|
|
|
- .in(TBUserArchives::getId, engineerDbIdList);
|
|
|
|
- tbUserArchivesService.update(archivesUpdateWrapper);
|
|
|
|
-
|
|
|
|
- // 删除派单关系
|
|
|
|
- this.removeByIds(dbList.stream().map(TBUserArchivesAllocation::getId).collect(Collectors.toList()));
|
|
|
|
- }
|
|
|
|
|
|
+ allocation.insertInfo(requestUser.getId());
|
|
|
|
+ return Stream.of(allocation);
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ this.saveBatch(addListData);
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(tbUserArchivesAllocationList)) {
|
|
|
|
- // 新增前先将工程师的状态设置为非空闲
|
|
|
|
- List<Long> engineerAddIdLIst = tbUserArchivesAllocationList.stream()
|
|
|
|
- .map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
|
|
|
|
- UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- archivesUpdateWrapper.lambda().set(TBUserArchives::getStatus, UserArchivesStatusEnum.OCCUPIED)
|
|
|
|
- .in(TBUserArchives::getId, engineerAddIdLIst);
|
|
|
|
- tbUserArchivesService.update(archivesUpdateWrapper);
|
|
|
|
-
|
|
|
|
- // 新增分配关系
|
|
|
|
- this.saveBatch(tbUserArchivesAllocationList);
|
|
|
|
|
|
+ tbSopInfoService.sopApproverExchange(crmDetailId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -271,183 +232,185 @@ public class TBUserArchivesAllocationServiceImpl
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public void autoEditCrmAllocationBatch(AutoAllocationParam autoAllocationParam) {
|
|
public void autoEditCrmAllocationBatch(AutoAllocationParam autoAllocationParam) {
|
|
- Long serviceUnitId = autoAllocationParam.getServiceUnitId();
|
|
|
|
- List<Long> crmIdList = autoAllocationParam.getCrmIdList();
|
|
|
|
- List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId,
|
|
|
|
- null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null, null);
|
|
|
|
- // crm按照差额倒序
|
|
|
|
- crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
|
|
|
|
- .sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- for (UserArchivesAllocationResult crmSource : crmSourceList) {
|
|
|
|
- String crmNo = crmSource.getCrmNo();
|
|
|
|
- String city = crmSource.getCity();
|
|
|
|
- String province = crmSource.getProvince();
|
|
|
|
-
|
|
|
|
- // 区域协调人差额
|
|
|
|
- Integer coordinatorUnDistributed = crmSource.getCoordinatorUnDistributed();
|
|
|
|
-
|
|
|
|
- // 实施工程师差额
|
|
|
|
- Integer effectUnDistributed = crmSource.getEffectUnDistributed();
|
|
|
|
-
|
|
|
|
- // 助理工程师差额
|
|
|
|
- Integer assistantUnDistributed = crmSource.getAssistantUnDistributed();
|
|
|
|
-
|
|
|
|
- // 该派单已经分配的人员名单
|
|
|
|
- List<CrmArchivesAllocationResult> crmArchivesAllocationResultList = this.findAllocationByCrmNo(crmNo);
|
|
|
|
- // 区域协调人
|
|
|
|
- List<CrmArchivesAllocationResult> coordinatorList = crmArchivesAllocationResultList.stream()
|
|
|
|
- .filter(e -> RoleTypeEnum.REGION_COORDINATOR.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
- // 实施工程师
|
|
|
|
- List<CrmArchivesAllocationResult> effectList = crmArchivesAllocationResultList.stream()
|
|
|
|
- .filter(e -> RoleTypeEnum.EFFECT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
- // 助理工程师
|
|
|
|
- List<CrmArchivesAllocationResult> assistantList = crmArchivesAllocationResultList.stream()
|
|
|
|
- .filter(e -> RoleTypeEnum.ASSISTANT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- // 可分配的人力资源
|
|
|
|
- List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(
|
|
|
|
- RoleTypeEnum.EFFECT_ENGINEER, null).stream()
|
|
|
|
- .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<ArchivesSourceResult> assistantFree = tbUserArchivesService.findFreeEngineerSourceByType(
|
|
|
|
- RoleTypeEnum.ASSISTANT_ENGINEER, null).stream()
|
|
|
|
- .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(
|
|
|
|
- serviceUnitId, null, true).stream()
|
|
|
|
- .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<AllocationParam> allocationParamList = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- // 先分实施工程师
|
|
|
|
- if (effectUnDistributed > 0) {
|
|
|
|
- SysRole effectRole = sysRoleService.list(
|
|
|
|
- new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.EFFECT_ENGINEER)).get(0);
|
|
|
|
- Long effectRoleId = effectRole.getId();
|
|
|
|
- List<Long> userIdList = new ArrayList<>();
|
|
|
|
- if (CollectionUtils.isNotEmpty(coordinatorList)) {
|
|
|
|
- // 实施工程师和区域协调人同供应商,实施工程师和crm客户同城市
|
|
|
|
- CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
|
|
|
|
- Long supplierId = coordinator.getSupplierId();
|
|
|
|
- effectFree = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
- .limit(effectUnDistributed).collect(Collectors.toList());
|
|
|
|
- userIdList.addAll(effectFree.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- this.addDistributeTemp(effectList, effectFree);
|
|
|
|
- } else {
|
|
|
|
- // 不存在区域协调人,实施工程师和crm客户同城市,且实施工程师尽可能集中在同一个供应商中
|
|
|
|
-
|
|
|
|
- // 供应商和实施工程师数量键值对
|
|
|
|
- Map<Long, Integer> supplierMap = effectFree.stream()
|
|
|
|
- .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
|
|
|
|
- supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
|
- for (Long supplierId : supplierMap.keySet()) {
|
|
|
|
- Integer count = supplierMap.get(supplierId);
|
|
|
|
- int effectDivide = effectUnDistributed - count;
|
|
|
|
- List<ArchivesSourceResult> cell;
|
|
|
|
- if (effectDivide > 0) {
|
|
|
|
- // 该供应商的不够分配配额
|
|
|
|
- cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- this.addDistributeTemp(effectList, cell);
|
|
|
|
- // 进入下一个供应商循环
|
|
|
|
- effectUnDistributed = effectUnDistributed - count;
|
|
|
|
- } else {
|
|
|
|
- // 该供应商的足够分配配额
|
|
|
|
- cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
- .limit(effectUnDistributed).collect(Collectors.toList());
|
|
|
|
- userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- this.addDistributeTemp(effectList, cell);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- AllocationParam allocationParam = new AllocationParam();
|
|
|
|
- allocationParam.setRoleId(effectRoleId);
|
|
|
|
- allocationParam.setUserIdList(userIdList);
|
|
|
|
- allocationParamList.add(allocationParam);
|
|
|
|
- }
|
|
|
|
- // 再分助理工程师
|
|
|
|
- if (assistantUnDistributed > 0) {
|
|
|
|
- SysRole assistantRole = sysRoleService.list(
|
|
|
|
- new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.ASSISTANT_ENGINEER))
|
|
|
|
- .get(0);
|
|
|
|
- Long assistantRoleId = assistantRole.getId();
|
|
|
|
- List<Long> userIdList = new ArrayList<>();
|
|
|
|
- Map<Long, Integer> supplierMap = assistantFree.stream()
|
|
|
|
- .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
|
|
|
|
- supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
|
- for (Long supplierId : supplierMap.keySet()) {
|
|
|
|
- Integer count = supplierMap.get(supplierId);
|
|
|
|
- int assistantDivide = assistantUnDistributed - count;
|
|
|
|
- List<ArchivesSourceResult> cell;
|
|
|
|
- if (assistantDivide > 0) {
|
|
|
|
- // 该供应商的不够分配配额
|
|
|
|
- cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- this.addDistributeTemp(assistantList, cell);
|
|
|
|
- assistantUnDistributed = assistantUnDistributed - count;
|
|
|
|
- } else {
|
|
|
|
- // 该供应商的足够分配配额
|
|
|
|
- cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
- .limit(assistantUnDistributed).collect(Collectors.toList());
|
|
|
|
- userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- this.addDistributeTemp(assistantList, cell);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- AllocationParam allocationParam = new AllocationParam();
|
|
|
|
- allocationParam.setRoleId(assistantRoleId);
|
|
|
|
- allocationParam.setUserIdList(userIdList);
|
|
|
|
- allocationParamList.add(allocationParam);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 最后分配区域协调人
|
|
|
|
- Long regionUserId = null;
|
|
|
|
- if (coordinatorUnDistributed > 0) {
|
|
|
|
- if (CollectionUtils.isNotEmpty(effectList)) {
|
|
|
|
- // 存在已经分配的实施工程师
|
|
|
|
- List<Long> supplierIdList = effectList.stream().map(CrmArchivesAllocationResult::getSupplierId)
|
|
|
|
- .distinct().collect(Collectors.toList());
|
|
|
|
- if (supplierIdList.size() == 1) {
|
|
|
|
- Long supplierId = supplierIdList.get(0);
|
|
|
|
- List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
|
|
|
|
- .filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
- .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- if (CollectionUtils.isNotEmpty(coordinator)) {
|
|
|
|
- regionUserId = coordinator.get(0).getUserId();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // 不存在实施工程师
|
|
|
|
- List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
|
|
|
|
- .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- if (CollectionUtils.isNotEmpty(coordinator)) {
|
|
|
|
- regionUserId = coordinator.get(0).getUserId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- UserArchivesAllocationParam userArchivesAllocationParam = new UserArchivesAllocationParam();
|
|
|
|
- userArchivesAllocationParam.setAllocationParams(allocationParamList);
|
|
|
|
- userArchivesAllocationParam.setServiceUnitId(serviceUnitId);
|
|
|
|
- userArchivesAllocationParam.setCrmNo(crmNo);
|
|
|
|
- userArchivesAllocationParam.setRegionUserId(regionUserId);
|
|
|
|
- this.editCrmAllocation(userArchivesAllocationParam);
|
|
|
|
- }
|
|
|
|
|
|
+ // TODO: 2024/5/20 先取消自动调配
|
|
|
|
+
|
|
|
|
+ // Long serviceUnitId = autoAllocationParam.getServiceUnitId();
|
|
|
|
+ // List<Long> crmIdList = autoAllocationParam.getCrmIdList();
|
|
|
|
+ // List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId,
|
|
|
|
+ // null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null, null);
|
|
|
|
+ // // crm按照差额倒序
|
|
|
|
+ // crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
|
|
|
|
+ // .sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ //
|
|
|
|
+ // for (UserArchivesAllocationResult crmSource : crmSourceList) {
|
|
|
|
+ // String crmNo = crmSource.getCrmNo();
|
|
|
|
+ // String city = crmSource.getCity();
|
|
|
|
+ // String province = crmSource.getProvince();
|
|
|
|
+ //
|
|
|
|
+ // // 区域协调人差额
|
|
|
|
+ // Integer coordinatorUnDistributed = crmSource.getCoordinatorUnDistributed();
|
|
|
|
+ //
|
|
|
|
+ // // 实施工程师差额
|
|
|
|
+ // Integer effectUnDistributed = crmSource.getEffectUnDistributed();
|
|
|
|
+ //
|
|
|
|
+ // // 助理工程师差额
|
|
|
|
+ // Integer assistantUnDistributed = crmSource.getAssistantUnDistributed();
|
|
|
|
+ //
|
|
|
|
+ // // 该派单已经分配的人员名单
|
|
|
|
+ // List<CrmArchivesAllocationResult> crmArchivesAllocationResultList = this.findAllocationByCrmNo(crmNo);
|
|
|
|
+ // // 区域协调人
|
|
|
|
+ // List<CrmArchivesAllocationResult> coordinatorList = crmArchivesAllocationResultList.stream()
|
|
|
|
+ // .filter(e -> RoleTypeEnum.REGION_COORDINATOR.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
+ // // 实施工程师
|
|
|
|
+ // List<CrmArchivesAllocationResult> effectList = crmArchivesAllocationResultList.stream()
|
|
|
|
+ // .filter(e -> RoleTypeEnum.EFFECT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
+ // // 助理工程师
|
|
|
|
+ // List<CrmArchivesAllocationResult> assistantList = crmArchivesAllocationResultList.stream()
|
|
|
|
+ // .filter(e -> RoleTypeEnum.ASSISTANT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
|
|
|
|
+ //
|
|
|
|
+ // // 可分配的人力资源
|
|
|
|
+ // List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(
|
|
|
|
+ // RoleTypeEnum.EFFECT_ENGINEER, null).stream()
|
|
|
|
+ // .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ //
|
|
|
|
+ // List<ArchivesSourceResult> assistantFree = tbUserArchivesService.findFreeEngineerSourceByType(
|
|
|
|
+ // RoleTypeEnum.ASSISTANT_ENGINEER, null).stream()
|
|
|
|
+ // .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ //
|
|
|
|
+ // List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(
|
|
|
|
+ // serviceUnitId, null, true).stream()
|
|
|
|
+ // .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ //
|
|
|
|
+ // List<AllocationParam> allocationParamList = new ArrayList<>();
|
|
|
|
+ //
|
|
|
|
+ // // 先分实施工程师
|
|
|
|
+ // if (effectUnDistributed > 0) {
|
|
|
|
+ // SysRole effectRole = sysRoleService.list(
|
|
|
|
+ // new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.EFFECT_ENGINEER)).get(0);
|
|
|
|
+ // Long effectRoleId = effectRole.getId();
|
|
|
|
+ // List<Long> userIdList = new ArrayList<>();
|
|
|
|
+ // if (CollectionUtils.isNotEmpty(coordinatorList)) {
|
|
|
|
+ // // 实施工程师和区域协调人同供应商,实施工程师和crm客户同城市
|
|
|
|
+ // CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
|
|
|
|
+ // Long supplierId = coordinator.getSupplierId();
|
|
|
|
+ // effectFree = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
+ // .limit(effectUnDistributed).collect(Collectors.toList());
|
|
|
|
+ // userIdList.addAll(effectFree.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
+ // .collect(Collectors.toList()));
|
|
|
|
+ // this.addDistributeTemp(effectList, effectFree);
|
|
|
|
+ // } else {
|
|
|
|
+ // // 不存在区域协调人,实施工程师和crm客户同城市,且实施工程师尽可能集中在同一个供应商中
|
|
|
|
+ //
|
|
|
|
+ // // 供应商和实施工程师数量键值对
|
|
|
|
+ // Map<Long, Integer> supplierMap = effectFree.stream()
|
|
|
|
+ // .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
|
|
|
|
+ // supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
|
+ // for (Long supplierId : supplierMap.keySet()) {
|
|
|
|
+ // Integer count = supplierMap.get(supplierId);
|
|
|
|
+ // int effectDivide = effectUnDistributed - count;
|
|
|
|
+ // List<ArchivesSourceResult> cell;
|
|
|
|
+ // if (effectDivide > 0) {
|
|
|
|
+ // // 该供应商的不够分配配额
|
|
|
|
+ // cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ // userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
+ // .collect(Collectors.toList()));
|
|
|
|
+ // this.addDistributeTemp(effectList, cell);
|
|
|
|
+ // // 进入下一个供应商循环
|
|
|
|
+ // effectUnDistributed = effectUnDistributed - count;
|
|
|
|
+ // } else {
|
|
|
|
+ // // 该供应商的足够分配配额
|
|
|
|
+ // cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
+ // .limit(effectUnDistributed).collect(Collectors.toList());
|
|
|
|
+ // userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
+ // .collect(Collectors.toList()));
|
|
|
|
+ // this.addDistributeTemp(effectList, cell);
|
|
|
|
+ // break;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // AllocationParam allocationParam = new AllocationParam();
|
|
|
|
+ // allocationParam.setRoleId(effectRoleId);
|
|
|
|
+ // allocationParam.setUserIdList(userIdList);
|
|
|
|
+ // allocationParamList.add(allocationParam);
|
|
|
|
+ // }
|
|
|
|
+ // // 再分助理工程师
|
|
|
|
+ // if (assistantUnDistributed > 0) {
|
|
|
|
+ // SysRole assistantRole = sysRoleService.list(
|
|
|
|
+ // new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.ASSISTANT_ENGINEER))
|
|
|
|
+ // .get(0);
|
|
|
|
+ // Long assistantRoleId = assistantRole.getId();
|
|
|
|
+ // List<Long> userIdList = new ArrayList<>();
|
|
|
|
+ // Map<Long, Integer> supplierMap = assistantFree.stream()
|
|
|
|
+ // .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
|
|
|
|
+ // supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
|
+ // for (Long supplierId : supplierMap.keySet()) {
|
|
|
|
+ // Integer count = supplierMap.get(supplierId);
|
|
|
|
+ // int assistantDivide = assistantUnDistributed - count;
|
|
|
|
+ // List<ArchivesSourceResult> cell;
|
|
|
|
+ // if (assistantDivide > 0) {
|
|
|
|
+ // // 该供应商的不够分配配额
|
|
|
|
+ // cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ // userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
+ // .collect(Collectors.toList()));
|
|
|
|
+ // this.addDistributeTemp(assistantList, cell);
|
|
|
|
+ // assistantUnDistributed = assistantUnDistributed - count;
|
|
|
|
+ // } else {
|
|
|
|
+ // // 该供应商的足够分配配额
|
|
|
|
+ // cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
+ // .limit(assistantUnDistributed).collect(Collectors.toList());
|
|
|
|
+ // userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
|
|
|
|
+ // .collect(Collectors.toList()));
|
|
|
|
+ // this.addDistributeTemp(assistantList, cell);
|
|
|
|
+ // break;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // AllocationParam allocationParam = new AllocationParam();
|
|
|
|
+ // allocationParam.setRoleId(assistantRoleId);
|
|
|
|
+ // allocationParam.setUserIdList(userIdList);
|
|
|
|
+ // allocationParamList.add(allocationParam);
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // // 最后分配区域协调人
|
|
|
|
+ // Long regionUserId = null;
|
|
|
|
+ // if (coordinatorUnDistributed > 0) {
|
|
|
|
+ // if (CollectionUtils.isNotEmpty(effectList)) {
|
|
|
|
+ // // 存在已经分配的实施工程师
|
|
|
|
+ // List<Long> supplierIdList = effectList.stream().map(CrmArchivesAllocationResult::getSupplierId)
|
|
|
|
+ // .distinct().collect(Collectors.toList());
|
|
|
|
+ // if (supplierIdList.size() == 1) {
|
|
|
|
+ // Long supplierId = supplierIdList.get(0);
|
|
|
|
+ // List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
|
|
|
|
+ // .filter(e -> supplierId.equals(e.getSupplierId()))
|
|
|
|
+ // .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ // if (CollectionUtils.isNotEmpty(coordinator)) {
|
|
|
|
+ // regionUserId = coordinator.get(0).getUserId();
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // } else {
|
|
|
|
+ // // 不存在实施工程师
|
|
|
|
+ // List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
|
|
|
|
+ // .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
|
|
|
|
+ // .collect(Collectors.toList());
|
|
|
|
+ // if (CollectionUtils.isNotEmpty(coordinator)) {
|
|
|
|
+ // regionUserId = coordinator.get(0).getUserId();
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // UserArchivesAllocationParam userArchivesAllocationParam = new UserArchivesAllocationParam();
|
|
|
|
+ // userArchivesAllocationParam.setAllocationParams(allocationParamList);
|
|
|
|
+ // userArchivesAllocationParam.setServiceUnitId(serviceUnitId);
|
|
|
|
+ // userArchivesAllocationParam.setCrmNo(crmNo);
|
|
|
|
+ // userArchivesAllocationParam.setRegionUserId(regionUserId);
|
|
|
|
+ // this.editCrmAllocation(userArchivesAllocationParam);
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|