AttributeBaseDomainService { public List<CategoryAttribute> findAllByCategoryId(Long categoryId) { List<Long> ancestorIds = backCategoryDomainReadService.findAncestorIdsOf(categoryId); Map<String, CategoryAttribute> leafCtgAttrMap = getAttrModelMap(categoryId); ancestorIds.remove(categoryId); ancestorIds.stream() .sorted(Comparator.reverseOrder()) .forEach(cid -> { List<CategoryAttribute> attributes = findByCategoryId(cid); for (CategoryAttribute attr : attributes) { leafCtgAttrMap.putIfAbsent(attrIdentity(attr), attr); } }); return leafCtgAttrMap.values().stream(). sorted(Comparator.comparingLong(CategoryAttribute::getIndex)). collect(Collectors.toList()); } AttributeBaseDomainService(CategoryAttributeDAO categoryAttributeDAO,
                                      BackCategoryDomainReadService backCategoryDomainReadService); List<CategoryAttribute> findAllByCategoryId(Long categoryId); Map<String, CategoryAttribute> getAttrModelMap(Long categoryId); List<CategoryAttribute> findByCategoryId(Long categoryId);  }
@Test public void testFindAllByCategoryId() { Long cid = setupTestFindAllByCategoryId(); List<CategoryAttribute> attrs = attributeBaseDomainService.findAllByCategoryId(cid); attrs.stream().map(CategoryAttribute::getAttrValsJson).forEach(System.out::println); assertThat(attrs.stream().map(CategoryAttribute::getAttrKey).collect(Collectors.toList())) .isNotEmpty() .hasSize(5) .containsExactly("同名属性-2", "三级类目属性", "二级类目属性", "同名属性", "一级类目属性"); }