/**
* 向上查询所有上级 递归
* @param deptAll 所有集合
* @param leafNodeDept 叶子节点
*/
public static List<ProductClassIficationDTO> getDeptUpList(List<ProductClassIficationDTO> deptAll,ProductClassIficationDTO leafNodeDept){
if(ObjectUtil.isNotEmpty(leafNodeDept)){
List<ProductClassIficationDTO> set = new ArrayList<>();
String parentId = leafNodeDept.getParentGid();
List<ProductClassIficationDTO> parentDepts = deptAll.stream().filter(item -> item.getId().equals(parentId)).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(parentDepts)){
ProductClassIficationDTO parentDept = parentDepts.get(0);
set.add(parentDept);
List<ProductClassIficationDTO> deptUpTree = getDeptUpList(deptAll, parentDept);
if(deptUpTree!=null){
set.addAll(deptUpTree);
}
return set;
}
}
return null;
}
/**
* 向下查询所有下级 递归
* @param treeList 所有集合
* @param id 父节点
*/
public static List<ProductClassIficationDTO> buildTreeUseList(List<ProductClassIficationDTO> treeList,String id) {
//收集传递的集合中父id相同的TreeNode
List<ProductClassIficationDTO> children = new ArrayList<>();
for (ProductClassIficationDTO treeNode : treeList) {
//判断该节点的父id,是否与传入的父id相同,相同则递归设置其孩子节点,并将该节点放入children集合中
if (treeNode.getParentGid().equals(id)) {
//递归设置其孩子节点
treeNode.setChildren(buildTreeUseList(treeList, treeNode.getId()));
//放入children集合
children.add(treeNode);
}
}
return children;
}
重写equals
@Override
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(obj == null && getClass() != obj.getClass()){
return false;
}
ProductClassIficationDTO productClassIficationDTO = (ProductClassIficationDTO) obj;
//当type、color 内容都相等的时候,才返回true
return Objects.equals(classificationCode,productClassIficationDTO.getClassificationCode()) && Objects.equals(description,productClassIficationDTO.getDescription());
}
正则匹配
String regExp = "(\\w+)";
Pattern pattern=Pattern.compile(regExp);
Matcher matcher=pattern.matcher(productClassIficationParam.getKeyword());
while(matcher.find()) {
fenci.add(matcher.group(0));
productClassIficationParam.setKeyword(matcher.group(0).toUpperCase());
// false:组装树数据
List<ProductClassIficationDTO> productClassIficationDTOS = getProductClassIficationDTOS(productClassIficationParam,false);
list.addAll(productClassIficationDTOS);
}