|
@@ -1,10 +1,13 @@
|
|
|
package com.gis.web.controller;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.gis.common.exception.BaseRuntimeException;
|
|
|
import com.gis.common.proto.constant.ConstantCmd;
|
|
|
import com.gis.common.proto.constant.ConstantFileName;
|
|
@@ -13,6 +16,7 @@ import com.gis.common.util.FileUtils;
|
|
|
import com.gis.common.util.RandomUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.domain.dto.PageDto;
|
|
|
+import com.gis.domain.dto.RoamViableDto;
|
|
|
import com.gis.domain.dto.SceneDataDto;
|
|
|
import com.gis.domain.po.SceneEntity;
|
|
|
import com.gis.domain.po.SysUserEntity;
|
|
@@ -37,6 +41,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -79,10 +85,10 @@ public class SceneController extends BaseController {
|
|
|
@ApiOperation("场景编辑")
|
|
|
@PostMapping("edit")
|
|
|
public Result edit(@Valid @RequestBody SceneDataDto param) {
|
|
|
-
|
|
|
+ String sceneCode = param.getSceneCode();
|
|
|
SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
|
|
|
if (entity == null) {
|
|
|
- log.error("场景不存在 : {}", param.getSceneCode());
|
|
|
+ log.error("场景不存在 : {}", sceneCode);
|
|
|
return Result.failure("场景不存在");
|
|
|
}
|
|
|
|
|
@@ -116,21 +122,28 @@ public class SceneController extends BaseController {
|
|
|
// 处理model
|
|
|
JSONObject model = someDataJson.getJSONObject("model");
|
|
|
if (model != null) {
|
|
|
- model.put("name", infoJson.get("name"));
|
|
|
- model.put("summary", infoJson.get("summary"));
|
|
|
- model.put("camera_start", infoJson.getJSONObject("camera_start"));
|
|
|
-// model.put("camera_start", infoJson.get("camera_start"));
|
|
|
+// model.put("name", infoJson.get("name"));
|
|
|
+// model.put("summary", infoJson.get("summary"));
|
|
|
+// model.put("camera_start", infoJson.getJSONObject("camera_start"));
|
|
|
|
|
|
if (guidesArray != null) {
|
|
|
model.put("images", guidesArray);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ // camera_start放最外层
|
|
|
+// someDataJson.put("camera_start", infoJson.getJSONObject("camera_start"));
|
|
|
}
|
|
|
|
|
|
// 更新someDataJson
|
|
|
someDataJson.put("model", model);
|
|
|
- someDataJson.put("loadlogo", infoJson.get("loadlogo"));
|
|
|
+// someDataJson.put("loadlogo", infoJson.get("loadlogo"));
|
|
|
+
|
|
|
+ // info信息添加到someDataJson最外层
|
|
|
+ Set<String> infoKey = infoJson.keySet();
|
|
|
+ for (String key : infoKey) {
|
|
|
+
|
|
|
+ someDataJson.put(key, infoJson.get(key));
|
|
|
+ }
|
|
|
|
|
|
// 删除旧someDataJson
|
|
|
FileUtil.del(someDataPath);
|
|
@@ -153,19 +166,16 @@ public class SceneController extends BaseController {
|
|
|
String tourAudio = param.getTourAudio();
|
|
|
if (tourAudio != null) {
|
|
|
data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
|
|
|
-// data2Json.put("tourAudio", tourAudio);
|
|
|
+ } else {
|
|
|
+ data2Json.put("tourAudio", new JSONObject());
|
|
|
}
|
|
|
|
|
|
+ // overlays是数组
|
|
|
String overlays = param.getOverlays();
|
|
|
if (overlays != null) {
|
|
|
- data2Json.put("overlays", JSONObject.parseObject(overlays));
|
|
|
-// data2Json.put("overlays", overlays);
|
|
|
- }
|
|
|
-
|
|
|
- String hots = param.getHots();
|
|
|
- if (hots != null) {
|
|
|
- data2Json.put("hots", JSONObject.parseObject(hots));
|
|
|
-// data2Json.put("hots", hots);
|
|
|
+ data2Json.put("overlays", JSONObject.parseArray(overlays));
|
|
|
+ } else {
|
|
|
+ data2Json.put("overlays", new JSONArray());
|
|
|
}
|
|
|
|
|
|
// 处理guidesArray,将scan_id的值作为key, value: time":40000
|
|
@@ -174,26 +184,73 @@ public class SceneController extends BaseController {
|
|
|
timeJson.put("time", 40000);
|
|
|
if (guidesArray != null) {
|
|
|
|
|
|
+ // 将旧的audio字段删除
|
|
|
+ data2Json.remove("audio");
|
|
|
+
|
|
|
for (int i = 0; i < guidesArray.size() ; i++) {
|
|
|
- String scanId = guidesArray.getJSONObject(i).getString("scan_id");
|
|
|
- audioJson.put(scanId, timeJson);
|
|
|
+ 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对象重复引用问题,拿不到想要的效果
|
|
|
+// JSONObject timeJson = new JSONObject();
|
|
|
+// timeJson.put("time", 40000);
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // 将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();
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("漫游可行")
|
|
|
+ @PostMapping("roamViable")
|
|
|
+ public Result roamViable(@RequestBody RoamViableDto param) throws Exception {
|
|
|
+ return sceneService.roamViable(param);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 素材文件,真删除
|
|
@@ -434,6 +491,7 @@ public class SceneController extends BaseController {
|
|
|
log.info("文件转换完成");
|
|
|
|
|
|
// 场景url
|
|
|
+// String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
log.info("webSite: {}", webSite);
|
|
|
|
|
@@ -569,7 +627,8 @@ public class SceneController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @ApiOperation(value = "上传", notes = "编辑场景使用,根据场景码位置上传(应用程序项目、web),自定义上传位置,文件名需要验证中文字符")
|
|
|
+ @ApiOperation(value = "上传", notes = "编辑场景使用,根据场景码位置上传(应用程序项目、web),自定义上传位置,文件名需要验证中文字符" +
|
|
|
+ "会重命名文件")
|
|
|
@PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
|
|
|
public Result upload(MultipartFile file , @PathVariable String sceneCode) throws IOException {
|
|
|
|
|
@@ -585,12 +644,18 @@ public class SceneController extends BaseController {
|
|
|
}
|
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
+ String suffix = StringUtils.substringAfterLast(fileName, ".");
|
|
|
|
|
|
if (Validator.hasChinese(fileName)) {
|
|
|
log.error("文件名不能有中文字符: {}", fileName);
|
|
|
return Result.failure("文件名不能有中文字符:" + fileName);
|
|
|
}
|
|
|
|
|
|
+ String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
|
+
|
|
|
+ // 重命名
|
|
|
+ fileName = time + "." + suffix;
|
|
|
+
|
|
|
String savePath = entity.getPath() + "/edit/" + fileName;
|
|
|
FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
|
|
@@ -637,7 +702,7 @@ public class SceneController extends BaseController {
|
|
|
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 + "SuperTwo/hot_online/index.html?m=" + key;
|
|
|
+ String url = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
|
|
|
// 将link 添加进去
|
|
|
subJson.put("link", url);
|
|
|
}
|
|
@@ -705,7 +770,11 @@ public class SceneController extends BaseController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- String dataPath = entity.getPath() + entity.getSceneCode() + "/hot/js/data.js";
|
|
|
+
|
|
|
+ log.info("out data.js : {}", dataJsJson);
|
|
|
+
|
|
|
+
|
|
|
+ String dataPath = entity.getPath() + "/hot/js/data.js";
|
|
|
FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
|
|
|
|
|
|
log.info("新data.js写入完成: {}", dataPath);
|