From d4447ca99df2cfe978ca51790dd2891e9df0d492 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Thu, 25 Jul 2024 16:19:05 +0800
Subject: [PATCH] 修改人工拍照图片保存,新增面状航线保存、修改接口,图斑文件上传格式修改
---
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java | 118 ++++++++++++++++++++++++++++-------------------------------
1 files changed, 56 insertions(+), 62 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 3b944e5..8233451 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
@@ -22,6 +22,7 @@
import com.dji.sample.media.model.*;
import com.dji.sample.media.service.IFileService;
import com.dji.sample.media.util.ImgUtil;
+import com.dji.sample.media.util.MinioFileDownloader;
import com.dji.sample.patches.dao.GetPatchesMapper;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.utils.DistrictCodeUtils;
@@ -115,16 +116,24 @@
MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
fileEntity.setWorkspaceId(workspaceId);
fileEntity.setFileId(UUID.randomUUID().toString());
- if (!file.getObjectKey().endsWith(".mp4")){
- String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
- File file1 = TbFjServiceImpl.downloadFile(url);
- Object data = ImgUtil.getInfo(file1);
- fileEntity.setDroneData(data);
- }
- return mapper.insert(fileEntity);
+ int count = mapper.insert(fileEntity);
+ String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
+ if (file.getObjectKey().endsWith(".jpeg")) {
+ File file1 = TbFjServiceImpl.downloadFile(url);
+ Object data = ImgUtil.getInfo(file1);
+ fileEntity.setDroneData(data);
+ saveNailFile(workspaceId, file, file1,data);
+ count = mapper.insert(fileEntity);
+ file1.delete();
+ }
+ if (file.getObjectKey().endsWith(".mp4")) {
+ saveNailFile(workspaceId, file, null,null);
+ }
+ return count;
}
- public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException {
+ public void saveNailFile(String workspaceId, FileUploadDTO file, File file1,Object data) throws IOException {
+ updateStatue(file.getName());
boolean endsWith = file.getObjectKey().endsWith(".mp4");
if (endsWith) {
MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity((file));
@@ -132,53 +141,32 @@
nailEntity.setFileId(UUID.randomUUID().toString());
nailMapper.insert(nailEntity);
} else {
- String endpoint = pojo.getEndpoint();
- String accessKey = pojo.getAccessKey();
- String secretKey = pojo.getSecretKey();
- String bucketName = pojo.getBucket();
- String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
- File file1 = TbFjServiceImpl.downloadFile(url);
File nailFile = new File(ImgZipUtil.compressImage(file1, 50).toURI());
MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
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(endpoint, accessKey, secretKey, bucketName, nailName, nailFile, "image/jpeg");
+ uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
+ uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
nailMapper.insert(nailEntity);
- try {
- if (file.getName().contains("~")) {
- String name = TimerUtil.getDkbh(file.getName());
- List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
- if (!lotInfos.isEmpty()) {
- LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.eq(LotInfo::getDkbh, name)
- .eq(LotInfo::getInvestigate, 0)
- .set(LotInfo::getInvestigate, 1);
- patchesMapper.update(null, updateWrapper);
- }
- }
- MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
- long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
- File markFile = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
- file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree()).toURI());
- Object data = ImgUtil.getInfo(file1);
- mediaFileMarkEntity.setDronedata(data);
- mediaFileMarkEntity.setWorkspaceId(workspaceId);
- mediaFileMarkEntity.setIsadd(0);
- mediaFileMarkEntity.setIsOriginal(false);
- mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
- mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
- mediaFileMarkEntity.setFileName("mark" + file.getName());
- mediaFileMarkEntity.setFilePath("mark" + file.getPath());
- String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
- uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, markFile, "image/jpeg");
- markMapper.insert(mediaFileMarkEntity);
- } catch (Exception e) {
- e.printStackTrace();
+ }
+ }
+
+ public void updateStatue(String filename) {
+ if (filename.contains("~")) {
+ String name = TimerUtil.getDkbh(filename);
+ List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
+ if (!lotInfos.isEmpty()) {
+ LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
+ updateWrapper.eq(LotInfo::getDkbh, name)
+ .eq(LotInfo::getInvestigate, 0)
+ .set(LotInfo::getInvestigate, 1);
+ patchesMapper.update(null, updateWrapper);
}
}
}
@@ -432,24 +420,30 @@
}
@Override
- public void downloadImages(String jobId, HttpServletResponse response) {
- String address = pojo.getEndpoint() + "/" + pojo.getBucket();
- List<MediaFileEntity> entities = getMedia(jobId);
- List<String> urls = entities.stream()
- .map(MediaFileEntity::getObjectKey)
- .map(objectKey -> address + objectKey)
- .collect(Collectors.toList());
- String outputFolder = "images"; // 存放图片的文件夹
- new File(outputFolder).mkdirs(); // 创建文件夹
+ public ResponseResult downloadImages(List<String> jobIds) {
try {
- downloadAndSaveImages(urls, outputFolder);
- zipAndSendFolder(outputFolder, response);
+ String bucketPath = "/data/software/minio-data/cloud-bucket/";
+ // List<String> prefixes = getUniqueFilePaths(jobIds);
+ MinioFileDownloader downloader = new MinioFileDownloader(bucketPath);
+ // 下载并压缩文件到本地目录
+ String localSaveDir = "/data/software/minio-data/zip-bucket/"; // 修改为你想保存的本地目录
+ downloader.downloadAndZipFolders(jobIds, localSaveDir);
} catch (Exception e) {
e.printStackTrace();
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- } finally {
- cleanUp(outputFolder);
+ return ResponseResult.error("下载失败" + e.getMessage());
}
+ return ResponseResult.success("下载成功");
+ }
+
+ @Override
+ public List<String> getUniqueFilePaths(List<String> jobIds) {
+ return mapper.selectList(
+ new LambdaQueryWrapper<MediaFileEntity>()
+ .in(MediaFileEntity::getJobId, jobIds))
+ .stream()
+ .map(MediaFileEntity::getFilePath)
+ .distinct()
+ .collect(Collectors.toList());
}
@Override
@@ -514,6 +508,7 @@
if (file != null) {
builder.fileName(file.getName())
+ .filePath(file.getPath())
.fingerprint(file.getFingerprint())
.objectKey(file.getObjectKey())
.subFileType(file.getSubFileType())
@@ -543,6 +538,7 @@
.objectKey(file.getObjectKey())
.subFileType(file.getSubFileType())
.isOriginal(file.getExt().getIsOriginal())
+ .filePath(file.getPath())
.jobId(file.getExt().getFlightId())
.drone(file.getExt().getSn()).metadata(file.getMetadata())
.tinnyFingerprint(file.getExt().getTinnyFingerprint());
@@ -813,6 +809,7 @@
e.printStackTrace();
}
}
+
@Override
public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) {
List<MediaFileEntity> allRecords = new ArrayList<>();
@@ -867,8 +864,6 @@
}
-
-
@Override
public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) {
@@ -906,7 +901,6 @@
return new PaginationData<>(pagedUniqueFiles, pagination);
}
-
public List<MediaFileEntity> getMedia(String jobId) {
--
Gitblit v1.9.3