|
@@ -2,6 +2,7 @@ package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.RuntimeUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -10,12 +11,9 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fdkankan.common.constant.CommonStatus;
|
|
|
+import com.fdkankan.common.constant.*;
|
|
|
import com.fdkankan.model.constants.ConstantFileName;
|
|
|
import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
-import com.fdkankan.common.constant.ErrorCode;
|
|
|
-import com.fdkankan.common.constant.FileBizType;
|
|
|
-import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
@@ -707,29 +705,12 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
String bucket = scenePlusExt.getYunFileBucket();
|
|
|
|
|
|
- //文件上传的位置可以自定义
|
|
|
- String path = scenePlusExt.getDataSource() + "_obj2txt";
|
|
|
- String zipPath = path + "/zip/";
|
|
|
- String filePath = path + "/extras/";
|
|
|
- String resultPath = path + "/results/";
|
|
|
-
|
|
|
- //压缩文件处理:解压缩,解压缩后复制等操作
|
|
|
- this.objAndImgFileHandler(resultPath, filePath, zipPath, file);
|
|
|
-
|
|
|
- //创建data.json
|
|
|
- this.writeDataJson(path);
|
|
|
-
|
|
|
- //调用算法,不同的类型调用不同的算法
|
|
|
- if("V2".equals(scenePlusExt.getBuildType())){
|
|
|
- CreateObjUtil.objToTxt(path , "1");
|
|
|
- }
|
|
|
- if("V3".equals(scenePlusExt.getBuildType())){
|
|
|
- CreateObjUtil.build3dModel(path , "1");
|
|
|
+ if(ModelKind.THREE_D_TILE.code().equals(scenePlusExt.getModelKind())){
|
|
|
+ this.buildModel43dtiles(num, bucket, scenePlusExt.getDataSource(), file);
|
|
|
+ }else{
|
|
|
+ this.buildModel4Dam(num, bucket, scenePlusExt.getDataSource(), scenePlusExt.getBuildType(), file);
|
|
|
}
|
|
|
|
|
|
- //算法计算完后,生成压缩文件,上传到oss
|
|
|
- this.uploadFileofterRebuildPanoram(path, num, bucket);
|
|
|
-
|
|
|
//更新版本信息
|
|
|
SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
if(Objects.isNull(sceneEditInfo)){
|
|
@@ -754,6 +735,111 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 老算法(dam)上传模型逻辑
|
|
|
+ * @param num
|
|
|
+ * @param bucket
|
|
|
+ * @param dataSource
|
|
|
+ * @param buildType
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void buildModel4Dam(String num, String bucket, String dataSource, String buildType, MultipartFile file) throws Exception {
|
|
|
+ //文件上传的位置可以自定义
|
|
|
+ String path = dataSource + "_obj2txt";
|
|
|
+ String zipPath = path + "/zip/";
|
|
|
+ String filePath = path + "/extras/";
|
|
|
+ String resultPath = path + "/results/";
|
|
|
+
|
|
|
+ //压缩文件处理:解压缩,解压缩后复制等操作
|
|
|
+ this.objAndImgFileHandler(resultPath, filePath, zipPath, file);
|
|
|
+
|
|
|
+ //创建data.json
|
|
|
+ this.writeDataJson(path);
|
|
|
+
|
|
|
+ //调用算法,不同的类型调用不同的算法
|
|
|
+ if("V2".equals(buildType)){
|
|
|
+ CreateObjUtil.objToTxt(path , "1");
|
|
|
+ }
|
|
|
+ if("V3".equals(buildType)){
|
|
|
+ CreateObjUtil.build3dModel(path , "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ //算法计算完后,生成压缩文件,上传到oss
|
|
|
+ this.uploadFileofterRebuildPanoram(path, num, bucket);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新算法(3dtiles)上传模型逻辑
|
|
|
+ * @param num
|
|
|
+ * @param bucket
|
|
|
+ * @param dataSource
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void buildModel43dtiles(String num, String bucket, String dataSource, MultipartFile file) throws Exception {
|
|
|
+ //文件上传的位置可以自定义
|
|
|
+ String path = dataSource + "_obj2Tiles" + File.separator;
|
|
|
+ String meshPath = path + "mesh";
|
|
|
+ String zipPath = path + "zip" + File.separator;
|
|
|
+ String zipFilePath = zipPath + file.getOriginalFilename();
|
|
|
+
|
|
|
+
|
|
|
+ //压缩文件处理:解压缩,解压缩后复制等操作
|
|
|
+ FileUtil.del(path);
|
|
|
+ FileUtil.mkdir(zipPath);
|
|
|
+ File zipFile = new File(zipFilePath);
|
|
|
+ file.transferTo(zipFile);
|
|
|
+ ZipUtil.unzip(zipFilePath, meshPath);
|
|
|
+
|
|
|
+ //检测文件
|
|
|
+ String floorsJsonPath = meshPath + File.separator + "floors.json";
|
|
|
+ if(FileUtil.exist(floorsJsonPath)){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5068);
|
|
|
+ }
|
|
|
+ String floorsJsonStr = FileUtil.readUtf8String(floorsJsonPath);
|
|
|
+ JSONObject floorsJsonObj = JSON.parseObject(floorsJsonStr);
|
|
|
+ JSONArray floorArr = floorsJsonObj.getJSONArray("floors");
|
|
|
+ if(CollUtil.isEmpty(floorArr)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5069);
|
|
|
+ }
|
|
|
+ floorArr.stream().forEach(item->{
|
|
|
+ JSONObject itemObj = (JSONObject) item;
|
|
|
+ //楼层目录是否存在
|
|
|
+ String name = itemObj.getString("name");
|
|
|
+ if(StrUtil.isEmpty(name) || !FileUtil.exist(meshPath + File.separator + name)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
|
|
|
+ }
|
|
|
+ //检测obj文件是否存在
|
|
|
+ String objPath = itemObj.getString("objPath");
|
|
|
+ if(StrUtil.isEmpty(objPath) || FileUtil.exist(path + objPath)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //调用算法
|
|
|
+ String command = "bash Obj2Tiles.sh " + path;
|
|
|
+ log.info("上传3dtiles模型开始, num:{}, targetPath:{}", num, path);
|
|
|
+ RuntimeUtil.exec(command);
|
|
|
+ log.info("上传3dtiles模型结束, num:{}, targetPath:{}", num, path);
|
|
|
+
|
|
|
+ //检测计算结果
|
|
|
+ String tilesPath = path + "3dtiles";
|
|
|
+ String tilesetJsonPath = tilesPath + File.separator + "tileset.json";
|
|
|
+ boolean success = ComputerUtil.checkComputeCompleted(tilesetJsonPath, maxCheckTimes, waitTime);
|
|
|
+ if(!success){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除logs
|
|
|
+ FileUtil.del(tilesPath + File.separator + "logs");
|
|
|
+
|
|
|
+ //算法计算完后,生成压缩文件,上传到oss
|
|
|
+ //上传3dtiles
|
|
|
+ fYunFileService.uploadFileByCommand(bucket, tilesPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "3dtiles");
|
|
|
+ //上传mesh
|
|
|
+ fYunFileService.uploadFileByCommand(bucket, meshPath, String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void uploadFileofterRebuildPanoram(String path, String sceneNum, String bucket) throws Exception {
|
|
|
//因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
|
|
|
String uploadJsonPath = path + File.separator + "results" +File.separator+"upload.json";
|
|
@@ -919,6 +1005,43 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
|
|
|
SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
|
|
|
+ if(ModelKind.THREE_D_TILE.code().equals(scenePlusExt.getModelKind())){
|
|
|
+ return this.downloadModel43dtiles(num, bucket, scenePlusExt, sceneEditInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.downloadModel4Dam(num, bucket, scenePlusExt, sceneEditInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScenePro getByNum(String num) {
|
|
|
+ return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultData downloadModel43dtiles(String num, String bucket, ScenePlusExt scenePlusExt, SceneEditInfo sceneEditInfo){
|
|
|
+
|
|
|
+ //下载mesh到本地
|
|
|
+ String meshOssPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh";
|
|
|
+ String meshLocalPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "mesh";
|
|
|
+ String zipName = num + "_mesh.zip";
|
|
|
+ String zipFilePath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + zipName;
|
|
|
+ //下载
|
|
|
+ fYunFileService.downloadFileByCommand(bucket, meshLocalPath, meshOssPath);
|
|
|
+ //打包
|
|
|
+ ZipUtil.zip(meshLocalPath,zipFilePath);
|
|
|
+ //上传压缩包
|
|
|
+ fYunFileService.uploadFile(bucket, zipFilePath, "downloads/extras/" + zipName);
|
|
|
+ String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
+ return ResultData.ok(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ ZipUtil.zip("C:\\Users\\dsx\\Desktop\\新建文件夹\\temp\\mesh\\aaa\\mesh", "C:\\Users\\dsx\\Desktop\\新建文件夹\\temp\\mesh\\aaa\\mesh\\mesh.zip");
|
|
|
+ System.out.println(123);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ResultData downloadModel4Dam(String num, String bucket, ScenePlusExt scenePlusExt, SceneEditInfo sceneEditInfo){
|
|
|
String localImagePath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
|
|
|
if(!new File(localImagePath).exists()){
|
|
|
new File(localImagePath).mkdirs();
|
|
@@ -931,8 +1054,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
String zipPath = localImagePath + zipName;
|
|
|
//如果用户上传过模型,就打包上传到oss,直接返回
|
|
|
if(CommonStatus.YES.code().equals(sceneEditInfo.getIsUploadObj())
|
|
|
- && new File(newData).exists()
|
|
|
- && new File(newResultData).exists()){
|
|
|
+ && new File(newData).exists()
|
|
|
+ && new File(newResultData).exists()){
|
|
|
//打包
|
|
|
ZipUtil.zip(newData, zipPath);
|
|
|
//上传压缩包
|
|
@@ -959,11 +1082,11 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
if(file.isDirectory()){
|
|
|
for (File item : file.listFiles()) {
|
|
|
if(item.getName().endsWith(".obj") && !"output.house.obj".equals(item.getName()) &&
|
|
|
- !"mesh.obj".equals(item.getName())){
|
|
|
+ !"mesh.obj".equals(item.getName())){
|
|
|
item.delete();
|
|
|
}
|
|
|
if(item.getName().endsWith(".mtl") && !"output.house.mtl".equals(item.getName()) &&
|
|
|
- !"mesh.mtl".equals(item.getName())){
|
|
|
+ !"mesh.mtl".equals(item.getName())){
|
|
|
item.delete();
|
|
|
}
|
|
|
}
|
|
@@ -1034,9 +1157,4 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
return ResultData.ok(url);
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public ScenePro getByNum(String num) {
|
|
|
- return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
|
|
|
- }
|
|
|
}
|