123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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;
- using Datory;
- 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 =await _userRepository.CountAsync(Q.WhereIn(nameof(Entity.User.Id),userIds));
- }
- }
- return result;
- }
- }
- }
|