|
@@ -1,15 +1,20 @@
|
|
|
package com.gis.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
+import com.gis.common.constant.ErrorEnum;
|
|
|
+import com.gis.common.exception.BaseRuntimeException;
|
|
|
import com.gis.common.util.AliyunOssUtil;
|
|
|
import com.gis.common.util.FileUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
+import com.gis.domain.entity.FodderEntity;
|
|
|
import com.gis.domain.entity.WorkEntity;
|
|
|
+import com.gis.service.FodderService;
|
|
|
import com.gis.service.TestService;
|
|
|
import com.gis.service.WorkService;
|
|
|
import com.gis.util.ReplaceVo;
|
|
@@ -18,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.*;
|
|
@@ -47,21 +51,12 @@ public class TestServiceImpl implements TestService {
|
|
|
@Autowired
|
|
|
WorkService workService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ FodderService fodderService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// public Result upload(MultipartFile file) {
|
|
|
-// Map<String, Object> map = fileUtils.renameUploadOssBye(file, configConstant.ossBasePath, configConstant.ossDomain, "icon/");
|
|
|
-// IconEntity entity = new IconEntity();
|
|
|
-// entity.setFileName((String) map.get("fileName"));
|
|
|
-// Object ossUrl = map.get("ossUrl");
|
|
|
-// entity.setOssPath(ossUrl.toString());
|
|
|
-//
|
|
|
-//
|
|
|
-// return Result.success(ossUrl);
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public Result batchReplaceSomeData(String isBatch) {
|
|
|
String basePath = "F:\\work\\四维-全景看看\\data\\";
|
|
@@ -124,6 +119,184 @@ public class TestServiceImpl implements TestService {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2022-10-21
|
|
|
+ * @param isAll
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result updatePanoTourXml(String isAll) {
|
|
|
+
|
|
|
+ // 更新素材表字段
|
|
|
+// updateFodderTour(isAll);
|
|
|
+ // 作品创建tour.xml
|
|
|
+ createWorkTour(isAll);
|
|
|
+
|
|
|
+ return Result.success("更新完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-10-21
|
|
|
+ * 作品创建tour.xml
|
|
|
+ * @param isAll
|
|
|
+ */
|
|
|
+ private void createWorkTour(String isAll) {
|
|
|
+
|
|
|
+ // 1. 获取作品表
|
|
|
+
|
|
|
+ List<WorkEntity> list = workService.findByStatus(1);
|
|
|
+ log.info("作品数量:{}", list.size());
|
|
|
+ // 2. 上传tour.xml
|
|
|
+ int n = 0;
|
|
|
+ for (WorkEntity workEntity : list) {
|
|
|
+ String id = workEntity.getId();
|
|
|
+ String sceneCodes = workEntity.getSceneCodes();
|
|
|
+ createTour(sceneCodes, id);
|
|
|
+ n ++;
|
|
|
+ log.info("更新完成第:{} 个, 作品码为:{}", n, id);
|
|
|
+ if (!"1".equals(isAll)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createTour(String sceneCodes, String id) {
|
|
|
+ List<String> scenes = filterSceneCodesByPano(sceneCodes);
|
|
|
+ List<FodderEntity> list = fodderService.batchBySceneCodes(scenes);
|
|
|
+
|
|
|
+ // 读取tour.xml模板
|
|
|
+ String baseTour = getBaseTour();
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ builder.append(baseTour).append("\r\n");
|
|
|
+ for (FodderEntity entity : list) {
|
|
|
+ String tour = entity.getTour();
|
|
|
+ builder.append(tour).append("\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加结束标签
|
|
|
+ builder.append("</krpano>");
|
|
|
+
|
|
|
+
|
|
|
+ String tourPath = configConstant.serverBasePath + id + "/tour.xml";
|
|
|
+ FileUtil.writeUtf8String(builder.toString(), tourPath);
|
|
|
+ log.info("作品tour.xml写入完成");
|
|
|
+
|
|
|
+ // 上传oss
|
|
|
+ BaseRuntimeException.isTrue(!FileUtil.isFile(tourPath), ErrorEnum.FAILURE_CODE_3103.code(), "服务器tour.xml文件不存在");
|
|
|
+
|
|
|
+ String ossKeyPath = configConstant.ossBasePath + id + "/tour.xml";
|
|
|
+ aliyunOssUtil.upload(tourPath, ossKeyPath);
|
|
|
+ log.info("tour.xml上传完成 : {}", ossKeyPath);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getBaseTour(){
|
|
|
+ String baseTourPath = configConstant.serverBasePath + "baseData/tour.xml";
|
|
|
+ String s = FileUtil.readString(baseTourPath, "utf-8");
|
|
|
+ // 结束标签置空, 方便操作
|
|
|
+ s = s.replace("</krpano>", "");
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 过滤720场景
|
|
|
+ * @param sceneCodes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> filterSceneCodesByPano(String sceneCodes){
|
|
|
+ if (StrUtil.isBlank(sceneCodes)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ String[] split = sceneCodes.split(",");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String s : split) {
|
|
|
+ if (s.startsWith("fd720_")){
|
|
|
+ list.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-10-21
|
|
|
+ * 更新素材表字段
|
|
|
+ * @param isAll
|
|
|
+ */
|
|
|
+ private void updateFodderTour(String isAll) {
|
|
|
+
|
|
|
+ // 1.获取素材表,type=pano
|
|
|
+ List<FodderEntity> list = fodderService.findByType("pano");
|
|
|
+ log.info("场景数量:{}", list.size());
|
|
|
+ // 2.下载对应的tour.xml
|
|
|
+ String basePath = configConstant.serverBasePath;
|
|
|
+ int n = 0;
|
|
|
+ for (FodderEntity fodderEntity : list) {
|
|
|
+ n ++;
|
|
|
+ String tour = fodderEntity.getTour();
|
|
|
+ if (StrUtil.isNotBlank(tour)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String ossPath = fodderEntity.getOssPath();
|
|
|
+ String tourPath = ossPath + "/vtour/tour.xml";
|
|
|
+ String sceneCode = fodderEntity.getSceneCode();
|
|
|
+ String locPath = basePath + sceneCode + "/vtour/tour.xml";
|
|
|
+ log.info("正在执行第:{} 个, 场景码:{}, oss路径:{}", n, sceneCode, tourPath);
|
|
|
+ try {
|
|
|
+ HttpUtil.downloadFile(tourPath, locPath);
|
|
|
+ String tourXmlScene = getTourXmlScene(sceneCode);
|
|
|
+
|
|
|
+ fodderEntity.setTour(tourXmlScene);
|
|
|
+ fodderEntity.setUpdateTime(new Date());
|
|
|
+ fodderService.update(fodderEntity);
|
|
|
+
|
|
|
+ log.info("更新完成第:{} 个, 场景码为:{}", n, sceneCode);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+ // 遇到oss没有tour.xml 直接跳过, 不用更新此场景
|
|
|
+ log.error("此场景不存在, 执行第:{} 个, 场景码:{}, oss路径:{}", n, sceneCode, tourPath);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // isAll != 1 只更新一个
|
|
|
+ if (!"1".equals(isAll)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取切图后的tour.xml
|
|
|
+ private String getTourXmlScene(String code) {
|
|
|
+ log.info("处理tour.xml");
|
|
|
+ String tourPath = configConstant.serverBasePath + code + "/vtour/tour.xml";
|
|
|
+ log.info("tourPath: {}", tourPath);
|
|
|
+ BaseRuntimeException.isTrue(!FileUtil.isFile(tourPath), null, code + "_tour.xml文件不存在");
|
|
|
+
|
|
|
+ String tour = FileUtil.readString(tourPath, "utf-8");
|
|
|
+ tour = StrUtil.subAfter(tour, "</action>", true);
|
|
|
+ tour = StrUtil.subBefore(tour, "</krpano>", true);
|
|
|
+ String trim = StrUtil.trim(tour);
|
|
|
+ // log.info("trim: {}", trim);
|
|
|
+ BaseRuntimeException.isTrue(StrUtil.isAllBlank(trim), null, code + "_tour.xml文件不存在");
|
|
|
+
|
|
|
+ // 2022-09-15 加入相对路径
|
|
|
+ String basePath = "%CURRENTXML%../" + code + "/vtour/panos/";
|
|
|
+ trim = trim.replaceAll("panos/", basePath);
|
|
|
+
|
|
|
+ return trim;
|
|
|
+ }
|
|
|
+
|
|
|
// 下载初始场景图片
|
|
|
private void downloadThumb(Map<String, String> iconMap){
|
|
|
String basePath = "F:\\work\\项目-科学城(广州)信科集团-3D合作\\thumb";
|