DepartmentService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using AutoMapper;
  4. using GxPress.Repository.Interface;
  5. using GxPress.Request.Department;
  6. using GxPress.Result.Department;
  7. using GxPress.Service.Interface;
  8. using GxPress.Service.Interface.Department;
  9. using GxPress.Repository.Interface.DepartmentUser;
  10. using System.Linq;
  11. namespace GxPress.Service.Implement.Department
  12. {
  13. /// <summary>
  14. /// 部门
  15. /// </summary>
  16. public partial class DepartmentService : IDepartmentService
  17. {
  18. private readonly IMapper _mapper;
  19. private readonly IDepartmentRepository _departmentRepository;
  20. private readonly IUserRepository _userRepository;
  21. private readonly IUserService _userService;
  22. private readonly IDepartmentUserRepository departmentUserRepository;
  23. public DepartmentService(IMapper mapper, IDepartmentRepository departmentRepository,
  24. IUserRepository userRepository, IUserService userService, IDepartmentUserRepository departmentUserRepository)
  25. {
  26. _departmentRepository = departmentRepository;
  27. _userRepository = userRepository;
  28. _userService = userService;
  29. _mapper = mapper;
  30. this.departmentUserRepository = departmentUserRepository;
  31. }
  32. /// <summary>
  33. /// 根据部门ID获取成员以及下级部门
  34. /// </summary>
  35. /// <param name="request"></param>
  36. /// <returns></returns>
  37. public async Task<DepartmentUserResult> GetDepartmentUserResultAsync(DepartmentUserRequest request)
  38. {
  39. var result = await _departmentRepository.GetDepartmentUserResultAsync(request);
  40. if (result.Departments != null)
  41. {
  42. foreach (var item in result.Departments)
  43. {
  44. //获取部门
  45. var departments = new List<Entity.Department>();
  46. await _departmentRepository.GetDepartmentById(item.Id, departments);
  47. var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
  48. item.UserCount = userIds.Count();
  49. }
  50. }
  51. return result;
  52. }
  53. }
  54. }