|
@@ -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));
|
|
|
|
|
|
}
|
|
|
}
|