| | |
| | | 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; |
| | |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*; |
| | | |
| | | /** |
| | | * @author sean |
| | |
| | | } |
| | | |
| | | @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 |
| | | public List<MediaFileDTO> getFilesByWorkspaceAndJobId(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | |
| | | } |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) { |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | List<MediaFileEntity> allRecords = new ArrayList<>(); |
| | | int currentPageNum = 1; // 从第一页开始获取记录 |
| | | |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | // 用于存储去重后的记录 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = new HashMap<>(); |
| | | |
| | | // 根据 fileName 字段进行去重并设置 JobName |
| | | Map<String, MediaFileEntity> uniqueFilesMap = result.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .collect(Collectors.toMap( |
| | | MediaFileEntity::getFileName, |
| | | entity -> entity, |
| | | (existing, replacement) -> existing // 如果有重复的,保留已有的 |
| | | )); |
| | | 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); |
| | | |
| | | // 截取当前页的数据 |
| | | 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); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | |
| | | public List<MediaFileEntity> getMedia(String jobId){ |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().eq(MediaFileEntity::getJobId,jobId)); |
| | | 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); |
| | | UpdateWrapper<MediaFileMarkEntity> updateWrapper = new UpdateWrapper<>(); |