lyhzzz 4 月之前
父节点
当前提交
c3d5537dbf
共有 1 个文件被更改,包括 42 次插入13 次删除
  1. 42 13
      src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationServiceImpl.java

+ 42 - 13
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationServiceImpl.java

@@ -49,6 +49,8 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
     @Autowired
     IScenePlusService scenePlusService;
     @Autowired
+    IScenePlusExtService scenePlusExtService;
+    @Autowired
     LaserService fdkkLaserService;
     @Autowired
     ISceneResourceCooperationService sceneResourceCooperationService;
@@ -120,7 +122,6 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
 
         HashMap<String, List<User>> byNumList = this.getByNumList(numList,sceneType);
 
-
         for (Long userId : userIds) {
             for (String num : numList) {
                 List<User> users = byNumList.get(num);
@@ -438,13 +439,33 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
     }
 
     private HashMap<String,String> getTotalCount(List<String> numList, List<User> users,String sceneType,Long cameraId){
+        List<String> forList = new ArrayList<>(numList);
+
         List<SceneCooperationCount> freeCountList = sceneCooperationCountService.getByNumList(numList,sceneType);
         HashMap<String,Integer> freeMap = new HashMap<>();
         freeCountList.forEach(e -> freeMap.put(e.getNum(),e.getCount()));
-
         HashMap<String, List<User>> map = this.getByNumList(numList,sceneType);
         HashMap<String,String> needNumList = new HashMap<>();
-        for (String num : numList) {
+
+        if(cameraId != null && "mesh".equals(sceneType)){
+            CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
+            if(cameraDetail == null || cameraDetail.getType() == null){
+                throw new BusinessException(ResultCode.CAMERA_NOT_EXIT);
+            }
+            if(cameraDetail.getType() == 10 || cameraDetail.getType() == 11){
+                List<ScenePro> listByNums = sceneProService.getListByNums(numList);
+                List<String> newList = listByNums.stream().filter(e->e.getIsObj() == 1).map(ScenePro::getNum).collect(Collectors.toList());
+
+                List<ScenePlus> listByNums1 = scenePlusService.getListByNums(numList);
+                List<Long> ids = listByNums1.stream().map(ScenePlus::getId).collect(Collectors.toList());
+                HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(ids);
+                List<String> newList2 = listByNums1.stream().filter(e -> byPlusIds.get(e.getId()) != null && byPlusIds.get(e.getId()).getIsObj() == 1).map(ScenePlus::getNum).collect(Collectors.toList());
+                forList = newList;
+                forList.addAll(newList2);
+            }
+        }
+
+        for (String num : forList) {
             Integer freeCount = freeMap.get(num) == null ? 1 :freeMap.get(num);
 
             List<User> dbUserList = map.get(num);
@@ -493,17 +514,25 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         numList1.addAll(numList2);
 
 
+        if(StringUtils.isBlank(sceneType) && !collect1.isEmpty() && !collect2.isEmpty()){
+            List<String> newList = collect1.stream().filter(e->e.getIsObj() == 1).map(ScenePro::getNum).collect(Collectors.toList());
+            List<Long> ids = collect2.stream().map(ScenePlus::getId).collect(Collectors.toList());
+            HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(ids);
+            List<String> newList2 = collect2.stream().filter(e -> byPlusIds.get(e.getId()) != null && byPlusIds.get(e.getId()).getIsObj() == 1).map(ScenePlus::getNum).collect(Collectors.toList());
+            numList = new HashSet<>();
+            numList.addAll(newList2);
+            numList.addAll(newList);
+        }
+
+
         List<SceneCooperation> addList =new ArrayList<>();
-        if( !numList.isEmpty()){
-            if(StringUtils.isBlank(sceneType)){
-                addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,"mesh");
-                if(!numList1.isEmpty()){
-                    this.saveBatchByList(new ArrayList<>(numList1), userIds, type,"laser");
-                }
-            }else {
-                addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,sceneType);
-            }
+        if(numList1.isEmpty()){
+            addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,"mesh");
         }
+        if(!numList1.isEmpty()){
+            addList = this.saveBatchByList(new ArrayList<>(numList1), userIds, type,"laser");
+        }
+
         List<Long> collect3 = addList.stream().map(SceneCooperation::getUserId).collect(Collectors.toList());
         for (User user : userList) {
             if("aws".equals(NacosProperty.uploadType)){
@@ -528,7 +557,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         if(StringUtils.isNotBlank(sceneType) && "mesh".equals(sceneType)){
             return;
         }
-        String operatingMode = numList.size() > 1 ? "add" :"update";
+        String operatingMode = (StringUtils.isBlank(sceneType) || numList1.size() > 1) ? "add" :"update";
         laserService.saveBatchCooperation(new ArrayList<>(numList1),snCodeList,collect,type,operatingMode);
 
     }