|
@@ -0,0 +1,187 @@
|
|
|
|
+package com.fdkankan.openApi.service.system.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
|
+import com.fdkankan.openApi.bean.vo.SceneDataDownloadVO;
|
|
|
|
+import com.fdkankan.openApi.entity.laser.SceneEntity;
|
|
|
|
+import com.fdkankan.openApi.entity.system.SceneDataDownloadEntity;
|
|
|
|
+import com.fdkankan.openApi.mapper.system.SceneDataDownloadMapper;
|
|
|
|
+import com.fdkankan.openApi.service.laser.SceneService;
|
|
|
|
+import com.fdkankan.openApi.service.system.SceneDataDownloadService;
|
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Locale;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Created by Xiewj on 2022年11月21日11:22:02
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+@DS("system")
|
|
|
|
+public class SceneDataDownloadServiceImpl extends ServiceImpl<SceneDataDownloadMapper, SceneDataDownloadEntity> implements SceneDataDownloadService {
|
|
|
|
+ @Value("${laserConfig.defaultFolder}")
|
|
|
|
+ private String laserDefaultFolder;
|
|
|
|
+ @Value("${laserConfig.ossUrl}")
|
|
|
|
+ private String laserOSSUrl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Value("${laserConfig.bucket}")
|
|
|
|
+ private String laserBucket;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SceneService sceneService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public ResultData sceneDownloadDepthMapAndPly(String sceneCode, Long userId,SceneEntity sceneEntity) {
|
|
|
|
+ List<SceneDataDownloadEntity> sceneDataDownloadEntityList = findByOssDeleteIsNullBySceneCode(sceneCode);
|
|
|
|
+ if (ObjectUtil.isNotNull(sceneEntity)&&sceneEntity.getLocation()==6){
|
|
|
|
+ throw new BusinessException(-1,"不支持slam场景原始数据下载");
|
|
|
|
+ }
|
|
|
|
+ String e57Url=laserDefaultFolder + "/" + sceneCode + "/data/"+sceneCode+"_e57.zip";
|
|
|
|
+ boolean e57Flag=false;
|
|
|
|
+ if(fYunFileService.fileExist(laserBucket,e57Url)){
|
|
|
|
+ e57Flag=true;
|
|
|
|
+ }
|
|
|
|
+ boolean e57DBFlag=false;
|
|
|
|
+ boolean recountFlag=false;
|
|
|
|
+ for (SceneDataDownloadEntity sceneDataDownloadEntity : sceneDataDownloadEntityList) {
|
|
|
|
+ if (sceneDataDownloadEntity.getFileName().toLowerCase(Locale.ROOT).contains("e57") && !e57DBFlag){
|
|
|
|
+ e57DBFlag=true;
|
|
|
|
+ }
|
|
|
|
+ if (sceneDataDownloadEntity.getSceneVer()<sceneEntity.getRecount() && !recountFlag){
|
|
|
|
+ recountFlag=true;
|
|
|
|
+ }
|
|
|
|
+ if (e57DBFlag&&recountFlag){
|
|
|
|
+ break; // 终止整个循环
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtil.isNotEmpty(sceneDataDownloadEntityList)&& e57Flag && e57DBFlag && !recountFlag ){
|
|
|
|
+ log.info("场景存在库");
|
|
|
|
+ List<SceneDataDownloadVO> sceneDataDownloadVOS = sceneDataDownloadEntityList.stream()
|
|
|
|
+ .map(sceneData -> new SceneDataDownloadVO(sceneData.getFileName(),laserOSSUrl+sceneData.getOssKey()+"?t="+System.currentTimeMillis()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return ResultData.ok(sceneDataDownloadVOS);
|
|
|
|
+ }else {
|
|
|
|
+ List<String> copyFiles=new ArrayList<>();
|
|
|
|
+ //先检查e57
|
|
|
|
+ if(e57Flag){
|
|
|
|
+ String e57CopyUrl="sceneRawData/"+sceneCode+"/"+ FileUtil.getName(e57Url);
|
|
|
|
+ fYunFileService.copyFileInBucket(laserBucket,e57Url,e57CopyUrl);
|
|
|
|
+ copyFiles.add(e57CopyUrl);
|
|
|
|
+ e57Flag=true;
|
|
|
|
+ }
|
|
|
|
+ List<String> strings = fYunFileService.listRemoteFiles(laserBucket, laserDefaultFolder + "/" + sceneCode + "/data/" + sceneCode + "/depthmap/");
|
|
|
|
+ boolean has_cloud=false;
|
|
|
|
+ boolean has_png=false;
|
|
|
|
+ ArrayList<Map<String, Object>> rows =new ArrayList<>();
|
|
|
|
+ for (String file : strings) {
|
|
|
|
+ String name = FileUtil.getName(file);
|
|
|
|
+ if (name.contains("ply")&&e57Flag){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (FileUtil.extName(file).equalsIgnoreCase("png")&& !has_png){
|
|
|
|
+ has_png=true;
|
|
|
|
+ }
|
|
|
|
+ if (FileUtil.extName(file).equalsIgnoreCase("ply")&& !has_cloud){
|
|
|
|
+ has_cloud=true;
|
|
|
|
+ }
|
|
|
|
+ String copyUrl="sceneRawData/"+sceneCode+"/"+ FileUtil.getName(file);
|
|
|
|
+ fYunFileService.copyFileInBucket(laserBucket,file,copyUrl);
|
|
|
|
+ copyFiles.add(copyUrl);
|
|
|
|
+ }
|
|
|
|
+ if ((has_png && has_cloud )|| (has_png && e57Flag)){
|
|
|
|
+ removeBySceneCode(sceneCode);
|
|
|
|
+ return saveAndDownLoad(sceneCode, copyFiles,userId,sceneEntity.getRecount());
|
|
|
|
+ }else if (!has_png && !has_cloud ){
|
|
|
|
+ throw new BusinessException(-1,"数据不全,请重算后再尝试下载");
|
|
|
|
+ }else if (has_png && (!has_cloud||!e57Flag )){
|
|
|
|
+ throw new BusinessException(-1,"点云数据不全,请重算后再尝试下载");
|
|
|
|
+ }else if (!has_png && has_cloud){
|
|
|
|
+ throw new BusinessException(-1,"深度图数据不全,请重算后再尝试下载");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ResultData.ok();
|
|
|
|
+ }
|
|
|
|
+ private ResultData saveAndDownLoad(String sceneCode, List<String> data,Long userId,int ver) {
|
|
|
|
+ List<SceneDataDownloadEntity> dataDownloadEntities=new ArrayList<>();
|
|
|
|
+ for (String file : data) {
|
|
|
|
+ String name = FileUtil.getName(file);
|
|
|
|
+ //上传OSS并且入库
|
|
|
|
+ dataDownloadEntities.add(findAndSave(sceneCode, userId, file, name, 1,ver));
|
|
|
|
+ }
|
|
|
|
+ List<SceneDataDownloadVO> sceneDataDownloadVOS = dataDownloadEntities.stream()
|
|
|
|
+ .map(sceneData -> new SceneDataDownloadVO(sceneData.getFileName(),laserOSSUrl+sceneData.getOssKey()+"?t="+System.currentTimeMillis()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return ResultData.ok(sceneDataDownloadVOS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private SceneDataDownloadEntity findAndSave(String sceneCode, Long userId, String xlsxUrl,String fileName,int type,int ver) {
|
|
|
|
+ SceneDataDownloadEntity sceneDataDownload = findBySceneCodeAndFileNameAndOssDeleteIsNull( sceneCode,fileName);
|
|
|
|
+ if (ObjectUtil.isNull(sceneDataDownload)){
|
|
|
|
+ sceneDataDownload=new SceneDataDownloadEntity();
|
|
|
|
+ sceneDataDownload.setOssKey(xlsxUrl);
|
|
|
|
+ sceneDataDownload.setFileName(fileName);
|
|
|
|
+ sceneDataDownload.setType(type);
|
|
|
|
+ sceneDataDownload.setSceneCode(sceneCode);
|
|
|
|
+ sceneDataDownload.setBucket(laserBucket);
|
|
|
|
+ sceneDataDownload.setSceneVer(ver);
|
|
|
|
+ sceneDataDownload.setUserId(userId);
|
|
|
|
+ save(sceneDataDownload);
|
|
|
|
+ return sceneDataDownload;
|
|
|
|
+ }
|
|
|
|
+ return sceneDataDownload;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<SceneDataDownloadEntity> findByOssDeleteIsNull() {
|
|
|
|
+ return list(Wrappers.<SceneDataDownloadEntity>lambdaQuery().isNull(SceneDataDownloadEntity::getOssDelete));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<SceneDataDownloadEntity> findByOssDeleteIsNullBySceneCode(String sceneCode) {
|
|
|
|
+ LambdaQueryWrapper<SceneDataDownloadEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+ wrapper.isNull(SceneDataDownloadEntity::getOssDelete);
|
|
|
|
+ wrapper.eq(SceneDataDownloadEntity::getSceneCode,sceneCode);
|
|
|
|
+ return list(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public SceneDataDownloadEntity findBySceneCodeAndFileNameAndOssDeleteIsNull(String sceneCode, String fileName) {
|
|
|
|
+ LambdaQueryWrapper<SceneDataDownloadEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+ wrapper.isNull(SceneDataDownloadEntity::getOssDelete);
|
|
|
|
+ wrapper.eq(SceneDataDownloadEntity::getSceneCode,sceneCode);
|
|
|
|
+ wrapper.eq(SceneDataDownloadEntity::getFileName,fileName);
|
|
|
|
+ return getOne(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void removeBySceneCode(String sceneCode) {
|
|
|
|
+ LambdaQueryWrapper<SceneDataDownloadEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+ wrapper.eq(SceneDataDownloadEntity::getSceneCode,sceneCode);
|
|
|
|
+ remove(wrapper);
|
|
|
|
+ }
|
|
|
|
+}
|