BuildObjServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. @Value("${queue.modeling.obj.modeling-pre}")
  41. private String queueObjModelingPre;
  42. @Autowired
  43. private RabbitMqProducer mqProducer;
  44. @Autowired
  45. private FYunFileServiceInterface fYunFileService;
  46. @Autowired
  47. private ISceneProService sceneProService;
  48. @Autowired
  49. private IFdkkLaserService fdkkLaserService;
  50. @Autowired
  51. private FdkkV4Service fdkkV4Service;
  52. @Autowired
  53. private IBuildSceneDTService buildSceneDTService;
  54. @Autowired
  55. private ISceneProEditService sceneProEditService;
  56. @Autowired
  57. private IScenePlusService scenePlusService;
  58. @Autowired
  59. private ISceneBuildProcessLogService sceneBuildProcessLogService;
  60. @Override
  61. public void buildScenePre(BuildSceneCallMessage message) {
  62. boolean success = false;
  63. try {
  64. //记录日志
  65. sceneBuildProcessLogService.clearSceneBuildProcessLog(message.getSceneNum(), scenebuildt);
  66. String path = message.getPath();
  67. //根据相机类型,组装资源路径
  68. String laserObjFilePath = path + "_laser_obj";
  69. log.info("开始准备生成OBJ场景资源,路径:{}", laserObjFilePath);
  70. FileUtils.delAllFile(laserObjFilePath);
  71. //获取解压后的资源的data.fdage中的数据
  72. File folderPath = new File(path);
  73. fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage", path + "/capture/data.fdage");
  74. JSONObject jsonObject = FileUtils.readJson(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage");
  75. if(ObjectUtils.isEmpty(jsonObject)){
  76. log.error("data.fdage文件不存在");
  77. return ;
  78. }
  79. if (!jsonObject.containsKey("exportMeshObj") || jsonObject.getIntValue("exportMeshObj") != 1) {
  80. // 写入data.fdage 防止重算
  81. jsonObject.put("exportMeshObj", 1);
  82. FileUtils.writeFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString());
  83. fYunFileService.uploadFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage",
  84. ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage");
  85. }
  86. // 重新构造datafdage文件,添加生成obt文件选项
  87. jsonObject.put("OnlyExportMeshObj",true);
  88. FileUtils.writeFile(laserObjFilePath + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString());
  89. message.getBuildContext().put("previousPath",path);
  90. message.setCameraType("14");
  91. message.setResolution(jsonObject.getString("resolution"));
  92. message.setPath(laserObjFilePath);
  93. message.setResultReceiverMqName(queueObjModelingPost);
  94. //下载资源到本地
  95. this.downLoadSource(message, laserObjFilePath);
  96. //发送mq,就进行计算
  97. mqProducer.sendByWorkQueue(queueModelingCall, message);
  98. success = true;
  99. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  100. }catch (Exception e){
  101. log.error("场景计算前置处理出错", e);
  102. }finally {
  103. //如果前置处理失败,发送钉钉消息
  104. if(!success){
  105. buildSceneDTService.handBaseFail("生成OBJ场景资源准备异常", message.getPath(), message.getSceneNum(), "计算控制服务器");
  106. }
  107. }
  108. }
  109. @Override
  110. public void downLoadSource(BuildSceneCallMessage message,String path) throws Exception{
  111. String prevoisPath = message.getBuildContext().get("previousPath").toString();
  112. FileUtils.copyFile(prevoisPath + "/caches/reconstruction/final.bin", path + "/caches/reconstruction/final.bin", true);
  113. FileUtils.copyFile(prevoisPath + "/caches/reconstruction/chunk.json", path + "/caches/reconstruction/chunk.json", true);
  114. FileUtils.copyDirectiory(prevoisPath + "/caches/images", path + "/caches/images");
  115. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_csc", path + "/caches/depthmap_csc");
  116. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_vis", path + "/caches/depthmap_vis");
  117. FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap", path + "/caches/depthmap");
  118. FileUtils.copyFile(prevoisPath + "/caches/panorama.json", path + "/caches/panorama.json", true);
  119. FileUtils.copyFile(prevoisPath + "/results/laserData/laser.ply", path + "/results/laserData/laser.ply", true);
  120. }
  121. @Override
  122. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  123. if (!message.getBuildSuccess()) {
  124. log.error("生成OBJ场景计算失败!");
  125. // 发送钉钉消息,计算失败
  126. buildSceneDTService.handModelFail("生成OBJ场景计算失败!", message.getPath(), message.getBuildContext().get("sceneNum").toString(), message.getHostName());
  127. return;
  128. }
  129. String path = message.getPath();
  130. String projectNum = message.getBuildContext().get("sceneNum").toString();
  131. String laserObjFilePath = path;
  132. CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  133. CreateObjUtil.convertDamToLzma(laserObjFilePath + File.separator + "results/");
  134. CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  135. File file = new File(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma");
  136. while (!file.exists()) {
  137. Thread.sleep(60000);
  138. }
  139. 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");
  140. fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k.dam");
  141. String texPath = laserObjFilePath + File.separator + "results" + File.separator + "tex";
  142. File texFile = new File(texPath);
  143. if(texFile.exists()){
  144. for (File textureFile : texFile.listFiles()) {
  145. if(textureFile.getName().endsWith(".jpg")){
  146. fYunFileService.uploadFile(textureFile.getAbsolutePath(),
  147. String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/"+textureFile.getName());
  148. }
  149. }
  150. }
  151. fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + "tex/texture1.jpg",
  152. String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + "/" + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/texture1.jpg");
  153. // 拷贝结果
  154. log.info("开始拷贝obj文件");
  155. FileUtils.copyFolderAllFiles(laserObjFilePath + "/results/mesh", laserObjFilePath + "/laserData/mesh/", true);
  156. File meshFolder = new File(laserObjFilePath + "/results/mesh");
  157. for (File meshFile : meshFolder.listFiles()) {
  158. fYunFileService.uploadFile(meshFile.getAbsolutePath(), String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "mesh/" + meshFile.getName());
  159. }
  160. fdkkLaserService.pushBuildStatusToLaserSystem(projectNum, laserObjFilePath + "/laserData/mesh");
  161. ScenePro scenePro = sceneProService.getByNum(projectNum);
  162. if(!ObjectUtils.isEmpty(scenePro)){
  163. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<ScenePro>()
  164. .set(ScenePro::getStatus, -2).eq(ScenePro::getNum, projectNum);
  165. sceneProService.update(updateWrapper);
  166. sceneProEditService.update(new LambdaUpdateWrapper<SceneProEdit>().set(SceneProEdit::getMapVisi,0)
  167. .eq(SceneProEdit::getProId,scenePro.getId()));
  168. }
  169. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(projectNum);
  170. if(!ObjectUtils.isEmpty(scenePlus)){
  171. LambdaUpdateWrapper<ScenePlus> plusUpdateWrapper = new LambdaUpdateWrapper<ScenePlus>()
  172. .set(ScenePlus::getSceneStatus, -2).eq(ScenePlus::getNum, projectNum);
  173. scenePlusService.update(plusUpdateWrapper);
  174. }
  175. // 如果未升级V4,则升级V4
  176. fdkkV4Service.upgradeToV4(projectNum);
  177. }
  178. }