From 49e1bc66ebaf696ebd3fc3ed33d65c8795fd3cde Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期二, 01 七月 2025 18:05:12 +0800 Subject: [PATCH] 1.巡检定时任务 2.设备管理 3.文档查询 --- main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 158 insertions(+), 6 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java index a00c56e..4866ff5 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java @@ -3,17 +3,33 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.basic.entity.StorageAttachment; +import com.ruoyi.basic.entity.StorageBlob; +import com.ruoyi.basic.entity.dto.StorageBlobDTO; +import com.ruoyi.basic.mapper.StorageAttachmentMapper; +import com.ruoyi.basic.mapper.StorageBlobMapper; +import com.ruoyi.basic.service.StorageAttachmentService; import com.ruoyi.business.dto.ArchiveDto; import com.ruoyi.business.entity.Archive; +import com.ruoyi.business.entity.Tree; import com.ruoyi.business.mapper.ArchiveMapper; +import com.ruoyi.business.mapper.TreeMapper; import com.ruoyi.business.service.ArchiveService; import com.ruoyi.common.utils.bean.BeanUtils; +import com.ruoyi.common.utils.file.MinioUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.Objects; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static com.ruoyi.common.constant.StorageAttachmentConstants.StorageAttachmentFile; +import static com.ruoyi.common.enums.StorageAttachmentRecordType.Archives; + /** * <p> @@ -29,23 +45,153 @@ private final ArchiveMapper archiveMapper; + private final TreeMapper treeMapper; + + private final StorageAttachmentService storageAttachmentService; + + private final StorageBlobMapper storageBlobMapper; + + private final StorageAttachmentMapper storageAttachmentMapper; + + private final MinioUtils minioUtils; + + @Override - public IPage<Archive> selectArchiveList(Page page, ArchiveDto archiveDto) { + public IPage<ArchiveDto> selectArchiveList(Page<Archive> page, ArchiveDto archiveDto) { + // 1. 鍒嗛〉鏌ヨ涓绘暟鎹� LambdaQueryWrapper<Archive> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.orderByDesc(Archive::getCreateTime); - return archiveMapper.selectPage(page, queryWrapper); + if (archiveDto.getTreeId() != null) { + Long treeId = archiveDto.getTreeId(); + // 鍒ゆ柇鏄惁涓轰富ID + Tree tree = treeMapper.selectById(archiveDto.getTreeId()); + boolean isMainId = tree != null && tree.getParentId() == null; + + if (isMainId) { + // 鑾峰彇涓籌D鐨勬墍鏈夐�掑綊瀛愯妭鐐笽D + List<Long> recursiveSubIds = treeMapper.listRecursiveSubNodeIds(treeId); + + // 灏嗕富ID鏈韩鍜屾墍鏈夊瓙鑺傜偣ID鍔犲叆鏌ヨ鏉′欢 + recursiveSubIds.add(treeId); + queryWrapper.in(Archive::getTreeId, recursiveSubIds); + } else { + // 闈炰富ID锛岀洿鎺ユ寜鍘熸潯浠舵煡璇� + queryWrapper.eq(Archive::getTreeId, treeId); + } + } + if (archiveDto.getSearchAll() != null) { + queryWrapper.like(Archive::getName, archiveDto.getSearchAll()); + } + IPage<Archive> archivePage = archiveMapper.selectPage(page, queryWrapper); + + // 2. 鏃犳暟鎹彁鍓嶈繑鍥� + if (CollectionUtils.isEmpty(archivePage.getRecords())) { + return new Page<>(archivePage.getCurrent(), archivePage.getSize(), archivePage.getTotal()); + } + + // 3. 鎵归噺鑾峰彇鎵�鏈夋。妗圛D + List<Long> archiveIds = archivePage.getRecords() + .stream() + .map(Archive::getId) + .collect(Collectors.toList()); + + // 4. 鎵归噺鏌ヨ闄勪欢鏄犲皠鍏崇郴锛堥伩鍏峃+1锛� + + List<StorageAttachment> storageAttachments = storageAttachmentMapper + .selectList(new LambdaQueryWrapper<StorageAttachment>() + .in(StorageAttachment::getRecordId, archiveIds) + .eq(StorageAttachment::getRecordType, Archives.ordinal()) + ); + + Map<Long, List<StorageAttachment>> attachmentsMap = storageAttachmentMapper + .selectList(new LambdaQueryWrapper<StorageAttachment>() + .in(StorageAttachment::getRecordId, archiveIds) + .eq(StorageAttachment::getRecordType, Archives.ordinal()) + ).stream() + .collect(Collectors.groupingBy(StorageAttachment::getRecordId)); + + // 5. 鎵归噺鏌ヨ鎵�鏈夐渶瑕佺殑鏂囦欢鏁版嵁 + Set<Long> blobIds = attachmentsMap.values() + .stream() + .flatMap(List::stream) + .map(StorageAttachment::getStorageBlobId) + .collect(Collectors.toSet()); + Map<Long, StorageBlob> blobMap = blobIds.isEmpty() + ? Collections.emptyMap() + : storageBlobMapper.selectList(new LambdaQueryWrapper<StorageBlob>().in(StorageBlob::getId, blobIds)) + .stream() + .collect(Collectors.toMap(StorageBlob::getId, Function.identity())); + + // 6. 缁勮DTO锛堝崟娆″惊鐜畬鎴愭暟鎹閰嶏級 + List<ArchiveDto> dtoList = archivePage.getRecords().stream().map(archive -> { + ArchiveDto dto = new ArchiveDto(); + BeanUtils.copyProperties(archive, dto); // 澶嶅埗涓诲璞″睘鎬� + + // 鎸夐渶娣诲姞闄勪欢淇℃伅 + List<StorageBlobDTO> blobDTOs = Optional.ofNullable(attachmentsMap.get(archive.getId())) + .orElse(Collections.emptyList()) + .stream() + .map(att -> blobMap.get(att.getStorageBlobId())) + .filter(Objects::nonNull) + .map(blob -> { + StorageBlobDTO blobDTO = new StorageBlobDTO(); + BeanUtils.copyProperties(blob, blobDTO); + + // 鍔ㄦ�佺敓鎴愰瑙堝湴鍧�鍜屼笅杞藉湴鍧� + // 璁剧疆棰勮URL + blobDTO.setUrl(minioUtils.getPreviewUrls( + blob.getBucketFilename(), + blob.getBucketName(), + true + )); + + // 璁剧疆涓嬭浇URL + blobDTO.setDownloadUrl(minioUtils.getDownloadUrls( + blob.getBucketFilename(), + blob.getBucketName(), + blob.getOriginalFilename(), // 鍘熷鏂囦欢鍚� + true + )); + return blobDTO; + }) + .collect(Collectors.toList()); + + dto.setStorageBlobDTO(blobDTOs); + return dto; + }).collect(Collectors.toList()); + + // 7. 鏋勫缓杩斿洖鍒嗛〉瀵硅薄 + IPage<ArchiveDto> resultPage = new Page<>(); + BeanUtils.copyProperties(archivePage, resultPage); + resultPage.setRecords(dtoList); + return resultPage; } @Override public int addOrEditArchive(ArchiveDto archiveDto) { Archive archive = new Archive(); BeanUtils.copyProperties(archiveDto, archive); + int i; if (Objects.isNull(archiveDto.getId())) { - - return archiveMapper.insert(archive); + i = archiveMapper.insert(archive); } else { - return archiveMapper.updateById(archive); + i = archiveMapper.updateById(archive); } + if (archiveDto.getStorageBlobDTO() != null && !archiveDto.getStorageBlobDTO().isEmpty()) { + List<StorageAttachment> attachments = new ArrayList<>(); + + for (StorageBlobDTO storageBlobDTO : archiveDto.getStorageBlobDTO()) { + StorageAttachment storageAttachment = new StorageAttachment( + StorageAttachmentFile, + (long) Archives.ordinal(), + archive.getId() + ); + storageAttachment.setStorageBlobDTO(storageBlobDTO); + attachments.add(storageAttachment); + } + storageAttachmentService.saveStorageAttachment(attachments, archive.getId(), Archives, StorageAttachmentFile); + } + return i; } @Override @@ -61,4 +207,10 @@ // 鎵ц鎵归噺閫昏緫鍒犻櫎 return archiveMapper.update(null, updateWrapper); } + + @Override + public List<StorageAttachment> fileList(ArchiveDto archiveDto) { + List<StorageAttachment> storageAttachments = storageAttachmentService.selectStorageAttachments(archiveDto.getId(), Archives, StorageAttachmentFile); + return storageAttachments; + } } -- Gitblit v1.9.3