package com.lxzn.framework.domain.nc.ext; import com.fasterxml.jackson.annotation.JsonIgnore; import com.lxzn.framework.domain.nc.ComponentInfo; import com.lxzn.framework.utils.BeanMapper; import com.lxzn.framework.utils.ValidateUtil; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = false) @Slf4j public class ComponentExt extends ComponentInfo { private ComponentExt parent; private List children; @JsonIgnore private String userId; public boolean hasChild() { boolean b = true; if(this.getChildren() == null || this.getChildren().size() < 1) { b = false; } return b; } public List getAllChildren(List list) { if(this.hasChild()) { List extList = this.getChildren(); for(ComponentExt ext : extList) { list = ext.getAllChildren(list); } ComponentInfo en = new ComponentInfo(); BeanMapper.copy(this, en); list.add(en); }else { ComponentInfo en = new ComponentInfo(); BeanMapper.copy(this, en); list.add(en); } return list; } public static List convertToExtList(List componentInfoList){ List extList = new ArrayList<>(); ComponentExt ext; Map componentExtMap = new HashMap<>(); for(ComponentInfo info : componentInfoList){ ext = new ComponentExt(); BeanMapper.copy(info, ext); extList.add(ext); componentExtMap.put(ext.getComponentId(), ext); } for(ComponentExt e : extList){ if(ValidateUtil.validateString(e.getParentId()) && componentExtMap.containsKey(e.getParentId())){ e.setParent(componentExtMap.get(e.getParentId())); } } return extList; } }