首页 > 其他分享 >递归结果数据形成树

递归结果数据形成树

时间:2024-01-31 11:33:22浏览次数:15  
标签:deptInfo 递归 结果 数据 List equals null data po

一、根据条件查询结果数据

    // 查询每个分子公司的数据
    private List<OrgDeptCountData> getCompanyList( Map<String,Object> map){
        // 获得公司记录
        List<BusiGunAcessRecordRealEx> scgyList = gunRealDataMapper.getDbGunRealData(map);
        // 查询部门信息
        List<DeptInfo> scgyDeptList =deptInfoMapper.getDeptInfo(map);
        List<OrgDeptCountData>  scgyTree = new ArrayList<>();
        // 部门数据转换成组织树
        if(CollectionUtils.isNotEmpty(scgyDeptList)){
            scgyDeptList.forEach(deptInfo ->{
                if(deptInfo.getParentId() ==  0){
                    OrgDeptCountData data = new OrgDeptCountData();
                    data.setDeptId(deptInfo.getId());
                    data.setDeptCode(deptInfo.getDeptCode());
                    data.setDeptName(deptInfo.getDeptName());
                    data.setParentId(deptInfo.getParentId());
                    data.setChildren(new ArrayList<>());
                    data.setGunRealRecords(new ArrayList<>());
                    scgyTree.add(data);
                }else{
                    createDepTree(scgyTree,deptInfo);
                }
            });
        }
        // 有对应的存取记录
        if(CollectionUtils.isNotEmpty(scgyList)){
            List<BaseEmpInfo> empList = baseEmpInfoMapper.getEmpInfo(map);
            if(CollectionUtils.isNotEmpty(empList)){
                setPersonName(scgyList,empList, scgyTree);
            }
        }
       return scgyTree;
    }

二、循环结果形成部门树

    // 递归生成组织结构树
    private void createDepTree(List<OrgDeptCountData> list, DeptInfo data) {
       list.forEach(deptInfo ->{
           if(deptInfo.getDeptId().equals(data.getParentId())){
               OrgDeptCountData node = new OrgDeptCountData();
               node.setDeptId(data.getId());
               node.setDeptCode(data.getDeptCode());
               node.setDeptName(data.getDeptName());
               node.setParentId(data.getParentId());
               node.setChildren(new ArrayList<>());
               node.setGunRealRecords(new ArrayList<>());
               deptInfo.getChildren().add(node);
           }else if(deptInfo.getChildren().size() >0){
               createDepTree(deptInfo.getChildren(),data);
           }
       });
    }

三、主键转名称

    // 人员信息赋值
    private List<BusiGunAcessRecordRealEx> setPersonName( List<BusiGunAcessRecordRealEx> recordList,List<BaseEmpInfo> personList,List<OrgDeptCountData>  list ){
        recordList.forEach(s ->{
            String gunStatus =s.getGunStatus();
            // 存在枪支状态为空的数据
            if(gunStatus !=null){
                if(gunStatus.equals(Constants.SysOptionConf.IN_STATUS.getCode())){
                    s.setGunStatusName("在");
                }else {
                    s.setGunStatusName("离");
                }
            }else{
                s.setGunStatusName("未使用");
            }
            String takeEmpOne = s.getTakeEmpNo1();
            String takeEmpTwo = s.getTakeEmpNo2();
            String repayEmpOne =s.getRepayEmpNo1();
            String repayEmpTwo =s.getRepayEmpNo2();
            if(takeEmpOne !=null){
                BaseEmpInfo info =personList.stream().filter(e ->e.getEmpCode() !=null && e.getEmpCode().equals(takeEmpOne)).findFirst().orElse(null);
                if(info !=null){
                    s.setTakeEmpNoName1(info.getEmpName());
                }
            }
            if(takeEmpTwo !=null){
                BaseEmpInfo twoInfo =personList.stream().filter(e ->e.getEmpCode() !=null && e.getEmpCode().equals(takeEmpTwo)).findFirst().orElse(null);
                if(twoInfo !=null){
                    s.setTakeEmpNoName2(twoInfo.getEmpName());
                }
            }
            if(repayEmpOne !=null){
                BaseEmpInfo repayInfo =personList.stream().filter(e ->e.getEmpCode() !=null && e.getEmpCode().equals(repayEmpOne)).findFirst().orElse(null);
                if(repayInfo !=null){
                    s.setRepayEmpNoName1(repayInfo.getEmpName());
                }
            }
            if(repayEmpTwo !=null){
                BaseEmpInfo repayInfoTwo =personList.stream().filter(e ->e.getEmpCode() !=null && e.getEmpCode().equals(repayEmpTwo)).findFirst().orElse(null);
                if(repayInfoTwo !=null){
                    s.setRepayEmpNoName2(repayInfoTwo.getEmpName());
                }
            }
            cycleGun(list,s);
        });
        return recordList;
    }
// 将数据循环挂在具体部门下面
private List<OrgDeptCountData> cycleGun(List<OrgDeptCountData> list, BusiGunAcessRecordRealEx po){
if(CollectionUtils.isNotEmpty(list)){
list.forEach(t ->{
int count = t.getChildren().size();
if(t.getDeptId().equals(po.getDeptId())){
po.setDeptName(po.getGunCode());
t.getGunRealRecords().add(po);
} else if(count > 0){
cycleGun( t.getChildren(),po);
}
if(po.getDeptCode().indexOf(t.getDeptCode()) == 0){
int num = t.getGunCount();
num++;
t.setGunCount(num);
String status= po.getGunStatus();
if(status !=null){
if(po.getGunStatus().equals(Constants.SysOptionConf.OUT_STATUS.getCode())) {
int offCount = t.getOffCount();
offCount++;
t.setOffCount(offCount);
}else if(po.getGunStatus().equals(Constants.SysOptionConf.IN_STATUS.getCode())) {
int onCount = t.getOnCount();
onCount++;
t.setOnCount(onCount);
}
}else{
int onCount = t.getOnCount();
onCount++;
t.setOnCount(onCount);
}
}
});
}
return list;
}
 

 

标签:deptInfo,递归,结果,数据,List,equals,null,data,po
From: https://www.cnblogs.com/flyShare/p/17998862

相关文章

  • 数据可视化是如何帮助普通人适应大数据时代的?
    在迅速发展的大数据时代,数据可视化为普通人提供了一副魔法镜,让我们得以更轻松、更直观地适应这个充满数字信息的世界。下面我就以可视化从业者的角度,来简单聊聊这个话题。数据可视化首先以图形化的方式呈现了庞大而抽象的数据集,使得我们能够轻松理解和把握信息的本质。......
  • Js存储数据到LocalStorage并设置过期时间
    setLocal=function(key,val){varprefix="project_list_";key=prefix+key;varexpires=600;val=JSON.stringify({'val':val,'expires':newDate().getTime()+expires*1000});......
  • 如何筑造数据安全边界
    本文分享自华为云社区《【云享问答】第6期:如何筑造数据安全边界?》,作者:华为云社区精选。当前AI技术的快速发展,大模型、大数据正在加速对海量多样化数据的应用。数据已经成为核心资产,而数据安全和隐私保护的重要性也日益凸显。数据脱敏作为数据安全管控体系的关键环节,能够有效地保......
  • 白鲸开源荣膺2023年度大数据产业最具投资价值企业奖项
    北京时间2024年2月20日,中国领先的开源技术公司,白鲸开源科技有限公司(以下简称"白鲸开源")荣幸宣布,该公司获得了第六届"年度金猿季大型主题策划活动"颁发的"2023大数据产业年度最具投资价值"奖项。这一殊荣是对白鲸开源在大数据领域取得的卓越成就和突出贡献的认可。金猿季推动......
  • mysql 创建数据库、创建用户
    --设置密码SHOWVARIABLESLIKE'validate_password%';setglobalvalidate_password_check_user_name='ON';setglobalvalidate_password_policy='LOW';setglobalvalidate_password_length=6; --创建数据库createdatabaseifnotex......
  • 白鲸开源荣膺2023年度大数据产业最具投资价值企业奖项
    北京时间2024年2月20日,中国领先的开源技术公司,白鲸开源科技有限公司(以下简称"白鲸开源")荣幸宣布,该公司获得了第六届"年度金猿季大型主题策划活动"颁发的"2023大数据产业年度最具投资价值"奖项。这一殊荣是对白鲸开源在大数据领域取得的卓越成就和突出贡献的认可。金猿季推动......
  • 数据库新手必知!轻松学习SQL外键约束的核心原理和实用技巧
    SQL约束-外键约束简介外键约束(FOREIGNKEY,缩写FK)是用来实现数据库表的参照完整性的。它是指表中某个字段的值依赖于另一张表中某个字段的值,而被依赖的字段必须且有主键约束或者唯一约束。被依赖的表通常称之为父表或者主表,设置外键约束的表称为子表或从表。相关概念主键:可以唯一......
  • 如何将数据转化为可操作的业务洞察_光点科技
    在数字化的商业环境中,企业被海量的数据所包围。从社交媒体互动、销售交易记录到客户反馈,每一项数据都蕴含着潜在的业务价值。然而,数据本身并不能直接为企业带来改变,它需要被转化为可行的业务洞察,才能指导实际的决策和行动。以下是将数据转化为业务洞察的步骤,这些步骤可以帮助决策者......
  • VideoCrafter2:腾讯AI如何用少量数据生成更清晰视频
    引言去年10月,腾讯发布了VideoCrafter1模型,引起了广泛关注。短短3个月后,腾讯AI实验室再次创新,推出了VideoCrafter2模型。这一次,他们克服了高质量视频扩散模型的数据限制,仅使用有限数据就实现了显著改进,既保留了良好的动态效果,又大幅提升了视频质量。VideoCrafter2模型概述VideoCraft......
  • SQL vs NoSQL:系统设计中选择哪个数据库?
    SQLvsNoSQL:系统设计中选择哪个数据库?在设计系统时,您将面临的最关键的系统设计选择之一是选择合适的数据库管理系统(DBMS)。SQL与NoSQL数据库之间的选择可以极大地影响系统的整体性能、可扩展性和通常的成功。这就是为什么我们在系统设计中详细比较了SQL与NoSQL数据库,以帮助您......