瀏覽代碼

空间视频增加按时间倒叙排序

dengsixing 3 年之前
父節點
當前提交
b54c60e364

+ 64 - 15
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -494,6 +494,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         sceneInfoVO.setVideos(scenePlusExt.getVideos());
         sceneInfoVO.setMosaicList(this.getMosaicList(num));
 
+        this.SortBoxVideos(sceneInfoVO);
+
         // TODO: 2022/4/24 v3版本停机要切换---------------------------start
 //        this.setExtData(sceneInfoVO, scenePlus.getCameraId());
         this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
@@ -502,6 +504,35 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         return sceneInfoVO;
     }
 
+    private void SortBoxVideos(SceneInfoVO sceneInfoVO){
+        String boxVideos = sceneInfoVO.getBoxVideos();
+        if(StrUtil.isEmpty(boxVideos)){
+            return;
+        }
+        JSONArray boxVideoArr = JSON.parseArray(boxVideos);
+        if(CollUtil.isEmpty(boxVideoArr)){
+            return;
+        }
+        List<TagBean> tagBeanList = boxVideoArr.stream().map(o -> {
+                        JSONObject item = (JSONObject) o;
+                        return TagBean.builder()
+                            .createTime(item.getLong("createTime"))
+                            .tag(item).build();
+                    }).collect(Collectors.toList());
+
+        //按创建时间倒叙排序
+        tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
+
+        //移除createTime字段
+        List<JSONObject> boxVideoList = tagBeanList.stream().map(tagBean -> {
+            JSONObject tag = tagBean.getTag();
+            tag.remove("createTime");
+            return tag;
+        }).collect(Collectors.toList());
+
+        sceneInfoVO.setBoxVideos(JSON.toJSONString(boxVideoList));
+    }
+
     /**
      * <p>
      getInfo接口返回字段扩展
@@ -2401,10 +2432,24 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             boxVideosJson = new JSONArray();
         }
 
+        if(boxVideosJson.size() > 0){
+            int i = 1;
+            long timeInMillis = Calendar.getInstance().getTimeInMillis();
+            for (Object o : boxVideosJson) {
+                JSONObject item = (JSONObject)o;
+                if(Objects.nonNull(item.getLong("createTime"))){
+                    continue;
+                }
+                item.put("createTime", timeInMillis - (i++));
+            }
+        }
+
+
         String result = null;
         //删除
         if(type == OperationType.DELETE.code()){
-            Set<String> deleteFile = new HashSet<>();
+            Set<String> deleteVidoeFile = new HashSet<>();
+            Set<String> deletePicFile = new HashSet<>();
             if(boxVideosJson.size() == 0)
                 return null;
             for(int i=0;i<boxVideosJson.size();++i){
@@ -2413,25 +2458,33 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
 
                     String poster = ele.getString("poster");
                     if(StrUtil.isNotEmpty(poster))
-                        deleteFile.add(poster);
+                        deletePicFile.add(poster);
                     String url = ele.getString("url");
                     if(StrUtil.isNotEmpty(url)){
-                        deleteFile.add(url);
-                        deleteFile.add(url.replace(".mp4",".flv"));
+                        deleteVidoeFile.add(url);
+                        deleteVidoeFile.add(url.replace(".mp4",".flv"));
                     }
 
                     boxVideosJson.remove(i);
                 }
             }
 
-            //删除资源文件
-            if(CollUtil.isNotEmpty(deleteFile))
+            //删除视频文件
+            if(CollUtil.isNotEmpty(deleteVidoeFile))
                 sceneUploadService.delete(
                     DeleteFileParamVO.builder().num(num)
                         .bizType(FileBizType.BOX_VIDEO.code())
-                        .fileNames(new ArrayList<>(deleteFile)).build());
+                        .fileNames(new ArrayList<>(deleteVidoeFile)).build());
+            //删除封面图文件
+            if(CollUtil.isNotEmpty(deleteVidoeFile))
+                sceneUploadService.delete(
+                    DeleteFileParamVO.builder().num(num)
+                        .bizType(FileBizType.BOX_POSTER.code())
+                        .fileNames(new ArrayList<>(deletePicFile)).build());
         }else{
 
+            boxVideo.put("createTime", Calendar.getInstance().getTimeInMillis());
+
             //更新
             boolean exist = false;
             for(int i=0;i<boxVideosJson.size();++i){
@@ -2441,14 +2494,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                     exist = true;
                 }
             }
-        //新增
-        if(!exist){
-            boxVideosJson.add(boxVideo);
-        }
-
-//            boxVideosJson.clear();
-//            boxVideosJson.add(boxVideo);
-
+            //新增
+            if(!exist){
+                boxVideosJson.add(boxVideo);
+            }
         }
         if(boxVideosJson.size() != 0){
             result = boxVideosJson.toJSONString();