1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cn.iocoder.yudao.module.system.api.storage;
 
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageAttachmentListReqVO;
import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageAttachmentSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
import cn.iocoder.yudao.module.system.service.storage.SystemStorageAttachmentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
public class StorageAttachmentApiImpl implements StorageAttachmentApi {
 
    @Resource
    private SystemStorageAttachmentService systemStorageAttachmentService;
 
    @Override
    public void bindAttachments(String application, String recordType, Long recordId, List<Long> blobIds) {
        if (blobIds == null || blobIds.isEmpty()) {
            return;
        }
        SystemStorageAttachmentSaveReqVO reqVO = new SystemStorageAttachmentSaveReqVO();
        reqVO.setApplication(application != null ? application : "file");
        reqVO.setRecordType(recordType);
        reqVO.setRecordId(recordId);
        List<SystemStorageAttachmentSaveReqVO.BlobItem> blobItems = new ArrayList<>();
        for (Long blobId : blobIds) {
            SystemStorageAttachmentSaveReqVO.BlobItem item = new SystemStorageAttachmentSaveReqVO.BlobItem();
            item.setBlobId(blobId);
            blobItems.add(item);
        }
        reqVO.setBlobItems(blobItems);
        systemStorageAttachmentService.bindAttachments(reqVO);
    }
 
    @Override
    public List<StorageBlobRespDTO> listAttachments(String recordType, Long recordId) {
        SystemStorageAttachmentListReqVO reqVO = new SystemStorageAttachmentListReqVO();
        reqVO.setRecordType(recordType);
        reqVO.setRecordId(recordId);
        List<SystemStorageBlobRespVO> list = systemStorageAttachmentService.listAttachments(reqVO);
        return BeanUtils.toBean(list, StorageBlobRespDTO.class);
    }
 
    @Override
    public void deleteAttachments(List<Long> attachmentIds) {
        if (attachmentIds == null || attachmentIds.isEmpty()) {
            return;
        }
        systemStorageAttachmentService.deleteAttachments(attachmentIds);
    }
 
    @Override
    public void deleteAttachmentsByRecord(String recordType, Long recordId) {
        systemStorageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(recordType, recordId);
    }
 
}