gaoluyang
3 天以前 d39e4f7d839167c16425086dfa2f8747bccfdff9
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/util/storage/StorageFileUtil.java
@@ -41,7 +41,7 @@
 * - token使用次数控制(Redis)
 * - 图片压缩
 *
 * @author 芋道源码
 * @author 超级管理员
 */
@Component
@RequiredArgsConstructor
@@ -104,21 +104,20 @@
            throw new IllegalArgumentException("关联记录id不能为空");
        }
        // 删除旧附件信息
        // 只删除旧的附件关联记录,保留 blob 记录(文件本身不删除)
        if (application == null || application.trim().isEmpty()) {
            for (SystemStorageAttachmentSaveReqVO.BlobItem item : blobItems) {
                String itemApp = item.getApplication();
                if (itemApp == null || itemApp.trim().isEmpty()) {
                    throw new IllegalArgumentException("文件用途不能为空");
                }
                deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(itemApp, recordType.getType(), recordId);
                storageAttachmentMapper.deleteByApplicationAndRecordTypeAndRecordId(itemApp, recordType.getType(), recordId);
            }
        } else {
            deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType.getType(), recordId);
            storageAttachmentMapper.deleteByApplicationAndRecordTypeAndRecordId(application, recordType.getType(), recordId);
        }
        if (CollUtil.isEmpty(blobItems)) {
            deleteStorageAttachmentsByRecordTypeAndRecordId(recordType.getType(), recordId);
            return;
        }
@@ -142,6 +141,14 @@
        if (CollUtil.isEmpty(storageBlobIds)) {
            return;
        }
        // 生产工单依赖原始文件反映历史版本,不允许通过其他附件入口删除这些共享文件。
        Long snapshotReferences = storageAttachmentMapper.selectCount(
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SystemStorageAttachmentDO>()
                        .eq(SystemStorageAttachmentDO::getRecordType, "mes_work_order_technical_file")
                        .in(SystemStorageAttachmentDO::getStorageBlobId, storageBlobIds));
        if (snapshotReferences != null && snapshotReferences > 0) {
            throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400, "技术文件已被生产工单留存,不能删除");
        }
        // 同时删除磁盘文件
        List<SystemStorageBlobDO> blobs = storageBlobMapper.selectByIds(storageBlobIds);
        for (SystemStorageBlobDO blob : blobs) {