可以使用JSON格式的数据,一层一层包裹
{
BigName: ””,
code :”,
name:[
{
shortCode:””
shortName: ”’
}
]
@ApiModelProperty(value = "科室编号")
private String depcode;
@ApiModelProperty(value = "科室名称")
private String depname;
@ApiModelProperty(value = "下级节点")
private List<DepartmentVo> children;
}
ArrayList<DepartmentVo> result = new ArrayList<>();
//查询所有的科室信息
Department department = new Department();
department.setHoscode(hoscode);
Example<Department> example = Example.of(department);
List<Department> departmentList = departmentRepository.findAll(example);
//首先给根据把大科室 按照大科室编号进行分组(bigcode),在获取每个大科式里面的小科室
Map<String, List<Department>> departmentMap = departmentList.stream()
.collect(Collectors.groupingBy(Department::getBigcode));
//遍历map 集合
for(Map.Entry<String,List<Department>> entry : departmentMap.entrySet()){
//大科室 的编号
String bigCOde = entry.getKey();
//大科室 的编号 对应的全部数据
List<Department> departmentsList = entry.getValue();
//封装大科室
DepartmentVo departmentVo = new DepartmentVo();
departmentVo.setDepcode(bigCOde);
departmentVo.setDepname(departmentsList.get(0).getDepname());
//封装小科室 大科室里面有很多的小科室
ArrayList<DepartmentVo> children = new ArrayList<>();
for (Department departments : departmentsList){
DepartmentVo departmentVo1 = new DepartmentVo();
departmentVo1.setDepcode(departments.getDepcode());
departmentVo1.setDepname(departments.getDepname());
//封装到小科室里
children.add(departmentVo1);
}
//把小科室的信息放到大科室 里
departmentVo.setChildren(children);
//最终放到result 里面
result.add(departmentVo);
}
return result;
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/121410.html