Browse Source

add:可用工程师查询bug

caozixuan 1 year ago
parent
commit
8aa31a71d4

+ 44 - 37
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesServiceImpl.java

@@ -429,30 +429,34 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
 
     @Override
     public List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType, String crmNo) {
+        List<ArchivesSourceResult> result = new ArrayList<>();
         if (!RoleTypeEnum.EFFECT_ENGINEER.equals(roleType) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(roleType)) {
             throw ExceptionResultEnum.ERROR.exception("该方法只支持查询实施工程师和助理工程师");
         }
 
         List<ArchivesSourceResult> list = new ArrayList<>(this.baseMapper.findArchivesSourceByType(roleType));
+        if (CollectionUtils.isNotEmpty(list)) {
+            Long currentTime = System.currentTimeMillis();
+            list = list.stream()
+                    .filter(e -> e.getAuthenticationValidTime() != null && e.getAuthenticationValidTime() >= currentTime && UserArchivesStatusEnum.FREE.equals(e.getArchivesStatus()))
+                    .peek(e -> e.setRemainCount(1))
+                    .collect(Collectors.toList());
 
-        Long currentTime = System.currentTimeMillis();
-        list = list.stream()
-                .filter(e -> e.getAuthenticationValidTime() >= currentTime && UserArchivesStatusEnum.FREE.equals(e.getArchivesStatus()))
-                .peek(e -> e.setRemainCount(1))
-                .collect(Collectors.toList());
-
-        List<Long> idList = list.stream().map(ArchivesSourceResult::getUserId).collect(Collectors.toList());
+            List<Long> idList = list.stream().map(ArchivesSourceResult::getUserId).collect(Collectors.toList());
 
-        if (crmNo != null && crmNo.length() > 0) {
-            List<ArchivesSourceResult> choose = this.baseMapper.findArchivesUsed(roleType, crmNo);
-            choose = choose.stream().filter(e -> !idList.contains(e.getUserId())).collect(Collectors.toList());
-            list.addAll(choose);
+            if (crmNo != null && crmNo.length() > 0) {
+                List<ArchivesSourceResult> choose = this.baseMapper.findArchivesUsed(roleType, crmNo);
+                choose = choose.stream().filter(e -> !idList.contains(e.getUserId())).collect(Collectors.toList());
+                list.addAll(choose);
+            }
+            result = list;
         }
-        return list;
+        return result;
     }
 
     @Override
     public List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId, String crmNo) {
+        List<ArchivesSourceResult> result = new ArrayList<>();
         TBService tbService = tbServiceService.getById(serviceUnitId);
         if (Objects.isNull(tbService)) {
             throw ExceptionResultEnum.ERROR.exception("服务单元不存在");
@@ -462,34 +466,37 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
 
         Long currentTime = System.currentTimeMillis();
         List<ArchivesSourceResult> list = this.baseMapper.findArchivesSourceByType(RoleTypeEnum.REGION_COORDINATOR);
-        list = list.stream()
-                .filter(e -> e.getAuthenticationValidTime() >= currentTime)
-                .peek(e -> {
-                    Long userId = e.getUserId();
-                    int count = Math.toIntExact(tbCrmList.stream().filter(c -> userId.equals(c.getRegionCoordinatorId())).count());
-                    e.setRemainCount(rate - count);
-                })
-                .collect(Collectors.toList());
+        if (CollectionUtils.isNotEmpty(list)) {
+            list = list.stream()
+                    .filter(e -> e.getAuthenticationValidTime() != null && e.getAuthenticationValidTime() >= currentTime)
+                    .peek(e -> {
+                        Long userId = e.getUserId();
+                        int count = Math.toIntExact(tbCrmList.stream().filter(c -> userId.equals(c.getRegionCoordinatorId())).count());
+                        e.setRemainCount(rate - count);
+                    })
+                    .collect(Collectors.toList());
 
-        list = list.stream().filter(e -> e.getRemainCount() > 0).collect(Collectors.toList());
+            list = list.stream().filter(e -> e.getRemainCount() > 0).collect(Collectors.toList());
 
-        // 调配选人列表查询的特殊处理
-        if (crmNo != null && crmNo.length() > 0) {
-            List<TBCrm> temp = tbCrmList.stream().filter(e -> e.getCrmNo().equals(crmNo)).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(temp)) {
-                throw ExceptionResultEnum.ERROR.exception(String.format("派单号[%s]不存在在服务单元[%s]下", crmNo, tbService.getName()));
-            }
-            TBCrm chooseCrm = temp.get(0);
-            Long coordinatorId = chooseCrm.getRegionCoordinatorId();
-            if (coordinatorId != null && !list.stream().map(ArchivesSourceResult::getUserId).collect(Collectors.toList()).contains(coordinatorId)) {
-                TBUserArchives chooseArchives = tbUserArchivesService.findByUserId(coordinatorId);
-                ArchivesSourceResult choose = new ArchivesSourceResult();
-                choose.setArchivesId(chooseArchives.getId());
-                choose.setUserId(coordinatorId);
-                choose.setName(chooseArchives.getName());
-                list.add(choose);
+            // 调配选人列表查询的特殊处理
+            if (crmNo != null && crmNo.length() > 0) {
+                List<TBCrm> temp = tbCrmList.stream().filter(e -> e.getCrmNo().equals(crmNo)).collect(Collectors.toList());
+                if (CollectionUtils.isEmpty(temp)) {
+                    throw ExceptionResultEnum.ERROR.exception(String.format("派单号[%s]不存在在服务单元[%s]下", crmNo, tbService.getName()));
+                }
+                TBCrm chooseCrm = temp.get(0);
+                Long coordinatorId = chooseCrm.getRegionCoordinatorId();
+                if (coordinatorId != null && !list.stream().map(ArchivesSourceResult::getUserId).collect(Collectors.toList()).contains(coordinatorId)) {
+                    TBUserArchives chooseArchives = tbUserArchivesService.findByUserId(coordinatorId);
+                    ArchivesSourceResult choose = new ArchivesSourceResult();
+                    choose.setArchivesId(chooseArchives.getId());
+                    choose.setUserId(coordinatorId);
+                    choose.setName(chooseArchives.getName());
+                    list.add(choose);
+                }
             }
+            result = list;
         }
-        return list;
+        return result;
     }
 }