From 71fba5328a35b449b11088e540932787220f91d8 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 18 六月 2025 17:28:50 +0800
Subject: [PATCH] 1.生产加工变更库存回滚 2.巡检,档案上传完善

---
 main-business/src/main/java/com/ruoyi/business/service/impl/ArchiveServiceImpl.java |  126 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 116 insertions(+), 10 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 b5553a5..7443026 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,20 +3,27 @@
 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.mapper.ArchiveMapper;
 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.List;
-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;
@@ -38,26 +45,125 @@
 
     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 page, ArchiveDto archiveDto) {
+        // 1. 鍒嗛〉鏌ヨ涓绘暟鎹�
         LambdaQueryWrapper<Archive> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.orderByDesc(Archive::getCreateTime);
-        return archiveMapper.selectPage(page, queryWrapper);
+        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<>();
+        resultPage.setRecords(dtoList);
+        return resultPage;
     }
 
     @Override
     public int addOrEditArchive(ArchiveDto archiveDto) {
         Archive archive = new Archive();
         BeanUtils.copyProperties(archiveDto, archive);
-        int i ;
+        int i;
         if (Objects.isNull(archiveDto.getId())) {
-            i= archiveMapper.insert(archive);
+            i = archiveMapper.insert(archive);
         } else {
-            i= archiveMapper.updateById(archive);
+            i = archiveMapper.updateById(archive);
         }
-        storageAttachmentService.saveStorageAttachment(archiveDto.getAttachments(), archive.getId(),Archives,StorageAttachmentFile);
+        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;
     }
 
@@ -77,7 +183,7 @@
 
     @Override
     public List<StorageAttachment> fileList(ArchiveDto archiveDto) {
-        storageAttachmentService.selectStorageAttachments(archiveDto.getId(), Archives, StorageAttachmentFile);
-        return null;
+        List<StorageAttachment> storageAttachments = storageAttachmentService.selectStorageAttachments(archiveDto.getId(), Archives, StorageAttachmentFile);
+        return storageAttachments;
     }
 }

--
Gitblit v1.9.3