From c383c8ca7053005ffa3ee58efd89956fbf52c9ea Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 07 五月 2026 11:34:19 +0800
Subject: [PATCH] 重构客户档案
---
src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java | 74 +++++++++++++++++++++++++++++++-----
1 files changed, 63 insertions(+), 11 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..986e277 100644
--- a/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java
+++ b/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java
@@ -3,14 +3,17 @@
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.common.utils.bean.BeanUtils;
+import com.ruoyi.warehouse.dto.DocumentClassificationTreeDto;
+import com.ruoyi.warehouse.dto.DocumentationDto;
+import com.ruoyi.warehouse.mapper.DocumentClassificationMapper;
import com.ruoyi.warehouse.mapper.DocumentationMapper;
import com.ruoyi.warehouse.pojo.DocumentClassification;
-import com.ruoyi.warehouse.pojo.Documentation;
import com.ruoyi.warehouse.service.DocumentClassificationService;
-import com.ruoyi.warehouse.mapper.DocumentClassificationMapper;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -19,20 +22,69 @@
* @createDate 2025-08-15 10:44:23
*/
@Service
-public class DocumentClassificationServiceImpl extends ServiceImpl<DocumentClassificationMapper, DocumentClassification>
- implements DocumentClassificationService{
- @Autowired
- private DocumentationMapper documentationMapper;
+@RequiredArgsConstructor
+public class DocumentClassificationServiceImpl extends ServiceImpl<DocumentClassificationMapper, DocumentClassification> implements DocumentClassificationService{
+
+ private final DocumentationMapper documentationMapper;
+ private final 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() {
+ // 鏌ヨ鏍硅妭鐐癸紙parentId 涓� null锛�
+ LambdaQueryWrapper<DocumentClassification> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.isNull(DocumentClassification::getParentId);
+
+ // 鏌ヨ鏍硅妭鐐瑰垪琛�
+ 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