|
@@ -356,6 +356,24 @@ namespace GxPress.Repository.Implement
|
|
|
return departments;
|
|
|
}
|
|
|
/// <summary>
|
|
|
+ /// 获取所用下级部门
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <param name="departments"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<List<Department>> GetDepartmentByPid(int Pid, List<Department> departments, List<Department> allDepartments)
|
|
|
+ {
|
|
|
+ var departmentList = allDepartments.Where(n => n.ParentId == Pid);
|
|
|
+ if (departmentList.Count() == 0)
|
|
|
+ return departments;
|
|
|
+ foreach (var item in departmentList)
|
|
|
+ {
|
|
|
+ departments.Add(item);
|
|
|
+ await GetDepartmentByPid(item.Id, departments, allDepartments);
|
|
|
+ }
|
|
|
+ return departments;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
/// 根据部门ID获取全名称
|
|
|
/// </summary>
|
|
|
/// <param name="departmentId"></param>
|
|
@@ -381,5 +399,89 @@ namespace GxPress.Repository.Implement
|
|
|
{
|
|
|
return await _repository.GetAllAsync(query);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<IEnumerable<Entity.Department>> GetUserInDepartmentAsync(List<int> departmentIds)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ var departmentIdsList = new List<int>();
|
|
|
+ var result = new DepartmentUserInsResult();
|
|
|
+ result.Result = new List<DepartmentUserInResult>();
|
|
|
+ var allDepartment = await GetAllAsync(Q.Where(nameof(Entity.Department.Id), ">", 0));
|
|
|
+ foreach (var departmentId in departmentIds)
|
|
|
+ {
|
|
|
+ result.Result.Add(new DepartmentUserInResult
|
|
|
+ {
|
|
|
+ DepartmentId = departmentId,
|
|
|
+ Item = await GetDepartmentByPid(departmentId, new List<Entity.Department>(), allDepartment.ToList())
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (departmentIds.Count() == 1)
|
|
|
+ departmentIdsList.AddRange(departmentIds);
|
|
|
+ for (int i = 0; i < result.Result.Count; i++)
|
|
|
+ {
|
|
|
+ for (int k = i + 1; k < result.Result.Count; k++)
|
|
|
+ {
|
|
|
+ if (result.Result[i].Item.Any(n => n.Id == result.Result[k].DepartmentId))
|
|
|
+ {
|
|
|
+ departmentIdsList.Add(result.Result[i].DepartmentId);
|
|
|
+ }
|
|
|
+ else if (result.Result[k].Item.Any(n => n.Id == result.Result[i].DepartmentId))
|
|
|
+ {
|
|
|
+ departmentIdsList.Add(result.Result[k].DepartmentId);
|
|
|
+ result.Result[i].DepartmentId = result.Result[k].DepartmentId;
|
|
|
+ result.Result[i].Item = result.Result[k].Item;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //departmentIdsList.Add(result.Result[i].DepartmentId);
|
|
|
+ departmentIdsList.Add(result.Result[k].DepartmentId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ departmentIdsList = await GetDepartmentDistinct(allDepartment.ToList(), departmentIdsList.Distinct().ToList());
|
|
|
+ return await GetAllAsync(Q.WhereIn(nameof(Entity.Department.Id), departmentIdsList));
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<List<int>> GetDepartmentDistinct(List<Entity.Department> allDepartment, List<int> departmentIds)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ var departmentIdsList = new List<int>();
|
|
|
+ var result = new DepartmentUserInsResult();
|
|
|
+ result.Result = new List<DepartmentUserInResult>();
|
|
|
+ foreach (var departmentId in departmentIds)
|
|
|
+ {
|
|
|
+ result.Result.Add(new DepartmentUserInResult
|
|
|
+ {
|
|
|
+ DepartmentId = departmentId,
|
|
|
+ Item = await GetDepartmentByPid(departmentId, new List<Entity.Department>(), allDepartment.ToList())
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (departmentIds.Count() == 1)
|
|
|
+ departmentIdsList.AddRange(departmentIds);
|
|
|
+ for (int i = 0; i < result.Result.Count; i++)
|
|
|
+ {
|
|
|
+ for (int k = i + 1; k < result.Result.Count; k++)
|
|
|
+ {
|
|
|
+ if (result.Result[i].Item.Any(n => n.Id == result.Result[k].DepartmentId))
|
|
|
+ {
|
|
|
+ departmentIdsList.Add(result.Result[i].DepartmentId);
|
|
|
+ }
|
|
|
+ else if (result.Result[k].Item.Any(n => n.Id == result.Result[i].DepartmentId))
|
|
|
+ {
|
|
|
+ departmentIdsList.Add(result.Result[k].DepartmentId);
|
|
|
+ result.Result[i].DepartmentId = result.Result[k].DepartmentId;
|
|
|
+ result.Result[i].Item = result.Result[k].Item;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //departmentIdsList.Add(result.Result[i].DepartmentId);
|
|
|
+ departmentIdsList.Add(result.Result[i].DepartmentId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return departmentIdsList;
|
|
|
+ }
|
|
|
}
|
|
|
}
|