dsx 2 年之前
父节点
当前提交
f893374196
共有 1 个文件被更改,包括 34 次插入11 次删除
  1. 34 11
      src/main/java/com/fdkankan/openApi/service/www/impl/ScenePlusServiceImpl.java

+ 34 - 11
src/main/java/com/fdkankan/openApi/service/www/impl/ScenePlusServiceImpl.java

@@ -3,6 +3,7 @@ package com.fdkankan.openApi.service.www.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -39,10 +40,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -303,7 +301,7 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
     @Override
     public PageInfo<SceneVO> getScenesByUserId(Integer userId, SceneVO sceneVO) {
         LambdaQueryWrapper<ScenePlus> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(ScenePlus::getUserId,userId);
+//        queryWrapper.eq(ScenePlus::getUserId,userId);
 
         if (!ObjectUtils.isEmpty(sceneVO.getCameraType())) {
             switch (sceneVO.getCameraType()){
@@ -315,17 +313,42 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
                     break;
             }
         }
-        Map<Long, String> cameraMap = cameraService.list().stream().collect(Collectors.toMap(Camera::getId, Camera::getSnCode));
         Page<ScenePlus> scenePage = this.page(new Page<>(sceneVO.getPageNum(), sceneVO.getPageSize()), queryWrapper);
         if(CollUtil.isEmpty(scenePage.getRecords())){
             return PageInfo.PageInfo(scenePage);
         }
+        List<Long> plusIdList = new ArrayList<>();
+        List<String> megaSceneNumList = new ArrayList<>();
+        Set<Long> cameraIds = new HashSet<>();
+        scenePage.getRecords().stream().forEach(plus -> {
+            plusIdList.add(plus.getId());
+            if(plus.getSceneSource() == SceneSource.JG.code()){
+                megaSceneNumList.add(plus.getNum());
+            }
+            if(Objects.nonNull(plus.getCameraId())){
+                cameraIds.add(plus.getCameraId());
+            }
+        });
+        Map<Long, String> cameraMap = new HashMap<>();
+        if(CollUtil.isNotEmpty(cameraIds)){
+            cameraMap = cameraService
+                    .list(new LambdaQueryWrapper<Camera>().in(Camera::getId, cameraIds))
+                    .stream().collect(Collectors.toMap(Camera::getId, Camera::getSnCode));
+        }
 
-        List<Long> plusIdList = scenePage.getRecords().stream().map(plus -> plus.getId()).collect(Collectors.toList());
         List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().in(ScenePlusExt::getPlusId, plusIdList));
         Map<Long, ScenePlusExt> plusExtMap = new HashMap<>();
         scenePlusExtList.stream().forEach(ext->plusExtMap.put(ext.getPlusId(), ext));
+        List<SceneEntity> megaSceneList = null;
+        Map<String, SceneEntity> megaSceneMap = new HashMap<>();
+        if(CollUtil.isNotEmpty(megaSceneNumList)){
+            megaSceneList = sceneService.list(new LambdaQueryWrapper<SceneEntity>().in(SceneEntity::getSceneCode, megaSceneNumList));
+            if(CollUtil.isNotEmpty(megaSceneList)){
+                megaSceneList.stream().forEach(scene -> megaSceneMap.put(scene.getSceneCode(), scene));
+            }
+        }
 
+        Map<Long, String> finalCameraMap = cameraMap;
         List<SceneVO> sceneVos = scenePage.getRecords().stream().map(scenePlus -> {
             SceneVO vo = new SceneVO();
             vo.setSceneCode(scenePlus.getNum());
@@ -335,11 +358,11 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
             if(Objects.nonNull(plusExt)){
                 vo.setShootCount(plusExt.getShootCount());
             }
-            vo.setSnCode(cameraMap.get(scenePlus.getCameraId()));
+            vo.setSnCode(finalCameraMap.get(scenePlus.getCameraId()));
             vo.setCameraType("kankan");
             if (scenePlus.getSceneSource() == 4) {
-                SceneEntity scene = sceneService.findBySceneCode(scenePlus.getNum());
-                if (ObjectUtils.isEmpty(scene.getTitle())) {
+                SceneEntity scene = megaSceneMap.get(scenePlus.getNum());
+                if (Objects.nonNull(scene) && StrUtil.isNotEmpty(scene.getTitle())) {
                     vo.setSceneName(scene.getTitle());
                 }
                 vo.setCameraType("mega");
@@ -347,7 +370,7 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
             return vo;
         }).collect(Collectors.toList());
 
-        return PageInfo.PageInfo(scenePage);
+        return PageInfo.PageInfo(scenePage.getCurrent(), scenePage.getSize(), scenePage.getTotal(), sceneVos);
     }
 
     @Override