|
@@ -4,6 +4,8 @@ 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.constant.TypeCode;
|
|
|
+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;
|
|
@@ -12,17 +14,21 @@ import com.gis.common.util.RandomUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.domain.entity.SceneEntity;
|
|
|
import com.gis.service.SceneService;
|
|
|
+import com.gis.web.shiro.JwtUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.hibernate.event.spi.SaveOrUpdateEvent;
|
|
|
import org.junit.Test;
|
|
|
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 java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -41,7 +47,18 @@ public class ApiController extends BaseController {
|
|
|
|
|
|
@ApiOperation("Map表单上传多文件,指定保存路径,需要用postman测试")
|
|
|
@PostMapping("uploads")
|
|
|
- public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneTitle, String sceneCode) throws Exception {
|
|
|
+ public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneTitle, String sceneCode, HttpServletRequest request) throws Exception {
|
|
|
+ String token = request.getHeader("token");
|
|
|
+ if (token == null) {
|
|
|
+ log.error("token header is null");
|
|
|
+ return Result.failure("token header is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean verify = JwtUtil.isVerify(token, TypeCode.TOKEN_API_KEY);
|
|
|
+ if (!verify) {
|
|
|
+ log.error("api token 无效");
|
|
|
+ return Result.failure("token 无效");
|
|
|
+ }
|
|
|
|
|
|
param.forEach((path, file)->{
|
|
|
|
|
@@ -71,12 +88,20 @@ public class ApiController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
- // 调用算法图片转换
|
|
|
+ // 调用算法切图片转换
|
|
|
String cmd = ConstantCmd.SLICE_SKYBOX + entity.getPath();
|
|
|
log.info("cmd:{}", cmd);
|
|
|
CreateObjUtil.callshell(cmd);
|
|
|
log.info("算法切片完成");
|
|
|
|
|
|
+
|
|
|
+ // 调用算法将obj转txt
|
|
|
+ String objCmd = ConstantCmd.OBJ_TO_TXT + entity.getPath();
|
|
|
+ log.info("objCmd:{}", objCmd);
|
|
|
+ CreateObjUtil.callshell(objCmd);
|
|
|
+ log.info("算法obj转txt完成");
|
|
|
+
|
|
|
+
|
|
|
// 转换文件
|
|
|
convert(entity.getPath(), sceneCode, sceneTitle);
|
|
|
log.info("文件转换完成");
|
|
@@ -94,12 +119,30 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testToken(){
|
|
|
+ String token = JwtUtil.createJWT(TOKEN_EXPIRE, TypeCode.TOKEN_API_KEY);
|
|
|
+ System.out.println(token);
|
|
|
+
|
|
|
+ System.out.println(JwtUtil.isVerify(null, "123"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation("获取场景码")
|
|
|
@GetMapping("getSceneCode")
|
|
|
public Result getSceneCode() {
|
|
|
String sceneCode = RandomUtils.randowString(9);
|
|
|
sceneCode = "ar_" +sceneCode;
|
|
|
- return Result.success(sceneCode);
|
|
|
+
|
|
|
+ // 创建token,过期24h,
|
|
|
+ String token = JwtUtil.createJWT(TOKEN_EXPIRE, TypeCode.TOKEN_API_KEY);
|
|
|
+
|
|
|
+ HashMap<Object, Object> reuslt = new HashMap<>();
|
|
|
+ reuslt.put("sceneCode", sceneCode);
|
|
|
+ reuslt.put("token", token);
|
|
|
+
|
|
|
+ return Result.success(reuslt);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -110,7 +153,6 @@ 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(entity.getWebSite());
|
|
|
}
|
|
|
|
|
@@ -137,12 +179,8 @@ public class ApiController extends BaseController {
|
|
|
*/
|
|
|
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);
|
|
|
+ // 将result文件夹的upload.json是否存在,并处理业务逻辑
|
|
|
+ checkUploadJson(basePath);
|
|
|
|
|
|
|
|
|
if(!FileUtil.exist(basePath+"/vision.txt")){
|
|
@@ -164,37 +202,37 @@ public class ApiController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("文件转换")
|
|
|
- @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");
|
|
|
- String resourceUrl = FileUtils.getResourceUrl(ConstantFileName.modelUUID + "_50k.dam");
|
|
|
- FileUtil.writeUtf8String(resourceUrl, basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
-
|
|
|
-
|
|
|
- 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值为场景码目录
|
|
|
- String sceneTitle = "1111111111111";
|
|
|
- createSomeData(basePath, sceneCode, sceneTitle);
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
+// @ApiOperation("文件转换")
|
|
|
+// @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");
|
|
|
+// String resourceUrl = FileUtils.getResourceUrl(ConstantFileName.modelUUID + "_50k.dam");
|
|
|
+// FileUtil.writeUtf8String(resourceUrl, basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
+//
|
|
|
+//
|
|
|
+// 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值为场景码目录
|
|
|
+// String sceneTitle = "1111111111111";
|
|
|
+// createSomeData(basePath, sceneCode, sceneTitle);
|
|
|
+//
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
|
|
|
|
|
|
@Test
|
|
@@ -235,8 +273,12 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
-// createSomeData("F:\\test\\army\\convert\\", "1111111");
|
|
|
-// updateImagesData("33333");
|
|
|
+ String path = "F:\\test\\army\\upload.json";
|
|
|
+
|
|
|
+ String suffix = StringUtils.substringAfterLast(path, ".");
|
|
|
+ System.out.println(suffix);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -257,6 +299,52 @@ public class ApiController extends BaseController {
|
|
|
return imagesArray;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查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转换完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|