From 74d1c21ebb6b3b916904d95d13d289df23dcdedd Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Tue, 20 Aug 2024 18:06:46 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/ht-dev' into ht-dev
---
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java | 183 ++++++++++++++++++---------------------------
1 files changed, 74 insertions(+), 109 deletions(-)
diff --git a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
index 7873d13..b269878 100644
--- a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
+++ b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -32,6 +32,10 @@
import com.dji.sample.territory.service.impl.TbFjServiceImpl;
import com.dji.sample.territory.utils.ImgZipUtil;
import com.dji.sample.territory.utils.WaterMarkUtil;
+import com.dji.sample.wayline.dao.IWaylineFileMapper;
+import com.dji.sample.wayline.dao.IWaylineJobMapper;
+import com.dji.sample.wayline.model.entity.WaylineFileEntity;
+import com.dji.sample.wayline.model.entity.WaylineJobEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobService;
import com.drew.imaging.ImageProcessingException;
@@ -61,6 +65,7 @@
import java.util.stream.Collectors;
import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*;
+import static com.dji.sample.patches.utils.TimerUtil.getDkbh;
/**
* @author sean
@@ -95,6 +100,10 @@
private MinioPojo pojo;
private ObjectMapper objectMapper = new ObjectMapper();
+ @Autowired
+ private IWaylineJobMapper jobMapper;
+ @Autowired
+ private IWaylineFileMapper fileMapper;
private Optional<MediaFileEntity> getMediaByFingerprint(String workspaceId, String fingerprint) {
@@ -110,22 +119,25 @@
.eq(MediaFileEntity::getFileId, fileId));
return Optional.ofNullable(fileEntity);
}
- public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) {
+
+ public void saveMarkFile(String workspaceId, FileUploadDTO files, File file1) {
try {
- MediaFileMarkEntity mediaFileMarkEntity= new MediaFileMarkEntity();
+ MediaFileMarkEntity file=fileUploadConvertToMarkEntity(files);
+ MediaFileMarkEntity mediaFileMarkEntity = new MediaFileMarkEntity();
mediaFileMarkEntity.setWorkspaceId(workspaceId);
mediaFileMarkEntity.setIsadd(0);
mediaFileMarkEntity.setIsOriginal(false);
mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
- mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath()+ "/" + file.getFileName());
+ mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath() + "/" + file.getFileName());
mediaFileMarkEntity.setFileName("mark" + file.getFileName());
mediaFileMarkEntity.setFilePath("mark" + file.getFilePath());
- uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg");
+// uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", mediaFileMarkEntity.getObjectKey(), nailFile, "image/jpeg");
markMapper.insert(mediaFileMarkEntity);
} catch (Exception e) {
e.printStackTrace();
}
}
+
@Override
public Boolean checkExist(String workspaceId, String fingerprint) {
return this.getMediaByFingerprint(workspaceId, fingerprint).isPresent();
@@ -136,59 +148,47 @@
MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
fileEntity.setWorkspaceId(workspaceId);
fileEntity.setFileId(UUID.randomUUID().toString());
+ int isPlane=checkWaylineType(file.getExt().getFlightId());
//避免对视频处理引发报错
- if (file.getObjectKey().endsWith("jpeg")){
+ if (file.getObjectKey().endsWith("jpeg")&&isPlane!=2) {
fileEntity.setIsadd(0);
String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
File downloadedFile = TbFjServiceImpl.downloadFile(url);
Object data = ImgUtil.getInfo(downloadedFile);
fileEntity.setDroneData(data);
updateStatue(file.getName());
- saveFiles(workspaceId,file,downloadedFile);
+ saveFiles(workspaceId, file, downloadedFile);
+ if (isPlane==1){
+ saveMarkFile(workspaceId, file, downloadedFile);
+ }
}
+ if (fileEntity.getFileName().endsWith("~")) {
+ fileEntity.setDkbh(getDkbh(fileEntity.getFileName()));
+ }
+ waylineJobService.getName(fileEntity.getJobId());
return mapper.insert(fileEntity);
}
- public void saveFiles(String workspaceId, FileUploadDTO file,File mediaFile) {
+
+ public void saveFiles(String workspaceId, FileUploadDTO file, File mediaFile) {
// 更新文件状态
// updateStatue(file.getName());
try {
- // 处理图片文件
- File nailFile = new File(ImgZipUtil.compressImage(mediaFile, 50).toURI());
- MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
- Object data = ImgUtil.getInfo(mediaFile);
+ // 处理图片文件
+ File nailFile = new File(ImgZipUtil.compressImage(mediaFile, 50).toURI());
+ MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
+ Object data = ImgUtil.getInfo(mediaFile);
// nailEntity.setIsadd(0);
- nailEntity.setIsOriginal(false);
- nailEntity.setDronedata(data);
- nailEntity.setWorkspaceId(workspaceId);
- nailEntity.setFileName("nail" + file.getName());
- nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
- nailEntity.setFilePath("nail" + file.getPath());
- String nailName = nailEntity.getObjectKey();
- nailEntity.setFileId(UUID.randomUUID().toString());
-
- // 上传图片文件
-// uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket",nailName, nailFile, "image/jpeg");
- uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
+ nailEntity.setIsOriginal(false);
+ nailEntity.setDronedata(data);
+ nailEntity.setWorkspaceId(workspaceId);
+ nailEntity.setFileName("nail" + file.getName());
+ nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
+ nailEntity.setFilePath("nail" + file.getPath());
+ String nailName = nailEntity.getObjectKey();
+ nailEntity.setFileId(UUID.randomUUID().toString());
uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
- nailMapper.insert(nailEntity);
-
- // 处理压缩后的图片文件(如果有)
- File zipFile = new File(ImgZipUtil.compressImageAndGetFile(mediaFile, 0.5f).toURI());
- MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
- zipEntity.setIsOriginal(false);
- zipEntity.setWorkspaceId(workspaceId);
- zipEntity.setFileName("zip" + file.getName());
- zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
- zipEntity.setFilePath("zip" + file.getPath());
- String zipName = zipEntity.getObjectKey();
- zipEntity.setFileId(UUID.randomUUID().toString());
-
- // 上传压缩文件
- uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
- uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
- zipMapper.insert(zipEntity);
-
+ nailMapper.insert(nailEntity);
} catch (IOException | ImageProcessingException e) {
// 处理异常
e.printStackTrace();
@@ -198,7 +198,7 @@
public void updateStatue(String filename) {
if (filename.contains("~")) {
- String name = TimerUtil.getDkbh(filename);
+ String name = getDkbh(filename);
List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
if (!lotInfos.isEmpty()) {
LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
@@ -219,19 +219,6 @@
for (MediaFileEntity entity : entitys) {
if (entity.getDroneData() != null) {
return entity.getDroneData();
- }
- }
- }
-
- if (!filename.contains("mark")) {
- name = "mark" + filename;
- }
- List<MediaFileMarkEntity> entity = markMapper.selectList(new LambdaQueryWrapper<MediaFileMarkEntity>()
- .eq(MediaFileMarkEntity::getFileName, name));
- if (entity != null && !entity.isEmpty()) {
- for (MediaFileMarkEntity markEntity : entity) {
- if (markEntity.getDronedata() != null) {
- return markEntity.getDronedata();
}
}
} else {
@@ -259,7 +246,7 @@
}
@Override
- public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type,String jobId) {
+ public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type, String jobId) {
// 创建查询条件对象
LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>();
@@ -282,7 +269,7 @@
queryWrapper.in(MediaFileEntity::getJobId, jobIds);
}
if (jobId != null && !jobId.isEmpty()) {
- queryWrapper.eq(MediaFileEntity::getJobId,jobId);
+ queryWrapper.eq(MediaFileEntity::getJobId, jobId);
}
if (type != null && !type.isEmpty()) {
@@ -514,18 +501,18 @@
@Override
public ResponseResult downloadImages(List<String> jobIds) {
String localSaveDir = "/home/drone/web/zip";
- String downPath="https://wrj.shuixiongit.com/downloadZip/";
- String filepath=TimerUtil.getNowDay()+".zip";
+ String downPath = "https://wrj.shuixiongit.com/downloadZip/";
+ String filepath = TimerUtil.getNowDay() + ".zip";
try {
String bucketPath = "/data/software/minio-data/cloud-bucket";
List<String> prefixes = getUniqueFilePaths(jobIds);
MinioFileDownloader downloader = new MinioFileDownloader(bucketPath);
- downloader.downloadAndZipFolders(prefixes, localSaveDir,filepath);
+ downloader.downloadAndZipFolders(prefixes, localSaveDir, filepath);
} catch (Exception e) {
e.printStackTrace();
return ResponseResult.error("下载失败" + e.getMessage());
}
- return ResponseResult.success(downPath+filepath);
+ return ResponseResult.success(downPath + filepath);
}
@Override
@@ -622,8 +609,8 @@
return builder.build();
}
- private MediaFileZipEntity fileUploadConvertToZipEntity(FileUploadDTO file) {
- MediaFileZipEntity.MediaFileZipEntityBuilder builder = MediaFileZipEntity.builder();
+ private MediaFileMarkEntity fileUploadConvertToMarkEntity(FileUploadDTO file) {
+ MediaFileMarkEntity.MediaFileMarkEntityBuilder builder = MediaFileMarkEntity.builder();
if (file != null) {
builder.fileName(file.getName())
@@ -711,16 +698,23 @@
.eq(MediaFileEntity::getJobId, jobId));
}
+ public int checkWaylineType(String jobId) {
+ WaylineJobEntity jobEntity = jobMapper.selectOne(new LambdaQueryWrapper<WaylineJobEntity>().eq(WaylineJobEntity::getJobId, jobId));
+ WaylineFileEntity fileEntity=fileMapper.selectOne(new LambdaQueryWrapper<WaylineFileEntity>().eq(WaylineFileEntity::getWaylineId, jobEntity.getFileId()));
+ return fileEntity.getWaylineType();
+ }
public void updateMediaFileNames(String jobId) {
// 查询符合条件的数据
List<MediaFileEntity> mediaFiles = mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
.eq(MediaFileEntity::getJobId, jobId));
- boolean allContainTilde = mediaFiles.stream().allMatch(file -> file.getFileName().contains("~"));
- boolean noneContainTilde = mediaFiles.stream().noneMatch(file -> file.getFileName().contains("~"));
- // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1
- if (allContainTilde || noneContainTilde) {
+ // 判断所有的dkbh字段是否都不为空或者都为空
+ boolean allHaveDkbh = mediaFiles.stream().allMatch(file -> file.getDkbh() != null && !file.getDkbh().isEmpty());
+ boolean noneHaveDkbh = mediaFiles.stream().noneMatch(file -> file.getDkbh() != null && !file.getDkbh().isEmpty());
+
+ // 如果所有dkbh字段都不为空或者都为空,将is_add字段改为1
+ if (allHaveDkbh || noneHaveDkbh) {
mediaFiles.forEach(file -> {
file.setIsadd(1);
updateMediaById(file.getId(), file);
@@ -728,21 +722,22 @@
return;
}
- // 筛选出name字段不包含'~'的数据
+ // 筛选出dkbh字段为空的数据
List<MediaFileEntity> filteredFiles = mediaFiles.stream()
- .filter(file -> !file.getFileName().contains("~"))
+ .filter(file -> file.getDkbh() == null || file.getDkbh().isEmpty())
.collect(Collectors.toList());
+
for (MediaFileEntity currentFile : filteredFiles) {
String currentName = currentFile.getFileName();
Map<String, Object> currentMetadata = JSON.parseObject(JSON.toJSONString(currentFile.getMetadata()), Map.class);
Long currentCreatedTime = (Long) currentMetadata.get("createdTime");
+
// 找到metadata中的createdTime小于当前数据的createdTime且最接近的那条数据
Optional<MediaFileEntity> closestFileOpt = mediaFiles.stream()
.filter(file -> {
Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class);
Long createdTime = (Long) metadata.get("createdTime");
- String filename = file.getFileName();
- return createdTime < currentCreatedTime && filename.contains("~");
+ return createdTime < currentCreatedTime && file.getDkbh() != null && !file.getDkbh().isEmpty();
})
.min((file1, file2) -> {
Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class);
@@ -751,14 +746,14 @@
Long time2 = (Long) metadata2.get("createdTime");
return Long.compare(currentCreatedTime - time1, currentCreatedTime - time2);
});
+
if (closestFileOpt.isEmpty()) {
// 找不到小于的文件,尝试找大于且最接近的文件
closestFileOpt = mediaFiles.stream()
.filter(file -> {
Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class);
Long createdTime = (Long) metadata.get("createdTime");
- String filename = file.getFileName();
- return createdTime > currentCreatedTime && filename.contains("~");
+ return createdTime > currentCreatedTime && file.getDkbh() != null && !file.getDkbh().isEmpty();
})
.min((file1, file2) -> {
Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class);
@@ -768,40 +763,16 @@
return Long.compare(time1 - currentCreatedTime, time2 - currentCreatedTime);
});
}
- // 提取并替换name字段
+
+ // 将最接近的文件的dkbh值赋给当前文件
closestFileOpt.ifPresent(closestFile -> {
- String closestName = closestFile.getFileName();
- int startIndex = closestName.indexOf("V");
- if (startIndex == -1) startIndex = closestName.indexOf("W");
- if (startIndex == -1) startIndex = closestName.indexOf("Z");
- if (startIndex == -1) startIndex = closestName.indexOf("T");
- if (startIndex == -1) {
- return;
- }
- int endIndex = closestName.indexOf(".", startIndex);
- if (endIndex == -1) {
- return;
- }
- String replacement = closestName.substring(startIndex, endIndex);
- int currentStartIndex = currentName.indexOf("V");
- if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("W");
- if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("Z");
- if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("T");
- if (currentStartIndex == -1) {
- return;
- }
- int currentEndIndex = currentName.indexOf(".", currentStartIndex);
- if (currentEndIndex == -1) {
- return;
- }
- String newName = currentName.substring(0, currentStartIndex)
- + replacement
- + currentName.substring(currentEndIndex);
- currentFile.setFileName(newName);
+ currentFile.setDkbh(closestFile.getDkbh());
+ currentFile.setIsadd(1);
updateMediaById(currentFile.getId(), currentFile);
});
}
}
+
public void updateMediaZipFileNames(String jobId) {
// 查询符合条件的数据
@@ -1037,10 +1008,6 @@
}
-
-
-
-
@Override
public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) {
// 分页查询
@@ -1051,7 +1018,7 @@
// 添加查询条件
queryWrapper.eq(MediaFileEntity::getWorkspaceId, workspaceId);
- queryWrapper.eq(MediaFileEntity::getJobId,jobId);
+ queryWrapper.eq(MediaFileEntity::getJobId, jobId);
queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC");
Page<MediaFileEntity> resultPage = mapper.selectPage(page, queryWrapper);
List<MediaFileEntity> result = resultPage.getRecords();
@@ -1080,8 +1047,6 @@
Pagination pagination = new Pagination(newPage);
return new PaginationData<>(uniqueFiles, pagination);
}
-
-
public List<MediaFileEntity> getMedia(String jobId) {
--
Gitblit v1.9.3