dengsixing 2 dní pred
rodič
commit
2cbd378d43

+ 17 - 19
src/main/java/com/fdkankan/scene/service/impl/NjsSceneBoxModelServiceImpl.java

@@ -200,10 +200,12 @@ public class NjsSceneBoxModelServiceImpl extends ServiceImpl<INjsSceneBoxModelMa
 
 
     @Override
     @Override
     public void publicNjsSceneBoxModel(String num) throws IOException {
     public void publicNjsSceneBoxModel(String num) throws IOException {
-        List<NjsSceneBoxModel> list = lambdaQuery().eq(NjsSceneBoxModel::getNum, num).list();
+        BaseSceneParamVO param = new BaseSceneParamVO();
+        param.setNum(num);
+        List<JSONObject> list = this.listNjsBoxModel(param);
         String njsBoxModelKey = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModels.json";
         String njsBoxModelKey = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModels.json";
         String njsBoxModelDir = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModel";
         String njsBoxModelDir = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModel";
-        if(list.isEmpty()){
+        if(CollUtil.isEmpty(list)){
             if(fYunFileService.fileExist(njsBoxModelKey)){
             if(fYunFileService.fileExist(njsBoxModelKey)){
                 fYunFileService.deleteFile(njsBoxModelKey);
                 fYunFileService.deleteFile(njsBoxModelKey);
             }
             }
@@ -214,7 +216,7 @@ public class NjsSceneBoxModelServiceImpl extends ServiceImpl<INjsSceneBoxModelMa
         }
         }
 
 
         //删除无效文件
         //删除无效文件
-        Set<String> prefixList = list.stream().map(v -> njsBoxModelDir + "/" + v.getData().getString("sid")).collect(Collectors.toSet());
+        Set<String> prefixList = list.stream().map(v -> njsBoxModelDir + "/" + v.getString("sid")).collect(Collectors.toSet());
         List<String> keyList = fYunFileService.listRemoteFiles(njsBoxModelDir);
         List<String> keyList = fYunFileService.listRemoteFiles(njsBoxModelDir);
         if(!keyList.isEmpty()){
         if(!keyList.isEmpty()){
             keyList.removeIf(file ->
             keyList.removeIf(file ->
@@ -231,22 +233,18 @@ public class NjsSceneBoxModelServiceImpl extends ServiceImpl<INjsSceneBoxModelMa
             }
             }
         }
         }
 
 
-        List<JSONObject> collect = list.stream().map(v -> v.getData()).collect(Collectors.toList());
-        collect.sort(Comparator.comparing(
-                o -> ((JSONObject)o).getLong("createTime"),
-                Comparator.nullsLast(Long::compareTo)
-        ).reversed());
-        String localNjsModelJsonPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "njsBoxModels.json";
-        try (FileWriter writer = new FileWriter(localNjsModelJsonPath)) {
-            for (JSONObject jsonObject : collect) {
-                // 一行一个JSON,严格按照集合顺序写入
-                writer.write(jsonObject.toJSONString());
-                writer.write("\n"); // 换行
-            }
-            fYunFileService.uploadFile(localNjsModelJsonPath, njsBoxModelKey);
-        }finally {
-//            FileUtil.del(localNjsModelJsonPath);
-        }
+//        String localNjsModelJsonPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "njsBoxModels.json";
+//        try (FileWriter writer = new FileWriter(localNjsModelJsonPath)) {
+//            for (JSONObject jsonObject : collect) {
+//                // 一行一个JSON,严格按照集合顺序写入
+//                writer.write(jsonObject.toJSONString());
+//                writer.write("\n"); // 换行
+//            }
+////            writer.flush();
+            fYunFileService.uploadFile(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8), njsBoxModelKey);
+//        }finally {
+////            FileUtil.del(localNjsModelJsonPath);
+//        }
 
 
 
 
     }
     }