| package com.vincent.rsf.server.manager.service.impl; | 
|   | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.vincent.rsf.common.utils.Utils; | 
| import com.vincent.rsf.framework.common.R; | 
| import com.vincent.rsf.framework.exception.CoolException; | 
| import com.vincent.rsf.server.manager.mapper.MatnrGroupMapper; | 
| import com.vincent.rsf.server.manager.entity.MatnrGroup; | 
| import com.vincent.rsf.server.manager.service.MatnrGroupService; | 
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.List; | 
| import java.util.Map; | 
| import java.util.Objects; | 
| import java.util.stream.Collectors; | 
|   | 
| @Service("matnrGroupService") | 
| public class MatnrGroupServiceImpl extends ServiceImpl<MatnrGroupMapper, MatnrGroup> implements MatnrGroupService { | 
|   | 
|     @Override | 
|     public List<MatnrGroup> getTreeData(Map<String, Object> map) { | 
|         List<MatnrGroup> matnrs = new ArrayList<>(); | 
|         if (Objects.isNull(map)) { | 
|             matnrs = this.list(new LambdaQueryWrapper<MatnrGroup>().orderByAsc(MatnrGroup::getCode)); | 
|         } else { | 
|             if (Objects.isNull(map.get("condition"))) { | 
|                  throw new CoolException("condition参数不能为空!!"); | 
|             } | 
|             if (!StringUtils.isBlank(map.get("condition").toString())) { | 
|                 List<MatnrGroup> groups = this.list(new LambdaQueryWrapper<MatnrGroup>() | 
|                         .like(MatnrGroup::getName, map.get("condition")) | 
|                         .orderByAsc(MatnrGroup::getCode)); | 
|                 List<Long> collect = groups.stream().map(MatnrGroup::getId).collect(Collectors.toList()); | 
|                 List<MatnrGroup> list = this.list(new LambdaQueryWrapper<MatnrGroup>().in(MatnrGroup::getId, collect)); | 
|                 matnrs.addAll(list); | 
|                 if (matnrs.isEmpty()) { | 
|                     return new ArrayList<>(); | 
|                 } | 
|                 MatnrGroup one = this.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getParentId, 0)); | 
|                 if (Objects.isNull(one)) { | 
|                     throw new CoolException("顶级分组不存在,请添加后再操作!!"); | 
|                 } | 
|   | 
|                 List<MatnrGroup> treeData = Utils.toTreeData(matnrs, one.getId(), MatnrGroup::getParentId, MatnrGroup::getId, MatnrGroup::setChildren); | 
|                 return treeData; | 
|             } else { | 
|                 matnrs = this.list(new LambdaQueryWrapper<MatnrGroup>().orderByAsc(MatnrGroup::getCode)); | 
|             } | 
|         } | 
|         List<MatnrGroup> treeData = Utils.toTreeData(matnrs, 0L, MatnrGroup::getParentId, MatnrGroup::getId, MatnrGroup::setChildren); | 
|         if (treeData.isEmpty()) { | 
|             return new ArrayList<>(); | 
|         } | 
|         return treeData; | 
|     } | 
| } |