|
@@ -2,7 +2,9 @@ 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.proto.constant.ConstantCmd;
|
|
|
import com.gis.common.proto.constant.ConstantFileName;
|
|
|
import com.gis.common.proto.util.CreateObjUtil;
|
|
|
import com.gis.common.util.FileUtils;
|
|
@@ -36,36 +38,11 @@ public class ApiController extends BaseController {
|
|
|
@Autowired
|
|
|
private SceneService sceneService;
|
|
|
|
|
|
-// @ApiImplicitParams({
|
|
|
-// @ApiImplicitParam(name = "file", value = "文件", required = true),
|
|
|
-// @ApiImplicitParam(name = "savePath", value = "文件保存路径", required = true),
|
|
|
-// })
|
|
|
-// @ApiOperation("上传")
|
|
|
-// @PostMapping("upload")
|
|
|
-// public Result upload(MultipartFile file, String savePath) throws IOException {
|
|
|
-// if (StringUtils.isBlank(savePath)) {
|
|
|
-// log.error("保存路径不能为空");
|
|
|
-// return Result.failure("保存路径不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (file == null) {
|
|
|
-// log.error("文件不能为空");
|
|
|
-// return Result.failure("文件不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// savePath = FILE_PATH + savePath;
|
|
|
-// log.warn("savePath: {}", savePath);
|
|
|
-//
|
|
|
-//
|
|
|
-// boolean upload = FileUtils.upload(file, savePath);
|
|
|
-// return upload? Result.success() : Result.failure("上传失败");
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
@ApiOperation("Map表单上传多文件,指定保存路径,需要用postman测试")
|
|
|
@PostMapping("uploads")
|
|
|
- public Result uploads(@RequestParam Map<String, MultipartFile> param) {
|
|
|
+ public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneTitle, String sceneCode) throws Exception {
|
|
|
+
|
|
|
param.forEach((path, file)->{
|
|
|
|
|
|
if (StringUtils.isBlank(path)) {
|
|
@@ -86,7 +63,34 @@ public class ApiController extends BaseController {
|
|
|
|
|
|
});
|
|
|
|
|
|
- return Result.success();
|
|
|
+ SceneEntity entity = new SceneEntity();
|
|
|
+ entity.setSceneCode(sceneCode);
|
|
|
+ entity.setPath(FILE_PATH + sceneCode);
|
|
|
+ entity.setSceneTitle(sceneTitle);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 调用算法图片转换
|
|
|
+ String cmd = ConstantCmd.SLICE_SKYBOX + entity.getPath();
|
|
|
+ log.info("cmd:{}", cmd);
|
|
|
+ CreateObjUtil.callshell(cmd);
|
|
|
+ log.info("算法切片完成");
|
|
|
+
|
|
|
+ // 转换文件
|
|
|
+ convert(entity.getPath(), sceneCode, sceneTitle);
|
|
|
+ log.info("文件转换完成");
|
|
|
+
|
|
|
+ // 场景url
|
|
|
+ String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
+ log.info("webSite: {}", webSite);
|
|
|
+
|
|
|
+
|
|
|
+ entity.setWebSite(webSite);
|
|
|
+ sceneService.save(entity);
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success(entity.getWebSite());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -95,14 +99,7 @@ public class ApiController extends BaseController {
|
|
|
public Result getSceneCode() {
|
|
|
String sceneCode = RandomUtils.randowString(9);
|
|
|
sceneCode = "ar_" +sceneCode;
|
|
|
-
|
|
|
- SceneEntity entity = new SceneEntity();
|
|
|
- entity.setSceneCode(sceneCode);
|
|
|
- entity.setPath(FILE_PATH + sceneCode);
|
|
|
-
|
|
|
- sceneService.save(entity);
|
|
|
-
|
|
|
- return Result.success(entity.getSceneCode());
|
|
|
+ return Result.success(sceneCode);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -113,8 +110,8 @@ public class ApiController extends BaseController {
|
|
|
SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
assert entity != null;
|
|
|
|
|
|
- Object webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
- return Result.success(webSite);
|
|
|
+// Object webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
|
|
|
+ return Result.success(entity.getWebSite());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -133,16 +130,52 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 文件转换
|
|
|
+ * @param sceneCode
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void convert(String basePath, String sceneCode, String sceneTitle) throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ // 1. 将XXX_50k.dam写到服务器
|
|
|
+ String resourceUrl = FileUtils.getResourceUrl("data/" + ConstantFileName.modelUUID + "_50k.dam");
|
|
|
+ log.info("_50k.dam path: {}", resourceUrl);
|
|
|
+ // 复制一份
|
|
|
+ FileUtil.copy(resourceUrl, basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam", true);
|
|
|
+
|
|
|
+
|
|
|
+ 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");
|
|
|
+
|
|
|
+ // 3. 生成一个空的data2.js, 里面是一个空的json
|
|
|
+ FileUtil.writeUtf8String("{}",basePath+"/data2.js");
|
|
|
+
|
|
|
+ // 4. 创建someData.json, 修改sid值为场景码目录
|
|
|
+ createSomeData(basePath, sceneCode, sceneTitle);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation("文件转换")
|
|
|
- @GetMapping(value = "convert")
|
|
|
- public Result convert(String sceneCode) throws Exception {
|
|
|
+ @GetMapping(value = "convert/{sceneCode}")
|
|
|
+ public Result convert1(@PathVariable String sceneCode) throws Exception {
|
|
|
SceneEntity entity = sceneService.findBySceneCode(sceneCode);
|
|
|
assert entity != null;
|
|
|
String basePath = entity.getPath();
|
|
|
log.info("filePath: {}", basePath);
|
|
|
|
|
|
// 1. 将XXX_50k.dam写到服务器
|
|
|
- FileUtils.fielWrite("", basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
+// FileUtils.fielWrite("", basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
+ String resourceUrl = FileUtils.getResourceUrl(ConstantFileName.modelUUID + "_50k.dam");
|
|
|
+ FileUtil.writeUtf8String(resourceUrl, basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
|
|
|
|
|
|
if(!FileUtil.exist(basePath+"/vision.txt")){
|
|
@@ -157,7 +190,8 @@ public class ApiController extends BaseController {
|
|
|
FileUtil.writeUtf8String("{}",basePath+"/data2.js");
|
|
|
|
|
|
// 4. 创建someData.json, 修改sid值为场景码目录
|
|
|
- createSomeData(basePath, sceneCode);
|
|
|
+ String sceneTitle = "1111111111111";
|
|
|
+ createSomeData(basePath, sceneCode, sceneTitle);
|
|
|
|
|
|
return Result.success();
|
|
|
}
|
|
@@ -173,7 +207,7 @@ public class ApiController extends BaseController {
|
|
|
/**
|
|
|
* 创建someData.json
|
|
|
*/
|
|
|
- public static void createSomeData(String basePath, String sceneCode) throws FileNotFoundException {
|
|
|
+ private static void createSomeData(String basePath, String sceneCode, String sceneTitle) throws IOException {
|
|
|
log.info("run createSomeData" );
|
|
|
String path = ResourceUtils.getURL("classpath:").getPath();
|
|
|
path = path + "data/someData.json";
|
|
@@ -181,23 +215,46 @@ public class ApiController extends BaseController {
|
|
|
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);
|
|
|
|
|
|
+
|
|
|
FileUtil.writeUtf8String(jsonObject.toJSONString(), basePath+"/someData.json");
|
|
|
log.info("end createSomeData" );
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws FileNotFoundException {
|
|
|
-// String path = ResourceUtils.getURL("classpath:").getPath();
|
|
|
-// System.out.println(path);
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+// createSomeData("F:\\test\\army\\convert\\", "1111111");
|
|
|
+// updateImagesData("33333");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建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);
|
|
|
|
|
|
-// this.class.getResourceAsStream("/com/test/demo/test.properties")
|
|
|
+ JSONArray imagesArray = new JSONArray();
|
|
|
+ imagesArray.set(0, imageObject);
|
|
|
|
|
|
+ return imagesArray;
|
|
|
}
|
|
|
|
|
|
|