package org.jeecg.modules.dnc.dto; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.dnc.entity.ComponentInfo; import org.springframework.beans.BeanUtils; 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(); BeanUtils.copyProperties(this, en); list.add(en); }else { ComponentInfo en = new ComponentInfo(); BeanUtils.copyProperties(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(); BeanUtils.copyProperties(info, ext); extList.add(ext); componentExtMap.put(ext.getComponentId(), ext); } for(ComponentExt e : extList){ if(StrUtil.isEmpty(e.getParentId()) && componentExtMap.containsKey(e.getParentId())){ e.setParent(componentExtMap.get(e.getParentId())); } } return extList; } }