Browse Source

专家抽取逻辑优化

suntianwu 2 years ago
parent
commit
de589c81f5

+ 61 - 27
purchase-system/src/main/java/com/ozs/pm/service/impl/PmDemandServiceImpl.java

@@ -1019,6 +1019,24 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean extractExpertBatch(PmBaseExpertExtractReqVo pmBaseExpertExtractReqVo) throws Exception {
+        PmDemand pmDemand = this.getById(pmBaseExpertExtractReqVo.getDemandId());
+        if (ObjectUtils.isEmpty(pmDemand)) {
+            throw new Exception("参数错误");
+        }
+
+        String professional = pmBaseExpertExtractReqVo.getProfessional();
+        if ( ObjectUtils.isEmpty(professional)) {
+            throw new Exception("必须选择专家专业");
+        }
+
+        String localArea = pmBaseExpertExtractReqVo.getLocalArea();
+        if (ObjectUtils.isEmpty(localArea)) {
+            throw new Exception("必须选择地域");
+        }
+        if (!StringUtils.isNumeric(localArea)) {
+            throw new Exception("地域必须传数字代码");
+        }
+
         Integer technicalExpertNumber = pmBaseExpertExtractReqVo.getTechnicalExpertNumber();
         if (technicalExpertNumber == null) {
             technicalExpertNumber = 0;
@@ -1039,15 +1057,6 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
         if (technicalExpertNumber + economicExpertNumber + legalAffairsExpertNumber + spareExpertNumber == 0) {
             throw new Exception("必须至少填写一个数量");
         }
-        String professional = pmBaseExpertExtractReqVo.getProfessional();
-        if (spareExpertNumber > 0 && ObjectUtils.isEmpty(professional)) {
-            throw new Exception("抽取备用专家必须选择专家专业");
-        }
-
-        PmDemand pmDemand = this.getById(pmBaseExpertExtractReqVo.getDemandId());
-        if (ObjectUtils.isEmpty(pmDemand)) {
-            throw new Exception("参数错误");
-        }
 
         String needAvoidUnit = pmBaseExpertExtractReqVo.getNeedAvoidUnit();
         List<String> needAvoidUnitList = null;
@@ -1057,12 +1066,8 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
         }
 
 
-        String localArea = pmBaseExpertExtractReqVo.getLocalArea();
         List<String> sysRegionCodeList = new ArrayList<>();
         if (!ObjectUtils.isEmpty(localArea)) {
-            if (!StringUtils.isNumeric(localArea)) {
-                throw new Exception("地域必须传数字代码");
-            }
             sysRegionCodeList.add(localArea);
             //找到该地域code对应的子列表
             List<SysRegionVO> sysRegionVOList = iSysRegionService.findChildDivisions(localArea);
@@ -1078,7 +1083,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
         lw.eq(BaseExpert::getVarietyPurchase, pmDemand.getProjectType())
                 .eq(BaseExpert::getStatus, NameListType.WHITE.getCode())
                 .notIn(!ObjectUtils.isEmpty(needAvoidUnitList), BaseExpert::getUnitInformation, needAvoidUnitList)
-                .in(!ObjectUtils.isEmpty(sysRegionCodeList), BaseExpert::getLocalArea, sysRegionCodeList);
+                .in(!ObjectUtils.isEmpty(sysRegionCodeList), BaseExpert::getLocalArea, sysRegionCodeList); //地域
 
         List<BaseExpert> baseExpertList = baseExpertService.list(lw);
         if (ObjectUtils.isEmpty(baseExpertList)) {
@@ -1091,42 +1096,51 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
         List<BaseExpert> legalAffairsExpertList = new ArrayList<>();
         List<BaseExpert> spareExpertList = new ArrayList<>();
 
+        String[] arr = professional.split(",");
+        List<String> professionalList = Arrays.asList(arr);
 
         for (BaseExpert baseExpert : baseExpertList) {
+            //专业类型判断
+            String majorType = baseExpert.getMajorType();
+            if (!ObjectUtils.isEmpty(majorType)) {
+                String[] arr2 = majorType.split(",");
+                List<String> majorTypeList = Arrays.asList(arr2);
+                if (!hasIntersection(professionalList, majorTypeList)) { //不符合专业类型
+                   continue;
+                }
+            }
+            //备用专家
+            if (spareExpertNumber > 0) { //都加进去
+                spareExpertList.add(baseExpert);
+            }
+
             if (technicalExpertNumber > 0) {
                 if (baseExpert.getExpertType().contains(ExpertType.TECHNICAL_EXPERT.getCode())) {
                     technicalExpertList.add(baseExpert);
+                    continue;
                 }
             }
 
             if (economicExpertNumber > 0) {
                 if (baseExpert.getExpertType().contains(ExpertType.ECONOMIC_EXPERT.getCode())) {
                     economicExpertList.add(baseExpert);
+                    continue;
                 }
             }
 
             if (legalAffairsExpertNumber > 0) {
                 if (baseExpert.getExpertType().contains(ExpertType.LEGALAFFAIRS_EXPERT.getCode())) {
                     legalAffairsExpertList.add(baseExpert);
+                    continue;
                 }
             }
 
-            if (spareExpertNumber > 0) {
-                String[] arr = professional.split(",");
-                List<String> professionalList = Arrays.asList(arr);
-                String majorType = baseExpert.getMajorType();
-                if (!ObjectUtils.isEmpty(majorType)) {
-                    String[] arr2 = majorType.split(",");
-                    List<String> majorTypeList = Arrays.asList(arr2);
-                    if (hasIntersection(professionalList, majorTypeList)) {
-                        spareExpertList.add(baseExpert);
-                    }
-                }
-            }
         }
 
         //从子列表中随机抽取符合数据量的
+
         List<BaseExpert> alltExpertList = new ArrayList<>();
+
         if (!ObjectUtils.isEmpty(technicalExpertList)) {
             alltExpertList.addAll(RandomUtil.getRandomList(technicalExpertList, technicalExpertNumber));
         }
@@ -1136,8 +1150,28 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
         if (!ObjectUtils.isEmpty(legalAffairsExpertList)) {
             alltExpertList.addAll(RandomUtil.getRandomList(legalAffairsExpertList, legalAffairsExpertNumber));
         }
+
+        List<Integer> allExpertIdList = new ArrayList<>();
+        if(!ObjectUtils.isEmpty(alltExpertList)){
+            for(BaseExpert baseExpert : alltExpertList){
+                allExpertIdList.add(baseExpert.getId());
+            }
+        }
+
         if (!ObjectUtils.isEmpty(spareExpertList)) {
-            alltExpertList.addAll(RandomUtil.getRandomList(spareExpertList, spareExpertNumber));
+            List<BaseExpert> spareExpertListNew = new ArrayList<>();
+            if(!ObjectUtils.isEmpty(allExpertIdList)){ //去重
+                for(BaseExpert baseExpert : spareExpertList){
+                    if(!allExpertIdList.contains(baseExpert.getId())){
+                        spareExpertListNew.add(baseExpert);
+                    }
+                }
+            } else {
+                spareExpertListNew = spareExpertList;
+            }
+            if(!ObjectUtils.isEmpty(spareExpertListNew)){
+                alltExpertList.addAll(RandomUtil.getRandomList(spareExpertListNew, spareExpertNumber));
+            }
         }
 
         if (ObjectUtils.isEmpty(alltExpertList)) {