|
@@ -0,0 +1,200 @@
|
|
|
+package demo;
|
|
|
+
|
|
|
+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;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by owen on 2022/3/9 0009 9:09
|
|
|
+ * 测试类
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class SceneTest {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * scenes.json: 是数据库tb_work.scenes, 包含该作品下的所有场景
|
|
|
+ * 获取该作品下的所有场景
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void getSceneCode(){
|
|
|
+ String filePath = "E:\\data\\720yun_fd_manage_data\\test\\scenes.json";
|
|
|
+ String s = FileUtil.readString(filePath, "UTF-8");
|
|
|
+ JSONArray array = JSONArray.parseArray(s);
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ for (Object o : array) {
|
|
|
+ JSONObject parse = JSON.parseObject(o.toString());
|
|
|
+ String sceneCode = parse.getString("sceneCode");
|
|
|
+ jsonArray.add(sceneCode);
|
|
|
+ }
|
|
|
+ log.warn("场景数量:{}", jsonArray.size());
|
|
|
+ log.warn("场景: {}", jsonArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合并tour.xml
|
|
|
+ * 以第一个场景码为主, 将其他场景的tour.xml里的<scene></scene>标签负责到第一个的tour.xml里去
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void mergeTourXml(){
|
|
|
+
|
|
|
+ String firstScene = "fd720_8SFg0cwFI";
|
|
|
+ // 主文件路径
|
|
|
+ String firstPath = null;
|
|
|
+
|
|
|
+ // 路径结果集
|
|
|
+ List<String> paths = new ArrayList<>();
|
|
|
+ // 文件目录
|
|
|
+ String dir = "E:\\data\\720yun_fd_manage_data\\720yun_20220309_104456896";
|
|
|
+ // 执行目录递归
|
|
|
+ getLoopPath(dir, paths);
|
|
|
+ log.info("路径数量: {}", paths.size());
|
|
|
+
|
|
|
+ // 获取scene标签集合
|
|
|
+ StringBuffer sceneLabels = new StringBuffer();
|
|
|
+ int i = 0;
|
|
|
+ for (String path : paths) {
|
|
|
+ if (path.contains(firstScene)){
|
|
|
+ firstPath = path;
|
|
|
+ }
|
|
|
+ String scene = getSceneLabel(path);
|
|
|
+ sceneLabels.append(scene).append("\r\n");
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ log.info("标签数量: {}", i );
|
|
|
+
|
|
|
+ // 合并
|
|
|
+ String firstXml = handleFirstXml(firstPath);
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ buffer.append(firstXml).append(" ");
|
|
|
+ buffer.append(sceneLabels).append(" ");
|
|
|
+ buffer.append("</krpano>");
|
|
|
+ // 保存路径
|
|
|
+ String savePath = dir + "/tour.xml";
|
|
|
+ FileUtil.writeUtf8String(buffer.toString(), savePath);
|
|
|
+ log.info("合并完成,保存路径: {}", savePath);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归目录获取文件地址
|
|
|
+ * @path dir 目录:E:\data\720yun_fd_manage_data\fd720
|
|
|
+ * @result 结果集
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static void getLoopPath(String dir, List<String> result){
|
|
|
+ File[] faFiles = new File(dir).listFiles();
|
|
|
+ for (File file : faFiles) {
|
|
|
+ if (file.isFile()){
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
+ if (path.endsWith("tour.xml")){
|
|
|
+ result.add(path);
|
|
|
+ continue; // 结束本次循环
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ getLoopPath(file.getAbsolutePath(), result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 移动目录到指定目录
|
|
|
+ * @param dir 输入目录
|
|
|
+ * @param outDir 输出目录
|
|
|
+ */
|
|
|
+ private static void moveLoop(String dir, String outDir){
|
|
|
+ File[] faFiles = new File(dir).listFiles();
|
|
|
+ for (File file : faFiles) {
|
|
|
+ if (file.isDirectory()){
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
+ if (path.endsWith(".tiles")){
|
|
|
+ // 负责目录到指定目录
|
|
|
+ FileUtil.copy(new File(path), new File(outDir), true);
|
|
|
+ continue; // 结束本次循环
|
|
|
+ } else {
|
|
|
+ moveLoop(path, outDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取Scene标签值
|
|
|
+ * @param filePath tour.xml路径
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String getSceneLabel(String filePath){
|
|
|
+ String s = FileUtil.readString(filePath, "UTF-8");
|
|
|
+ // 截取</action>之后的
|
|
|
+ s = StrUtil.subAfter(s, "</action>", true);
|
|
|
+ // 截取</krpano>之前的
|
|
|
+ s = StrUtil.subBefore(s, "</krpano>", true);
|
|
|
+ return s;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理第一个xml
|
|
|
+ * @param filePath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String handleFirstXml(String filePath){
|
|
|
+
|
|
|
+ String s = FileUtil.readString(filePath, "UTF-8");
|
|
|
+
|
|
|
+ // 截取</krpano>之前的
|
|
|
+ s = StrUtil.subBefore(s, "<scene name=", false);
|
|
|
+ return s;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void readTourXml(){
|
|
|
+ String filePath = "E:\\data\\720yun_fd_manage_data\\fd720\\fd720_ae0kVy9Gr\\vtour\\tour.xml";
|
|
|
+ String s = handleFirstXml(filePath);
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void moveDir(){
|
|
|
+ String dir = "E:\\data\\720yun_fd_manage_data\\720yun_20220309_104456896";
|
|
|
+ String outDir = "E:\\data\\720yun_fd_manage_data\\out\\";
|
|
|
+ moveLoop(dir, outDir);
|
|
|
+ log.info("移动完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void urlTest(){
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+// list.add("/manage/work/edit");
|
|
|
+ list.add("/manage/work/add");
|
|
|
+ if (list.contains("/manage/work/edit")){
|
|
|
+ System.out.println("包含edit");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void readJson(){
|
|
|
+ String path = "E:\\data\\720yun_fd_manage_data\\log\\2\\873.json";
|
|
|
+// String str = FileUtil.readString(path, "utf-8");
|
|
|
+ String str="{\"MsgId\":1,\"TotalCount\":10,\"FilterCount\":8,\"SentCount\":7,\"ErrorCount\":1}";
|
|
|
+ log.info("1: {}", str);
|
|
|
+ String s = StringEscapeUtils.unescapeJava(str);
|
|
|
+ log.info("2: {}", s);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|