| | |
| | | import com.dji.sample.media.dao.IFileMapper; |
| | | import com.dji.sample.media.dao.IMarkMapper; |
| | | import com.dji.sample.media.dao.INailMapper; |
| | | import com.dji.sample.media.dao.IZipMapper; |
| | | import com.dji.sample.media.model.*; |
| | | import com.dji.sample.media.service.IFileService; |
| | | import com.dji.sample.media.util.ImgUtil; |
| | |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*; |
| | |
| | | private IMarkMapper markMapper; |
| | | @Autowired |
| | | private INailMapper nailMapper; |
| | | @Autowired |
| | | private IZipMapper zipMapper; |
| | | @Autowired |
| | | private GetPatchesMapper patchesMapper; |
| | | @Autowired |
| | |
| | | .eq(MediaFileEntity::getFileId, fileId)); |
| | | return Optional.ofNullable(fileEntity); |
| | | } |
| | | |
| | | public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) { |
| | | try { |
| | | MediaFileMarkEntity mediaFileMarkEntity= new MediaFileMarkEntity(); |
| | | mediaFileMarkEntity.setWorkspaceId(workspaceId); |
| | | mediaFileMarkEntity.setIsadd(0); |
| | | mediaFileMarkEntity.setIsOriginal(false); |
| | | mediaFileMarkEntity.setFileId(UUID.randomUUID().toString()); |
| | | mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath()+ "/" + file.getFileName()); |
| | | mediaFileMarkEntity.setFileName("mark" + file.getFileName()); |
| | | mediaFileMarkEntity.setFilePath("mark" + file.getFilePath()); |
| | | uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg"); |
| | | markMapper.insert(mediaFileMarkEntity); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | @Override |
| | | public Boolean checkExist(String workspaceId, String fingerprint) { |
| | | return this.getMediaByFingerprint(workspaceId, fingerprint).isPresent(); |
| | | } |
| | | |
| | | @Override |
| | | public Integer saveFile(String workspaceId, FileUploadDTO file) { |
| | | public Integer saveFile(String workspaceId, FileUploadDTO file) throws ImageProcessingException, IOException { |
| | | MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); |
| | | fileEntity.setWorkspaceId(workspaceId); |
| | | fileEntity.setFileId(UUID.randomUUID().toString()); |
| | | //避免对视频处理引发报错 |
| | | if (file.getObjectKey().endsWith("jpeg")){ |
| | | fileEntity.setIsadd(0); |
| | | String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey(); |
| | | File downloadedFile = TbFjServiceImpl.downloadFile(url); |
| | | Object data = ImgUtil.getInfo(downloadedFile); |
| | | fileEntity.setDroneData(data); |
| | | updateStatue(file.getName()); |
| | | } |
| | | return mapper.insert(fileEntity); |
| | | } |
| | | |
| | | public void saveNailFile(String workspaceId, FileUploadDTO file) throws IOException, ImageProcessingException { |
| | | public void saveFiles(String workspaceId, FileUploadDTO file) { |
| | | // 更新文件状态 |
| | | updateStatue(file.getName()); |
| | | 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 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); |
| | | Object data = ImgUtil.getInfo(file1); |
| | | nailEntity.setIsadd(0); |
| | | 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(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 { |
| | | // 下载文件 |
| | | boolean endsWithMp4 = file.getObjectKey().endsWith(".mp4"); |
| | | |
| | | if (endsWithMp4) { |
| | | // 处理视频文件 |
| | | // MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file); |
| | | // zipEntity.setWorkspaceId(workspaceId); |
| | | // zipEntity.setFileId(UUID.randomUUID().toString()); |
| | | // zipMapper.insert(zipEntity); |
| | | |
| | | // 处理视频文件的其他逻辑(如果有) |
| | | } else { |
| | | // 处理图片文件 |
| | | String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey(); |
| | | File downloadedFile = TbFjServiceImpl.downloadFile(url); |
| | | File nailFile = new File(ImgZipUtil.compressImage(downloadedFile, 50).toURI()); |
| | | MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file); |
| | | Object data = ImgUtil.getInfo(downloadedFile); |
| | | nailEntity.setIsadd(0); |
| | | 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("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", file.getObjectKey(), downloadedFile, "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); |
| | | |
| | | // 处理压缩后的图片文件(如果有) |
| | | // File zipFile = new File(ImgZipUtil.compressImageAndGetFile(downloadedFile, 0.5f).toURI()); |
| | | // MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file); |
| | | // zipEntity.setIsOriginal(false); |
| | | // zipEntity.setWorkspaceId(workspaceId); |
| | | // zipEntity.setFileName("zip" + file.getName()); |
| | | // zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName()); |
| | | // zipEntity.setFilePath("zip" + file.getPath()); |
| | | // String zipName = zipEntity.getObjectKey(); |
| | | // zipEntity.setFileId(UUID.randomUUID().toString()); |
| | | |
| | | // 上传压缩文件 |
| | | // uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg"); |
| | | // uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg"); |
| | | // zipMapper.insert(zipEntity); |
| | | } |
| | | } catch (IOException | ImageProcessingException e) { |
| | | // 处理异常 |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void updateStatue(String filename) { |
| | | if (filename.contains("~")) { |
| | |
| | | } |
| | | } |
| | | } else { |
| | | String names = "nail" + filename; |
| | | String names = "nail" + filename; |
| | | List<MediaFileNailEntity> entities = nailMapper.selectList(new LambdaQueryWrapper<MediaFileNailEntity>() |
| | | .eq(MediaFileNailEntity::getFileName, names)); |
| | | if (entities != null && !entities.isEmpty()) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type) { |
| | | public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type,String jobId) { |
| | | // 创建查询条件对象 |
| | | LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | |
| | | return new PaginationData<>(Collections.emptyList(), new Pagination(new Page<>(page, pageSize))); |
| | | } |
| | | queryWrapper.in(MediaFileEntity::getJobId, jobIds); |
| | | } |
| | | if (jobId != null && !jobId.isEmpty()) { |
| | | queryWrapper.eq(MediaFileEntity::getJobId,jobId); |
| | | } |
| | | |
| | | if (type != null && !type.isEmpty()) { |
| | |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (page - 1) * pageSize; |
| | | int end = Math.min(start + pageSize, total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileEntity> resultPage = new Page<>(page, pageSize); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> mediaQuerys(Integer page, Integer pageSize, String workspaceId) { |
| | | // 创建查询条件对象 |
| | | LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 添加查询条件 |
| | | queryWrapper.eq(MediaFileEntity::getWorkspaceId, workspaceId); |
| | | |
| | | |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | |
| | | // 执行查询获取所有结果 |
| | | List<MediaFileEntity> allResults = mapper.selectList(queryWrapper); |
| | | |
| | | // 处理结果去重并设置任务名称 |
| | | Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileEntity> uniqueResults = allResults.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getJobId(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算分页信息 |
| | |
| | | |
| | | @Override |
| | | public ResponseResult downloadImages(List<String> jobIds) { |
| | | String localSaveDir = "/home/drone/web/zip"; |
| | | String downPath="https://wrj.shuixiongit.com/downloadZip/"; |
| | | String filepath=TimerUtil.getNowDay()+".zip"; |
| | | try { |
| | | String bucketPath = "/data/software/minio-data/cloud-bucket/"; |
| | | // List<String> prefixes = getUniqueFilePaths(jobIds); |
| | | 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); |
| | | downloader.downloadAndZipFolders(prefixes, localSaveDir,filepath); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResponseResult.error("下载失败" + e.getMessage()); |
| | | } |
| | | return ResponseResult.success("下载成功"); |
| | | return ResponseResult.success(downPath+filepath); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return builder.build(); |
| | | } |
| | | |
| | | private MediaFileMarkEntity fileUploadConvertToMarkEntity(FileUploadDTO file) { |
| | | MediaFileMarkEntity.MediaFileMarkEntityBuilder builder = MediaFileMarkEntity.builder(); |
| | | private MediaFileNailEntity fileUploadConvertToNailEntity(FileUploadDTO file) { |
| | | MediaFileNailEntity.MediaFileNailEntityBuilder builder = MediaFileNailEntity.builder(); |
| | | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .fingerprint(file.getFingerprint()) |
| | | .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()); |
| | |
| | | return builder.build(); |
| | | } |
| | | |
| | | private MediaFileNailEntity fileUploadConvertToNailEntity(FileUploadDTO file) { |
| | | MediaFileNailEntity.MediaFileNailEntityBuilder builder = MediaFileNailEntity.builder(); |
| | | private MediaFileZipEntity fileUploadConvertToZipEntity(FileUploadDTO file) { |
| | | MediaFileZipEntity.MediaFileZipEntityBuilder builder = MediaFileZipEntity.builder(); |
| | | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | |
| | | |
| | | // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1 |
| | | if (allContainTilde || noneContainTilde) { |
| | | mediaFiles.forEach(file -> { |
| | | file.setIsadd(1); |
| | | updateMediaById(file.getId(), file); |
| | | }); |
| | | return; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public void updateMediaZipFileNames(String jobId) { |
| | | // 查询符合条件的数据 |
| | | List<MediaFileZipEntity> mediaFiles = zipMapper.selectList(new LambdaQueryWrapper<MediaFileZipEntity>() |
| | | .eq(MediaFileZipEntity::getJobId, jobId)); |
| | | boolean allContainTilde = mediaFiles.stream().allMatch(file -> file.getFileName().contains("~")); |
| | | boolean noneContainTilde = mediaFiles.stream().noneMatch(file -> file.getFileName().contains("~")); |
| | | |
| | | // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1 |
| | | if (allContainTilde || noneContainTilde) { |
| | | return; |
| | | } |
| | | |
| | | // 筛选出name字段不包含'~'的数据 |
| | | List<MediaFileZipEntity> filteredFiles = mediaFiles.stream() |
| | | .filter(file -> !file.getFileName().contains("~")) |
| | | .collect(Collectors.toList()); |
| | | for (MediaFileZipEntity currentFile : filteredFiles) { |
| | | String currentName = currentFile.getFileName(); |
| | | Map<String, Object> currentMetadata = JSON.parseObject(JSON.toJSONString(currentFile.getMetadata()), Map.class); |
| | | Long currentCreatedTime = (Long) currentMetadata.get("createdTime"); |
| | | // 找到metadata中的createdTime小于当前数据的createdTime且最接近的那条数据 |
| | | Optional<MediaFileZipEntity> closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime < currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(currentCreatedTime - time1, currentCreatedTime - time2); |
| | | }); |
| | | if (closestFileOpt.isEmpty()) { |
| | | // 找不到小于的文件,尝试找大于且最接近的文件 |
| | | closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime > currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(time1 - currentCreatedTime, time2 - currentCreatedTime); |
| | | }); |
| | | } |
| | | // 提取并替换name字段 |
| | | closestFileOpt.ifPresent(closestFile -> { |
| | | String closestName = closestFile.getFileName(); |
| | | int startIndex = closestName.indexOf("V"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("W"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("Z"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("T"); |
| | | if (startIndex == -1) { |
| | | return; |
| | | } |
| | | int endIndex = closestName.indexOf(".", startIndex); |
| | | if (endIndex == -1) { |
| | | return; |
| | | } |
| | | String replacement = closestName.substring(startIndex, endIndex); |
| | | int currentStartIndex = currentName.indexOf("V"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("W"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("Z"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("T"); |
| | | if (currentStartIndex == -1) { |
| | | return; |
| | | } |
| | | int currentEndIndex = currentName.indexOf(".", currentStartIndex); |
| | | if (currentEndIndex == -1) { |
| | | return; |
| | | } |
| | | String newName = currentName.substring(0, currentStartIndex) |
| | | + replacement |
| | | + currentName.substring(currentEndIndex); |
| | | currentFile.setFileName(newName); |
| | | updateZipById(currentFile.getId(), currentFile); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateMarkMediaFileNames(String jobId) { |
| | | public void updateNailMediaFileNames(String jobId) { |
| | | try { |
| | | // 查询符合条件的数据 |
| | | List<MediaFileNailEntity> mediaFiles = nailMapper.selectList(new LambdaQueryWrapper<MediaFileNailEntity>() |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | |
| | | public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) { |
| | | List<MediaFileEntity> allRecords = new ArrayList<>(); |
| | | int currentPageNum = 1; // 从第一页开始获取记录 |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); |
| | | |
| | | // 用于存储去重后的记录 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = new HashMap<>(); |
| | | // 使用 QueryWrapper 执行查询 |
| | | QueryWrapper<MediaFileEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper |
| | | .eq("workspace_id", workspaceId) |
| | | .orderByDesc("create_time"); // 根据 create_time 降序排序 |
| | | |
| | | while (true) { |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(currentPageNum, pageSize); |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | // 执行分页查询 |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, queryWrapper); |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | |
| | | // 检查是否还有更多记录 |
| | | if (result.isEmpty()) { |
| | | break; // 没有更多记录了,停止请求 |
| | | } |
| | | // 根据 job_id 字段进行去重 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = result.stream() |
| | | .collect(Collectors.toMap( |
| | | MediaFileEntity::getJobId, |
| | | entity -> entity, |
| | | (existing, replacement) -> existing // 如果有重复的,保留已有的 |
| | | )); |
| | | |
| | | // 根据 fileName 字段进行去重并设置 JobName |
| | | result.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .forEach(mediaFile -> uniqueFilesMap.putIfAbsent(mediaFile.getFileName(), mediaFile)); |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | |
| | | // 增加当前页数以获取更多记录 |
| | | currentPageNum++; |
| | | |
| | | // 为每个 MediaFileEntity 设置 jobName |
| | | for (MediaFileEntity mediaFile : uniqueFiles) { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | } |
| | | |
| | | // 获取去重后的实际总数 |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | int uniqueTotal = uniqueFiles.size(); |
| | | // 使用分页对象构造 Pagination |
| | | Page<MediaFileEntity> newPage = new Page<>(pageNum, pageSize); |
| | | newPage.setRecords(uniqueFiles); |
| | | newPage.setTotal(resultPage.getTotal()); // 设置总记录数为原始查询的总记录数 |
| | | |
| | | // 计算当前页的起始和结束索引 |
| | | 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); |
| | | Pagination pagination = new Pagination(newPage); |
| | | return new PaginationData<>(uniqueFiles, 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)); |
| | | |
| | | // 使用 QueryWrapper 来执行查询 |
| | | LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 添加查询条件 |
| | | queryWrapper.eq(MediaFileEntity::getWorkspaceId, workspaceId); |
| | | queryWrapper.eq(MediaFileEntity::getJobId,jobId); |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, queryWrapper); |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | |
| | | // 根据 fileName 字段进行去重 |
| | | // 根据 file_name 字段进行去重 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = result.stream() |
| | | .collect(Collectors.toMap( |
| | | MediaFileEntity::getFileName, |
| | |
| | | |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | |
| | | // 使用去重后的列表重新计算总数 |
| | | int uniqueTotal = uniqueFiles.size(); |
| | | // 为每个 MediaFileEntity 设置 jobName |
| | | for (MediaFileEntity mediaFile : uniqueFiles) { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | } |
| | | |
| | | // 创建新的分页对象,使用去重后的总数 |
| | | Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal); |
| | | // 使用分页对象构造 Pagination |
| | | Page<MediaFileEntity> newPage = new Page<>(pageNum, pageSize); |
| | | newPage.setRecords(uniqueFiles); |
| | | newPage.setTotal(uniqueFiles.size()); // 设置总记录数为去重后的记录数 |
| | | |
| | | // 截取当前页的数据 |
| | | 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); |
| | | Pagination pagination = new Pagination(newPage); |
| | | return new PaginationData<>(uniqueFiles, pagination); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public List<MediaFileEntity> getMedia(String jobId) { |
| | |
| | | } |
| | | |
| | | public void updateById(Integer id, MediaFileNailEntity entity) { |
| | | entity.setIsadd(1); |
| | | // entity.setIsadd(1); |
| | | UpdateWrapper<MediaFileNailEntity> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id); |
| | | nailMapper.update(entity, updateWrapper); |
| | | } |
| | | |
| | | public void updateZipById(Integer id, MediaFileZipEntity entity) { |
| | | UpdateWrapper<MediaFileZipEntity> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id); |
| | | zipMapper.update(entity, updateWrapper); |
| | | } |
| | | |
| | | |
| | | public void updateMediaById(Integer id, MediaFileEntity entity) { |
| | | entity.setIsadd(1); |
| | | UpdateWrapper<MediaFileEntity> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id); |
| | | mapper.update(entity, updateWrapper); |
| | | } |
| | | |
| | | public void getNoaddFile() { |
| | | List<MediaFileNailEntity> markEntities = nailMapper.selectList(new LambdaQueryWrapper<MediaFileNailEntity>().eq(MediaFileNailEntity::getIsadd, 0)); |
| | | for (MediaFileNailEntity mark : markEntities) { |
| | | updateMarkMediaFileNames(mark.getJobId()); |
| | | updateMediaFileNames(mark.getJobId()); |
| | | List<MediaFileEntity> mediaEntities = mapper.selectList( |
| | | new LambdaQueryWrapper<MediaFileEntity>().eq(MediaFileEntity::getIsadd, 0)); |
| | | for (MediaFileEntity media : mediaEntities) { |
| | | // updateNailMediaFileNames(media.getJobId()); |
| | | updateMediaFileNames(media.getJobId()); |
| | | // updateMediaZipFileNames(media.getJobId()); |
| | | } |
| | | } |
| | | |