|
@@ -1,13 +1,16 @@
|
|
package com.gis.service.impl;
|
|
package com.gis.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
import com.gis.common.proto.util.ConvertUtils;
|
|
import com.gis.common.proto.util.ConvertUtils;
|
|
import com.gis.common.util.FileUtils;
|
|
import com.gis.common.util.FileUtils;
|
|
import com.gis.common.util.Result;
|
|
import com.gis.common.util.Result;
|
|
import com.gis.domain.dto.PageDto;
|
|
import com.gis.domain.dto.PageDto;
|
|
import com.gis.domain.dto.RoamViableDto;
|
|
import com.gis.domain.dto.RoamViableDto;
|
|
|
|
+import com.gis.domain.dto.SceneDataDto;
|
|
import com.gis.domain.dto.ScenePageDto;
|
|
import com.gis.domain.dto.ScenePageDto;
|
|
import com.gis.domain.po.SceneEntity;
|
|
import com.gis.domain.po.SceneEntity;
|
|
import com.gis.mapper.SceneMapper;
|
|
import com.gis.mapper.SceneMapper;
|
|
@@ -19,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,11 +63,13 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
return Result.failure("场景不存在");
|
|
return Result.failure("场景不存在");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
// 1. 从oss下载vision.modeldata
|
|
// 1. 从oss下载vision.modeldata
|
|
String visionModelDataName = "vision.modeldata";
|
|
String visionModelDataName = "vision.modeldata";
|
|
// 注意网络下载会有缓存,必须加时间戳
|
|
// 注意网络下载会有缓存,必须加时间戳
|
|
// log.info("网络下载文件地址: {}", urlPath);
|
|
// log.info("网络下载文件地址: {}", urlPath);
|
|
- String localBasePath = FILE_PATH + sceneCode;
|
|
|
|
|
|
+// String localBasePath = FILE_PATH + sceneCode;
|
|
|
|
+ String localBasePath = configConstant.serverBasePath + sceneCode;
|
|
|
|
|
|
// 2. 将vision.modeldata 转 vision.json
|
|
// 2. 将vision.modeldata 转 vision.json
|
|
String visionModelDataPath = localBasePath + "/" + visionModelDataName;
|
|
String visionModelDataPath = localBasePath + "/" + visionModelDataName;
|
|
@@ -134,4 +140,220 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
|
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result edit(SceneDataDto param) {
|
|
|
|
+ String sceneCode = param.getSceneCode();
|
|
|
|
+ SceneEntity entity = this.findBySceneCode(param.getSceneCode());
|
|
|
|
+ if (entity == null) {
|
|
|
|
+ log.error("场景不存在 : {}", sceneCode);
|
|
|
|
+ return Result.failure("场景不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String basePath = configConstant.serverBasePath + sceneCode;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 处理someData.json
|
|
|
|
+
|
|
|
|
+// String someDataPath = entity.getPath() + "/someData.json";
|
|
|
|
+ String someDataPath = basePath + "/someData.json";
|
|
|
|
+ if (!FileUtil.isFile(someDataPath)) {
|
|
|
|
+ log.error("someData.json文件不存在");
|
|
|
|
+ return Result.failure("someData.json文件不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 读取someDataJson
|
|
|
|
+ String someData = FileUtil.readUtf8String(someDataPath);
|
|
|
|
+ JSONObject someDataJson = JSONObject.parseObject(someData);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String info = param.getInfo();
|
|
|
|
+ String guides = param.getGuides();
|
|
|
|
+ JSONArray guidesArray = new JSONArray();
|
|
|
|
+ if (guides != null) {
|
|
|
|
+ guidesArray = JSONObject.parseArray(guides);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (info != null) {
|
|
|
|
+ JSONObject infoJson = JSONObject.parseObject(info);
|
|
|
|
+
|
|
|
|
+ // 处理model
|
|
|
|
+ JSONObject model = someDataJson.getJSONObject("model");
|
|
|
|
+ if (model != null) {
|
|
|
|
+ if (guidesArray != null) {
|
|
|
|
+ model.put("images", guidesArray);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新someDataJson
|
|
|
|
+ someDataJson.put("model", model);
|
|
|
|
+
|
|
|
|
+ // info信息添加到someDataJson最外层
|
|
|
|
+ Set<String> infoKey = infoJson.keySet();
|
|
|
|
+ for (String key : infoKey) {
|
|
|
|
+
|
|
|
|
+ someDataJson.put(key, infoJson.get(key));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 删除旧someDataJson
|
|
|
|
+ FileUtil.del(someDataPath);
|
|
|
|
+ // 写入新someDataJson
|
|
|
|
+ FileUtil.writeUtf8String(someDataJson.toJSONString(), someDataPath);
|
|
|
|
+ log.info("someData.json写入完成");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理data2.js
|
|
|
|
+ String data2Path = basePath + "/data2.js";
|
|
|
|
+ boolean file = FileUtil.isFile(data2Path);
|
|
|
|
+ if (!file) {
|
|
|
|
+ log.error("data2.js文件不存在");
|
|
|
|
+ return Result.failure("data2.js文件不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String data2 = FileUtil.readUtf8String(data2Path);
|
|
|
|
+ JSONObject data2Json = JSONObject.parseObject(data2);
|
|
|
|
+
|
|
|
|
+ String tourAudio = param.getTourAudio();
|
|
|
|
+ if (tourAudio != null) {
|
|
|
|
+ data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
|
|
|
|
+ } else {
|
|
|
|
+ data2Json.put("tourAudio", new JSONObject());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // overlays是数组
|
|
|
|
+ String overlays = param.getOverlays();
|
|
|
|
+ if (overlays != null) {
|
|
|
|
+ data2Json.put("overlays", JSONObject.parseArray(overlays));
|
|
|
|
+ } else {
|
|
|
|
+ data2Json.put("overlays", new JSONArray());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理guidesArray,将scan_id的值作为key, value: time":40000
|
|
|
|
+ JSONObject audioJson = new JSONObject();
|
|
|
|
+ JSONObject timeJson = new JSONObject();
|
|
|
|
+ timeJson.put("time", 40000);
|
|
|
|
+ if (guidesArray != null) {
|
|
|
|
+
|
|
|
|
+ // 将旧的audio字段删除
|
|
|
|
+ data2Json.remove("audio");
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < guidesArray.size() ; i++) {
|
|
|
|
+ JSONObject metadata = guidesArray.getJSONObject(i).getJSONObject("metadata");
|
|
|
|
+ if (metadata != null) {
|
|
|
|
+ String scanId = metadata.getString("scan_id");
|
|
|
|
+ if (scanId == null) {
|
|
|
|
+ log.error("guides.metadata.scan_id为空: {}", i);
|
|
|
|
+ return Result.failure("guides.metadata.scan_id为空: " + i);
|
|
|
|
+ }
|
|
|
|
+ // Fastjson-fastjson中$ref对象重复引用问题,拿不到想要的效果
|
|
|
|
+ audioJson.put(scanId, JSON.toJSONString(timeJson, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 新增audio
|
|
|
|
+ data2Json.put("audio", audioJson);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // host在data2.js、data.js都需要处理
|
|
|
|
+ String hots = param.getHots();
|
|
|
|
+ log.info("input hots: {}", hots);
|
|
|
|
+ if (hots != null) {
|
|
|
|
+ // 获取所有key
|
|
|
|
+ JSONObject hotJson = JSONObject.parseObject(hots);
|
|
|
|
+
|
|
|
|
+ Set<String> strings = hotJson.keySet();
|
|
|
|
+ for (String key: strings) {
|
|
|
|
+ JSONObject subJson = hotJson.getJSONObject(key);
|
|
|
|
+// String url = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
|
|
|
|
+// String url = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
|
|
|
|
+ String url = "/edit-backstage/hot_online/index.html?m=" + key;
|
|
|
|
+
|
|
|
|
+ // 将link 添加进去
|
|
|
|
+ subJson.put("link", url);
|
|
|
|
+ }
|
|
|
|
+ data2Json.put("hots", hotJson);
|
|
|
|
+ } else {
|
|
|
|
+ data2Json.put("hots", new JSONObject());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 删除旧data2.js
|
|
|
|
+ FileUtil.del(data2Path);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 写入新data2.js
|
|
|
|
+ FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
|
|
|
|
+ log.info("新data2.js写入完成");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //处理data.js 文件
|
|
|
|
+ editDataJs(entity, hots);
|
|
|
|
+
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理data.js 文件
|
|
|
|
+ */
|
|
|
|
+ private void editDataJs(SceneEntity entity, String hots ) {
|
|
|
|
+
|
|
|
|
+ // 因为data.js只是热点信息,所以直接创建上传oss
|
|
|
|
+ JSONObject dataJsJson = new JSONObject();
|
|
|
|
+ if (hots != null) {
|
|
|
|
+ dataJsJson = JSONObject.parseObject(hots);
|
|
|
|
+
|
|
|
|
+ Set<String> strings = dataJsJson.keySet();
|
|
|
|
+ for (String key: strings) {
|
|
|
|
+ JSONObject subJson = dataJsJson.getJSONObject(key);
|
|
|
|
+ JSONObject infoAttribute = subJson.getJSONObject("infoAttribute");
|
|
|
|
+ if (infoAttribute != null) {
|
|
|
|
+ Set<String> infoKey = infoAttribute.keySet();
|
|
|
|
+
|
|
|
|
+ for (String s: infoKey) {
|
|
|
|
+ Object val = null;
|
|
|
|
+ // 添加到第一层, 空值不添加
|
|
|
|
+ if ("images".equals(s) || "styleImg".equals(s) || "model".equals(s) || "video".equals(s) || "iframe".equals(s)) {
|
|
|
|
+ JSONArray jsonArray = infoAttribute.getJSONArray(s);
|
|
|
|
+ if (jsonArray.size() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ val = jsonArray;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ String a = infoAttribute.getString(s);
|
|
|
|
+ if (StringUtils.isBlank(a)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ val = a;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ subJson.put(s, val);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 删除infoAttribute
|
|
|
|
+ subJson.remove("infoAttribute");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("out data.js : {}", dataJsJson);
|
|
|
|
+ String basePath = configConstant.serverBasePath + entity.getSceneCode();
|
|
|
|
+
|
|
|
|
+ String dataPath = basePath + "/hot/js/data.js";
|
|
|
|
+ FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
|
|
|
|
+
|
|
|
|
+ log.info("新data.js写入完成: {}", dataPath);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|