From b33e6f53dd537abaebad066de12474580fcc33b2 Mon Sep 17 00:00:00 2001 From: yaowanxin <3588231647@qq.com> Date: 星期四, 21 八月 2025 15:03:14 +0800 Subject: [PATCH] Merge branch 'pim_ywx' --- src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 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 new file mode 100644 index 0000000..54c642e --- /dev/null +++ b/src/main/java/com/ruoyi/warehouse/service/impl/DocumentClassificationServiceImpl.java @@ -0,0 +1,97 @@ +package com.ruoyi.warehouse.service.impl; + +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; +import com.ruoyi.warehouse.service.DocumentClassificationService; +import com.ruoyi.warehouse.mapper.DocumentClassificationMapper; +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 +* @description 閽堝琛ㄣ�恉ocument_classification(鏂囨。鍒嗙被琛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇 +* @createDate 2025-08-15 10:44:23 +*/ +@Service +public class DocumentClassificationServiceImpl extends ServiceImpl<DocumentClassificationMapper, DocumentClassification> + implements DocumentClassificationService{ + @Autowired + private DocumentationMapper documentationMapper; + @Autowired + private DocumentClassificationMapper documentClassificationMapper; + @Override + public boolean deleteByIds(List<Long> ids) { + 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()); + } + 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