| | |
| | | } |
| | | |
| | | /** |
| | | * 保存附件信息 |
| | | * |
| | | * @param recordType 关联记录类型 |
| | | * @param recordId 关联记录id |
| | | * @param storageBlobDTOS 文件信息 |
| | | */ |
| | | public void saveStorageAttachmentByRecordTypeAndRecordId(String application,RecordTypeEnum recordType, Long recordId, List<StorageBlobDTO> storageBlobDTOS) { |
| | | if (recordType == null) { |
| | | throw new RuntimeException("关联记录类型不能为空"); |
| | | } |
| | | if (recordId == null) { |
| | | throw new RuntimeException("关联记录id不能为空"); |
| | | } |
| | | |
| | | // 删除旧附件信息 |
| | | if (application == null) { |
| | | for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) { |
| | | deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.getByType(storageBlobDTO.getApplication()), recordType, recordId); |
| | | } |
| | | } else { |
| | | deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.getByType(application), recordType, recordId); |
| | | } |
| | | |
| | | if (CollectionUtils.isEmpty(storageBlobDTOS)) { |
| | | deleteStorageAttachmentsByRecordTypeAndRecordId(recordType, recordId); |
| | | } |
| | | |
| | | List<StorageAttachment> storageAttachments = new ArrayList<>(); |
| | | for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) { |
| | | StorageAttachment storageAttachment = new StorageAttachment(); |
| | | storageAttachment.setApplication(Objects.requireNonNullElseGet(application, () -> ApplicationTypeEnum.getByType(storageBlobDTO.getApplication()).getType())); |
| | | storageAttachment.setRecordType(recordType.getType()); |
| | | storageAttachment.setRecordId(recordId); |
| | | storageAttachment.setStorageBlobId(storageBlobDTO.getId()); |
| | | storageAttachment.setDeleted(0L); |
| | | storageAttachments.add(storageAttachment); |
| | | } |
| | | storageAttachmentMapper.insert(storageAttachments); |
| | | } |
| | | |
| | | /** |
| | | * 删除文件信息 |
| | | * |
| | | * @param storageBlobIds 文件id |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过关联记录类型、关联记录id删除文件信息 |
| | | * |
| | | * @param recordType 关联记录类型 |
| | | * @param recordId 关联记录id |
| | | */ |
| | | public void deleteStorageBlobsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) { |
| | | if (recordId == null || recordId <= 0) { |
| | | throw new RuntimeException("关联记录id不能为空"); |
| | | } |
| | | if (recordType == null) { |
| | | throw new RuntimeException("关联记录类型不能为空"); |
| | | } |
| | | List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordType, recordType.getType()) |
| | | .eq(StorageAttachment::getRecordId, recordId)); |
| | | if (CollectionUtils.isNotEmpty(storageAttachments)) { |
| | | List<Long> storageAttachmentIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId) |
| | | .collect(Collectors.toList()); |
| | | deleteStorageBlobsByStorageAttachmentIds(storageAttachmentIds); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除文件关联信息 |
| | | * |
| | | * @param storageAttachmentIds 文件关联id |
| | |
| | | .eq(StorageAttachment::getRecordType, recordType.getType()) |
| | | .eq(StorageAttachment::getRecordId, recordId) |
| | | .eq(StorageAttachment::getApplication, application.getType())); |
| | | } |
| | | |
| | | /** |
| | | * 删除文件关联信息 |
| | | * |
| | | * @param recordType 关联记录类型 |
| | | * @param recordId 关联记录id |
| | | */ |
| | | public void deleteStorageAttachmentsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) { |
| | | if (recordId == null || recordId <= 0) { |
| | | throw new RuntimeException("关联记录id不能为空"); |
| | | } |
| | | if (recordType == null) { |
| | | throw new RuntimeException("关联记录类型不能为空"); |
| | | } |
| | | deleteStorageBlobsByRecordTypeAndRecordId(recordType, recordId); |
| | | storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordType, recordType.getType()) |
| | | .eq(StorageAttachment::getRecordId, recordId)); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过文件用途、关联记录类型、关联记录id获取文件关联信息 attachment |
| | | * |
| | | * @param recordType 关联记录类型 |
| | | * @param recordId 关联记录id |
| | | */ |
| | | public List<StorageAttachment> getStorageAttachmentsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) { |
| | | if (recordId == null || recordId <= 0) { |
| | | throw new RuntimeException("关联记录id不能为空"); |
| | | } |
| | | if (recordType == null) { |
| | | throw new RuntimeException("关联记录类型不能为空"); |
| | | } |
| | | return storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordType, recordType.getType()) |
| | | .eq(StorageAttachment::getRecordId, recordId)); |
| | | } |
| | | |
| | | /** |
| | | * 通过文件用途、关联记录类型、关联记录id获取文件信息 blob |
| | | * |
| | | * @param application 文件用途 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过文件用途、关联记录类型、关联记录id获取文件信息 blob |
| | | * |
| | | * @param recordType 关联记录类型 |
| | | * @param recordId 关联记录id |
| | | */ |
| | | public List<StorageBlobVO> getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) { |
| | | List<StorageAttachment> storageAttachments = getStorageAttachmentsByRecordTypeAndRecordId(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 文件用途 |