|
@@ -1,38 +1,33 @@
|
|
|
package com.gis.web.controller;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gis.common.util.FileUtils;
|
|
|
import com.gis.common.util.QiniuOssUtil;
|
|
|
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.FileEntity;
|
|
|
import com.gis.domain.po.SceneEntity;
|
|
|
import com.gis.mapper.SceneMapper;
|
|
|
import com.gis.service.SceneService;
|
|
|
import com.gis.web.aop.WebControllerLog;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
|
|
+import com.qiniu.common.QiniuException;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.shiro.authz.annotation.Logical;
|
|
|
-import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -61,125 +56,58 @@ public class SceneController extends BaseController {
|
|
|
return Result.success(page);
|
|
|
}
|
|
|
|
|
|
-// @ApiOperation("场景编辑")
|
|
|
-// @PostMapping("edit")
|
|
|
-// public Result edit(@Valid @RequestBody SceneDataDto param) {
|
|
|
-//
|
|
|
-// SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("场景不存在 : {}", param.getSceneCode());
|
|
|
-// return Result.failure("场景不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// // 处理someData.json
|
|
|
-// // 下载someData.json
|
|
|
-//
|
|
|
-// String someDataPath = entity.getPath() + "/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) {
|
|
|
-// 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"));
|
|
|
-//
|
|
|
-// if (guidesArray != null) {
|
|
|
-// model.put("images", guidesArray);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 更新someDataJson
|
|
|
-// someDataJson.put("model", model);
|
|
|
-// someDataJson.put("loadlogo", infoJson.get("loadlogo"));
|
|
|
-//
|
|
|
-// // 删除旧someDataJson
|
|
|
-// FileUtil.del(someDataPath);
|
|
|
-// // 写入新someDataJson
|
|
|
-// FileUtil.writeUtf8String(someDataJson.toJSONString(), someDataPath);
|
|
|
-// log.info("someData.json写入完成");
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 处理data2.js
|
|
|
-// String data2Path = entity.getPath() + "/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));
|
|
|
-//// data2Json.put("tourAudio", tourAudio);
|
|
|
-// }
|
|
|
-//
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 处理guidesArray,将scan_id的值作为key, value: time":40000
|
|
|
-// JSONObject audioJson = new JSONObject();
|
|
|
-// JSONObject timeJson = new JSONObject();
|
|
|
-// timeJson.put("time", 40000);
|
|
|
-// if (guidesArray != null) {
|
|
|
-//
|
|
|
-// for (int i = 0; i < guidesArray.size() ; i++) {
|
|
|
-// String scanId = guidesArray.getJSONObject(i).getString("scan_id");
|
|
|
-// audioJson.put(scanId, timeJson);
|
|
|
-// }
|
|
|
-//
|
|
|
-// data2Json.put("audio", audioJson);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// // 删除旧data2.js
|
|
|
-// FileUtil.del(data2Path);
|
|
|
-// // 写入新data2.js
|
|
|
-// FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
|
|
|
-// log.info("新data2.js写入完成");
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
+
|
|
|
+ @ApiOperation("创建场景码")
|
|
|
+ @GetMapping("createSceneCode/{sceneCode}")
|
|
|
+ public Result createSceneCode(@PathVariable String sceneCode) throws QiniuException {
|
|
|
+ if (StringUtils.isBlank(sceneCode)) {
|
|
|
+ log.error("场景码不能为空");
|
|
|
+ return Result.failure("场景码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 场景url
|
|
|
+ String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
+ log.info("webSite: {}", webSite);
|
|
|
+
|
|
|
+ // 服务器文件路径
|
|
|
+ String serverPath = FILE_PATH + sceneCode;
|
|
|
+
|
|
|
+ // oss文件路径
|
|
|
+ String ossPath = OSS_PATH + sceneCode;
|
|
|
+
|
|
|
+
|
|
|
+ // 创建data2.js
|
|
|
+ String data2Info = "/data2.js";
|
|
|
+ String data2Path = serverPath + data2Info;
|
|
|
+ FileUtil.writeUtf8String("{}", data2Path);
|
|
|
+ if (!FileUtil.exist(data2Path)){
|
|
|
+ log.error("data2.js不存在");
|
|
|
+ return Result.failure("data2.js不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // data2.js上传oss
|
|
|
+ QiniuOssUtil.upload(data2Path, ossPath + data2Info);
|
|
|
+
|
|
|
+ SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
+ if (entity == null) {
|
|
|
+ entity = new SceneEntity();
|
|
|
+ entity.setSceneCode(sceneCode);
|
|
|
+ entity.setWebSite(webSite);
|
|
|
+ entity.setPath(serverPath);
|
|
|
+ entity.setOssPath(ossPath);
|
|
|
+ entity.setSceneTitle(sceneCode);
|
|
|
+ sceneService.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -196,6 +124,8 @@ public class SceneController extends BaseController {
|
|
|
sceneService.update(entity);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -213,131 +143,445 @@ public class SceneController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// /**
|
|
|
-// * 只有一个场景是显示状态
|
|
|
-// */
|
|
|
-// @ApiOperation("场景显示")
|
|
|
-// @GetMapping("display/{id}")
|
|
|
-// public Result display(@PathVariable Long id) {
|
|
|
-// SceneEntity entity = sceneService.findById(id);
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("对象id不存在 : {}", id);
|
|
|
-// return Result.failure("对象id不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 把所有禁止
|
|
|
-// sceneMapper.setDisable();
|
|
|
-// // 开启对应id
|
|
|
-// sceneMapper.setDisplay(id);
|
|
|
-//
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// @ApiOperation(value = "场景上传")
|
|
|
-// @PostMapping(value = "upload", consumes = {"multipart/form-data"})
|
|
|
-// public Result upload(MultipartFile file, String sceneCode) throws IOException {
|
|
|
-//
|
|
|
-// if (file == null) {
|
|
|
-// log.error("文件不能为空");
|
|
|
-// return Result.failure("文件不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// String basePath = FILE_PATH + sceneCode + "/";
|
|
|
-//
|
|
|
-// String fileName = file.getOriginalFilename();
|
|
|
-// String savePath = basePath + fileName;
|
|
|
-//
|
|
|
-// FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
-//
|
|
|
-// // 上传到oss
|
|
|
-// String ossPath = OSS_DOMAIN + OSS_PATH + fileName;
|
|
|
-// QiniuOssUtil.upload(savePath, ossPath);
|
|
|
-// log.info("文件上传到oss完成: {}", ossPath);
|
|
|
-//
|
|
|
-// // 返回前端数据
|
|
|
-// return Result.success();
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true),
|
|
|
- @ApiImplicitParam(name = "param", value = "Map传参", required = true),
|
|
|
- })
|
|
|
- @ApiOperation(value = "场景上传", notes = "自定义上传位置,Map表单上传多文件,指定保存路径,需要用postman测试")
|
|
|
- @PostMapping("uploads")
|
|
|
- public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneCode) throws Exception {
|
|
|
-
|
|
|
- SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
- if (entity != null) {
|
|
|
- log.error("场景码已存在,请更换新场景码: {}", sceneCode);
|
|
|
- return Result.failure("场景码已存在,请更换新场景码");
|
|
|
- }
|
|
|
|
|
|
- // 服务器文件路径
|
|
|
- String serverPath = FILE_PATH + sceneCode;
|
|
|
|
|
|
- // oss文件路径
|
|
|
- String ossPath = OSS_PATH + sceneCode;
|
|
|
-
|
|
|
-
|
|
|
- // oss上传封装
|
|
|
- HashMap<String, String> ossMap = new HashMap<>();
|
|
|
-
|
|
|
- param.forEach((path, file)->{
|
|
|
+ @ApiOperation(value = "场景上传")
|
|
|
+ @PostMapping("uploads")
|
|
|
+ public Result uploads(MultipartFile file, String path) {
|
|
|
|
|
|
if (StringUtils.isBlank(path)) {
|
|
|
log.error("保存路径不能为空");
|
|
|
+ return Result.failure("保存路径不能为空");
|
|
|
}
|
|
|
|
|
|
if (file == null) {
|
|
|
log.error("文件不能为空");
|
|
|
+ return Result.failure("文件不能为空");
|
|
|
}
|
|
|
|
|
|
- String filePath = serverPath + path;
|
|
|
+ String filePath = FILE_PATH + path;
|
|
|
log.info("savePath: {}", filePath);
|
|
|
try {
|
|
|
FileUtil.writeFromStream(file.getInputStream(), filePath);
|
|
|
- ossMap.put(filePath, ossPath + path);
|
|
|
+ log.info("文件写入完成");
|
|
|
+ if (!FileUtil.exist(filePath)) {
|
|
|
+ log.error("文件不存在: {}", filePath);
|
|
|
+ return Result.failure("文件不存在 : " + filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ QiniuOssUtil.upload(filePath, OSS_PATH + path);
|
|
|
+ log.info("oss文件上传完成 ");
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("编辑场景")
|
|
|
+ @PostMapping("edit")
|
|
|
+ public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException {
|
|
|
+
|
|
|
+ String sceneCode = param.getSceneCode();
|
|
|
+
|
|
|
+ SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
+ if (entity == null) {
|
|
|
+ log.error("场景不存在 : {}", sceneCode);
|
|
|
+ return Result.failure("场景不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 处理someData.json, 网络下载someData.json
|
|
|
+ String someDataName = "someData.json";
|
|
|
+ // 注意网络下载会有缓存,必须加时间戳
|
|
|
+ String someDataUrl = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + someDataName+ "?m=" + System.currentTimeMillis();
|
|
|
+ log.info("网络下载文件地址: {}", someDataUrl);
|
|
|
+ String localBasePath = FILE_PATH + sceneCode;
|
|
|
+ FileUtils.downLoadFromUrl(someDataUrl, someDataName, localBasePath);
|
|
|
+ String someDataPath = entity.getPath() + "/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) {
|
|
|
+ String name = infoJson.getString("name");
|
|
|
+ model.put("name", name);
|
|
|
+
|
|
|
+ // update 场景名称
|
|
|
+ if (!name.equals(entity.getSceneTitle())) {
|
|
|
+ entity.setSceneTitle(name);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ sceneService.update(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ model.put("summary", infoJson.get("summary"));
|
|
|
+ model.put("camera_start", infoJson.getJSONObject("camera_start"));
|
|
|
+
|
|
|
+ if (guidesArray != null) {
|
|
|
+ model.put("images", guidesArray);
|
|
|
+ } else {
|
|
|
+ model.put("images", new JSONArray());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新someDataJson
|
|
|
+ someDataJson.put("model", model);
|
|
|
+ someDataJson.put("loadlogo", infoJson.get("loadlogo"));
|
|
|
+ someDataJson.put("supportsVR", infoJson.getBoolean("supportsVR"));
|
|
|
+ someDataJson.put("backgroundMusic", infoJson.getString("backgroundMusic"));
|
|
|
+
|
|
|
+ // 删除旧someDataJson
|
|
|
+ FileUtil.del(someDataPath);
|
|
|
+ // 写入新someDataJson
|
|
|
+ FileUtil.writeUtf8String(someDataJson.toJSONString(), someDataPath);
|
|
|
+ log.info("someData.json写入完成");
|
|
|
+
|
|
|
+ // 将新的someDataJson上传oss
|
|
|
+ QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
|
|
|
+ log.info(someDataName+ "已上传到七牛云");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理data2.js
|
|
|
+
|
|
|
+ String data2Name = "data2.js";
|
|
|
+ // 注意网络下载会有缓存,必须加时间戳
|
|
|
+ String data2Url = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + data2Name+ "?m=" + System.currentTimeMillis();
|
|
|
+ log.info("网络下载文件地址: {}", data2Url);
|
|
|
+ FileUtils.downLoadFromUrl(data2Url, data2Name, localBasePath);
|
|
|
+
|
|
|
+ String data2Path = entity.getPath() + "/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());
|
|
|
+ }
|
|
|
+
|
|
|
+ String overlays = param.getOverlays();
|
|
|
+ if (overlays != null) {
|
|
|
+ data2Json.put("overlays", JSONObject.parseArray(overlays));
|
|
|
+ } else {
|
|
|
+ data2Json.put("overlays", new JSONArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ String hots = param.getHots();
|
|
|
+ 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;
|
|
|
+ // 将link 添加进去
|
|
|
+ subJson.put("link", url);
|
|
|
+ }
|
|
|
+ data2Json.put("hots", hotJson);
|
|
|
+ } else {
|
|
|
+ data2Json.put("hots", new JSONObject());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理guidesArray,将scan_id的值作为key, value: time":40000
|
|
|
+ JSONObject audioJson = new JSONObject();
|
|
|
+ JSONObject timeJson = new JSONObject();
|
|
|
+ timeJson.put("time", 40000);
|
|
|
+ if (guidesArray != null) {
|
|
|
+
|
|
|
+ for (int i = 0; i < guidesArray.size() ; i++) {
|
|
|
+ JSONObject metadata = guidesArray.getJSONObject(i).getJSONObject("metadata");
|
|
|
+ if (metadata != null) {
|
|
|
+ String scanId = metadata.getString("scan_id");
|
|
|
+ audioJson.put(scanId, timeJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ data2Json.put("audio", audioJson);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 删除旧data2.js
|
|
|
+ FileUtil.del(data2Path);
|
|
|
+ // 写入新data2.js
|
|
|
+ FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
|
|
|
+ log.info("新data2.js写入完成");
|
|
|
+
|
|
|
+ // 将新的someDataJson上传oss
|
|
|
+ QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
|
|
|
+ log.info(data2Name+ "已上传到七牛云");
|
|
|
+
|
|
|
+ //处理data.js 文件
|
|
|
+ editDataJs(sceneCode, entity, hots);
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理data.js 文件
|
|
|
+ */
|
|
|
+ private void editDataJs(String sceneCode, SceneEntity entity, String hots ) throws QiniuException {
|
|
|
+
|
|
|
+ // 因为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");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ String dataPath = entity.getPath() + "/data.js";
|
|
|
+ FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
|
|
|
+// log.info("data.js {}", dataJsJson);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //上传oss
|
|
|
+ String ossPath = OSS_PATH + sceneCode + "/hot/js/data.js";
|
|
|
+ QiniuOssUtil.upload(dataPath, ossPath);
|
|
|
+ log.info("data.js已上传到七牛云: {}", ossPath);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("漫游可行")
|
|
|
+ @PostMapping("roamViable")
|
|
|
+ public Result roamViable(@RequestBody RoamViableDto param) throws Exception {
|
|
|
+ return sceneService.roamViable(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("生成json")
|
|
|
+ @GetMapping("getJson/{code}")
|
|
|
+ @ApiImplicitParam(name = "code", value = "matterPort码", required = true)
|
|
|
+ public Result getJson(@PathVariable String code) throws IOException {
|
|
|
+ String url = "https://my.matterportvr.cn/api/player/models/" + code;
|
|
|
+ log.info("url: {}", url);
|
|
|
+ String s = HttpUtil.get(url);
|
|
|
+ if (s == null) {
|
|
|
+ log.error("matterPort码无效: {}", url);
|
|
|
+ return Result.failure("matterPort码无效:" + url);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success(editMatterPortvrData(s));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理matterportvr 数据转为大场景可使用的数据
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public JSONObject editMatterPortvrData(String data) throws IOException {
|
|
|
+ JSONObject mpoJson = JSONObject.parseObject(data);
|
|
|
+
|
|
|
+ // 1. 删除第一层无用字段
|
|
|
+ String[] delFiles = new String[] {"image","enable_social_sharing","social_sharing_enabled","account_social_sharing_default",
|
|
|
+ "icon","address","vr_url","is_vr","vision_version","created","unit_type","owner","has_public_access_password"};
|
|
|
+ for (String key : delFiles) {
|
|
|
+ mpoJson.remove(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. images数组只保留第一个
|
|
|
+ JSONArray imagesArray = mpoJson.getJSONArray("images");
|
|
|
+ JSONObject images0Json= imagesArray.getJSONObject(0);
|
|
|
+ // 删除images0无用字段
|
|
|
+ String[] delImage0Files = new String[] {"url", "signed_src", "thumbnail_signed_src", "download_url", "src"};
|
|
|
+ for (String key : delImage0Files) {
|
|
|
+ images0Json.remove(key);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 将images更新到mpoJson
|
|
|
+ imagesArray = new JSONArray();
|
|
|
+ imagesArray.add(images0Json);
|
|
|
+
|
|
|
+ mpoJson.put("images", imagesArray);
|
|
|
+
|
|
|
+
|
|
|
+ // 3. 处理metadata, 封装到camera_start
|
|
|
+ JSONObject metadataJson = images0Json.getJSONObject("metadata");
|
|
|
+ String scanId = metadataJson.getString("scan_id");
|
|
|
+ Integer orthZoom = metadataJson.getInteger("ortho_zoom");
|
|
|
+ Integer cameraMode = metadataJson.getInteger("camera_mode");
|
|
|
+ JSONObject cameraQuaternionJson = metadataJson.getJSONObject("camera_quaternion");
|
|
|
+ Object x = cameraQuaternionJson.get("x");
|
|
|
+ Object y = cameraQuaternionJson.get("y");
|
|
|
+ Object z = cameraQuaternionJson.get("z");
|
|
|
+ Object w = cameraQuaternionJson.get("w");
|
|
|
+
|
|
|
+ JSONObject cameraJson = new JSONObject();
|
|
|
+ cameraJson.put("zoom", orthZoom);
|
|
|
+
|
|
|
+ JSONArray quaternionJson = new JSONArray();
|
|
|
+ quaternionJson.add(0, x);
|
|
|
+ quaternionJson.add(1, y);
|
|
|
+ quaternionJson.add(2, z);
|
|
|
+ quaternionJson.add(3, w);
|
|
|
+
|
|
|
+ cameraJson.put("quaternion", quaternionJson);
|
|
|
+
|
|
|
+ JSONObject cameraStartJson = new JSONObject();
|
|
|
+ cameraStartJson.put("camera", cameraJson);
|
|
|
+
|
|
|
+ JSONObject uuidJson = new JSONObject();
|
|
|
+ uuidJson.put("uuid", scanId);
|
|
|
+ cameraStartJson.put("pano", uuidJson);
|
|
|
+ cameraStartJson.put("mode", cameraMode);
|
|
|
+
|
|
|
+ // 更新camera_start
|
|
|
+ mpoJson.put("camera_start", cameraStartJson);
|
|
|
+
|
|
|
+
|
|
|
+ // 4. 处理player_options, defaultPlayer是默认值,
|
|
|
+ HashMap<String, Object> defaultPlayer = new HashMap<>();
|
|
|
+ defaultPlayer.put("presented_by", true);
|
|
|
+ defaultPlayer.put("highlight_reel", true);
|
|
|
+ defaultPlayer.put("floor_plan", true);
|
|
|
+ defaultPlayer.put("tour_buttons", true);
|
|
|
+ defaultPlayer.put("dollhouse", true);
|
|
|
+ defaultPlayer.put("fast_transitions", false);
|
|
|
+ defaultPlayer.put("autoplay", false);
|
|
|
+
|
|
|
+ // 更新默认值
|
|
|
+ JSONObject playerOptionsJson = mpoJson.getJSONObject("player_options");
|
|
|
+ defaultPlayer.forEach((key, value)->{
|
|
|
+ playerOptionsJson.put(key, value);
|
|
|
});
|
|
|
|
|
|
- // 创建data.js、 data2.js
|
|
|
- String data2Info = "/data2.js";
|
|
|
-// String dataInfo = "/hot/js/data2.js";
|
|
|
+ // 更新player_options
|
|
|
+ mpoJson.put("player_options", playerOptionsJson);
|
|
|
|
|
|
- String data2Path = serverPath + data2Info;
|
|
|
-// String dataPath = serverPath + dataInfo;
|
|
|
|
|
|
- FileUtil.writeUtf8String("{}", data2Path);
|
|
|
-// FileUtil.writeUtf8String("{}", dataPath);
|
|
|
+ // 5. 添加files
|
|
|
+ JSONArray templates = new JSONArray();
|
|
|
+ templates.add("data/{{number}}/{{filename}}");
|
|
|
|
|
|
- ossMap.put(data2Path, ossPath + data2Info);
|
|
|
-// ossMap.put(dataPath, ossPath + dataInfo);
|
|
|
- log.info("文件上传完成");
|
|
|
+ JSONObject templatesJson = new JSONObject();
|
|
|
+ templatesJson.put("templates", templates);
|
|
|
|
|
|
- QiniuOssUtil.uploads(ossMap);
|
|
|
- log.info("oss文件上传完成");
|
|
|
|
|
|
+ // 6. 创建model
|
|
|
+ JSONObject someDataJson = new JSONObject();
|
|
|
+ someDataJson.put("model", mpoJson);
|
|
|
+ someDataJson.put("files", templatesJson);
|
|
|
|
|
|
+ // 处理json value null
|
|
|
+ return someDataJson;
|
|
|
|
|
|
- // 场景url
|
|
|
- String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
- log.info("webSite: {}", webSite);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- entity = new SceneEntity();
|
|
|
- entity.setSceneCode(sceneCode);
|
|
|
- entity.setWebSite(webSite);
|
|
|
- entity.setPath(serverPath);
|
|
|
- entity.setOssPath(ossPath);
|
|
|
- sceneService.save(entity);
|
|
|
+ /**
|
|
|
+ * 编辑场景上传多媒体资料
|
|
|
+ * @param file
|
|
|
+ * @param sceneCode
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "编辑场景上传", notes = "编辑场景使用,根据场景码位置上传")
|
|
|
+ @PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
|
|
|
+ public Result upload(MultipartFile file , @PathVariable String sceneCode) throws IOException {
|
|
|
+
|
|
|
+ if (file == null) {
|
|
|
+ log.error("文件不能为空");
|
|
|
+ return Result.failure("文件不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
+ if (entity == null) {
|
|
|
+ log.error("场景不存在: {}", sceneCode);
|
|
|
+ return Result.failure("场景不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String basePath = entity.getPath() + "/edit/";
|
|
|
+ // 时间戳重新命名
|
|
|
+ HashMap<String, String> map = FileUtils.upload(file, basePath);
|
|
|
+ String newName = map.get("newName");
|
|
|
+ String savePath = basePath + newName;
|
|
|
+
|
|
|
+ log.info("文件写入成功: {}", savePath);
|
|
|
+
|
|
|
+ // 上传到oss
|
|
|
+ String ossUploadPath = OSS_PATH + sceneCode + "/edit/" + newName;
|
|
|
+ String ossPath = OSS_DOMAIN + ossUploadPath;
|
|
|
+ QiniuOssUtil.upload(savePath, ossUploadPath);
|
|
|
+ log.info("文件上传到oss完成: {}", ossPath);
|
|
|
+
|
|
|
+ // 返回前端数据
|
|
|
+ return Result.success((Object) ossPath);
|
|
|
|
|
|
- return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
|