BuildReverseE57SceneServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import cn.hutool.extra.qrcode.QrCodeUtil;
  6. import cn.hutool.extra.qrcode.QrConfig;
  7. import cn.hutool.http.HttpUtil;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  11. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  12. import com.fdkankan.common.constant.*;
  13. import com.fdkankan.common.util.FileUtils;
  14. import com.fdkankan.contro.constant.UserEditDataType;
  15. import com.fdkankan.contro.entity.*;
  16. import com.fdkankan.contro.mq.service.IBuildSceneService;
  17. import com.fdkankan.contro.service.*;
  18. import com.fdkankan.fyun.config.FYunFileConfig;
  19. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  20. import com.fdkankan.model.constants.ConstantFileName;
  21. import com.fdkankan.model.constants.ConstantFilePath;
  22. import com.fdkankan.model.constants.UploadFilePath;
  23. import com.fdkankan.model.enums.ModelTypeEnums;
  24. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  25. import com.fdkankan.model.utils.CreateObjUtil;
  26. import com.fdkankan.model.utils.SceneUtil;
  27. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  28. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  29. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.apache.commons.lang3.ObjectUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Value;
  34. import org.springframework.cloud.context.config.annotation.RefreshScope;
  35. import org.springframework.stereotype.Service;
  36. import javax.annotation.Resource;
  37. import java.io.File;
  38. import java.io.IOException;
  39. import java.nio.charset.StandardCharsets;
  40. import java.util.*;
  41. /**
  42. * <p>
  43. * TODO
  44. * </p>
  45. *
  46. * @author dengsixing
  47. * @since 2022/4/20
  48. **/
  49. @Slf4j
  50. @Service
  51. @RefreshScope
  52. public class BuildReverseE57SceneServiceImpl implements IBuildSceneService {
  53. public static final String logUrlFormat = "**algorithm-log**: [%sbuild_log/%s/e57/console.log](%sbuild_log/%s/e57/console.log)";
  54. @Value("${queue.modeling.reverseE57.modeling-post:reverseE57-modeling-post}")
  55. private String queueModelingPost;
  56. @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
  57. private List<String> notDeleteNasNumList;
  58. @Value("${queue.application.laser.e57-modeling-done:e57-modeling-done}")
  59. private String queueE57ModelingDone;
  60. @Autowired
  61. private RabbitMqProducer mqProducer;
  62. @Value("${model.type:#{null}}")
  63. private String modelType;
  64. @Resource
  65. private FYunFileServiceInterface fYunFileService;
  66. @Autowired
  67. private FYunFileConfig fYunFileConfig;
  68. @Autowired
  69. private IScenePlusService scenePlusService;
  70. @Autowired
  71. private IScenePlusExtService scenePlusExtService;
  72. @Autowired
  73. private IBuildSceneDTService buildSceneDTService;
  74. @Autowired
  75. private ICommonService commonService;
  76. @Autowired
  77. private IFdkkLaserService fdkkLaserService;
  78. @Autowired
  79. private ISceneEditControlsService sceneEditControlsService;
  80. @Autowired
  81. private IBuildService buildService;
  82. @Value("${main.url}")
  83. private String mainUrl;
  84. @Override
  85. public void buildScenePre(BuildSceneCallMessage message) throws Exception{
  86. String num = message.getSceneNum();
  87. Integer rebuild = (Integer)message.getExt().get("rebuild");
  88. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  89. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  90. try {
  91. String dataSource = scenePlusExt.getDataSource();
  92. String homePath = SceneUtil.getHomePath(dataSource);
  93. message.setPath(dataSource);
  94. String homeKey = homePath + "input.e57";
  95. if(Objects.isNull(rebuild) || rebuild == CommonStatus.NO.code().intValue()){
  96. String path = (String)message.getExt().get("path");
  97. //复制原始资源到home目录
  98. fYunFileService.copyFileInBucket(path, homeKey);
  99. //删除临时文件
  100. fYunFileService.deleteFile(path);
  101. }
  102. //删除点位校准数据
  103. if (message.getExt().containsKey("deleteExtras")
  104. && (Boolean) message.getExt().get("deleteExtras")) {
  105. String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
  106. if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
  107. fYunFileService.deleteFolder(extras);
  108. }
  109. }
  110. //下载资源到本地
  111. String destPath = dataSource + "/capture/";
  112. fYunFileService.downloadFileByCommand(destPath, homeKey);
  113. List<File> files = FileUtil.loopFiles(dataSource + "/capture/");
  114. files.stream().forEach(file->{
  115. if(file.getAbsolutePath().endsWith(".e57")){
  116. FileUtil.rename(file, "input.e57", true);
  117. }
  118. });
  119. //发送mq,就进行计算
  120. // message.setPath(path);
  121. message.setResultReceiverMqName(queueModelingPost);
  122. message.setBizType("reverseE57");
  123. String splitType = "SPLIT_V29";
  124. String skyboxType = "SKYBOX_V11";
  125. String otherType = (String)message.getExt().get("otherType");
  126. Integer isObj = (Integer) message.getExt().get("isObj");
  127. if(StrUtil.isNotEmpty(modelType) && ModelTypeEnums.TILE_CODE.equals(modelType)){
  128. skyboxType = "SKYBOX_V15";
  129. }
  130. if(Objects.nonNull(isObj) && isObj == CommonStatus.YES.code().intValue()){
  131. splitType = "SPLIT_V30";
  132. }
  133. this.createProjectAndDataFile(message.getPath(), num, splitType, skyboxType,otherType,null,null);
  134. log.info("上传e57计算资源准备结束,场景码:{}", message.getSceneNum());
  135. }catch (Exception e){
  136. log.error("上传e57计算前置处理出错,num"+num, e);
  137. scenePlus.setSceneStatus(CommonSuccessStatus.FAIL.code());
  138. scenePlusService.updateById(scenePlus);
  139. fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt, null);
  140. buildSceneDTService.handBaseFail("上传e57计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  141. throw e;
  142. }
  143. }
  144. public void createProjectAndDataFile(String path, String sceneNum, String splitType, String skyboxType, String otherType, Map<String, Object> projectExtras, Map<String, Object> dataExtras) {
  145. JSONObject projectJson = new JSONObject();
  146. if (!org.apache.commons.lang3.ObjectUtils.isEmpty(projectExtras)) {
  147. projectJson.putAll(projectExtras);
  148. }
  149. projectJson.put("sceneNum", sceneNum);
  150. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  151. JSONObject dataJson = new JSONObject();
  152. if (!org.apache.commons.lang3.ObjectUtils.isEmpty(dataExtras)) {
  153. dataJson.putAll(dataExtras);
  154. }
  155. dataJson.put("split_type", splitType);
  156. dataJson.put("skybox_type", skyboxType);
  157. dataJson.put("extras", (Object)null);
  158. dataJson.put("other_type", otherType);
  159. FileUtils.writeFile(path + File.separator + "data.json", dataJson.toString());
  160. }
  161. private String getOssPath(String path) {
  162. String ossPath = ConstantFilePath.OSS_PREFIX
  163. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  164. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  165. if (!ossPath.endsWith("/")) {
  166. ossPath = ossPath.concat("/");
  167. }
  168. return ossPath;
  169. }
  170. @Override
  171. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  172. String ossPath = getOssPath(buildSceneMqMessage.getPath());
  173. fYunFileService.downloadFileByCommand(path + "/capture", ossPath);
  174. }
  175. @Override
  176. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  177. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  178. String path = message.getPath();
  179. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  180. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  181. try {
  182. // 上传计算日志
  183. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  184. log.info("开始上传计算日志");
  185. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  186. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  187. log.info("计算日志上传完成");
  188. if (!message.getBuildSuccess()) {
  189. log.error("建模失败,修改状态为失败状态");
  190. scenePlus.setSceneStatus(CommonSuccessStatus.FAIL.code());
  191. scenePlusService.updateById(scenePlus);
  192. fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt, null);
  193. // 发送钉钉消息,计算失败
  194. buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
  195. return;
  196. }
  197. Integer isObj = scenePlusExt.getIsObj();
  198. JSONObject fdageData = new JSONObject();
  199. if(isObj == CommonStatus.YES.code().intValue()){
  200. fdageData.put("exportMeshObj", 1);
  201. }
  202. Map<String, String> uploadFiles = commonService.getUploadFiles(scenePlus,path,14,fdageData);
  203. String rebuild = message.getRebuild();
  204. //新拍场景默认是已支付状态,补拍、重算的场景,支付状态无需改变
  205. if("0".equals(rebuild)){
  206. log.info("是新拍");
  207. scenePlus.setPayStatus(PayStatus.PAY.code());
  208. }
  209. scenePlus.setUpdateTime(new Date());
  210. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  211. // Integer videoVersion = fdageData.getInteger("videoVersion");
  212. // //读取计算结果文件生成videosJson
  213. // JSONObject videosJson = null;
  214. //上传全景图俯视图
  215. this.uploadFloorCad(path, sceneCode, uploadFiles);
  216. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  217. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  218. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  219. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ModelKind.THREE_D_TILE.code());
  220. //上传文件
  221. fYunFileService.uploadMulFiles(uploadFiles);
  222. //修改oss上dam的内容编码
  223. Map<String,String> damFileHeaders = new HashMap<>();
  224. damFileHeaders.put("Content-Encoding","gzip");
  225. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  226. fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  227. //拷贝部分文件到编辑目录,用于用户编辑
  228. this.copyToEditDir(sceneCode);
  229. //计算完毕后,同步全景图到缓存目录
  230. // this.cachePanorama(path, sceneCode);
  231. //生成houseTypejson并上传
  232. boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  233. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  234. //生成floorpan.json
  235. commonService.uploadFloorplanJson(sceneCode, path);
  236. //重置异步操作记录
  237. commonService.removeSceneAsynOperLog(sceneCode);
  238. //清除用户编辑业务数据
  239. Set<String> bizs = new HashSet<>();
  240. bizs.add(UserEditDataType.BOX_MODEL.message());
  241. bizs.add(UserEditDataType.FLOORPLAN.message());
  242. bizs.add(UserEditDataType.FILTERS.message());
  243. commonService.initUserEditData(sceneCode, bizs, null);
  244. //上传计算结果文件
  245. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  246. //容量统计
  247. Long space = commonService.getSpace(sceneCode);
  248. //写入数据库
  249. this.updateDbPlus(scenePlus.getSceneSource(), space, null, message.getComputeTime(),isObj,scenePlusExt);
  250. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  251. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  252. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  253. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  254. //更新场景主表
  255. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  256. // scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  257. //统计原始资源大小
  258. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  259. scenePlusExt.setWebSite(mainUrl + "/smg.html?m=" + sceneCode);
  260. String visionTxt = FileUtil.readUtf8String(path + "/results/vision.txt");
  261. JSONObject visionObj = JSON.parseObject(visionTxt);
  262. JSONArray sweepLocations = visionObj.getJSONArray("sweepLocations");
  263. scenePlusExt.setShootCount(sweepLocations.size());
  264. String laserPath = fdkkLaserService.syncBuildResult4E57(path);
  265. fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt, laserPath);
  266. sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
  267. .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
  268. sceneEditControls.setShowMap(0);
  269. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  270. //写scene.json
  271. commonService.writeSceneJson(sceneCode,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt, null);
  272. createQrCode(sceneCode, scenePlusExt, null);
  273. this.uploadStatusJson(scenePlus, scenePlusExt);
  274. scenePlusService.updateById(scenePlus);
  275. scenePlusExtService.updateById(scenePlusExt);
  276. if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  277. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  278. }
  279. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  280. }catch (Exception e){
  281. log.error("场景计算结果处理出错,num"+sceneCode, e);
  282. scenePlus.setSceneStatus(CommonSuccessStatus.FAIL.code());
  283. scenePlusService.updateById(scenePlus);
  284. fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt, null);
  285. buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  286. throw e;
  287. }
  288. }
  289. public boolean uploadHouseTypeJson(String num, String dataSource) {
  290. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  291. if (!new File(floorPlanCardFilePath).exists()) {
  292. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  293. return false;
  294. }
  295. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  296. if(Objects.isNull(json)){
  297. return false;
  298. }
  299. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  300. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  301. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  302. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  303. return true;
  304. }
  305. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,Integer isObj,ScenePlusExt scenePlusExt){
  306. scenePlusExt.setSpace(space);
  307. scenePlusExt.setComputeTime(computeTime);
  308. scenePlusExt.setAlgorithmTime(new Date());
  309. scenePlusExt.setVideos(videosJson);
  310. scenePlusExt.setIsObj(isObj);
  311. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  312. scenePlusExt.setSceneScheme(3);
  313. }
  314. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  315. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  316. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  317. scenePlusExt.setSceneKind(sceneKind);
  318. // scenePlusExt.setModelKind(modelKind);
  319. //统计点位数量
  320. scenePlusExtService.updateById(scenePlusExt);
  321. }
  322. private void copyToEditDir(String num) throws IOException {
  323. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  324. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  325. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  326. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  327. Map<String, String> map = new HashMap<>();
  328. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  329. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  330. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  331. for (Map.Entry<String, String> entry : map.entrySet()) {
  332. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  333. }
  334. }
  335. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  336. String localLogoPath = null;
  337. if (!ObjectUtils.isEmpty(qrLogo)) {
  338. try {
  339. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  340. HttpUtil.downloadFile(qrLogo, localLogoPath);
  341. } catch (Exception e) {
  342. log.error("公司logo下载失败:{}", qrLogo);
  343. localLogoPath = null;
  344. }
  345. }
  346. //生成二维码
  347. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  348. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  349. QrConfig qrConfig = QrConfig.create();
  350. qrConfig.setWidth(1024);
  351. qrConfig.setHeight(1024);
  352. if(StrUtil.isNotEmpty(localLogoPath)){
  353. qrConfig.setImg(localLogoPath);
  354. }
  355. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  356. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  357. //上传二维码
  358. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  359. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  360. if(!ObjectUtils.isEmpty(localLogoPath)){
  361. FileUtils.deleteFile(localLogoPath);
  362. }
  363. }
  364. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  365. //户型图上传
  366. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  367. String floorCadPath = path + "/results/floorplan_cad";
  368. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  369. if(CollUtil.isNotEmpty(floorCadList)){
  370. floorCadList.stream().forEach(str->{
  371. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  372. String[] arr = substring.split("floor");
  373. String[] arr2 = arr[1].split("\\.");
  374. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  375. });
  376. }
  377. }
  378. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  379. String num = scenePlus.getNum();
  380. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  381. Integer status = 0;
  382. // 上传status JSON.
  383. JSONObject statusJson = new JSONObject();
  384. //临时将-2改成1,app还没完全更新
  385. statusJson.put("status", status);
  386. statusJson.put("webSite", scenePlusExt.getWebSite());
  387. statusJson.put("sceneNum", num);
  388. statusJson.put("thumb", scenePlusExt.getThumb());
  389. statusJson.put("payStatus", scenePlus.getPayStatus());
  390. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  391. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  392. fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataViewPath + "status.json");
  393. }
  394. private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path) throws Exception {
  395. if (ObjectUtils.isEmpty(scenePlus)) {
  396. throw new Exception("未找到场景信息:" + path);
  397. }
  398. String projectNum = scenePlus.getNum();
  399. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
  400. String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
  401. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
  402. String resultsPath = path + File.separator + "results" + File.separator;
  403. String uploadData = FileUtils.readFile(resultsPath + "upload.json");
  404. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  405. JSONObject fileJson = null;
  406. String fileName = "";
  407. Map<String, String> map = new HashMap();
  408. for (int i = 0; i < array.size(); ++i) {
  409. fileJson = array.getJSONObject(i);
  410. fileName = fileJson.getString("file");
  411. String filePath = resultsPath + fileName;
  412. if (!(new File(filePath)).exists()) {
  413. throw new Exception(filePath + "文件不存在");
  414. }
  415. if ("vision2.txt".equals(fileName)) {
  416. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  417. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  418. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  419. }
  420. if (fileJson.getIntValue("clazz") == 2) {
  421. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  422. } else if (fileJson.getIntValue("clazz") == 3) {
  423. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  424. } else if (fileJson.getIntValue("clazz") == 4) {
  425. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  426. } else if (fileJson.getIntValue("clazz") == 5) {
  427. map.put(filePath, imagesPath + fileName);
  428. } else if (fileJson.getIntValue("clazz") == 7) {
  429. map.put(filePath, imagesPath + fileName);
  430. } else if (fileJson.getIntValue("clazz") == 10) {
  431. String updown = FileUtils.readFile(filePath);
  432. JSONObject updownJson = JSONObject.parseObject(updown);
  433. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  434. map.put(filePath, mappingOssPath);
  435. } else {
  436. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  437. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  438. if (fileName.contains(".mp4")) {
  439. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  440. }
  441. }
  442. if (fileJson.getIntValue("clazz") == 16) {
  443. map.put(filePath, dataViewPath + fileName);
  444. }
  445. if (fileJson.getIntValue("clazz") == 18) {
  446. map.put(filePath, imagesPath + fileName);
  447. }
  448. }
  449. }
  450. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  451. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  452. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  453. log.info("数据转换完成:" + projectNum);
  454. if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
  455. FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  456. }
  457. // map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  458. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  459. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  460. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  461. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  462. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  463. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  464. return map;
  465. }
  466. }