SceneDataDownloadServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.fdkankan.openApi.service.system.impl;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.fdkankan.common.exception.BusinessException;
  9. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  10. import com.fdkankan.openApi.bean.vo.SceneDataDownloadVO;
  11. import com.fdkankan.openApi.entity.laser.SceneEntity;
  12. import com.fdkankan.openApi.entity.system.SceneDataDownloadEntity;
  13. import com.fdkankan.openApi.mapper.system.SceneDataDownloadMapper;
  14. import com.fdkankan.openApi.service.laser.SceneService;
  15. import com.fdkankan.openApi.service.system.SceneDataDownloadService;
  16. import com.fdkankan.web.response.ResultData;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Locale;
  25. import java.util.Map;
  26. import java.util.stream.Collectors;
  27. /**
  28. * Created by Xiewj on 2022年11月21日11:22:02
  29. */
  30. @Slf4j
  31. @Service
  32. public class SceneDataDownloadServiceImpl extends ServiceImpl<SceneDataDownloadMapper, SceneDataDownloadEntity> implements SceneDataDownloadService {
  33. @Value("${laserConfig.defaultFolder}")
  34. private String laserDefaultFolder;
  35. @Value("${laserConfig.ossUrl}")
  36. private String laserOSSUrl;
  37. @Value("${laserConfig.bucket}")
  38. private String laserBucket;
  39. @Autowired
  40. SceneService sceneService;
  41. @Autowired
  42. private FYunFileServiceInterface fYunFileService;
  43. @Override
  44. @Transactional(rollbackFor = Exception.class)
  45. public ResultData sceneDownloadDepthMapAndPly(String sceneCode, Long userId) {
  46. List<SceneDataDownloadEntity> sceneDataDownloadEntityList = findByOssDeleteIsNullBySceneCode(sceneCode);
  47. SceneEntity sceneEntity = sceneService.findBySceneCode(sceneCode);
  48. if (ObjectUtil.isNotNull(sceneEntity)&&sceneEntity.getLocation()==6){
  49. throw new BusinessException(-1,"不支持slam场景原始数据下载");
  50. }
  51. String e57Url=laserDefaultFolder + "/" + sceneCode + "/data/"+sceneCode+"_e57.zip";
  52. boolean e57Flag=false;
  53. if(fYunFileService.fileExist(laserBucket,e57Url)){
  54. e57Flag=true;
  55. }
  56. boolean e57DBFlag=false;
  57. boolean recountFlag=false;
  58. for (SceneDataDownloadEntity sceneDataDownloadEntity : sceneDataDownloadEntityList) {
  59. if (sceneDataDownloadEntity.getFileName().toLowerCase(Locale.ROOT).contains("e57") && !e57DBFlag){
  60. e57DBFlag=true;
  61. }
  62. if (sceneDataDownloadEntity.getSceneVer()<sceneEntity.getRecount() && !recountFlag){
  63. recountFlag=true;
  64. }
  65. if (e57DBFlag&&recountFlag){
  66. break; // 终止整个循环
  67. }
  68. }
  69. if (CollectionUtil.isNotEmpty(sceneDataDownloadEntityList)&& e57Flag && e57DBFlag && !recountFlag ){
  70. log.info("场景存在库");
  71. List<SceneDataDownloadVO> sceneDataDownloadVOS = sceneDataDownloadEntityList.stream()
  72. .map(sceneData -> new SceneDataDownloadVO(sceneData.getFileName(),laserOSSUrl+sceneData.getOssKey()))
  73. .collect(Collectors.toList());
  74. return ResultData.ok(sceneDataDownloadVOS);
  75. }else {
  76. List<String> copyFiles=new ArrayList<>();
  77. //先检查e57
  78. if(e57Flag){
  79. String e57CopyUrl="sceneRawData/"+sceneCode+"/"+ FileUtil.getName(e57Url);
  80. fYunFileService.copyFileInBucket(laserBucket,e57Url,e57CopyUrl);
  81. copyFiles.add(e57CopyUrl);
  82. e57Flag=true;
  83. }
  84. List<String> strings = fYunFileService.listRemoteFiles(laserBucket, laserDefaultFolder + "/" + sceneCode + "/data/" + sceneCode + "/depthmap/");
  85. boolean has_cloud=false;
  86. boolean has_png=false;
  87. ArrayList<Map<String, Object>> rows =new ArrayList<>();
  88. for (String file : strings) {
  89. String name = FileUtil.getName(file);
  90. if (name.contains("ply")&&e57Flag){
  91. continue;
  92. }
  93. if (FileUtil.extName(file).equalsIgnoreCase("png")&& has_png==false){
  94. has_png=true;
  95. }
  96. if (FileUtil.extName(file).equalsIgnoreCase("ply")&& has_cloud==false){
  97. has_cloud=true;
  98. }
  99. String copyUrl="sceneRawData/"+sceneCode+"/"+ FileUtil.getName(file);
  100. fYunFileService.copyFileInBucket(laserBucket,file,copyUrl);
  101. copyFiles.add(copyUrl);
  102. }
  103. if ((has_png && has_cloud )|| (has_png && e57Flag)){
  104. return saveAndDownLoad(sceneCode, copyFiles,userId,sceneEntity.getRecount());
  105. }else if (!has_png && !has_cloud ){
  106. throw new BusinessException(-1,"数据不全,请重算后再尝试下载");
  107. }else if (has_png && (!has_cloud||!e57Flag )){
  108. throw new BusinessException(-1,"点云数据不全,请重算后再尝试下载");
  109. }else if (!has_png && has_cloud){
  110. throw new BusinessException(-1,"深度图数据不全,请重算后再尝试下载");
  111. }
  112. }
  113. return ResultData.ok();
  114. }
  115. private ResultData saveAndDownLoad(String sceneCode, List<String> data,Long userId,int ver) {
  116. List<SceneDataDownloadEntity> dataDownloadEntities=new ArrayList<>();
  117. for (String file : data) {
  118. String name = FileUtil.getName(file);
  119. //上传OSS并且入库
  120. dataDownloadEntities.add(findAndSave(sceneCode, userId, file, name, 1,ver));
  121. }
  122. List<SceneDataDownloadVO> sceneDataDownloadVOS = dataDownloadEntities.stream()
  123. .map(sceneData -> new SceneDataDownloadVO(sceneData.getFileName(),laserOSSUrl+sceneData.getOssKey()))
  124. .collect(Collectors.toList());
  125. return ResultData.ok(sceneDataDownloadVOS);
  126. }
  127. private SceneDataDownloadEntity findAndSave(String sceneCode, Long userId, String xlsxUrl,String fileName,int type,int ver) {
  128. SceneDataDownloadEntity sceneDataDownload = findBySceneCodeAndFileNameAndOssDeleteIsNull( sceneCode,fileName);
  129. if (ObjectUtil.isNull(sceneDataDownload)){
  130. sceneDataDownload=new SceneDataDownloadEntity();
  131. sceneDataDownload.setOssKey(xlsxUrl);
  132. sceneDataDownload.setFileName(fileName);
  133. sceneDataDownload.setType(type);
  134. sceneDataDownload.setSceneCode(sceneCode);
  135. sceneDataDownload.setBucket(laserBucket);
  136. sceneDataDownload.setSceneVer(ver);
  137. sceneDataDownload.setUserId(userId);
  138. save(sceneDataDownload);
  139. return sceneDataDownload;
  140. }
  141. return sceneDataDownload;
  142. }
  143. //
  144. @Override
  145. public List<SceneDataDownloadEntity> findByOssDeleteIsNull() {
  146. return list(Wrappers.<SceneDataDownloadEntity>lambdaQuery().isNull(SceneDataDownloadEntity::getOssDelete));
  147. }
  148. @Override
  149. public List<SceneDataDownloadEntity> findByOssDeleteIsNullBySceneCode(String sceneCode) {
  150. LambdaQueryWrapper<SceneDataDownloadEntity> wrapper = Wrappers.lambdaQuery();
  151. wrapper.isNull(SceneDataDownloadEntity::getOssDelete);
  152. wrapper.eq(SceneDataDownloadEntity::getSceneCode,sceneCode);
  153. return list(wrapper);
  154. }
  155. @Override
  156. public SceneDataDownloadEntity findBySceneCodeAndFileNameAndOssDeleteIsNull(String sceneCode, String fileName) {
  157. LambdaQueryWrapper<SceneDataDownloadEntity> wrapper = Wrappers.lambdaQuery();
  158. wrapper.isNull(SceneDataDownloadEntity::getOssDelete);
  159. wrapper.eq(SceneDataDownloadEntity::getSceneCode,sceneCode);
  160. wrapper.eq(SceneDataDownloadEntity::getFileName,fileName);
  161. return getOne(wrapper);
  162. }
  163. }