BuildE57SceneServiceImpl.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.util.ZipUtil;
  3. import com.fdkankan.common.constant.CommonSuccessStatus;
  4. import com.fdkankan.contro.entity.ScenePlus;
  5. import com.fdkankan.contro.entity.ScenePlusExt;
  6. import com.fdkankan.contro.mq.service.IBuildSceneService;
  7. import com.fdkankan.contro.service.*;
  8. import com.fdkankan.fyun.config.FYunFileConfig;
  9. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  10. import com.fdkankan.model.constants.ConstantFilePath;
  11. import com.fdkankan.model.constants.UploadFilePath;
  12. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  13. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  14. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.cloud.context.config.annotation.RefreshScope;
  19. import org.springframework.stereotype.Service;
  20. import javax.annotation.Resource;
  21. import java.io.File;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. /**
  26. * <p>
  27. * TODO
  28. * </p>
  29. *
  30. * @author dengsixing
  31. * @since 2022/4/20
  32. **/
  33. @Slf4j
  34. @Service
  35. @RefreshScope
  36. public class BuildE57SceneServiceImpl implements IBuildSceneService {
  37. public static final String logUrlFormat = "**algorithm-log**: [%sbuild_log/%s/e57/console.log](%sbuild_log/%s/e57/console.log)";
  38. @Value("${queue.modeling.e57.modeling-post}")
  39. private String queueModelingPost;
  40. @Value("${model.type:#{null}}")
  41. private String modelType;
  42. @Value("${env:gn}")
  43. private String env;
  44. @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
  45. private List<String> notDeleteNasNumList;
  46. @Value("${queue.application.laser.e57-modeling-done:e57-modeling-done}")
  47. private String queueE57ModelingDone;
  48. @Autowired
  49. private RabbitMqProducer mqProducer;
  50. @Resource
  51. private FYunFileServiceInterface fYunFileService;
  52. @Autowired
  53. private FYunFileConfig fYunFileConfig;
  54. @Autowired
  55. private IScenePlusService scenePlusService;
  56. @Autowired
  57. private IScenePlusExtService scenePlusExtService;
  58. @Autowired
  59. private IBuildSceneDTService buildSceneDTService;
  60. @Autowired
  61. private ICommonService commonService;
  62. @Autowired
  63. private ISceneColdStorageService sceneColdStorageService;
  64. @Autowired
  65. private IntermitSceneService intermitSceneService;
  66. @Override
  67. public void buildScenePre(BuildSceneCallMessage message) throws Exception{
  68. String num = message.getSceneNum();
  69. try {
  70. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  71. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  72. String dataSource = scenePlusExt.getDataSource();
  73. String path = dataSource + "_e57";
  74. message.setPath(dataSource);
  75. //根据相机类型,组装资源路径
  76. //下载资源到本地
  77. this.downLoadSource(message, path);
  78. //发送mq,就进行计算
  79. message.setPath(path);
  80. message.setResultReceiverMqName(queueModelingPost);
  81. log.info("e57计算资源准备结束,场景码:{}", message.getSceneNum());
  82. }catch (Exception e){
  83. log.error("e57计算前置处理出错,num"+num, e);
  84. buildSceneDTService.handBaseFail("e57计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  85. throw e;
  86. }
  87. }
  88. private String getOssPath(String path) {
  89. String ossPath = ConstantFilePath.OSS_PREFIX
  90. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  91. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  92. if (!ossPath.endsWith("/")) {
  93. ossPath = ossPath.concat("/");
  94. }
  95. return ossPath;
  96. }
  97. @Override
  98. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  99. String ossPath = getOssPath(buildSceneMqMessage.getPath());
  100. fYunFileService.downloadFileByCommand(path + "/capture", ossPath);
  101. }
  102. @Override
  103. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  104. String num = message.getBuildContext().get("sceneNum").toString();
  105. String path = message.getPath();
  106. String bucket = (String)message.getExt().get("bucket");
  107. String bizId = (String)message.getExt().get("bizId");
  108. String ossKeyFormat = (String)message.getExt().get("ossKey");
  109. try {
  110. // 上传计算日志
  111. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  112. log.info("开始上传计算日志");
  113. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, num) + "e57/";
  114. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  115. log.info("计算日志上传完成");
  116. Map<String, Object> laserMqContent = new HashMap<>();
  117. laserMqContent.put("num", num);
  118. laserMqContent.put("bizId", bizId);
  119. if (!message.getBuildSuccess()) {
  120. //发送mq通知激光系统
  121. laserMqContent.put("status", CommonSuccessStatus.FAIL.code());
  122. mqProducer.sendByWorkQueue(queueE57ModelingDone, laserMqContent);
  123. // 发送钉钉消息,计算失败
  124. String logUrl = String.format(logUrlFormat,fYunFileConfig.getHost(),num,fYunFileConfig.getHost(),num);
  125. buildSceneDTService.handModelFail("计算失败", message.getPath(), num, message.getHostName(), logUrl);
  126. return;
  127. }
  128. //压缩e57
  129. String localPath = path + "/results/laserData/laser.e57";
  130. String zipPath = path + "/results/laserData/laser-e57.zip";
  131. String ossKey = String.format(ossKeyFormat, num, num);
  132. ZipUtil.zip(localPath, zipPath);
  133. fYunFileService.uploadFile(bucket, zipPath, ossKey);
  134. //发送mq通知激光系统
  135. laserMqContent.put("status", CommonSuccessStatus.SUCCESS.code());
  136. mqProducer.sendByWorkQueue(queueE57ModelingDone, laserMqContent);
  137. log.info("e57场景计算结果处理结束,场景码:{}", num);
  138. }catch (Exception e){
  139. log.error("e57场景计算结果处理出错,num"+num, e);
  140. buildSceneDTService.handBaseFail("e57场景计算结果处理出错!", message.getPath(), num, "计算控制服务器");
  141. throw e;
  142. }
  143. }
  144. }