|
@@ -1,22 +1,30 @@
|
|
|
package com.gis.web.controller;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.domain.dto.PageDto;
|
|
|
+import com.gis.domain.dto.SceneDataDto;
|
|
|
import com.gis.domain.po.SceneEntity;
|
|
|
import com.gis.service.SceneService;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Created by owen on 2020/5/8 0008 9:54
|
|
|
*/
|
|
|
@Log4j2
|
|
|
-@Api(tags = "场景列表")
|
|
|
+@Api(tags = "场景管理")
|
|
|
+@ApiSort(value = 2)
|
|
|
@RestController
|
|
|
@RequestMapping("manage/scene")
|
|
|
public class SceneController extends BaseController {
|
|
@@ -35,29 +43,119 @@ public class SceneController extends BaseController {
|
|
|
return Result.success(page);
|
|
|
}
|
|
|
|
|
|
-// @ApiOperation("新增/修改部信息")
|
|
|
-// @PostMapping("save")
|
|
|
-// public Result save(@Valid @RequestBody SceneDto param) {
|
|
|
-//
|
|
|
-// SceneEntity entity = null;
|
|
|
-// if (param.getId() == null) {
|
|
|
-// entity = new SceneEntity();
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// sceneService.save(entity);
|
|
|
-// } else {
|
|
|
-// entity = sceneService.findById(param.getId());
|
|
|
-// if (entity == null) {
|
|
|
-// return Result.failure("对象id不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// entity.setUpdateTime(new Date());
|
|
|
-// sceneService.update(entity);
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
+ @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.getJSONObject("name"));
|
|
|
+ model.put("summary", infoJson.getJSONObject("summary"));
|
|
|
+ model.put("camera_start", infoJson.getJSONObject("camera_start"));
|
|
|
+
|
|
|
+ if (guidesArray != null) {
|
|
|
+ model.put("images", guidesArray);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新someDataJson
|
|
|
+ someDataJson.put("model", model);
|
|
|
+ someDataJson.put("loadlogo", infoJson.getJSONObject("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));
|
|
|
+ }
|
|
|
+
|
|
|
+ String overlays = param.getOverlays();
|
|
|
+ if (overlays != null) {
|
|
|
+ data2Json.put("overlays", JSONObject.parseObject(overlays));
|
|
|
+ }
|
|
|
+
|
|
|
+ String hots = param.getHots();
|
|
|
+ if (hots != null) {
|
|
|
+ data2Json.put("hots", JSONObject.parseObject(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();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|