¶Ô±ÈÐÂÎļþ |
| | |
| | | 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 é对表ãdocument_classification(ææ¡£å类表)ãçæ°æ®åºæä½Serviceå®ç° |
| | | * @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为空ï¼è¯´ææ¯æ ¹èç¹ï¼éè¦å é¤ææ¡£ä¿¡æ¯è¡¨ä¸çæ°æ® |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |