一、根据条件查询结果数据
// 查询每个分子公司的数据 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