|
@@ -12,6 +12,8 @@ import com.gis.common.proto.util.CreateObjUtil;
|
|
|
import com.gis.common.util.FileUtils;
|
|
|
import com.gis.common.util.RandomUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
+import com.gis.domain.dto.SceneDataDto;
|
|
|
+import com.gis.domain.po.FileEntity;
|
|
|
import com.gis.domain.po.SceneEntity;
|
|
|
import com.gis.service.SceneService;
|
|
|
import com.gis.web.shiro.JwtUtil;
|
|
@@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
@@ -147,7 +150,7 @@ public class ApiController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("Map表单上传多文件,指定保存路径,需要用postman测试")
|
|
|
+ @ApiOperation(value = "Map表单上传多文件,指定保存路径,需要用postman测试", notes = "自定义上传位置")
|
|
|
@PostMapping("uploads")
|
|
|
public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneTitle, String sceneCode, HttpServletRequest request) throws Exception {
|
|
|
String token = request.getHeader("token");
|
|
@@ -442,9 +445,155 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @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
|
|
|
+ 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++) {
|
|
|
+ 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写入完成");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @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 fileName = file.getOriginalFilename();
|
|
|
+ String savePath = entity.getPath() + "/edit/" + fileName;
|
|
|
+ FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+
|
|
|
+ Object urlPath = SERVER_DOMAIN + "data/" + sceneCode + "/edit/" + fileName;
|
|
|
+ log.info("文件写入成功: {}", urlPath);
|
|
|
+
|
|
|
+ // 返回前端数据
|
|
|
+ return Result.success(urlPath);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|