|
@@ -1,50 +1,26 @@
|
|
|
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;
|
|
|
-import com.gis.common.proto.util.CreateObjUtil;
|
|
|
-import com.gis.common.util.FileUtils;
|
|
|
-import com.gis.common.util.RandomUtils;
|
|
|
+import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
+import com.gis.common.util.RegexUtil;
|
|
|
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.dto.ScenePageDto;
|
|
|
import com.gis.domain.po.SceneEntity;
|
|
|
-import com.gis.domain.po.SlideshowEntity;
|
|
|
-import com.gis.domain.po.SysUserEntity;
|
|
|
import com.gis.mapper.SceneMapper;
|
|
|
import com.gis.service.SceneService;
|
|
|
-import com.gis.service.SysUserService;
|
|
|
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.util.ResourceUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
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.*;
|
|
|
|
|
@@ -52,7 +28,6 @@ import java.util.*;
|
|
|
/**
|
|
|
* Created by owen on 2020/5/8 0008 9:54
|
|
|
*/
|
|
|
-//@RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
@Log4j2
|
|
|
@Api(tags = "大场景")
|
|
|
@RestController
|
|
@@ -103,8 +78,6 @@ public class SceneController extends BaseController {
|
|
|
for (SceneEntity entity: entities) {
|
|
|
FileUtil.del(basePath + entity.getSceneCode());
|
|
|
sceneService.delete(entity);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return Result.success();
|
|
@@ -151,7 +124,6 @@ public class SceneController extends BaseController {
|
|
|
}
|
|
|
|
|
|
// 把所有禁止
|
|
|
-// sceneMapper.setDisable();
|
|
|
sceneMapper.setDisableByType(type);
|
|
|
// 开启对应id
|
|
|
sceneMapper.setDisplay(id);
|
|
@@ -159,225 +131,9 @@ public class SceneController extends BaseController {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- /************************************** 应用程序项目部接口 **************************************/
|
|
|
-
|
|
|
- /**
|
|
|
- * map的key值是json参数,value是文件
|
|
|
- * @param param
|
|
|
- * @param sceneCode
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- */
|
|
|
-// @ApiOperation(value = "box视频上传", notes = "自定义上传位置,文件名需要验证中文字符")
|
|
|
-// @PostMapping("uploadBox")
|
|
|
-// @ApiImplicitParams({
|
|
|
-// @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true),
|
|
|
-// @ApiImplicitParam(name = "param", value = "Map传参", required = true),
|
|
|
-// })
|
|
|
-//
|
|
|
-// public Result uploadBox(@RequestParam Map<String, MultipartFile> param, String sceneCode, HttpServletRequest request) throws IOException {
|
|
|
-//
|
|
|
-// SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("对象不存在:{}", sceneCode);
|
|
|
-// return Result.failure("场景码不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 保存位置(箭头函数传参,需要定义final, 使用时需要赋值使用)
|
|
|
-// String basePath = configConstant.serverBasePath + sceneCode;
|
|
|
-// final String saveBasePath = basePath + "/boxVideo/";
|
|
|
-//
|
|
|
-// // box视频信息
|
|
|
-// JSONArray overlaysArray = new JSONArray();
|
|
|
-//
|
|
|
-// param.forEach((key, file)->{
|
|
|
-//
|
|
|
-// if (StringUtils.isBlank(key)) {
|
|
|
-// log.error("key值不能为空");
|
|
|
-// throw new BaseRuntimeException("key值不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (file == null) {
|
|
|
-// log.error("文件不能为空");
|
|
|
-// throw new BaseRuntimeException("文件不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// String fileName = file.getOriginalFilename();
|
|
|
-//
|
|
|
-// if (Validator.hasChinese(fileName)) {
|
|
|
-// log.error("文件名不能有中文字符: {}", fileName);
|
|
|
-// throw new BaseRuntimeException("文件名不能有中文字符");
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// JSONObject keyJson = JSONObject.parseObject(key);
|
|
|
-//
|
|
|
-// // 给相对路径,tomcat配置静态资源让前端读取
|
|
|
-// // http://192.168.0.44:8101/data/ar_I4Ef2SS4y/boxVideo/20180201_101827.mp4
|
|
|
-//// String boxVideoPath = FILE_ADDRESS + entity.getSceneCode()+ "/boxVideo/" + fileName;
|
|
|
-// String boxVideoPath = configConstant.serverUrlPrefix + entity.getSceneCode()+ "/boxVideo/" + fileName;
|
|
|
-//// log.info("boxVideoPath: {}", boxVideoPath);
|
|
|
-//
|
|
|
-// // 添加视频参数到overlayJaon
|
|
|
-// keyJson.put("file", boxVideoPath);
|
|
|
-// overlaysArray.add(keyJson);
|
|
|
-//
|
|
|
-//
|
|
|
-// // final值需要赋值使用
|
|
|
-// String filePath = saveBasePath;
|
|
|
-//
|
|
|
-// filePath += fileName;
|
|
|
-// log.info("filePath: {}", filePath);
|
|
|
-// try {
|
|
|
-// FileUtil.writeFromStream(file.getInputStream(), filePath);
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-//
|
|
|
-// });
|
|
|
-//
|
|
|
-// JSONObject dataJson = new JSONObject();
|
|
|
-// dataJson.put("overlays", overlaysArray);
|
|
|
-//
|
|
|
-// // 创建data2.js文件
|
|
|
-// String saveDataJsonPath = basePath + "/data2.js";
|
|
|
-// log.info("data2.js path :{}", saveDataJsonPath);
|
|
|
-// FileUtil.writeUtf8String(dataJson.toJSONString(), saveDataJsonPath);
|
|
|
-// log.info("data2.js创建完成");
|
|
|
-//
|
|
|
-// return Result.success(entity.getWebSite());
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 文件转换
|
|
|
- * @param sceneCode
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private void convert(String basePath, String sceneCode, String sceneTitle) throws Exception {
|
|
|
-
|
|
|
- // 将result文件夹的upload.json是否存在,并处理业务逻辑
|
|
|
- checkUploadJson(basePath);
|
|
|
-
|
|
|
-
|
|
|
- if(!FileUtil.exist(basePath+"/vision.txt")){
|
|
|
- log.error("文件不存在: " + basePath+"/vision.txt");
|
|
|
- Result.failure("文件不存在: " + basePath+"/vision.txt");
|
|
|
- }
|
|
|
-
|
|
|
- // 2.vision.txt转vision.modeldata
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(basePath+"/vision.txt", basePath+"/vision.modeldata");
|
|
|
- log.info("vision.modeldata转换完成");
|
|
|
-
|
|
|
- // 3. 生成一个空的data2.js, 里面是一个空的json
|
|
|
- FileUtil.writeUtf8String("{}",basePath+"/data2.js");
|
|
|
- log.info("data2.js创建完成");
|
|
|
-
|
|
|
- // 4. 创建someData.json, 修改sid值为场景码目录
|
|
|
- createSomeData(basePath, sceneCode, sceneTitle);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查upload.json文件是否存在,执行业务逻辑
|
|
|
- */
|
|
|
- private static void checkUploadJson(String basePath) throws Exception {
|
|
|
- String uploadJsonPath = basePath + "/results/upload.json";
|
|
|
-// String uploadJsonPath = "F:\\test\\army\\upload.json";
|
|
|
- boolean isUploadJsonPath = FileUtil.isFile(uploadJsonPath);
|
|
|
- if (!isUploadJsonPath) {
|
|
|
- log.error("算法的upload.json不存在");
|
|
|
- throw new BaseRuntimeException(5000, "算法的upload.json不存在");
|
|
|
-
|
|
|
- }
|
|
|
- // 判断upload.json文件是否都存在
|
|
|
- String os = FileUtil.readUtf8String(uploadJsonPath);
|
|
|
- JSONObject imageObject = JSONObject.parseObject(os);
|
|
|
-
|
|
|
- // json数组
|
|
|
- JSONArray jsonArray = imageObject.getJSONArray("upload");
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
- String fileName = jsonObject.getString("file");
|
|
|
- String filePath = basePath + "/results/" + fileName;
|
|
|
-
|
|
|
- boolean isFilePath = FileUtil.isFile(filePath);
|
|
|
- if (!isFilePath) {
|
|
|
- log.error("算法的upload.json数据文件: {}", filePath );
|
|
|
- throw new BaseRuntimeException(5000, "算法的upload.json数据文件不存在");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- String suffix = StringUtils.substringAfterLast(filePath, ".");
|
|
|
- // 把图片复制到指定目录(dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high)
|
|
|
- if ("jpg".equals(suffix)) {
|
|
|
- FileUtil.copy(filePath, basePath+"/" + ConstantFileName.modelUUID+"_50k_texture_jpg_high/" + fileName, true);
|
|
|
- }
|
|
|
-
|
|
|
- // 将modeldata.txt转xxx.dam
|
|
|
- if ("txt".equals(suffix)) {
|
|
|
- CreateObjUtil.convertTxtToDam(filePath, basePath+"/" + ConstantFileName.modelUUID+"_50k.dam");
|
|
|
- log.info("dam转换完成");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建someData.json
|
|
|
- */
|
|
|
- private static void createSomeData(String basePath, String sceneCode, String sceneTitle) throws IOException {
|
|
|
- String path = ResourceUtils.getURL("classpath:").getPath();
|
|
|
- path = path + "data/someData.json";
|
|
|
- log.info("path: {}", path);
|
|
|
- String os = FileUtil.readUtf8String(path);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(os);
|
|
|
- JSONObject model = jsonObject.getJSONObject("model");
|
|
|
-
|
|
|
-
|
|
|
- // 更新images json
|
|
|
- JSONArray imagesJson = updateImagesData(sceneCode);
|
|
|
- model.put("images", imagesJson);
|
|
|
-
|
|
|
- // 修改sid值
|
|
|
- model.put("sid", sceneCode);
|
|
|
- model.put("name", sceneTitle);
|
|
|
-
|
|
|
- // 更新json
|
|
|
- jsonObject.put("model", model);
|
|
|
- jsonObject.put("name", sceneTitle);
|
|
|
-
|
|
|
-
|
|
|
- FileUtil.writeUtf8String(jsonObject.toJSONString(), basePath+"/someData.json");
|
|
|
-
|
|
|
- log.info("someData.json创建完成");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建images.json
|
|
|
- * 如果数据格式有变动,要作出响应的修改
|
|
|
- */
|
|
|
- private static JSONArray updateImagesData(String sceneCode) throws IOException {
|
|
|
- String resourceUrl = FileUtils.getResourceUrl("data/images.json");
|
|
|
- String os = FileUtil.readUtf8String(resourceUrl);
|
|
|
- JSONObject imageObject = JSONObject.parseObject(os);
|
|
|
- imageObject.put("sid", sceneCode);
|
|
|
-
|
|
|
- JSONArray imagesArray = new JSONArray();
|
|
|
- imagesArray.set(0, imageObject);
|
|
|
|
|
|
- return imagesArray;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- @ApiOperation(value = "上传", notes = "编辑场景使用,根据场景码位置上传(应用程序项目、web),自定义上传位置,文件名需要验证中文字符" +
|
|
|
- "会重命名文件")
|
|
|
+ @ApiOperation(value = "上传到指定场景码目录", notes = "中文名称转拼音命名")
|
|
|
@PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
|
|
|
public Result upload(MultipartFile file , @PathVariable String sceneCode) throws IOException {
|
|
|
|
|
@@ -395,17 +151,24 @@ public class SceneController extends BaseController {
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
String suffix = StringUtils.substringAfterLast(fileName, ".");
|
|
|
|
|
|
-
|
|
|
// 转小写
|
|
|
suffix = StringUtils.lowerCase(suffix);
|
|
|
|
|
|
- String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
|
+
|
|
|
+ // 去除特殊符号
|
|
|
+ String pinyinName = RegexUtil.specificSymbol(fileName);
|
|
|
+ pinyinName = PinyinUtil.getPinyin(pinyinName, "");
|
|
|
+
|
|
|
+ // 转小写
|
|
|
+ pinyinName = StringUtils.lowerCase(pinyinName);
|
|
|
+
|
|
|
+// String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
|
|
|
|
// 重命名
|
|
|
- fileName = time + "." + suffix;
|
|
|
+ fileName = pinyinName + "." + suffix;
|
|
|
String basePath = configConstant.serverBasePath + sceneCode;
|
|
|
String savePath = basePath + "/edit/" + fileName;
|
|
|
- log.info("文件保存位置:{}" + savePath);
|
|
|
+ log.info("文件保存位置:" + savePath);
|
|
|
FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
|
|
|
// Object urlPath = SERVER_DOMAIN + "data/" + sceneCode + "/edit/" + fileName;
|
|
@@ -419,131 +182,5 @@ public class SceneController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 一般运用于新的场景添加热点。跟前端的编辑添加热点有点不一样,功能比较单一
|
|
|
- * 参数只用:hots、sceneCode
|
|
|
- * @return
|
|
|
- */
|
|
|
-// @ApiOperation(value = "编辑热点(应用程序项目部)", notes = "应用程序项目部编辑场景热点")
|
|
|
-// @PostMapping("editHots")
|
|
|
-// public Result editHots(@Valid @RequestBody SceneDataDto param){
|
|
|
-// String sceneCode = param.getSceneCode();
|
|
|
-// SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("场景不存在 : {}", sceneCode);
|
|
|
-// return Result.failure("场景不存在");
|
|
|
-// }
|
|
|
-// String basePath = configConstant.serverBasePath + sceneCode;
|
|
|
-//
|
|
|
-// // 处理data2.js
|
|
|
-// String data2Path = basePath + "/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 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;
|
|
|
-//// String url = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
|
|
|
-// String url = "/edit-backstage/hot_online/index.html?m=" + key;
|
|
|
-// // 将link 添加进去
|
|
|
-// subJson.put("link", url);
|
|
|
-// }
|
|
|
-// data2Json.put("hots", hotJson);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 删除旧data2.js
|
|
|
-// FileUtil.del(data2Path);
|
|
|
-// // 写入新data2.js
|
|
|
-// FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
|
|
|
-// log.info("新data2.js写入完成");
|
|
|
-//
|
|
|
-// //处理data.js 文件
|
|
|
-// editDataJs(entity, hots);
|
|
|
-//
|
|
|
-//
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理data.js 文件
|
|
|
- */
|
|
|
- private void editDataJs(SceneEntity entity, String hots ) {
|
|
|
-
|
|
|
- // 因为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");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- log.info("out data.js : {}", dataJsJson);
|
|
|
-
|
|
|
-
|
|
|
- String dataPath = entity.getPath() + "/hot/js/data.js";
|
|
|
- FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
|
|
|
-
|
|
|
- log.info("新data.js写入完成: {}", dataPath);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("获取场景码")
|
|
|
- @GetMapping("getSceneCode")
|
|
|
- public Result getSceneCode() {
|
|
|
- String sceneCode = RandomUtils.randowString(9);
|
|
|
- sceneCode = "ar_" +sceneCode;
|
|
|
- return Result.success((Object) sceneCode);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|