| | |
| | | * @param storageBlobDTOS 文件信息 |
| | | */ |
| | | public void saveStorageAttachment(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, List<StorageBlobDTO> storageBlobDTOS) { |
| | | if (CollectionUtils.isEmpty(storageBlobDTOS)) { |
| | | throw new RuntimeException("文件信息不能为空"); |
| | | } |
| | | if (application == null) { |
| | | throw new RuntimeException("文件用途不能为空"); |
| | | } |
| | |
| | | } |
| | | // 删除旧附件信息 |
| | | deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId); |
| | | if (CollectionUtils.isEmpty(storageBlobDTOS)) { |
| | | return; |
| | | } |
| | | List<StorageAttachment> storageAttachments = new ArrayList<>(); |
| | | for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) { |
| | | StorageAttachment storageAttachment = new StorageAttachment(); |
| | | storageAttachment.setApplication(application.getType()); |
| | | storageAttachment.setRecordType(recordType.getType()); |
| | | storageAttachment.setRecordId(recordId); |
| | | storageAttachment.setStorageBlobId(storageBlobDTO.getId()); |
| | | storageAttachment.setDeleted(0L); |
| | | storageAttachments.add(storageAttachment); |
| | | } |
| | | storageAttachmentMapper.insert(storageAttachments); |
| | | } |
| | | |
| | | /** |
| | | * 保存附件信息 |
| | | * |
| | | * @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()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过关联记录类型、关联记录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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除文件关联信息 |
| | | * |
| | | * @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)); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除文件关联信息 attachment |
| | | * |
| | | * @param application 文件用途 |