直接上代码:
/**
* 根据创建人部门id分组,使得一个共享部门一个树形结构
*
* @param bmShares
* @return {@link JSONArray}
*/
private JSONArray getShareBybmGroup(List<DghyYjhcHcxShare> bmShares) {
JSONArray array = new JSONArray();
//通过部门id分组
bmShares.stream().collect(Collectors.groupingBy(DghyYjhcHcxShare::getCreatedUnitId, Collectors.toList()))
.forEach((id, items) -> {
JSONObject result = new JSONObject();
result.put("bmid", id);
result.put("bmName", items.get(0).getCreatedUnitName());
result.put("datas", items);
array.add(result);
});
return array;
}
该篇文章介绍了如何使用Java编程实现根据创建人部门ID对共享数据进行分组,生成每个共享部门的树形结构,使用了StreamAPI和收集器功能。

3652

被折叠的 条评论
为什么被折叠?



