lyhzzz 5 miesięcy temu
rodzic
commit
554a6bdec9

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/ISceneCooperationService.java

@@ -24,7 +24,7 @@ public interface ISceneCooperationService extends IService<SceneCooperation> {
     void deleteCooperationList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList,List<Long> userIds) ;
     void deleteCooperationList(List<String> numList,List<Long> userIds) ;
 
-    void saveBatchByList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList, Long userId ,List<Long>resourceIds);
+    void saveBatchByList(List<String> numList, List<Long> userId ,String type);
 
     JSONObject sceneResourceList(SceneCooperationParam param);
 

+ 9 - 42
src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java

@@ -330,51 +330,18 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
         cameraDetailService.updateCooperationByIds(cameraIds, user.getId());
         sceneResourceCameraService.deleteByCameraIds(cameraIds);
 
-        //保存相机和场景资源的关联关系你
-        List<Long> resourceIdList = new ArrayList<>();
-        List<SceneResource> v3List = new ArrayList<>();
-        List<SceneResource> v4List = new ArrayList<>();
-        if (StringUtils.isNotEmpty(resourceIds)) {
-            for (String rId : resourceIds.split(",")) {
-                resourceIdList.add(Long.valueOf(rId));
-            }
-            List<SceneResource> sceneResources = sceneResourceService.listByIds(resourceIdList);
-            v3List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v3")).collect(Collectors.toList());
-            v4List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v4")).collect(Collectors.toList());
-
-            sceneResourceCameraService.saveBatchByCameraIds(cameraIds,resourceIdList);
-        }else {
-            List<Long> laserCameraIds = new ArrayList<>();
-            for (Long cameraId : detailMap.keySet()) {
-                CameraDetail detail = detailMap.get(cameraId);
-                CameraType cameraType = cameraTypeService.getByCameraType(detail.getType());
-                if (cameraType.getIsLaser() == 1) {
-                    laserCameraIds.add(cameraId);
-                }
-            }
-            if(laserCameraIds.size() >0){
-                List<SceneResource> sceneResources = sceneResourceService.list();
-                List<Long> collect = sceneResources.stream().map(SceneResource::getId).collect(Collectors.toList());
-                sceneResourceCameraService.saveBatchByCameraIds(laserCameraIds,collect);
-
-                v3List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v3")).collect(Collectors.toList());
-                v4List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v4")).collect(Collectors.toList());
-            }
-
-        }
 
         List<ScenePro> sceneProList = sceneProService.getListByCameraIds(cameraIds);
         List<ScenePlus> scenePlusList = scenePlusService.getListByCameraIds(cameraIds);
-        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList,Arrays.asList(user.getId()));
-
-        if(!v3List.isEmpty() && !sceneProList.isEmpty()){
-            List<Long> v3Ids = v3List.stream().map(SceneResource::getId).collect(Collectors.toList());
-            sceneCooperationService.saveBatchByList(sceneProList,new ArrayList<>(),user.getId(),v3Ids);
-        }
-
-        if(!v4List.isEmpty() && !scenePlusList.isEmpty()){
-            List<Long> v4Ids = v4List.stream().map(SceneResource::getId).collect(Collectors.toList());
-            sceneCooperationService.saveBatchByList(new ArrayList<>(),scenePlusList,user.getId(),v4Ids);
+        //sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList,Arrays.asList(user.getId()));
+
+        List<String> numList = new ArrayList<>();
+        List<String> v3List = sceneProList.stream().map(ScenePro::getNum).collect(Collectors.toList());
+        List<String> v4List = scenePlusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
+        numList.addAll(v3List);
+        numList.addAll(v4List);
+        if( !numList.isEmpty()){
+            sceneCooperationService.saveBatchByList(numList,Arrays.asList(user.getId()),"camera");
         }
 
 

+ 2 - 1
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationCountServiceImpl.java

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -29,7 +30,7 @@ public class SceneCooperationCountServiceImpl extends ServiceImpl<ISceneCooperat
             return;
         }
         List<SceneCooperationCount> sceneCooperationCounts = this.getByNumList(numList);
-        List<String> dbNumList = sceneCooperationCounts.stream().map(SceneCooperationCount::getNum).collect(Collectors.toList());
+        Set<String> dbNumList = sceneCooperationCounts.stream().map(SceneCooperationCount::getNum).collect(Collectors.toSet());
 
         List<SceneCooperationCount> saveList = new ArrayList<>();
         for (String num : numList) {

+ 59 - 29
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationServiceImpl.java

@@ -110,31 +110,57 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
     }
 
     @Override
-    public void saveBatchByList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList, Long userId,List<Long> resourceIdList) {
+    public void saveBatchByList(List<String> numList,  List<Long> userIds,String type) {
         List<SceneCooperation> list = new ArrayList<>();
-        for (ScenePro scenePro : sceneProList) {
-            SceneCooperation sceneCooperationEntity = new SceneCooperation();
-            sceneCooperationEntity.setUserId(userId);
-            sceneCooperationEntity.setSceneNum(scenePro.getNum());
-            sceneCooperationEntity.setRecStatus("A");
-            sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
-            sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
-            list.add(sceneCooperationEntity);
-        }
-        for (ScenePlus scenePlus : scenePlusList) {
-            SceneCooperation sceneCooperationEntity = new SceneCooperation();
-            sceneCooperationEntity.setUserId(userId);
-            sceneCooperationEntity.setSceneNum(scenePlus.getNum());
-            sceneCooperationEntity.setRecStatus("A");
-            sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
-            sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
-            list.add(sceneCooperationEntity);
+        List<String> delList = new ArrayList<>();
+
+        HashMap<String, List<User>> byNumList = this.getByNumList(numList);
+
+
+        for (Long userId : userIds) {
+            for (String num : numList) {
+                List<User> users = byNumList.get(num);
+                List<Long> collect1 = users.stream().map(User::getId).collect(Collectors.toList());
+                if(collect1.contains(userId)){
+                    continue;
+                }
+                if("scene".equals(type)){
+                    for (Long l : collect1) {
+                        if(!userIds.contains(l)){
+                            delList.add(num + "," +l);
+                        }
+                    }
+                }
+
+
+                SceneCooperation sceneCooperationEntity = new SceneCooperation();
+                sceneCooperationEntity.setUserId(userId);
+                sceneCooperationEntity.setSceneNum(num);
+                sceneCooperationEntity.setRecStatus("A");
+                sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
+                sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
+                list.add(sceneCooperationEntity);
+            }
         }
+
         for (SceneCooperation sceneCooperation : list) {
             redisUtil.hset(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID, sceneCooperation.getSceneNum(), sceneCooperation.getUserId() + "");
         }
         this.saveBatch(list);
 
+        for (String num : delList) {
+            String[] split = num.split(",");
+            delCooperation(split[0],Long.valueOf(split[1]));
+        }
+
+    }
+
+    private void delCooperation(String num ,Long userId){
+        redisUtil.hdel(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID,num,userId);
+        LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SceneCooperation::getSceneNum,num);
+        wrapper.eq(SceneCooperation::getUserId,userId);
+        this.remove(wrapper);
     }
 
     @Override
@@ -240,7 +266,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         List<String> numList =  Arrays.asList(nums);
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
-        this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
+        //this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
 
         saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList,null,"scene");
     }
@@ -326,14 +352,14 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
         List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
-        this.deleteCooperationList(proList,plusList,userIds);
+        //this.deleteCooperationList(proList,plusList,userIds);
 
         saveCooperationCommon(loginUser,lang,users,proList,plusList,null,"scene");
     }
 
     @Override
     public void  successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang){
-        this.deleteCooperationList(numList,userIds);
+        //this.deleteCooperationList(numList,userIds);
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
         List<User> users = userService.listByIds(userIds);
@@ -352,7 +378,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
 
     private void  successAddCooperation(List<ScenePro> v3List,List<ScenePlus> v4List,List<User> users,String lang,User loginUser,List<Camera>cameraList){
         List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
-        this.deleteCooperationList(v3List,v4List,userIds);
+        //this.deleteCooperationList(v3List,v4List,userIds);
         saveCooperationCommon(loginUser,lang,users,v3List,v4List,cameraList,"camera");
 
     }
@@ -382,14 +408,18 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
 
     private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList,List<Camera >cameraList,String type){
 
-        for (User user : userList) {
-            if( !proList.isEmpty()){
-                this.saveBatchByList(proList,new ArrayList<>(),user.getId(),null);
-            }
-            if(!plusList.isEmpty()){
-                this.saveBatchByList(new ArrayList<>(),plusList,user.getId(),null);
-            }
+        List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
+        List<String> numList = new ArrayList<>();
+        List<String> v3List = proList.stream().map(ScenePro::getNum).collect(Collectors.toList());
+        List<String> v4List = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
+        numList.addAll(v3List);
+        numList.addAll(v4List);
 
+        if( !numList.isEmpty()){
+            this.saveBatchByList(numList,userIds,type);
+        }
+
+        for (User user : userList) {
             if("aws".equals(NacosProperty.uploadType)){
                 if("camera".equals(type) && cameraList != null){
                     HashMap<Long, Camera> cameraMap = new HashMap<>();