chenhj
5 天以前 4b9dc71d162f3fcd79bc88b170154b7516fc4962
src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java
@@ -3,9 +3,9 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.StorageBlobDTO;
import com.ruoyi.basic.pojo.StorageAttachment;
import com.ruoyi.basic.mapper.StorageAttachmentMapper;
import com.ruoyi.basic.mapper.StorageBlobMapper;
import com.ruoyi.basic.pojo.StorageAttachment;
import com.ruoyi.basic.pojo.StorageBlob;
import com.ruoyi.basic.service.StorageAttachmentService;
import com.ruoyi.basic.service.StorageBlobService;
@@ -43,17 +43,17 @@
    private MinioUtils minioUtils;
    @Override
    public List<StorageAttachment> selectStorageAttachments(Long recordId, StorageAttachmentRecordType recordType, StorageAttachmentConstants fileType) {
    public List<StorageAttachment> selectStorageAttachments(Long recordId, StorageAttachmentRecordType recordType, String fileType) {
        List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>()
                .eq(StorageAttachment::getRecordId, recordId)
                .eq(StorageAttachment::getRecordType, recordType.ordinal())
                .eq(StorageAttachment::getName, fileType.toString()));
                .eq(StorageAttachment::getName, fileType));
        if (storageAttachments != null) {
            for (StorageAttachment storageAttachment : storageAttachments) {
                StorageBlob storageBlob = storageBlobMapper.selectById(storageAttachment.getStorageBlobId());
                StorageBlobDTO storageBlobDTO = new StorageBlobDTO();
                BeanUtils.copyProperties(storageBlob, storageBlobDTO);
                storageBlobDTO.setUrl(minioUtils.getPreviewUrl(storageBlob.getBucketName(), storageBlob.getBucketName(), true));
                storageBlobDTO.setUrl(minioUtils.getPreviewUrl(storageBlob.getBucketFilename(), storageBlob.getBucketName(), true));
                storageAttachment.setStorageBlobDTO(storageBlobDTO);
            }
        }
@@ -74,17 +74,36 @@
            attachment.setStorageBlobId(storageBlob.getId());
            storageAttachmentMapper.insert(attachment);
        }
    }
    @Override
    public void saveStorageAttachmentByStorageBlob(List<StorageBlobDTO> storageBlobs, Long recordId, StorageAttachmentRecordType recordType, String fileType) {
        // 删除旧图
        deleteStorageAttachment(new StorageAttachment(fileType, (long) recordType.ordinal(), recordId));
        for (StorageBlobDTO storageBlobDTO : storageBlobs) {
            StorageAttachment attachment = new StorageAttachment(
                    fileType,
                    (long) recordType.ordinal(),
                    recordId
            );
            attachment.setStorageBlobDTO(storageBlobDTO);
            // 绑定关联记录
            attachment.setName(fileType);
            attachment.setRecordType((long) recordType.ordinal());
            attachment.setRecordId(recordId);
            attachment.setStorageBlobId(storageBlobDTO.getId());
            storageAttachmentMapper.insert(attachment);
        }
    }
    @Override
    public void saveStorageAttachment(List<StorageAttachment> attachments, Long recordId, StorageAttachmentRecordType recordType, String fileType) {
        // 删除旧图
        deleteStorageAttachment(new StorageAttachment(fileType.toString(), (long) recordType.ordinal(), recordId));
        deleteStorageAttachment(new StorageAttachment(fileType, (long) recordType.ordinal(), recordId));
        for (StorageAttachment attachment : attachments) {
            // 获取关联记录
            StorageBlob storageBlob = attachment.getStorageBlobDTO();
            attachment.setName(fileType.toString());
            attachment.setName(fileType);
            attachment.setRecordType((long) recordType.ordinal());
            attachment.setRecordId(recordId);
            attachment.setStorageBlobId(storageBlob.getId());
@@ -96,8 +115,16 @@
    @Override
    public int deleteStorageAttachment(StorageAttachment storageAttachment) {
        // 先删除明细表
        storageBlobService.deleteStorageBlobs(storageAttachment);
        return storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>()
                .eq(StorageAttachment::getRecordId, storageAttachment.getRecordId())
                .eq(StorageAttachment::getRecordType, storageAttachment.getRecordType())
                .eq(StorageAttachment::getName, storageAttachment.getName()));
    }
    @Override
    public int deleteStorageAttachmentAndBlob(StorageAttachment storageAttachment) {
        // 先删除明细表
        storageBlobService.deleteStorageBlobs(storageAttachment);
        return storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>()
                .eq(StorageAttachment::getRecordId, storageAttachment.getRecordId())