From 9d5128803ebebb5788f13924a5775ac16494dfef Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期一, 18 八月 2025 10:05:05 +0800
Subject: [PATCH] 仓库,树,文档,借出修改

---
 src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java |   71 +++++++++++++++++++++++++++++++++--
 1 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java b/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java
index 63e4640..a36a143 100644
--- a/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java
+++ b/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java
@@ -3,6 +3,12 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.dto.ProductTreeDto;
+import com.ruoyi.basic.pojo.Product;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.warehouse.dto.DocumentClassificationDto;
+import com.ruoyi.warehouse.dto.DocumentClassificationTreeDto;
+import com.ruoyi.warehouse.dto.DocumentationDto;
 import com.ruoyi.warehouse.mapper.DocumentationMapper;
 import com.ruoyi.warehouse.pojo.DocumentClassification;
 import com.ruoyi.warehouse.pojo.Documentation;
@@ -11,7 +17,9 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 /**
 * @author 86151
@@ -23,16 +31,69 @@
     implements DocumentClassificationService{
     @Autowired
     private DocumentationMapper documentationMapper;
-
+    @Autowired
+    private DocumentClassificationMapper documentClassificationMapper;
     @Override
     public boolean deleteByIds(List<Long> ids) {
-        List<Documentation> documentations = documentationMapper.selectList(new LambdaQueryWrapper<Documentation>().in(Documentation::getDocumentClassificationId, ids));
-        if(!CollectionUtils.isEmpty(documentations)){
-            return false;
+        List<DocumentClassification> list = documentClassificationMapper.selectList(new LambdaQueryWrapper<DocumentClassification>().in(DocumentClassification::getId, ids));
+        for (DocumentClassification documentClassification : list) {
+          //濡傛灉姣忛」鐨勭埗id涓虹┖锛岃鏄庢槸鏍硅妭鐐癸紝闇�瑕佸垹闄ゆ枃妗d俊鎭〃涓殑鏁版嵁
+            List<DocumentationDto> documentationDtos = documentationMapper.listByDocumentClassificationId(documentClassification.getId());
+            if (CollectionUtils.isNotEmpty(documentationDtos)){
+                throw new RuntimeException("瀛樺湪鏂囨。淇℃伅锛屼笉鑳藉垹闄�");
+            }
+            documentClassificationMapper.deleteById(documentClassification.getId());
         }
-        baseMapper.deleteBatchIds(ids);
         return true;
     }
+
+    @Override
+    public List<DocumentClassificationTreeDto> selectDocumentClassificationList(DocumentClassificationDto documentClassificationDto) {
+        // 鏌ヨ鏍硅妭鐐癸紙parentId 涓� null锛�
+        LambdaQueryWrapper<DocumentClassification> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.isNull(DocumentClassification::getParentId);
+
+        if (documentClassificationDto.getCategory() != null && !documentClassificationDto.getCategory().isEmpty()) {
+            queryWrapper.like(DocumentClassification::getCategory, documentClassificationDto.getCategory());
+        }
+
+        // 鏌ヨ鏍硅妭鐐瑰垪琛�
+        List<DocumentClassification> rootList = baseMapper.selectList(queryWrapper);
+
+        // 杞崲涓烘爲鑺傜偣骞堕�掑綊鏋勫缓瀛愭爲
+        List<DocumentClassificationTreeDto> tree = new ArrayList<>();
+        for (DocumentClassification documentClassification : rootList) {
+            DocumentClassificationTreeDto node = convertToTreeDto(documentClassification);
+            node.setChildren(buildDocumentChildrenNodes(documentClassification.getId()));
+            tree.add(node);
+        }
+        return tree;
+    }
+    // 閫掑綊鏋勫缓瀛愯妭鐐�
+    private List<DocumentClassificationTreeDto> buildDocumentChildrenNodes(Long parentId) {
+        // 鏌ヨ褰撳墠鐖惰妭鐐圭殑瀛愯妭鐐�
+        LambdaQueryWrapper<DocumentClassification> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(DocumentClassification::getParentId, parentId);
+        List<DocumentClassification> childList = baseMapper.selectList(queryWrapper);
+
+        // 杞崲瀛愯妭鐐瑰苟閫掑綊鏋勫缓瀹冧滑鐨勫瓙鏍�
+        List<DocumentClassificationTreeDto> children = new ArrayList<>();
+        for (DocumentClassification child : childList) {
+            DocumentClassificationTreeDto childNode = convertToTreeDto(child);
+            childNode.setChildren(buildDocumentChildrenNodes(child.getId()));
+            children.add(childNode);
+        }
+
+        return children;
+    }
+    // 灏� DocumentClassification 杞崲涓� DocumentClassificationTreeDto
+    private DocumentClassificationTreeDto convertToTreeDto(DocumentClassification documentClassification) {
+        DocumentClassificationTreeDto dto = new DocumentClassificationTreeDto();
+        BeanUtils.copyProperties(documentClassification, dto);
+        dto.setCategory(documentClassification.getCategory()); // 璁剧疆 label 涓轰骇鍝佸悕绉�
+        dto.setChildren(new ArrayList<>());
+        return dto;
+    }
 }
 
 

--
Gitblit v1.9.3