瀏覽代碼

云端场景修复

lyhzzz 2 年之前
父節點
當前提交
f2bd896d4c

+ 63 - 31
src/main/java/com/fdkankan/ucenter/service/impl/AppSceneService.java

@@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import java.io.File;
@@ -61,28 +62,40 @@ public class AppSceneService {
         if(StringUtils.isEmpty(param.getAppUserName()) && StringUtils.isEmpty(param.getPhoneNum()) ){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
-        Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(), param.getAppPassword());
-        if(camera == null){
-            throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
-        }
-        CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
-        if(cameraDetail == null){
-            throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
-        }
-        User user = userService.getByUserName(param.getPhoneNum());
-        if(user == null){
-            throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
+        if(!StringUtils.isEmpty(param.getAppUserName()) && !StringUtils.isEmpty(param.getAppPassword())){
+            Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(), param.getAppPassword());
+            if(camera == null){
+                throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
+            }
+            CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
+            if(cameraDetail == null){
+                throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
+            }
+            param.setSnCode(camera.getSnCode());
+            param.setCameraId(camera.getId());
         }
-        List<String> cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()));
-        if(cooperationNumList.size() >0){
-            String cooperationNums = cooperationNumList.stream().map(num->"'"+num+"'").collect(Collectors.joining(","));
-            param.setCooperationNums(cooperationNums );
+
+        List<String> cooperationNumList = new ArrayList<>();
+        if(StringUtils.isNotBlank(param.getPhoneNum())){
+            User user = userService.getByUserName(param.getPhoneNum());
+            if(user == null){
+                throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
+            }
+            cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()));
+            if(cooperationNumList.size() >0){
+                String cooperationNums = cooperationNumList.stream().map(num->"'"+num+"'").collect(Collectors.joining(","));
+                param.setCooperationNums(cooperationNums );
+            }
+            param.setUserId(user.getId());
         }
 
-        param.setUserId(user.getId());
-        param.setSnCode(camera.getSnCode());
-        param.setCameraId(camera.getId());
         Page<AppSceneVo> page =  scenePlusMapper.pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
+
+        Set<Long> cameraIdSet = page.getRecords().stream().map(AppSceneVo::getCameraId).collect(Collectors.toSet());
+        List<Long> cameraIds =  new ArrayList<>(cameraIdSet);
+        HashMap<Long, Camera> cameraHashMap = cameraService.getByIds(cameraIds);
+        HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
+
         for (AppSceneVo record : page.getRecords()) {
             record.setChildName(record.getSnCode());
             if (record.getStatus() == -1) {
@@ -90,22 +103,41 @@ public class AppSceneService {
             } else if (record.getStatus() == 500) {
                 record.setStatus(-1);
             }
-            //相机的userId为空,表示相机的场景
-            if (cameraDetail.getUserId() == null || user.getId() == null) {
-                record.setSceneSourceType(0);
-            } else if (cameraDetail.getUserId().longValue() == user.getId().longValue()) {
-                //相机用户id等于该用户id,既为用户的场景
-                record.setSceneSourceType(1);
-            } else if (camera.getId() != null && cameraDetail.getCameraId().longValue() == camera.getId().longValue()) {
-                if (cameraDetail.getCooperationUser() == null) {
-                    //场景相机id等于该相机id
-                    record.setSceneSourceType(0);
-                } else if (cameraDetail.getCooperationUser().longValue() == user.getId().longValue()) {
+            if(record.getCameraId() == null){
+                record.setSceneSourceType(record.getUserId().longValue() ==param.getUserId() ? 1 : 2);
+            }else {
+                Camera camera = cameraHashMap.get(record.getCameraId());
+                if(ObjectUtils.isEmpty(camera)){
+                    continue;
+                }
+                record.setChildName(camera.getChildName());
+                record.setSnCode(camera.getSnCode());
+                if(cooperationNumList.contains(record.getNum())){
                     record.setSceneSourceType(2);
+                    continue;
+                }
+                CameraDetail cameraDetail = detailHashMap.get(camera.getId());
+                if(ObjectUtils.isEmpty(cameraDetail)){
+                    continue;
+                }
+                //相机的userId为空,表示相机的场景
+                if (cameraDetail.getUserId() == null || param.getUserId() == null) {
+                    record.setSceneSourceType(0);
+                } else if (cameraDetail.getUserId().longValue() == param.getUserId().longValue()) {
+                    //相机用户id等于该用户id,既为用户的场景
+                    record.setSceneSourceType(1);
+                } else if (camera.getId() != null && cameraDetail.getCameraId().longValue() == camera.getId().longValue()) {
+                    if (cameraDetail.getCooperationUser() == null) {
+                        //场景相机id等于该相机id
+                        record.setSceneSourceType(0);
+                    } else if (cameraDetail.getCooperationUser().longValue() == param.getUserId().longValue()) {
+                        record.setSceneSourceType(2);
+                    }
+                } else {
+                    record.setSceneSourceType(0);
                 }
-            } else {
-                record.setSceneSourceType(0);
             }
+
         }
         return PageInfo.PageInfo(page);
     }

+ 6 - 4
src/main/java/com/fdkankan/ucenter/service/impl/CameraDetailServiceImpl.java

@@ -60,11 +60,13 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
 
     @Override
     public HashMap<Long, CameraDetail> getByCameraIds(List<Long> cameraIds) {
-        LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
-        wrapper.in(CameraDetail::getCameraId,cameraIds);
-        List<CameraDetail> list = this.list(wrapper);
         HashMap<Long, CameraDetail> map = new HashMap<>();
-        list.forEach(entity -> map.put(entity.getCameraId(),entity));
+        if(cameraIds.size() >0){
+            LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(CameraDetail::getCameraId,cameraIds);
+            List<CameraDetail> list = this.list(wrapper);
+            list.forEach(entity -> map.put(entity.getCameraId(),entity));
+        }
         return map;
     }
 

+ 6 - 4
src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java

@@ -79,11 +79,13 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
 
     @Override
     public HashMap<Long, Camera> getByIds(List<Long> cameraIds) {
-        LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
-        wrapper.in(Camera::getId,cameraIds);
-        List<Camera> list = this.list(wrapper);
         HashMap<Long, Camera> map = new HashMap<>();
-        list.forEach(entity -> map.put(entity.getId(),entity));
+        if(cameraIds.size() >0){
+            LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(Camera::getId,cameraIds);
+            List<Camera> list = this.list(wrapper);
+            list.forEach(entity -> map.put(entity.getId(),entity));
+        }
         return map;
     }