wuweihao 3 лет назад
Родитель
Сommit
59311e7c75

+ 10 - 3
720yun_local_manage/gis_pano/src/main/java/com/gis/cms/controller/OpsController.java

@@ -2,7 +2,6 @@ package com.gis.cms.controller;
 
 import com.gis.cms.entity.po.WorkEntity;
 import com.gis.cms.service.OpsService;
-import com.gis.common.base.entity.dto.PageDto;
 import com.gis.common.util.Result;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -21,14 +20,22 @@ public class OpsController {
     OpsService entityService;
 
     @ApiOperation(value = "下载-作品目录", notes = "支持批量导出, 多个作品id, 用逗号分隔")
-    @GetMapping("downloadWork/{ids}")
+    @GetMapping("/downloadWork/{ids}")
     public Result<WorkEntity> downloadWork(@PathVariable String ids) {
         return entityService.downloadWork(ids);
     }
 
     @ApiOperation(value = "下载-根据作品id下载全景图目录", notes = "根据作品id, 多个作品id, 用逗号分隔")
-    @GetMapping("downloadPano/{ids}")
+    @GetMapping("/downloadPano/{ids}")
     public Result<WorkEntity> downloadPano(@PathVariable String ids) {
         return entityService.downloadPano(ids);
     }
+
+    @ApiOperation(value = "根据作品码合并tourXml", notes = "返回值直接下载结果文件")
+    @GetMapping("/mergeTour/{workId}")
+    public Result mergeTour(@PathVariable String workId) {
+        return entityService.mergeTour(workId);
+    }
+
+
 }

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

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

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

@@ -1,5 +1,7 @@
 package com.gis.cms.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -44,6 +46,9 @@ public class OpsServiceImpl  implements OpsService {
     @Autowired
     WorkService workService;
 
+    @Autowired
+    FileUtils fileUtils;
+
 
     @Override
     public Result<WorkEntity> downloadWork(String ids) {
@@ -99,10 +104,88 @@ public class OpsServiceImpl  implements OpsService {
         return Result.success(zipName);
     }
 
+    @Override
+    public Result mergeTour(String workId) {
+        WorkEntity entity = workService.getById(workId);
+        BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
+        String sceneCodes = entity.getSceneCodes();
+        log.info("场景码:{}", sceneCodes);
+        BaseRuntimeException.isBlank(sceneCodes, null, "场景码为空, 不需要合并");
+
+        List<String> list = Arrays.asList(sceneCodes);
+        // tourXml路径
+        String tourPath;
+        String basePath = configConstant.serverBasePath;
+        int size = list.size();
+        String firstTourPath = basePath + File.separator + list.get(0) + "/vtour/tour.xml";
+        if (size == 1){
+            tourPath = firstTourPath;
+        } else {
+            // 获取scene标签集合
+            StringBuffer sceneLabels = new StringBuffer();
+            int i = 0;
+            for (String sceneCode : list) {
+                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(firstTourPath);
+            // 合并
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(firstXml).append(" ");
+            buffer.append(sceneLabels).append(" ");
+            buffer.append("</krpano>");
+            // 保存路径
+            String tourXmlPath = "/download/" + workId + "_tour.xml";
+            String savePath =  configConstant.serverBasePath + File.separator + tourXmlPath;
+            FileUtil.writeUtf8String(buffer.toString(), savePath);
+            log.info("合并完成,保存路径: {}", savePath);
+            tourPath = tourXmlPath;
+
+        }
+
+        return Result.success(tourPath);
+    }
+
+    /**
+     * 处理第一个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;
+
+    }
+
+    /**
+     * 获取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;
+
+    }
+
+
     @Test
     public void test(){
-        String str = "1,2,3,";
-        System.out.println(StringUtils.substringBeforeLast(str, ","));
+        String str = "1";
+        System.out.println(Arrays.asList(str));
 
     }
 }