From 203aa55d3bd0316967c217bd4bd475d6b170550c Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 23 一月 2026 11:31:33 +0800
Subject: [PATCH] yys  金鹰黄金修改巡检管理

---
 src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java |  110 ++++++++++++++++++++++---------------------------------
 1 files changed, 44 insertions(+), 66 deletions(-)

diff --git a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
index 26e3bdd..a1ac3b2 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -11,6 +11,7 @@
 import com.ruoyi.basic.pojo.StorageAttachment;
 import com.ruoyi.basic.pojo.StorageBlob;
 import com.ruoyi.basic.service.StorageAttachmentService;
+import com.ruoyi.common.enums.FileNameType;
 import com.ruoyi.common.utils.MinioUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -21,10 +22,15 @@
 import com.ruoyi.inspectiontask.service.InspectionTaskService;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.sales.mapper.CommonFileMapper;
+import com.ruoyi.sales.pojo.CommonFile;
+import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -59,6 +65,12 @@
     @Autowired
     private SysUserMapper sysUserMapper;
 
+    @Autowired
+    private CommonFileServiceImpl commonFileService;
+
+    @Autowired
+    private CommonFileMapper commonFileMapper;
+
     @Override
     public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) {
         LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>();
@@ -70,9 +82,9 @@
             return new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
         }
         // 鑾峰彇id闆嗗悎
-        List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).toList();
+        List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).collect(Collectors.toList());
         //鐧昏浜篿ds
-        List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).toList();
+        List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList());
         // 鎵归噺鏌ヨ鐧昏浜�
         Map<Long, SysUser> sysUserMap;
         if (!registrantIds.isEmpty()) {
@@ -81,9 +93,6 @@
         } else {
             sysUserMap = new HashMap<>();
         }
-        //宸℃浜篿ds
-        List<String> inspectorIds = entityPage.getRecords().stream().map(InspectionTask::getInspectorId).toList();
-
         //鑾峰彇鎵�鏈変笉閲嶅鐨勭敤鎴稩D
         Set<Long> allUserIds = entityPage.getRecords().stream()
                 .map(InspectionTask::getInspectorId) // 鑾峰彇"2,3"杩欐牱鐨勫瓧绗︿覆
@@ -110,22 +119,13 @@
                         (existing, replacement) -> existing));
 
         //澶勭悊闄勪欢
-        Map<Long, List<StorageAttachment>> attachmentsMap = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>().in(StorageAttachment::getRecordId, ids)
-                        .eq(StorageAttachment::getRecordType, InspectionTasks.ordinal()))
-                .stream()
-                .collect(Collectors.groupingBy(StorageAttachment::getRecordId));
-        //  鎵归噺鏌ヨ鎵�鏈夐渶瑕佺殑鏂囦欢鏁版嵁
-        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()));
-
+        List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                .in(CommonFile::getCommonId, ids)
+                .in(CommonFile::getType, Arrays.asList(FileNameType.INSPECTION.getValue(), FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue(), FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())));
+        if(commonFiles == null){
+            commonFiles = new ArrayList<>();
+        }
+        List<CommonFile> finalCommonFiles = commonFiles;
         List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
             InspectionTaskDto dto = new InspectionTaskDto();
             BeanUtils.copyProperties(inspectionTask, dto);  // 澶嶅埗涓诲璞″睘鎬�
@@ -151,37 +151,11 @@
                 dto.setInspector(inspectorNames);
             }
 
-            // 鍒濆鍖栦笁涓檮浠跺垪琛�
-            dto.setBeforeProduction(new ArrayList<>());
-            dto.setAfterProduction(new ArrayList<>());
-            dto.setProductionIssues(new ArrayList<>());
+            dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
 
-            // 澶勭悊闄勪欢鍒嗙被
-            Optional.ofNullable(attachmentsMap.get(inspectionTask.getId()))
-                    .orElse(Collections.emptyList())
-                    .forEach(attachment -> {
-                        StorageBlob blob = blobMap.get(attachment.getStorageBlobId());
-                        if (blob != null) {
-                            // 鍒涘缓闄勪欢DTO
-                            StorageBlobDTO blobDto = createBlobDto(blob);
-
-                            // 鏍规嵁type鍒嗙被
-                            switch ((int) blob.getType().longValue()) {
-                                case 0:
-                                    dto.getBeforeProduction().add(blobDto);
-                                    break;
-                                case 1:
-                                    dto.getAfterProduction().add(blobDto);
-                                    break;
-                                case 2:
-                                    dto.getProductionIssues().add(blobDto);
-                                    break;
-                                default:
-                                    // 鍙�夛細璁板綍鏈垎绫荤被鍨�
-                                    break;
-                            }
-                        }
-                    });
+            dto.setCommonFileList(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION.getValue())).collect(Collectors.toList()));
+            dto.setCommonFileListAfter(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())).collect(Collectors.toList()));
+            dto.setCommonFileListBefore(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue())).collect(Collectors.toList()));
 
             return dto;
         }).collect(Collectors.toList());
@@ -216,7 +190,7 @@
     }
 
     @Override
-    public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) {
+    public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) throws IOException {
         InspectionTask inspectionTask = new InspectionTask();
         BeanUtils.copyProperties(inspectionTaskDto, inspectionTask);
         inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId());
@@ -228,20 +202,21 @@
             i = inspectionTaskMapper.updateById(inspectionTask);
         }
 
-        if (inspectionTaskDto.getStorageBlobDTO() != null && !inspectionTaskDto.getStorageBlobDTO().isEmpty()) {
-            List<StorageAttachment> attachments = new ArrayList<>();
-
-            for (StorageBlobDTO storageBlobDTO : inspectionTaskDto.getStorageBlobDTO()) {
-                StorageAttachment storageAttachment = new StorageAttachment(
-                        StorageAttachmentFile,
-                        (long) InspectionTasks.ordinal(),
-                        inspectionTask.getId()
-                );
-                storageAttachment.setStorageBlobDTO(storageBlobDTO);
-                attachments.add(storageAttachment);
-            }
-            storageAttachmentService.saveStorageAttachment(attachments, inspectionTask.getId(), InspectionTasks, StorageAttachmentFile);
-        }
+//        if (inspectionTaskDto.getStorageBlobDTO() != null && !inspectionTaskDto.getStorageBlobDTO().isEmpty()) {
+//            List<StorageAttachment> attachments = new ArrayList<>();
+//
+//            for (StorageBlobDTO storageBlobDTO : inspectionTaskDto.getStorageBlobDTO()) {
+//                StorageAttachment storageAttachment = new StorageAttachment(
+//                        StorageAttachmentFile,
+//                        (long) InspectionTasks.ordinal(),
+//                        inspectionTask.getId()
+//                );
+//                storageAttachment.setStorageBlobDTO(storageBlobDTO);
+//                attachments.add(storageAttachment);
+//            }
+//            storageAttachmentService.saveStorageAttachment(attachments, inspectionTask.getId(), InspectionTasks, StorageAttachmentFile);
+//        }
+        commonFileService.migrateTempFilesToFormal(inspectionTask.getId(),inspectionTaskDto.getTempFileIds());
         return i;
     }
 
@@ -251,6 +226,9 @@
         if (ids == null || ids.length == 0) {
             return 0;
         }
+        commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION.getValue());
+        commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue());
+        commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_AFTER.getValue());
         return inspectionTaskMapper.deleteBatchIds(Arrays.asList(ids));
     }
 

--
Gitblit v1.9.3