|
@@ -6,24 +6,25 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.sop.business.bean.params.AllocationParam;
|
|
|
import com.qmth.sop.business.bean.params.UserArchivesAllocationParam;
|
|
|
+import com.qmth.sop.business.bean.result.CrmArchivesAllocationResult;
|
|
|
import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
|
|
|
import com.qmth.sop.business.bean.result.UserArchivesAllocationSubTotalResult;
|
|
|
-import com.qmth.sop.business.entity.SysRole;
|
|
|
-import com.qmth.sop.business.entity.TBCrm;
|
|
|
-import com.qmth.sop.business.entity.TBService;
|
|
|
-import com.qmth.sop.business.entity.TBUserArchivesAllocation;
|
|
|
+import com.qmth.sop.business.bean.result.UserArchivesResult;
|
|
|
+import com.qmth.sop.business.entity.*;
|
|
|
import com.qmth.sop.business.mapper.TBUserArchivesAllocationMapper;
|
|
|
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.enums.ExceptionResultEnum;
|
|
|
import com.qmth.sop.common.enums.RoleTypeEnum;
|
|
|
+import com.qmth.sop.common.enums.UserArchivesStatusEnum;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -46,6 +47,8 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
private SysRoleService sysRoleService;
|
|
|
@Resource
|
|
|
private SysUserRoleService sysUserRoleService;
|
|
|
+ @Resource
|
|
|
+ private TBUserArchivesService tbUserArchivesService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<UserArchivesAllocationResult> findCrmAllocationPage(Long serviceUnitId, String province, String city, String area, String customName, Integer gap, Integer pageNumber, Integer pageSize) {
|
|
@@ -106,6 +109,8 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
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));
|
|
@@ -141,8 +146,16 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
if (!sysRoleIdList.contains(roleId)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("所选用户不包含认证角色[" + role.getType().getDesc() + "]");
|
|
|
}
|
|
|
+ TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
|
|
|
+ if (UserArchivesStatusEnum.FREE.equals(tbUserArchives.getStatus())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不能分配非空闲状态的用户");
|
|
|
+ }
|
|
|
+ tbUserArchives.setStatus(UserArchivesStatusEnum.NON_EXECUTION_SOP);
|
|
|
+ tbUserArchivesService.updateById(tbUserArchives);
|
|
|
+
|
|
|
TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
|
|
|
tbUserArchivesAllocation.setCrmNo(crmNo);
|
|
|
+ tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
|
|
|
tbUserArchivesAllocation.setServiceId(serviceUnitId);
|
|
|
tbUserArchivesAllocation.setUserId(userId);
|
|
|
tbUserArchivesAllocation.setRoleId(roleId);
|
|
@@ -152,15 +165,10 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 如果实施和助理工程师都不存在,但是区域负责人存在,也新增一条记录
|
|
|
- if (CollectionUtils.isEmpty(tbUserArchivesAllocationList)) {
|
|
|
- if (regionUserId != null && regionUserId > 0) {
|
|
|
- TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
|
|
|
- tbUserArchivesAllocation.setCrmNo(crmNo);
|
|
|
- tbUserArchivesAllocation.setServiceId(serviceUnitId);
|
|
|
- tbUserArchivesAllocation.setRegionUserId(regionUserId);
|
|
|
- tbUserArchivesAllocationList.add(tbUserArchivesAllocation);
|
|
|
- }
|
|
|
+ // 更新区域负责人
|
|
|
+ if (regionUserId != null && regionUserId > 0) {
|
|
|
+ tbCrm.setRegionCoordinatorId(regionUserId);
|
|
|
+ tbCrmService.updateById(tbCrm);
|
|
|
}
|
|
|
|
|
|
// 如果存在要分配的记录则根据crm单号删除原先数据并新增
|
|
@@ -174,8 +182,81 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<CrmArchivesAllocationResult> findAllocationByCrmNo(String crmNo) {
|
|
|
+ List<CrmArchivesAllocationResult> list = this.baseMapper.findAllocationByCrmNo(crmNo);
|
|
|
+ TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
|
|
|
+ Long regionCoordinatorId = tbCrm.getRegionCoordinatorId();
|
|
|
+
|
|
|
+ if (regionCoordinatorId != null && regionCoordinatorId > 0) {
|
|
|
+
|
|
|
+ UserArchivesResult userArchivesResult = tbUserArchivesService.findUserArchivesByArchivesIdORUserId(null, regionCoordinatorId);
|
|
|
+ CrmArchivesAllocationResult region = new CrmArchivesAllocationResult();
|
|
|
+ region.setType(RoleTypeEnum.REGION_COORDINATOR);
|
|
|
+ region.setArchivesId(userArchivesResult.getUserArchivesId());
|
|
|
+ region.setArchiverName(userArchivesResult.getName());
|
|
|
+ region.setSupplierId(userArchivesResult.getSupplierId());
|
|
|
+ region.setSupplierName(userArchivesResult.getSupplierName());
|
|
|
+ region.setArchivesProvince(userArchivesResult.getProvince());
|
|
|
+ region.setArchivesCity(userArchivesResult.getCity());
|
|
|
+ region.setUserId(userArchivesResult.getUserId());
|
|
|
+ list.add(region);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void autoEditCrmAllocationBatch(Long serviceUnitId) {
|
|
|
+ List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, 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();
|
|
|
+
|
|
|
+ // 区域协调人差额
|
|
|
+ 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());
|
|
|
+
|
|
|
+ // 先分实施工程师
|
|
|
+ if (effectUnDistributed > 0) {
|
|
|
+ // 如果存在区域协调人,则要分配的实施工程师必须跟区域协调人处于相同的供应商
|
|
|
+ if (CollectionUtils.isNotEmpty(coordinatorList)){
|
|
|
+ CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
|
|
|
+ Long supplierId = coordinator.getSupplierId();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-}
|
|
|
+}
|