| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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(prefixes, localSaveDir); |
| | | |
| | | System.out.println("压缩文件已保存到:" + 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 |
| | | public List<MediaFileDTO> getFilesByWorkspaceAndJobId(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |