| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public List<SvyLibScriptCategoryVO> selectSvyLibScriptCategoryList(SvyLibScriptCategory svyLibScriptCategory) { |
| | | List<SvyLibScriptCategory> svyLibScriptCategories = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory); |
| | | //将pid为空的,过滤掉 |
| | | svyLibScriptCategories = svyLibScriptCategories.stream().filter(assort -> assort.getPid() == null).collect(Collectors.toList()); |
| | | //// //将pid为空的,过滤掉 |
| | | // svyLibScriptCategories = svyLibScriptCategories.stream().filter(assort -> assort.getPid() == null).collect(Collectors.toList()); |
| | | // |
| | | // List<SvyLibScriptCategoryVO> SvyLibScriptCategoryVO = DtoConversionUtils.sourceToTarget(svyLibScriptCategories, SvyLibScriptCategoryVO.class); |
| | | // //遍历查出来的数据,通过 id=pid 获取他们的子数据 |
| | | // for (SvyLibScriptCategoryVO svyLibScriptCategoryVO : SvyLibScriptCategoryVO) { |
| | | // if (svyLibScriptCategoryVO.getPid() != null) { |
| | | // continue; |
| | | // } |
| | | // SvyLibScriptCategory svyLibScriptCategory1 = new SvyLibScriptCategory(); |
| | | // svyLibScriptCategory1.setPid(svyLibScriptCategoryVO.getId()); |
| | | // List<SvyLibScriptCategory> svyLibScriptCategories1 = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory1); |
| | | // if (!Collections.isEmpty(svyLibScriptCategories1)) { |
| | | // svyLibScriptCategoryVO.setSvyLibScriptCategoryList(svyLibScriptCategories1); |
| | | // } |
| | | // } |
| | | List<SvyLibScriptCategoryVO> svyLibScriptCategoryVOS = DtoConversionUtils.sourceToTarget(svyLibScriptCategories, SvyLibScriptCategoryVO.class); |
| | | |
| | | List<SvyLibScriptCategoryVO> SvyLibScriptCategoryVO = DtoConversionUtils.sourceToTarget(svyLibScriptCategories, SvyLibScriptCategoryVO.class); |
| | | //遍历查出来的数据,通过 id=pid 获取他们的子数据 |
| | | for (SvyLibScriptCategoryVO svyLibScriptCategoryVO : SvyLibScriptCategoryVO) { |
| | | if (svyLibScriptCategoryVO.getPid() != null) { |
| | | continue; |
| | | } |
| | | SvyLibScriptCategory svyLibScriptCategory1 = new SvyLibScriptCategory(); |
| | | svyLibScriptCategory1.setPid(svyLibScriptCategoryVO.getId()); |
| | | List<SvyLibScriptCategory> svyLibScriptCategories1 = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory1); |
| | | if (!Collections.isEmpty(svyLibScriptCategories1)) { |
| | | svyLibScriptCategoryVO.setSvyLibScriptCategoryList(svyLibScriptCategories1); |
| | | List<SvyLibScriptCategoryVO> rootList = new ArrayList<>(); |
| | | Map<Long, SvyLibScriptCategoryVO> categoryMap = new HashMap<>(); |
| | | |
| | | // 建立id->对象的映射 |
| | | for (SvyLibScriptCategoryVO category : svyLibScriptCategoryVOS) { |
| | | categoryMap.put(category.getId(), category); |
| | | } |
| | | |
| | | for (SvyLibScriptCategoryVO category : svyLibScriptCategoryVOS) { |
| | | if (category.getPid() == null || category.getPid() == -1) { |
| | | // 顶层节点 |
| | | rootList.add(category); |
| | | } else { |
| | | // 找到父节点,并添加到其子节点列表 |
| | | SvyLibScriptCategoryVO parent = categoryMap.get(category.getPid()); |
| | | if (parent != null) { |
| | | SvyLibScriptCategory sc = DtoConversionUtils.sourceToTarget(category, SvyLibScriptCategory.class); |
| | | parent.getSvyLibScriptCategoryList().add(sc); |
| | | } |
| | | } |
| | | } |
| | | return SvyLibScriptCategoryVO; |
| | | return rootList; |
| | | } |
| | | |
| | | /** |