/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.label.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import io.swagger.models.auth.In; import org.springblade.common.node.TreeIntegerNode; import org.springblade.common.utils.NodeTreeUtil; import org.springblade.modules.label.entity.LabelEntity; import org.springblade.modules.label.mapper.LabelMapper; import org.springblade.modules.label.service.ILabelService; import org.springblade.modules.label.vo.LabelVO; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * 标签管理 服务实现类 * * @author BladeX * @since 2023-10-28 */ @Service public class LabelServiceImpl extends ServiceImpl implements ILabelService { @Override public IPage selectLabelPage(IPage page, LabelVO label) { return page.setRecords(baseMapper.selectLabelPage(page, label)); } /** * 标签查询,按父id查询下级 * * @param label * @return */ @Override public Object getLabelList(LabelVO label) { Map labelList = baseMapper.getLabelList(label); List list = new ArrayList<>(); // 遍历 labelList.forEach((id, treeNode) -> { if (treeNode.getHasChildren()) { list.add(id); } }); if (list.size() > 0) { // 查询子集 Map childrenLabelList = baseMapper.getChildrenLabelList(list); // 合并集合 labelList.putAll(childrenLabelList); } // 处理并返回 return NodeTreeUtil.getNodeTree(labelList); } @Override public List tree(LabelVO label) { Map labelTreeList = baseMapper.getLabelTreeList(label); List nodeTree = NodeTreeUtil.getNodeTree(labelTreeList); nodeTree.forEach(node -> recursion(node)); return nodeTree; } private void recursion(TreeIntegerNode node) { if (node.getChildren() != null && node.getChildren().size() > 0) { // BigDecimal bigDecimal = BigDecimal.valueOf(0); // node.setCount(node.getChildren().stream().map(item -> { // bigDecimal.add(BigDecimal.valueOf(item.getCount())); // })); node.getChildren().forEach(node2 -> recursion(node2)); } else { node.setChildren(null); } } /** * 查询人员标签(不包含人这一级) * @param label * @return */ @Override public List getPersonLabelList(LabelVO label) { Map labelTreeList = baseMapper.getPersonLabelList(label); List nodeTree = NodeTreeUtil.getNodeTree(labelTreeList); nodeTree.forEach(node -> recursion(node)); return nodeTree; } }