目录
1 代码
代码语言:javascript
复制public class ConvertUtils {
public static List<DateSourceType> departmentTransferVO2(List<DateSourceType> list) {
if (ObjectUtils.isEmpty(list)) {
return null;
}
Map<String, DateSourceType> map = list.stream().collect(Collectors.toMap(DateSourceType::getId, v -> v, (a, b) -> a));
return getDepartmentChildVO2(list, map);
}
private static List<DateSourceType> getDepartmentChildVO2(List<DateSourceType> list, Map<String, DateSourceType> map) {
List<DateSourceType> res = new ArrayList<>();
for (DateSourceType departmentVo : list) {
DateSourceType departmentVo1 = map.get(departmentVo.getParentId());
if (departmentVo1 != null) {
List<DateSourceType> childes = departmentVo1.getChildDepartments();
if (childes != null) {
childes.add(departmentVo);
} else {
departmentVo1.setChildDepartments(Lists.newArrayList(departmentVo));
}
} else {
res.add(departmentVo);
}
}
return res;
}
// public static void main(String[] args) {
//
//
// }
}