BuildObjServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package com.fdkankan.contro.mq.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.fdkankan.common.util.FileUtils;
  5. import com.fdkankan.contro.entity.ScenePlus;
  6. import com.fdkankan.contro.entity.ScenePro;
  7. import com.fdkankan.contro.entity.SceneProEdit;
  8. import com.fdkankan.contro.mq.service.IBuildSceneService;
  9. import com.fdkankan.contro.service.*;
  10. import com.fdkankan.contro.service.impl.FdkkV4Service;
  11. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  12. import com.fdkankan.model.constants.ConstantFileName;
  13. import com.fdkankan.model.constants.ConstantFilePath;
  14. import com.fdkankan.model.constants.UploadFilePath;
  15. import com.fdkankan.model.utils.CreateObjUtil;
  16. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  17. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  18. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.util.ObjectUtils;
  24. import java.io.File;
  25. /**
  26. * <p>
  27. * TODO
  28. * </p>
  29. *
  30. * @author dengsixing
  31. * @since 2022/3/1
  32. **/
  33. @Slf4j
  34. @Service
  35. public class BuildObjServiceImpl implements IBuildSceneService {
  36. @Value("${queue.modeling.modeling-call}")
  37. private String queueModelingCall;
  38. @Value("${queue.modeling.obj.modeling-post}")
  39. private String queueObjModelingPost;
  40. @Autowired
  41. private RabbitMqProducer mqProducer;
  42. @Autowired
  43. private FYunFileServiceInterface fYunFileService;
  44. @Autowired
  45. private ISceneProService sceneProService;
  46. @Autowired
  47. private IFdkkLaserService fdkkLaserService;
  48. @Autowired
  49. private FdkkV4Service fdkkV4Service;
  50. @Autowired
  51. private IBuildSceneDTService buildSceneDTService;
  52. @Autowired
  53. private ISceneProEditService sceneProEditService;
  54. @Autowired
  55. private IScenePlusService scenePlusService;
  56. @Override
  57. public void buildScenePre(BuildSceneCallMessage message) {
  58. boolean success = false;
  59. try {
  60. String path = message.getPath();
  61. //根据相机类型,组装资源路径
  62. String laserObjFilePath = path + "_laser_obj";
  63. log.info("开始准备生成OBJ场景资源,路径:{}", laserObjFilePath);
  64. FileUtils.delAllFile(laserObjFilePath);
  65. //获取解压后的资源的data.fdage中的数据
  66. File folderPath = new File(path);
  67. fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage", path + "/capture/data.fdage");
  68. JSONObject jsonObject = FileUtils.readJson(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage");
  69. if(ObjectUtils.isEmpty(jsonObject)){
  70. log.error("data.fdage文件不存在");
  71. return ;
  72. }
  73. if (!jsonObject.containsKey("exportMeshObj") || jsonObject.getIntValue("exportMeshObj") != 1) {
  74. // 写入data.fdage 防止重算
  75. jsonObject.put("exportMeshObj", 1);
  76. FileUtils.writeFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString());
  77. fYunFileService.uploadFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage",
  78. ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage");
  79. }
  80. // 重新构造datafdage文件,添加生成obt文件选项
  81. jsonObject.put("OnlyExportMeshObj",true);
  82. FileUtils.writeFile(laserObjFilePath + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString());
  83. message.getBuildContext().put("previousPath",path);
  84. message.setCameraType("14");
  85. message.setResolution(jsonObject.getString("resolution"));
  86. message.setPath(laserObjFilePath);
  87. message.setResultReceiverMqName(queueObjModelingPost);
  88. //下载资源到本地
  89. this.downLoadSource(message, laserObjFilePath);
  90. //发送mq,就进行计算
  91. mqProducer.sendByWorkQueue(queueModelingCall, message);
  92. success = true;
  93. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  94. }catch (Exception e){
  95. log.error("场景计算前置处理出错", e);
  96. }finally {
  97. //如果前置处理失败,发送钉钉消息
  98. if(!success){
  99. buildSceneDTService.handBaseFail("生成OBJ场景资源准备异常", message.getPath(), message.getSceneNum(), "计算控制服务器");
  100. }
  101. }
  102. }
  103. @Override
  104. public void downLoadSource(BuildSceneCallMessage message,String path) throws Exception{
  105. String prevoisPath = message.getBuildContext().get("previousPath").toString();
  106. FileUtils.copyFile(prevoisPath + "/caches/reconstruction/final.bin", path + "/caches/reconstruction/final.bin", true);
  107. FileUtils.copyFile(prevoisPath + "/caches/reconstruction/chunk.json", path + "/caches/reconstruction/chunk.json", true);
  108. FileUtils.copyDirectiory(prevoisPath + "/caches/images", path + "/caches/images");
  109. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_csc", path + "/caches/depthmap_csc");
  110. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_vis", path + "/caches/depthmap_vis");
  111. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap", path + "/caches/depthmap");
  112. FileUtils.copyFile(prevoisPath + "/caches/panorama.json", path + "/caches/panorama.json", true);
  113. FileUtils.copyFile(prevoisPath + "/results/laserData/laser.ply", path + "/results/laserData/laser.ply", true);
  114. }
  115. @Override
  116. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  117. if (!message.getBuildSuccess()) {
  118. log.error("生成OBJ场景计算失败!");
  119. // 发送钉钉消息,计算失败
  120. buildSceneDTService.handModelFail("生成OBJ场景计算失败!", message.getPath(), message.getBuildContext().get("sceneNum").toString(), message.getHostName());
  121. return;
  122. }
  123. String path = message.getPath();
  124. String projectNum = message.getBuildContext().get("sceneNum").toString();
  125. String laserObjFilePath = path;
  126. CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  127. CreateObjUtil.convertDamToLzma(laserObjFilePath + File.separator + "results/");
  128. CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  129. File file = new File(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma");
  130. while (!file.exists()) {
  131. Thread.sleep(60000);
  132. }
  133. fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k.dam.lzma");
  134. fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k.dam");
  135. String texPath = laserObjFilePath + File.separator + "results" + File.separator + "tex";
  136. File texFile = new File(texPath);
  137. if(texFile.exists()){
  138. for (File textureFile : texFile.listFiles()) {
  139. if(textureFile.getName().endsWith(".jpg")){
  140. fYunFileService.uploadFile(textureFile.getAbsolutePath(),
  141. String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/"+textureFile.getName());
  142. }
  143. }
  144. }
  145. fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + "tex/texture1.jpg",
  146. String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + "/" + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/texture1.jpg");
  147. // 拷贝结果
  148. log.info("开始拷贝obj文件");
  149. FileUtils.copyFolderAllFiles(laserObjFilePath + "/results/mesh", laserObjFilePath + "/laserData/mesh/", true);
  150. File meshFolder = new File(laserObjFilePath + "/results/mesh");
  151. for (File meshFile : meshFolder.listFiles()) {
  152. fYunFileService.uploadFile(meshFile.getAbsolutePath(), String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "mesh/" + meshFile.getName());
  153. }
  154. fdkkLaserService.pushBuildStatusToLaserSystem(projectNum, laserObjFilePath + "/laserData/mesh");
  155. ScenePro scenePro = sceneProService.getByNum(projectNum);
  156. if(!ObjectUtils.isEmpty(scenePro)){
  157. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<ScenePro>()
  158. .set(ScenePro::getStatus, -2).eq(ScenePro::getNum, projectNum);
  159. sceneProService.update(updateWrapper);
  160. sceneProEditService.update(new LambdaUpdateWrapper<SceneProEdit>().set(SceneProEdit::getMapVisi,0)
  161. .eq(SceneProEdit::getProId,scenePro.getId()));
  162. }
  163. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(projectNum);
  164. if(!ObjectUtils.isEmpty(scenePlus)){
  165. LambdaUpdateWrapper<ScenePlus> plusUpdateWrapper = new LambdaUpdateWrapper<ScenePlus>()
  166. .set(ScenePlus::getSceneStatus, -2).eq(ScenePlus::getNum, projectNum);
  167. scenePlusService.update(plusUpdateWrapper);
  168. }
  169. // 如果未升级V4,则升级V4
  170. fdkkV4Service.upgradeToV4(projectNum);
  171. }
  172. }