递归调用获取所有父子节点数据

2019-06-26  本文已影响0人  ml66
    @RequestMapping("/zhiwei")
    @ResponseBody
    public Result orgChart(Model model,String orgId){
        try {
            //查询最高级别的职务
            List<OrganizationStructure> dutys = orgService.getStructureDutysForParentIsNull(orgId);
            List<OrganizationStructure> dutyLists=new ArrayList<OrganizationStructure>();
            return Result.success( getChild(dutys,dutyLists));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed(e.getMessage());
        }
    }
 public List<OrganizationStructure> getChild(List<OrganizationStructure> dutys,List<OrganizationStructure> dutyLists){

        if (CollectionUtils.isEmpty(dutys)) {

        }else{
            for (OrganizationStructure orgStructure : dutys){
                String imgPathProfix = ConstantUtil.OSS_FILE_PATH;
                String defaultImgPath = "";
                String imgPath= attachmentDetaillService.getByResourceId(orgStructure.getUserId()).getAttachURL();
                orgStructure.setUserImgUrl(StringUtils.isBlank(imgPath) ? defaultImgPath : imgPathProfix + imgPath);
                dutyLists.add(orgStructure);
                List<OrganizationStructure> childDutyLists = orgService.getStructureDutysForDutyParentId(orgStructure.getDutyId());
                getChild(childDutyLists,dutyLists);
            }
        }
        return dutyLists;
    }
上一篇下一篇

猜你喜欢

热点阅读