zss
8 天以前 c93fc713fedb68cc96f6f29e0442d949b44b7caa
src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -286,41 +286,20 @@
    /**
     * 通过记录类型获取文件信息 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()));
    }
    /**
@@ -355,6 +334,9 @@
        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<>();
@@ -363,6 +345,7 @@
            BeanUtils.copyProperties(storageBlob, storageBlobVO);
            storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
            storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
            storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
            storageBlobDTOS.add(storageBlobVO);
        }
        return storageBlobDTOS;
@@ -398,6 +381,10 @@
        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<>();
@@ -406,6 +393,7 @@
            BeanUtils.copyProperties(storageBlob, storageBlobVO);
            storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
            storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
            storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
            storageBlobDTOS.add(storageBlobVO);
        }
        return storageBlobDTOS;
@@ -448,6 +436,10 @@
        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<>();
@@ -456,6 +448,7 @@
            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;