From 836fa006b1db985671c16d0aea232f8438bc20e6 Mon Sep 17 00:00:00 2001
From: aix <vip_xiaobin810@163.com>
Date: Sat, 20 Jul 2024 09:33:23 +0800
Subject: [PATCH] 新建面状航线
---
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java | 234 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 189 insertions(+), 45 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 27fdcb0..3b944e5 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
@@ -43,6 +43,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
@@ -54,6 +55,8 @@
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
+
+import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*;
/**
* @author sean
@@ -108,50 +111,55 @@
}
@Override
- public Integer saveFile(String workspaceId, FileUploadDTO file) {
+ public Integer saveFile(String workspaceId, FileUploadDTO file) throws IOException, ImageProcessingException {
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);
}
- public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException {
- 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.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");
- nailMapper.insert(nailEntity);
- try {
- boolean contains = file.getName().contains("~");
- if (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);
- }
-
- boolean endsWith = file.getObjectKey().endsWith(".mp4");
- if (endsWith) {
- MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
- mediaFileMarkEntity.setWorkspaceId(workspaceId);
- mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
- markMapper.insert(mediaFileMarkEntity);
+ public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException {
+ boolean endsWith = file.getObjectKey().endsWith(".mp4");
+ if (endsWith) {
+ MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity((file));
+ nailEntity.setWorkspaceId(workspaceId);
+ 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.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");
+ 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());
@@ -169,26 +177,41 @@
String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, markFile, "image/jpeg");
markMapper.insert(mediaFileMarkEntity);
+ } catch (Exception e) {
+ e.printStackTrace();
}
- } catch (Exception e) {
- e.printStackTrace();
}
- }
+ }
@Override
public Object mediaInfo(String filename) {
String name = filename;
+ List<MediaFileEntity> entitys = mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
+ .eq(MediaFileEntity::getFileName, name));
+ if (entitys != null && !entitys.isEmpty()) {
+ 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) {
- return entity.get(0).getDronedata();
- } else {
- return "该图片信息正在加载";
+ if (entity != null && !entity.isEmpty()) {
+ for (MediaFileMarkEntity markEntity : entity) {
+ if (markEntity.getDronedata() != null) {
+ return markEntity.getDronedata();
+ }
+ }
}
+
+ return "null";
}
+
@Override
public List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId) {
@@ -406,6 +429,27 @@
}
return ossService.getObjectUrl(OssConfiguration.bucket, mediaFileOpt.get().getObjectKey());
+ }
+
+ @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(); // 创建文件夹
+ try {
+ downloadAndSaveImages(urls, outputFolder);
+ zipAndSendFolder(outputFolder, response);
+ } catch (Exception e) {
+ e.printStackTrace();
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ } finally {
+ cleanUp(outputFolder);
+ }
}
@Override
@@ -769,7 +813,107 @@
e.printStackTrace();
}
}
+ @Override
+ public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) {
+ List<MediaFileEntity> allRecords = new ArrayList<>();
+ int currentPageNum = 1; // 从第一页开始获取记录
+ // 用于存储去重后的记录
+ Map<String, MediaFileEntity> uniqueFilesMap = new HashMap<>();
+
+ while (true) {
+ // 分页查询
+ Page<MediaFileEntity> page = new Page<>(currentPageNum, pageSize);
+ Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>()
+ .eq(MediaFileEntity::getWorkspaceId, workspaceId));
+
+ List<MediaFileEntity> result = resultPage.getRecords();
+
+ // 检查是否还有更多记录
+ if (result.isEmpty()) {
+ break; // 没有更多记录了,停止请求
+ }
+
+ // 根据 fileName 字段进行去重并设置 JobName
+ result.stream()
+ .peek(mediaFile -> {
+ String taskNameResult = waylineJobService.getName(mediaFile.getJobId());
+ mediaFile.setJobName(taskNameResult);
+ })
+ .forEach(mediaFile -> uniqueFilesMap.putIfAbsent(mediaFile.getFileName(), mediaFile));
+
+ // 增加当前页数以获取更多记录
+ currentPageNum++;
+ }
+
+ // 获取去重后的实际总数
+ List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values());
+ int uniqueTotal = uniqueFiles.size();
+
+ // 计算当前页的起始和结束索引
+ int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal);
+ int toIndex = Math.min(fromIndex + pageSize, uniqueTotal);
+
+ // 获取当前页的数据
+ List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex);
+
+ // 创建新的分页对象,使用去重后的总数
+ Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal);
+
+ // 使用新的分页对象构造 Pagination
+ Pagination pagination = new Pagination(uniquePage);
+
+ return new PaginationData<>(pagedUniqueFiles, pagination);
+ }
+
+
+
+
+ @Override
+ public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) {
+
+ // 分页查询
+ Page<MediaFileEntity> page = new Page<>(pageNum, pageSize);
+ Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>()
+ .eq(MediaFileEntity::getJobId, jobId)
+ .eq(MediaFileEntity::getWorkspaceId, workspaceId));
+
+ List<MediaFileEntity> result = resultPage.getRecords();
+
+ // 根据 fileName 字段进行去重
+ Map<String, MediaFileEntity> uniqueFilesMap = result.stream()
+ .collect(Collectors.toMap(
+ MediaFileEntity::getFileName,
+ entity -> entity,
+ (existing, replacement) -> existing // 如果有重复的,保留已有的
+ ));
+
+ List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values());
+
+ // 使用去重后的列表重新计算总数
+ int uniqueTotal = uniqueFiles.size();
+
+ // 创建新的分页对象,使用去重后的总数
+ Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal);
+
+ // 截取当前页的数据
+ int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal);
+ int toIndex = Math.min(fromIndex + pageSize, uniqueTotal);
+ List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex);
+
+ // 使用新的分页对象构造 Pagination
+ Pagination pagination = new Pagination(uniquePage);
+
+ return new PaginationData<>(pagedUniqueFiles, pagination);
+ }
+
+
+
+ public List<MediaFileEntity> getMedia(String jobId) {
+ return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
+ .eq(MediaFileEntity::getJobId, jobId)
+ .groupBy(MediaFileEntity::getFileName)); // 使用groupBy去重
+ }
public void updateById(Integer id, MediaFileMarkEntity entity) {
entity.setIsadd(1);
--
Gitblit v1.9.3