chenhj
2026-04-24 4b2a52eecd3b425bfe592ff7fc2959ef7391b4b6
src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -74,6 +74,7 @@
            storageAttachment.setRecordId(recordId);
            storageAttachment.setStorageBlobId(storageBlobDTO.getId());
            storageAttachment.setDeleted(0L);
            storageAttachments.add(storageAttachment);
        }
        storageAttachmentMapper.insert(storageAttachments);
    }
@@ -154,7 +155,7 @@
    }
    /**
     * 通过文件关联id获取文件信息
     * 通过文件关联id获取文件信息 attachment
     *
     * @param storageAttachmentIds 文件id
     */
@@ -166,7 +167,7 @@
    }
    /**
     * 通过文件用途、关联记录类型、关联记录id获取文件关联信息
     * 通过文件用途、关联记录类型、关联记录id获取文件关联信息 attachment
     *
     * @param application 文件用途
     * @param recordType  关联记录类型
@@ -188,11 +189,11 @@
    }
    /**
     * 通过文件关联id获取文件信息
     * 通过文件关联id获取文件信息 blob
     *
     * @param storageAttachmentIds 文件id
     */
    public List<StorageBlobVO> getStorageBlobDTOsByStorageAttachmentIds(List<Long> storageAttachmentIds) {
    public List<StorageBlobVO> getStorageBlobVOsByStorageAttachmentIds(List<Long> storageAttachmentIds) {
        List<StorageAttachment> storageAttachments = getStorageAttachmentsByStorageAttachmentIds(storageAttachmentIds);
        if (CollectionUtils.isEmpty(storageAttachments)) {
            return null;
@@ -211,12 +212,63 @@
    }
    /**
     * 通过文件关联id获取文件信息存在过期时间
     * 通过文件用途、关联记录类型、关联记录id获取文件信息 blob
     *
     * @param application 文件用途
     * @param recordType  关联记录类型
     * @param recordId    关联记录id
     */
    public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
        if (CollectionUtils.isEmpty(storageAttachments)) {
            return null;
        }
        List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList());
        List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds);
        List<StorageBlobVO> storageBlobDTOS = new ArrayList<>();
        for (StorageBlob storageBlob : storageBlobs) {
            StorageBlobVO storageBlobVO = new StorageBlobVO();
            BeanUtils.copyProperties(storageBlob, storageBlobVO);
            storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
            storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
            storageBlobDTOS.add(storageBlobVO);
        }
        return storageBlobDTOS;
    }
    /**
     * 通过文件用途、关联记录类型、关联记录id获取文件信息 自定义过期时间(分钟) blob
     *
     * @param application 文件用途
     * @param recordType  关联记录类型
     * @param recordId    关联记录id
     * @param expired     过期时间
     */
    public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, BigDecimal expired) {
        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
        if (CollectionUtils.isEmpty(storageAttachments)) {
            return null;
        }
        List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList());
        List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds);
        List<StorageBlobVO> storageBlobDTOS = new ArrayList<>();
        for (StorageBlob storageBlob : storageBlobs) {
            StorageBlobVO storageBlobVO = new StorageBlobVO();
            BeanUtils.copyProperties(storageBlob, storageBlobVO);
            storageBlobVO.setPreviewURL(buildSignedUrl(storageBlobVO, "/preview/", expired));
            storageBlobVO.setDownloadURL(buildSignedUrl(storageBlobVO, "/download/", expired));
            storageBlobDTOS.add(storageBlobVO);
        }
        return storageBlobDTOS;
    }
    /**
     * 通过文件关联id获取文件信息存在过期时间 自定义过期时间(分钟) blob
     *
     * @param storageAttachmentIds 文件id
     * @param expired              过期时间
     */
    public List<StorageBlobVO> getStorageBlobDTOsByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
    public List<StorageBlobVO> getStorageBlobVOsByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
        List<StorageAttachment> storageAttachments = getStorageAttachmentsByStorageAttachmentIds(storageAttachmentIds);
        if (CollectionUtils.isEmpty(storageAttachments)) {
            return null;
@@ -235,7 +287,7 @@
    }
    /**
     * 通过文件关联id获取文件信息
     * 通过文件关联id获取文件信息 attachment
     *
     * @param storageAttachmentIds 文件id
     */
@@ -248,7 +300,7 @@
        for (StorageAttachment storageAttachment : storageAttachments) {
            StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
            BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
            if (CollectionUtils.isEmpty(storageBlobVOS)) {
                storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
            } else {
@@ -260,7 +312,7 @@
    }
    /**
     * 通过文件关联id获取文件信息存在过期时间
     * 通过文件关联id获取文件信息存在过期时间 自定义过期时间(分钟) attachment
     *
     * @param storageAttachmentIds 文件id
     * @param expired              过期时间
@@ -274,7 +326,7 @@
        for (StorageAttachment storageAttachment : storageAttachments) {
            StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
            BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
            if (CollectionUtils.isEmpty(storageBlobVOS)) {
                storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
            } else {
@@ -286,7 +338,7 @@
    }
    /**
     * 通过文件关联id获取文件信息
     * 通过文件关联id获取文件信息 attachment
     *
     * @param application 应用
     * @param recordType  记录类型
@@ -301,7 +353,7 @@
        for (StorageAttachment storageAttachment : storageAttachments) {
            StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
            BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
            if (CollectionUtils.isEmpty(storageBlobVOS)) {
                storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
            } else {
@@ -313,7 +365,7 @@
    }
    /**
     * 通过文件关联id获取文件信息存在过期时间
     * 通过文件关联id获取文件信息存在过期时间 自定义过期时间(分钟) attachment
     *
     * @param application 应用
     * @param recordType  记录类型
@@ -329,7 +381,7 @@
        for (StorageAttachment storageAttachment : storageAttachments) {
            StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
            BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
            if (CollectionUtils.isEmpty(storageBlobVOS)) {
                storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
            } else {
@@ -347,7 +399,7 @@
     */
    public List<String> getFilePreviewURLByStorageAttachmentIds(List<Long> storageAttachmentIds) {
        List<String> res = new ArrayList<>();
        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
        for (StorageBlobVO storageBlobVO : storageBlobVOS) {
            res.add(buildSignedPreviewUrl(storageBlobVO));
        }
@@ -355,14 +407,14 @@
    }
    /**
     * 通过文件关联id获取文件预览地址存在过期时间
     * 通过文件关联id获取文件预览地址存在过期时间 自定义过期时间(分钟)
     *
     * @param storageAttachmentIds 文件关联id
     * @param expired              过期时间
     */
    public List<String> getFilePreviewURLByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
        List<String> res = new ArrayList<>();
        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
        for (StorageBlobVO storageBlobVO : storageBlobVOS) {
            res.add(buildSignedUrl(storageBlobVO, "/preview/", expired));
        }
@@ -376,7 +428,7 @@
     */
    public List<String> getFileDownloadURLByStorageAttachmentIds(List<Long> storageAttachmentIds) {
        List<String> res = new ArrayList<>();
        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
        for (StorageBlobVO storageBlobVO : storageBlobVOS) {
            res.add(buildSignedDownloadUrl(storageBlobVO));
        }
@@ -384,14 +436,14 @@
    }
    /**
     * 通过文件关联id获取文件下载地址存在过期时间
     * 通过文件关联id获取文件下载地址存在过期时间 自定义过期时间(分钟)
     *
     * @param storageAttachmentIds 文件关联id
     * @param expired              过期时间
     */
    public List<String> getFileDownloadURLByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
        List<String> res = new ArrayList<>();
        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
        for (StorageBlobVO storageBlobVO : storageBlobVOS) {
            res.add(buildSignedUrl(storageBlobVO, "/download/", expired));
        }
@@ -490,7 +542,7 @@
    }
    /**
     * 压缩文件
     * 压缩文件 图片
     *
     * @param file 文件
     * @return 压缩后的文件