| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); |
| | | fileEntity.setWorkspaceId(workspaceId); |
| | | fileEntity.setFileId(UUID.randomUUID().toString()); |
| | | 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)); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult downloadImages(List<String> jobIds) { |
| | | try { |
| | | 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(); |
| | | 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>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | |
| | | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .fingerprint(file.getFingerprint()) |
| | | .objectKey(file.getObjectKey()) |
| | | .subFileType(file.getSubFileType()) |
| | |
| | | .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()); |
| | |
| | | } |
| | | } |
| | | |
| | | 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)); |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String 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(); |
| | | |
| | | // 使用分页对象构造 Pagination |
| | | Pagination pagination = new Pagination(resultPage); |
| | | return new PaginationData<>(uniqueFiles, pagination); |
| | | // 计算当前页的起始和结束索引 |
| | | 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) { |
| | | public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) { |
| | | |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); |
| | |
| | | |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | |
| | | // 使用分页对象构造 Pagination |
| | | Pagination pagination = new Pagination(resultPage); |
| | | return new PaginationData<>(uniqueFiles, pagination); |
| | | // 使用去重后的列表重新计算总数 |
| | | 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); |
| | | UpdateWrapper<MediaFileMarkEntity> updateWrapper = new UpdateWrapper<>(); |