| | |
| | | /** |
| | | * 通过记录类型获取文件信息 attachment(分页) |
| | | * |
| | | * @param page 分页参数 |
| | | * @param storageAttachmentDTO 关联记录信息 |
| | | */ |
| | | public IPage<StorageAttachmentVO> getStorageAttachmentVosPageListByApplicationAndRecordTypeAndRecordId(Page page, StorageAttachmentDTO storageAttachmentDTO) { |
| | | // 分页查询符合条件的 StorageAttachment 记录 |
| | | public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(StorageAttachmentDTO storageAttachmentDTO) { |
| | | LambdaQueryWrapper<StorageAttachment> queryWrapper = new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordType, storageAttachmentDTO.getRecordType()) |
| | | .eq(StorageAttachment::getRecordId, storageAttachmentDTO.getRecordId()); |
| | | if (storageAttachmentDTO.getApplication() != null) { |
| | | queryWrapper.eq(StorageAttachment::getApplication, storageAttachmentDTO.getApplication()); |
| | | } |
| | | IPage<StorageAttachmentVO> storageAttachmentIPage = storageAttachmentMapper.selectPage(page, queryWrapper); |
| | | |
| | | // 转换为 StorageAttachmentVO 并获取对应的 StorageBlobVO |
| | | List<StorageAttachmentVO> storageAttachmentVOS = new ArrayList<>(); |
| | | if (CollectionUtils.isNotEmpty(storageAttachmentIPage.getRecords())) { |
| | | for (StorageAttachment storageAttachment : storageAttachmentIPage.getRecords()) { |
| | | StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO(); |
| | | BeanUtils.copyProperties(storageAttachment, storageAttachmentVO); |
| | | List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId())); |
| | | if (CollectionUtils.isEmpty(storageBlobVOS)) { |
| | | storageAttachmentVO.setStorageBlobVOS(new ArrayList<>()); |
| | | } else { |
| | | storageAttachmentVO.setStorageBlobVOS(storageBlobVOS); |
| | | } |
| | | storageAttachmentVOS.add(storageAttachmentVO); |
| | | } |
| | | List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(queryWrapper); |
| | | if (CollectionUtils.isEmpty(storageAttachments)) { |
| | | return null; |
| | | } |
| | | |
| | | // 构建分页结果 |
| | | IPage<StorageAttachmentVO> resultPage = new Page<>(); |
| | | BeanUtils.copyProperties(storageAttachmentIPage, resultPage); |
| | | resultPage.setRecords(storageAttachmentVOS); |
| | | |
| | | return resultPage; |
| | | return getStorageBlobVOsByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList())); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (CollectionUtils.isEmpty(storageAttachments)) { |
| | | return null; |
| | | } |
| | | Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream() |
| | | .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId)); |
| | | |
| | | List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList()); |
| | | List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds); |
| | | List<StorageBlobVO> storageBlobDTOS = new ArrayList<>(); |
| | |
| | | BeanUtils.copyProperties(storageBlob, storageBlobVO); |
| | | storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO)); |
| | | storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO)); |
| | | storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId())); |
| | | storageBlobDTOS.add(storageBlobVO); |
| | | } |
| | | return storageBlobDTOS; |
| | |
| | | if (CollectionUtils.isEmpty(storageAttachments)) { |
| | | return null; |
| | | } |
| | | // 构建 storageBlobId -> storageAttachmentId 的映射 |
| | | Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream() |
| | | .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId)); |
| | | |
| | | List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList()); |
| | | List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds); |
| | | List<StorageBlobVO> storageBlobDTOS = new ArrayList<>(); |
| | |
| | | BeanUtils.copyProperties(storageBlob, storageBlobVO); |
| | | storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO)); |
| | | storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO)); |
| | | storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId())); |
| | | storageBlobDTOS.add(storageBlobVO); |
| | | } |
| | | return storageBlobDTOS; |
| | |
| | | if (CollectionUtils.isEmpty(storageAttachments)) { |
| | | return null; |
| | | } |
| | | // 构建 storageBlobId -> storageAttachmentId 的映射 |
| | | Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream() |
| | | .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId)); |
| | | |
| | | List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList()); |
| | | List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds); |
| | | List<StorageBlobVO> storageBlobDTOS = new ArrayList<>(); |
| | |
| | | BeanUtils.copyProperties(storageBlob, storageBlobVO); |
| | | storageBlobVO.setPreviewURL(buildSignedUrl(storageBlobVO, "/preview/", expired)); |
| | | storageBlobVO.setDownloadURL(buildSignedUrl(storageBlobVO, "/download/", expired)); |
| | | storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId())); |
| | | storageBlobDTOS.add(storageBlobVO); |
| | | } |
| | | return storageBlobDTOS; |