|
@@ -3,9 +3,12 @@ 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.FileUtils;
|
|
|
+import com.gis.common.util.QiniuOssUtil;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.domain.dto.PageDto;
|
|
|
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;
|
|
@@ -13,25 +16,30 @@ import com.gis.web.aop.WebControllerLog;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
|
|
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;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Created by owen on 2020/5/8 0008 9:54
|
|
|
*/
|
|
|
-@RequiresRoles(value = {"sys_admin", "sys_high", "sys_normal"}, logical = Logical.OR)
|
|
|
@Log4j2
|
|
|
@Api(tags = "大场景")
|
|
|
-@ApiSort(value = 2)
|
|
|
@RestController
|
|
|
@RequestMapping("manage/scene")
|
|
|
public class SceneController extends BaseController {
|
|
@@ -53,125 +61,125 @@ 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("场景编辑")
|
|
|
+// @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();
|
|
|
+// }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -205,24 +213,131 @@ 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不存在");
|
|
|
+// /**
|
|
|
+// * 只有一个场景是显示状态
|
|
|
+// */
|
|
|
+// @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("场景码已存在,请更换新场景码");
|
|
|
}
|
|
|
|
|
|
- // 把所有禁止
|
|
|
- sceneMapper.setDisable();
|
|
|
- // 开启对应id
|
|
|
- sceneMapper.setDisplay(id);
|
|
|
+ // 服务器文件路径
|
|
|
+ String serverPath = FILE_PATH + sceneCode;
|
|
|
|
|
|
- return Result.success();
|
|
|
+ // oss文件路径
|
|
|
+ String ossPath = OSS_PATH + sceneCode;
|
|
|
+
|
|
|
+
|
|
|
+ // oss上传封装
|
|
|
+ HashMap<String, String> ossMap = new HashMap<>();
|
|
|
+
|
|
|
+ param.forEach((path, file)->{
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(path)) {
|
|
|
+ log.error("保存路径不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (file == null) {
|
|
|
+ log.error("文件不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String filePath = serverPath + path;
|
|
|
+ log.info("savePath: {}", filePath);
|
|
|
+ try {
|
|
|
+ FileUtil.writeFromStream(file.getInputStream(), filePath);
|
|
|
+ ossMap.put(filePath, ossPath + path);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建data.js、 data2.js
|
|
|
+ String data2Info = "/data2.js";
|
|
|
+// String dataInfo = "/hot/js/data2.js";
|
|
|
+
|
|
|
+ String data2Path = serverPath + data2Info;
|
|
|
+// String dataPath = serverPath + dataInfo;
|
|
|
+
|
|
|
+ FileUtil.writeUtf8String("{}", data2Path);
|
|
|
+// FileUtil.writeUtf8String("{}", dataPath);
|
|
|
+
|
|
|
+ ossMap.put(data2Path, ossPath + data2Info);
|
|
|
+// ossMap.put(dataPath, ossPath + dataInfo);
|
|
|
+ log.info("文件上传完成");
|
|
|
+
|
|
|
+ QiniuOssUtil.uploads(ossMap);
|
|
|
+ log.info("oss文件上传完成");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 场景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);
|
|
|
+
|
|
|
+ return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
|