BuildObjServiceImpl.java 11 KB

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