|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
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.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -79,7 +80,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
city = SystemConstant.translateSpecificSign(city);
|
|
|
area = SystemConstant.translateSpecificSign(area);
|
|
|
customName = SystemConstant.translateSpecificSign(customName);
|
|
|
- List<UserArchivesAllocationResult> list = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, province, city, area, customName, gap, null, dpr);
|
|
|
+ List<UserArchivesAllocationResult> list = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, province, city, area, customName, gap, null, null, dpr);
|
|
|
Integer publishedCrmCount = Math.toIntExact(list.stream().filter(e -> CrmStatusEnum.PUBLISH.equals(e.getCrmStatus())).count());
|
|
|
Integer totalCrmCount = list.size();
|
|
|
|
|
@@ -166,11 +167,10 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
if (Objects.isNull(occupiedCrm)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("人员占用状态异常");
|
|
|
}
|
|
|
- throw ExceptionResultEnum.ERROR.exception(String.format("该工程师已经被派单号为[%s],名称为[%s],状态为[%s]的派单占用,请先将工程师从派单中移出", occupiedCrm.getCrmNo(), occupiedCrm.getName(), occupiedCrm.getStatus()));
|
|
|
+ if (!crmNo.equals(occupiedCrm.getCrmNo())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("工程师[%s]已经被派单号为[%s],名称为[%s],状态为[%s]的派单占用,请先将工程师从派单中移出", tbUserArchives.getName(), occupiedCrm.getCrmNo(), occupiedCrm.getName(), occupiedCrm.getStatus()));
|
|
|
+ }
|
|
|
}
|
|
|
- tbUserArchives.setStatus(UserArchivesStatusEnum.OCCUPIED);
|
|
|
- tbUserArchivesService.updateById(tbUserArchives);
|
|
|
-
|
|
|
TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
|
|
|
tbUserArchivesAllocation.setCrmNo(crmNo);
|
|
|
tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
|
|
@@ -189,12 +189,31 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
tbCrmService.updateById(tbCrm);
|
|
|
}
|
|
|
|
|
|
- // 如果存在要分配的记录则根据crm单号删除原先数据并新增
|
|
|
+
|
|
|
+ // 新增前删除派单关系
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(tbUserArchivesAllocationList)) {
|
|
|
- // 新增前删除派单关系
|
|
|
- if (CollectionUtils.isNotEmpty(dbList)) {
|
|
|
- this.removeByIds(dbList);
|
|
|
- }
|
|
|
+ // 新增前先将工程师的状态设置为非空闲
|
|
|
+ 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);
|
|
|
}
|
|
@@ -228,7 +247,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
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, null);
|
|
|
+ List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null);
|
|
|
// crm按照差额倒序
|
|
|
crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
|
|
|
.sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
|
|
@@ -267,17 +286,17 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 可分配的人力资源
|
|
|
- List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(RoleTypeEnum.EFFECT_ENGINEER)
|
|
|
+ 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)
|
|
|
+ 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)
|
|
|
+ List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(serviceUnitId, null)
|
|
|
.stream()
|
|
|
.filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
|
|
|
.collect(Collectors.toList());
|
|
@@ -307,13 +326,15 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
for (Long supplierId : supplierMap.keySet()) {
|
|
|
Integer count = supplierMap.get(supplierId);
|
|
|
- effectUnDistributed = effectUnDistributed - count;
|
|
|
+ int effectDivide = effectUnDistributed - count;
|
|
|
List<ArchivesSourceResult> cell;
|
|
|
- if (effectUnDistributed > 0) {
|
|
|
+ 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());
|
|
@@ -337,13 +358,14 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
supplierMap = SystemConstant.sortMapByValues(supplierMap);
|
|
|
for (Long supplierId : supplierMap.keySet()) {
|
|
|
Integer count = supplierMap.get(supplierId);
|
|
|
- assistantUnDistributed = assistantUnDistributed - count;
|
|
|
+ int assistantDivide = assistantUnDistributed - count;
|
|
|
List<ArchivesSourceResult> cell;
|
|
|
- if (assistantUnDistributed > 0) {
|
|
|
+ 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());
|
|
@@ -407,7 +429,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
Long crmId = tbCrm.getId();
|
|
|
List<Long> crmIdList = new ArrayList<>();
|
|
|
crmIdList.add(crmId);
|
|
|
- List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, null);
|
|
|
+ List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, null, null);
|
|
|
if (CollectionUtils.isEmpty(crmSourceList)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
|
|
|
} else if (crmSourceList.size() > 1) {
|