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);
|
}
|
|
}
|