|
@@ -207,7 +207,47 @@ namespace GxPress.Repository.Implement
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 获取树列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<List<DepartmentTreeResult>> GetTreeAsync()
|
|
|
+ {
|
|
|
+ var departments = await GetAllAsync(Q.Where(nameof(Department.Id), ">", 0));
|
|
|
|
|
|
+ var departmentParent = departments.Where(n => n.ParentId == 0);
|
|
|
+ var list = _mapper.Map<List<DepartmentTreeResult>>(departmentParent);
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ item.HasChildren = departments.Any(n => n.ParentId == item.Id);
|
|
|
+ if (item.HasChildren)
|
|
|
+ {
|
|
|
+ var departmentChildren = departments.Where(n => n.ParentId == item.Id);
|
|
|
+ var departmentChildrenTree = departmentChildren.Select(n => _mapper.Map<DepartmentTreeResult>(n));
|
|
|
+ item.ChildrenItems = GetTreeAsync(departments.ToList(), item.Id, departmentChildrenTree.ToList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ public List<DepartmentTreeResult> GetTreeAsync(List<Department> departments, int id, List<DepartmentTreeResult> items)
|
|
|
+ {
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ item.HasChildren = departments.Any(n => n.ParentId == item.Id);
|
|
|
+ if (item.HasChildren)
|
|
|
+ {
|
|
|
+ var departmentParent = departments.Where(n => n.ParentId == item.Id);
|
|
|
+ item.ChildrenItems = _mapper.Map<List<DepartmentTreeResult>>(departmentParent);
|
|
|
+ foreach (var childrenItem in item.ChildrenItems)
|
|
|
+ {
|
|
|
+ GetTreeAsync(departments, childrenItem.Id, items);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 根据部门ID获取成员以及下级部门
|
|
|
/// </summary>
|