wuweihao 3 vuotta sitten
vanhempi
commit
905653f4df

+ 6 - 0
720yun_local_manage/gis_pano/src/main/java/com/gis/cms/controller/OpsController.java

@@ -37,5 +37,11 @@ public class OpsController {
         return entityService.mergeTour(workId);
     }
 
+    @ApiOperation(value = "根据作品码打包数据", notes = "返回值直接下载结果文件")
+    @GetMapping("/pack/{workId}")
+    public Result pack(@PathVariable String workId) {
+        return entityService.pack(workId);
+    }
+
 
 }

+ 2 - 0
720yun_local_manage/gis_pano/src/main/java/com/gis/cms/service/OpsService.java

@@ -16,4 +16,6 @@ public interface OpsService  {
     Result<WorkEntity> downloadPano(String ids);
 
     Result mergeTour(String workId);
+
+    Result pack(String workId);
 }

+ 102 - 0
720yun_local_manage/gis_pano/src/main/java/com/gis/cms/service/impl/OpsServiceImpl.java

@@ -156,6 +156,108 @@ public class OpsServiceImpl  implements OpsService {
         return Result.success(downloadPath);
     }
 
+    @Override
+    public Result pack(String workId) {
+        // 复制作品目录
+        WorkEntity entity = workService.getById(workId);
+        BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
+        copyWork(workId);
+
+        // 复制场景目录
+        copyScene(workId, entity.getSceneCodes());
+
+        // 合并tour.xml
+        mergeTour(workId, entity.getSceneCodes());
+
+        // 压缩
+        zipWork(workId);
+        String filePath = "/download/" + workId + ".zip";
+        log.info("zip地址:{}", configConstant.serverBasePath + filePath);
+        return Result.success(filePath);
+    }
+
+    private void zipWork(String workId) {
+        String outPath = configConstant.serverBasePath + "/download/" + workId +".zip";
+        String intPath = configConstant.serverBasePath + "/download/" + workId ;
+        String cmd = StrUtil.format("zip -r {} {} ", outPath,  intPath);
+        CmdUtils.callCmd(cmd);
+    }
+
+    private void copyScene(String workId, String sceneCodes) {
+        log.info("场景码: {}", sceneCodes);
+        if (StringUtils.isBlank(sceneCodes)){
+            log.info("场景码为空, 不需要下载");
+            return;
+        }
+        String[] split = sceneCodes.split(",");
+        log.info("场景数量 : {}", split.length);
+        String outPath = configConstant.serverBasePath + "/download/" + workId;
+        String inPath;
+        for (String sceneCode : split) {
+            inPath = configConstant.serverBasePath + "/" + sceneCode + "/vtour/panos/" + sceneCode + ".tiles";
+            String cmd = StrUtil.format("cp -r {} {} ", inPath,  outPath);
+            CmdUtils.callCmd(cmd);
+        }
+
+    }
+
+    private void copyWork(String workId) {
+        // 复制到指定目录
+        String outPath = configConstant.serverBasePath + "/download/";
+        String checkPath = outPath + workId;
+        // 存在则删除
+        if (FileUtil.isDirectory(checkPath)){
+            FileUtil.del(checkPath);
+        }
+        String inPath = configConstant.serverBasePath + "/work/" + workId;
+        String cmd = StrUtil.format("cp -r {} {} ", inPath,  outPath);
+        CmdUtils.callCmd(cmd);
+
+    }
+
+    private void mergeTour(String workId, String sceneCodes) {
+        String[] split = sceneCodes.split(",");
+        // tourXml路径
+        String downloadPath;
+        String outPath = configConstant.serverBasePath + "/download/" + workId;
+        String basePath = configConstant.serverBasePath;
+        int size = split.length;
+        log.info("场景数量: {}", size);
+        BaseRuntimeException.isHas(size==0, null, "场景码为空, 不需要合并");
+        String firstTourPath = File.separator + split[0] + "/vtour/tour.xml";
+        if (size == 1){
+            log.info("firstTourPath:{}", firstTourPath);
+            FileUtil.copy(configConstant.serverBasePath + firstTourPath, outPath, true);
+        } else {
+            // 获取scene标签集合
+            StringBuffer sceneLabels = new StringBuffer();
+            int i = 0;
+            String tourPath;
+            for (String sceneCode : split) {
+                tourPath = basePath + File.separator + sceneCode + "/vtour/tour.xml";
+                String scene = getSceneLabel(tourPath);
+                sceneLabels.append(scene).append("\r\n");
+                i++;
+            }
+            log.info("标签数量: {}", i );
+
+            // 获取第一个xml, 做为基础模板
+            String firstXml = handleFirstXml(basePath + firstTourPath);
+            // 合并
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(firstXml).append(" ");
+            buffer.append(sceneLabels).append(" ");
+            buffer.append("</krpano>");
+            // 保存路径
+            downloadPath = "/download/" + workId + "/tour.xml";
+            String savePath =  configConstant.serverBasePath + File.separator + downloadPath;
+            FileUtil.writeUtf8String(buffer.toString(), savePath);
+            log.info("合并完成,保存路径: {}", savePath);
+
+        }
+
+    }
+
     /**
      * 处理第一个xml
      * @param filePath