DepartmentService.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. using Datory;
  12. namespace GxPress.Service.Implement.Department
  13. {
  14. /// <summary>
  15. /// 部门
  16. /// </summary>
  17. public partial class DepartmentService : IDepartmentService
  18. {
  19. private readonly IMapper _mapper;
  20. private readonly IDepartmentRepository _departmentRepository;
  21. private readonly IUserRepository _userRepository;
  22. private readonly IUserService _userService;
  23. private readonly IDepartmentUserRepository departmentUserRepository;
  24. public DepartmentService(IMapper mapper, IDepartmentRepository departmentRepository,
  25. IUserRepository userRepository, IUserService userService, IDepartmentUserRepository departmentUserRepository)
  26. {
  27. _departmentRepository = departmentRepository;
  28. _userRepository = userRepository;
  29. _userService = userService;
  30. _mapper = mapper;
  31. this.departmentUserRepository = departmentUserRepository;
  32. }
  33. /// <summary>
  34. /// 根据部门ID获取成员以及下级部门
  35. /// </summary>
  36. /// <param name="request"></param>
  37. /// <returns></returns>
  38. public async Task<DepartmentUserResult> GetDepartmentUserResultAsync(DepartmentUserRequest request)
  39. {
  40. var result = await _departmentRepository.GetDepartmentUserResultAsync(request);
  41. if (result.Departments != null)
  42. {
  43. foreach (var item in result.Departments)
  44. {
  45. //获取部门
  46. var departments = new List<Entity.Department>();
  47. await _departmentRepository.GetDepartmentById(item.Id, departments);
  48. var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
  49. item.UserCount =await _userRepository.CountAsync(Q.WhereIn(nameof(Entity.User.Id),userIds));
  50. }
  51. }
  52. return result;
  53. }
  54. }
  55. }