|
@@ -219,7 +219,16 @@ namespace GxPress.Repository.Implement
|
|
|
{
|
|
|
var result = new DepartmentUserResult();
|
|
|
var departments = await GetListAsync(request);
|
|
|
- result.Departments = departments.ToList();
|
|
|
+ var departmentResults = await GetParentDepartmentResults(request.DepartmentIds.ToList());
|
|
|
+ var departmentList = new List<DepartmentResult>();
|
|
|
+ foreach (var item in departments)
|
|
|
+ {
|
|
|
+ if (departmentResults.Any(n => n.Id.Equals(item.Id)))
|
|
|
+ departmentList.Add(item);
|
|
|
+ }
|
|
|
+ // if (departmentList.Count == 0)
|
|
|
+ // return result;
|
|
|
+ result.Departments = departmentList;
|
|
|
//获取用户ID
|
|
|
var departmentUsers = await departmentUserRepository.GetAllAsync<int>(Q.Where(nameof(Entity.DepartmentUser.DepartmentId), request.DepartmentId).Select(nameof(Entity.DepartmentUser.UserId)));
|
|
|
//判断是否包含该用户
|
|
@@ -483,5 +492,30 @@ namespace GxPress.Repository.Implement
|
|
|
}
|
|
|
return departmentIdsList;
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<IEnumerable<DepartmentResult>> GetParentDepartmentResults(List<int> departmentIds)
|
|
|
+ {
|
|
|
+ var departmentResults = new List<DepartmentResult>();
|
|
|
+ foreach (var item in departmentIds)
|
|
|
+ {
|
|
|
+ await GetParentDepartmentResults(item, departmentResults);
|
|
|
+ }
|
|
|
+ return departmentResults;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<IEnumerable<DepartmentResult>> GetParentDepartmentResults(int departmentId, List<DepartmentResult> departmentResults)
|
|
|
+ {
|
|
|
+ var department = await _repository.GetAsync<DepartmentResult>(Q.Where(nameof(Entity.Department.Id), departmentId));
|
|
|
+ if (department == null)
|
|
|
+ return departmentResults;
|
|
|
+ departmentResults.Add(department);
|
|
|
+ var parentDepartment = await _repository.GetAsync<DepartmentResult>(Q.Where(nameof(Entity.Department.Id), department.ParentId));
|
|
|
+ if (parentDepartment == null)
|
|
|
+ return departmentResults;
|
|
|
+ departmentResults.Add(parentDepartment);
|
|
|
+ await GetParentDepartmentResults(parentDepartment.Id, departmentResults);
|
|
|
+ return departmentResults;
|
|
|
+ }
|
|
|
}
|
|
|
}
|