|
@@ -1550,170 +1550,17 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
@Override
|
|
@Override
|
|
public ResultData addMosaics(BaseDataParamVO param) throws Exception {
|
|
public ResultData addMosaics(BaseDataParamVO param) throws Exception {
|
|
|
|
|
|
- JSONArray mosaicArr = JSONArray.parseArray(param.getData());
|
|
|
|
- if (CollUtil.isEmpty(mosaicArr) || mosaicArr.size() > 1) {
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
|
- }
|
|
|
|
- JSONObject mosicObj= mosaicArr.getJSONObject(0);
|
|
|
|
-
|
|
|
|
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
|
- if(Objects.isNull(scenePlus)){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
|
- }
|
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
|
- SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
|
|
|
|
- SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
|
-
|
|
|
|
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum());
|
|
|
|
- String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, param.getNum());
|
|
|
|
-
|
|
|
|
- String path = scenePlusExt.getDataSource();
|
|
|
|
- if(StrUtil.isNotEmpty(path) && path.startsWith("http")){
|
|
|
|
- path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
|
|
|
|
- }
|
|
|
|
- String target = path + "_roi";
|
|
|
|
-
|
|
|
|
- cn.hutool.core.io.FileUtil.del(target);
|
|
|
|
-
|
|
|
|
- //文件上传的位置可以自定义
|
|
|
|
- String filePath = target + File.separator + "extras" + File.separator + "images/";
|
|
|
|
- File imageFile = new File(filePath);
|
|
|
|
- if(!imageFile.getParentFile().exists()){
|
|
|
|
- imageFile.getParentFile().mkdirs();
|
|
|
|
- }
|
|
|
|
- FileUtils.copyFolderAllFiles(path + "/caches/images/", filePath, true);
|
|
|
|
-
|
|
|
|
- String mosaicData = sceneEditInfoExt.getMosaics();
|
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
|
- if(StrUtil.isNotEmpty(mosaicData)){
|
|
|
|
- jsonArray = JSONArray.parseArray(mosaicData);
|
|
|
|
- }
|
|
|
|
- jsonArray.add(mosicObj);
|
|
|
|
-
|
|
|
|
- // 准备算法数据
|
|
|
|
- List<JSONObject> mosaicsList = new ArrayList<>();
|
|
|
|
- for(int i = 0, len = jsonArray.size(); i < len; i++){
|
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
- boolean contains = false;
|
|
|
|
- for (JSONObject item : mosaicsList) {
|
|
|
|
- if(StringUtils.equals(item.getString("panoId"),jsonObject.getString("panoId"))){
|
|
|
|
- contains = true;
|
|
|
|
- item.getJSONArray("rect").addAll(jsonObject.getJSONArray("rect"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(!contains){
|
|
|
|
- mosaicsList.add(jsonObject);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- JSONObject roiImageJSon = new JSONObject();
|
|
|
|
- roiImageJSon.put("batch",mosaicsList);
|
|
|
|
-
|
|
|
|
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "image-ROI.json", JSON.toJSONString(roiImageJSon,SerializerFeature.DisableCircularReferenceDetect));
|
|
|
|
-
|
|
|
|
- FileUtils.copyFile(path + File.separator + "results/vision.txt", target + File.separator+"extras/vision.txt", true);
|
|
|
|
- FileUtils.copyFile(path + File.separator + "results/vision2.txt", target + File.separator+"extras/vision2.txt", true);
|
|
|
|
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
|
|
|
|
- String data = FileUtils.readFile(target + File.separator+"data.json");
|
|
|
|
- if(data != null){
|
|
|
|
- JSONObject floorplanJson = new JSONObject();
|
|
|
|
- floorplanJson.put("has_source_images", true);
|
|
|
|
- floorplanJson.put("has_vision_txt", true);
|
|
|
|
-
|
|
|
|
- JSONObject dataJson = JSONObject.parseObject(data);
|
|
|
|
- dataJson.put("extras", floorplanJson);
|
|
|
|
- //V5表示不需要生成high,low文件
|
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V6");
|
|
|
|
- if(scenePlusExt.getSceneScheme() == 11){
|
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V7");
|
|
|
|
- }
|
|
|
|
- dataJson.put("split_type", "SPLIT_V18");
|
|
|
|
- //sceneScheme为3切成瓦片图
|
|
|
|
- if(scenePlusExt.getSceneScheme() == 3){
|
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V4");
|
|
|
|
- }
|
|
|
|
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
|
|
|
|
-
|
|
|
|
- //进行计算
|
|
|
|
- log.info("马赛克建模开始, num:{}, path:{}" + param.getNum(), target);
|
|
|
|
- CreateObjUtil.build3dModel2(target , "1");
|
|
|
|
- log.info("马赛克建模结束, num:{}, path:{}" + param.getNum(), target);
|
|
|
|
-
|
|
|
|
- //读取upload文件,检验需要上传的文件是否存在
|
|
|
|
- String uploadJsonPath = target + File.separator + "results" + File.separator + "upload.json";
|
|
|
|
- boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
|
|
|
|
- if(!exist){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
|
|
|
|
- }
|
|
|
|
- String uploadData = FileUtils.readFile(target + File.separator + "results" + File.separator + "upload.json");
|
|
|
|
- JSONObject uploadJson = JSONObject.parseObject(uploadData);
|
|
|
|
- JSONArray array = uploadJson.getJSONArray("upload");
|
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
|
- JSONObject fileJson = null;
|
|
|
|
- String fileName = "";
|
|
|
|
- for(int i = 0, len = array.size(); i < len; i++){
|
|
|
|
- fileJson = array.getJSONObject(i);
|
|
|
|
- fileName = fileJson.getString("file");
|
|
|
|
- //文件不存在抛出异常
|
|
|
|
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
|
|
|
|
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //high文件夹
|
|
|
|
- if(fileJson.getIntValue("clazz") == 3){
|
|
|
|
- map.put(target + File.separator + "results" +File.separator+ fileName,
|
|
|
|
- imgViewPath + "pan/high/"+ fileName.replace("high/", ""));
|
|
|
|
- }
|
|
|
|
- //low文件夹
|
|
|
|
- if(fileJson.getIntValue("clazz") == 4){
|
|
|
|
- map.put(target + File.separator + "results" +File.separator+ fileName,
|
|
|
|
- imgViewPath + "pan/low/"+ fileName.replace("low/", ""));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
|
|
|
|
- if(fileJson.getIntValue("clazz") == 5){
|
|
|
|
- map.put(target + File.separator + "results" + File.separator+ fileName,
|
|
|
|
- imgViewPath + fileName);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //tiles文件夹,亚马逊瓦片图
|
|
|
|
- if(fileJson.getIntValue("clazz") == 7 ){
|
|
|
|
- map.put(target + File.separator + "results" + File.separator+ fileName,
|
|
|
|
- imgViewPath + fileName);
|
|
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(param.getData());
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject mosaic = (JSONObject) o;
|
|
|
|
+ String panoId = mosaic.getString("panoId");
|
|
|
|
+ if(StrUtil.isEmpty(panoId)){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
}
|
|
}
|
|
|
|
+ map.put(panoId, JSON.toJSONString(mosaic));
|
|
}
|
|
}
|
|
-
|
|
|
|
- for(String imagesName : imageFile.list()){
|
|
|
|
- //覆盖原始图片资源
|
|
|
|
- FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
|
|
|
|
- path + File.separator + "caches/images/" + imagesName, true);
|
|
|
|
- FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- uploadToOssUtil.uploadMulFiles(map);
|
|
|
|
-
|
|
|
|
- this.upgradeVersionById(sceneEditInfo.getId());
|
|
|
|
-
|
|
|
|
- sceneEditInfoExt.setMosaics(JSON.toJSONString(jsonArray,SerializerFeature.DisableCircularReferenceDetect));
|
|
|
|
- sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
|
-
|
|
|
|
- // 更新 scene.json
|
|
|
|
- String sceneJsonPath = dataViewPath + "scene.json";
|
|
|
|
- String sceneJson = uploadToOssUtil.getObjectContent(this.bucket, sceneJsonPath);
|
|
|
|
- JSONObject scenejson = new JSONObject();
|
|
|
|
- if(StrUtil.isNotEmpty(sceneJson)) {
|
|
|
|
- scenejson = JSONObject.parseObject(sceneJson);
|
|
|
|
- }
|
|
|
|
- scenejson.put("mosaics",JSON.toJSONString(jsonArray, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
|
- Integer version = scenejson.getIntValue("version");
|
|
|
|
- version = Objects.isNull(version) ? 1 : version + 1;
|
|
|
|
- scenejson.put("version", version);
|
|
|
|
- uploadToOssUtil.upload(scenejson.toJSONString().getBytes(), sceneJsonPath);
|
|
|
|
-
|
|
|
|
- Map<String,Object> result = new HashMap<>(1);
|
|
|
|
- result.put("mosaics",jsonArray);
|
|
|
|
|
|
+ redisUtil.hmset(RedisKey.SCENE_MOSAIC_DATA, map);
|
|
|
|
|
|
return ResultData.ok(result);
|
|
return ResultData.ok(result);
|
|
}
|
|
}
|