dengsixing пре 2 година
родитељ
комит
717959de66

+ 6 - 0
src/main/java/com/fdkankan/scene/SceneApplication.java

@@ -1,11 +1,17 @@
 package com.fdkankan.scene;
 
+import com.alibaba.druid.pool.DruidDataSource;
 import com.dtflys.forest.springboot.annotation.ForestScan;
+import io.seata.rm.datasource.xa.DataSourceProxyXA;
+import javax.sql.DataSource;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 

+ 69 - 19
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -432,11 +432,42 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         sceneInfoVO.setVideos(scenePlusExt.getVideos());
         sceneInfoVO.setMosaicList(this.getMosaicList(num));
 
+        this.SortBoxVideos(sceneInfoVO);
+
         this.setExtData(sceneInfoVO, scenePlus.getCameraId());
 
         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接口返回字段扩展
@@ -2246,11 +2277,23 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         }else {
             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){
@@ -2259,11 +2302,11 @@ 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);
@@ -2271,27 +2314,34 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             }
 
             //删除资源文件
-            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{
 
-            // TODO: 2022/3/1 目前需求只保留一个,所以这里先注释掉,sid不同时,不追加
+            boxVideo.put("createTime", Calendar.getInstance().getTimeInMillis());
+
             //更新
-//            boolean exist = false;
-//            for(int i=0;i<boxVideosJson.size();++i){
-//                JSONObject ele = boxVideosJson.getJSONObject(i);
-//                if(ele.getString("sid").equals(sid)){
-//                    boxVideosJson.set(i, boxVideo);
-//                    exist = true;
-//                }
-//            }
-//        //新增
-//        if(!exist){
-//            boxVideosJson.add(boxVideo);
-//        }
+            boolean exist = false;
+            for(int i=0;i<boxVideosJson.size();++i){
+                JSONObject ele = boxVideosJson.getJSONObject(i);
+                if(ele.getString("sid").equals(sid)){
+                    boxVideosJson.set(i, boxVideo);
+                    exist = true;
+                }
+            }
+            //新增
+            if(!exist){
+                boxVideosJson.add(boxVideo);
+            }
 
             boxVideosJson.clear();
             boxVideosJson.add(boxVideo);