From bd02d873d7bbcae36a2a1262d921f2fc6b0cce09 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 06 五月 2026 14:33:41 +0800
Subject: [PATCH] feat(sales): 新增发货台账详情功能并优化库存管理

---
 src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java |  132 +++++++------------------------------------
 1 files changed, 22 insertions(+), 110 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 a84a70d..410336e 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -5,13 +5,9 @@
 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.dto.StorageBlobDTO;
-import com.ruoyi.basic.mapper.StorageAttachmentMapper;
-import com.ruoyi.basic.mapper.StorageBlobMapper;
-import com.ruoyi.basic.pojo.StorageAttachment;
-import com.ruoyi.basic.pojo.StorageBlob;
-import com.ruoyi.basic.service.StorageAttachmentService;
-import com.ruoyi.common.utils.MinioUtils;
+import com.ruoyi.basic.enums.ApplicationTypeEnum;
+import com.ruoyi.basic.enums.RecordTypeEnum;
+import com.ruoyi.basic.utils.FileUtil;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
@@ -21,17 +17,15 @@
 import com.ruoyi.inspectiontask.service.InspectionTaskService;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.format.DateTimeFormatter;
 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.InspectionTasks;
 
 /**
  * @author :yys
@@ -39,26 +33,15 @@
  */
 @Service
 @Slf4j
+@RequiredArgsConstructor
 public class InspectionTaskServiceImpl extends ServiceImpl<InspectionTaskMapper, InspectionTask> implements InspectionTaskService {
 
 
-    @Autowired
-    private InspectionTaskMapper inspectionTaskMapper;
+    private final InspectionTaskMapper inspectionTaskMapper;
 
-    @Autowired
-    private StorageAttachmentService storageAttachmentService;
+    private final SysUserMapper sysUserMapper;
 
-    @Autowired
-    private StorageBlobMapper storageBlobMapper;
-
-    @Autowired
-    private StorageAttachmentMapper storageAttachmentMapper;
-
-    @Autowired
-    private MinioUtils minioUtils;
-
-    @Autowired
-    private SysUserMapper sysUserMapper;
+    private final FileUtil fileUtil;
 
     @Override
     public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) {
@@ -112,24 +95,6 @@
                         SysUser::getUserId,
                         SysUser::getNickName,
                         (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<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
             InspectionTaskDto dto = new InspectionTaskDto();
             BeanUtils.copyProperties(inspectionTask, dto);  // 澶嶅埗涓诲璞″睘鎬�
@@ -156,38 +121,11 @@
             }
 
             dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
-
             // 鍒濆鍖栦笁涓檮浠跺垪琛�
-            dto.setBeforeProduction(new ArrayList<>());
-            dto.setAfterProduction(new ArrayList<>());
-            dto.setProductionIssues(new ArrayList<>());
+            dto.setCommonFileListVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
+            dto.setCommonFileListAfterVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
+            dto.setCommonFileListBeforeVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.BEFORE_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
 
-            // 澶勭悊闄勪欢鍒嗙被
-            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;
-                            }
-                        }
-                    });
 
             return dto;
         }).collect(Collectors.toList());
@@ -199,29 +137,8 @@
         return resultPage;
     }
 
-    // 鎻愬彇鍒涘缓BlobDTO鐨勫叕鍏辨柟娉�
-    private StorageBlobDTO createBlobDto(StorageBlob blob) {
-        StorageBlobDTO dto = new StorageBlobDTO();
-        BeanUtils.copyProperties(blob, dto);
-
-        // 璁剧疆URL
-        dto.setUrl(minioUtils.getPreviewUrls(
-                blob.getBucketFilename(),
-                blob.getBucketName(),
-                true
-        ));
-
-        // 璁剧疆涓嬭浇URL
-        dto.setDownloadUrl(minioUtils.getDownloadUrls(
-                blob.getBucketFilename(),
-                blob.getBucketName(),
-                blob.getOriginalFilename(),
-                true
-        ));
-        return dto;
-    }
-
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) {
         InspectionTask inspectionTask = new InspectionTask();
         BeanUtils.copyProperties(inspectionTaskDto, inspectionTask);
@@ -233,30 +150,25 @@
         } else {
             i = inspectionTaskMapper.updateById(inspectionTask);
         }
+        // 淇濆瓨鏂囦欢
+        fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId(), inspectionTaskDto.getCommonFileListDTO());
+        fileUtil.saveStorageAttachment(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId(), inspectionTaskDto.getCommonFileListAfterDTO());
+        fileUtil.saveStorageAttachment(ApplicationTypeEnum.BEFORE_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId(), inspectionTaskDto.getCommonFileListBeforeDTO());
 
-        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);
-        }
         return i;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int delByIds(Long[] ids) {
         // 妫�鏌ュ弬鏁�
         if (ids == null || ids.length == 0) {
             return 0;
         }
+        // 鍒犻櫎鏂囦欢
+        fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, Arrays.asList(ids));
+        fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, Arrays.asList(ids));
+        fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.BEFORE_FILE, RecordTypeEnum.INSPECTION_TASK, Arrays.asList(ids));
         return inspectionTaskMapper.deleteBatchIds(Arrays.asList(ids));
     }
 

--
Gitblit v1.9.3