package org.springblade.business.feignClient;

import lombok.AllArgsConstructor;
import org.springblade.manager.feign.WbsTreeContractClient;
import org.springblade.manager.vo.WbsTreeContractTreeVOS;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
public class ClientTreePublicCodeClientImpl {

    private final WbsTreeContractClient wbsTreeContractClient;
    
    public List<WbsTreeContractTreeVOS> queryContractWbsTreeByContractIdAndType(String contractId, Integer wbsType, String parentId){
        List<WbsTreeContractTreeVOS> rootTreeNode = this.wbsTreeContractClient.queryContractWbsTreeByContractIdAndType(contractId, wbsType, parentId);
        if(rootTreeNode != null && rootTreeNode.size() != 0){
            rootTreeNode.forEach(vo -> {
                //获取一级子节点
                List<WbsTreeContractTreeVOS> treeNodes = this.wbsTreeContractClient.queryContractWbsTreeByContractIdAndType(contractId, wbsType, vo.getId());
                if(treeNodes != null && treeNodes.size() != 0){
                    vo.setChildren(treeNodes);
                }
            });
        }
        return rootTreeNode;
    }
    
}
