1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using AutoMapper;
- using GxPress.Repository.Interface;
- using GxPress.Request.Department;
- using GxPress.Result.Department;
- using GxPress.Service.Interface;
- using GxPress.Service.Interface.Department;
- using GxPress.Repository.Interface.DepartmentUser;
- using System.Linq;
- namespace GxPress.Service.Implement.Department
- {
- /// <summary>
- /// 部门
- /// </summary>
- public partial class DepartmentService : IDepartmentService
- {
- private readonly IMapper _mapper;
- private readonly IDepartmentRepository _departmentRepository;
- private readonly IUserRepository _userRepository;
- private readonly IUserService _userService;
- private readonly IDepartmentUserRepository departmentUserRepository;
- public DepartmentService(IMapper mapper, IDepartmentRepository departmentRepository,
- IUserRepository userRepository, IUserService userService, IDepartmentUserRepository departmentUserRepository)
- {
- _departmentRepository = departmentRepository;
- _userRepository = userRepository;
- _userService = userService;
- _mapper = mapper;
- this.departmentUserRepository = departmentUserRepository;
- }
- /// <summary>
- /// 根据部门ID获取成员以及下级部门
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<DepartmentUserResult> GetDepartmentUserResultAsync(DepartmentUserRequest request)
- {
- var result = await _departmentRepository.GetDepartmentUserResultAsync(request);
- if (result.Departments != null)
- {
- foreach (var item in result.Departments)
- {
- //获取部门
- var departments = new List<Entity.Department>();
- await _departmentRepository.GetDepartmentById(item.Id, departments);
- var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
- item.UserCount = userIds.Count();
- }
- }
- return result;
- }
- }
- }
|