李昊 4 years ago
parent
commit
638fcd8fe8

+ 10 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/UserController.cs

@@ -440,5 +440,15 @@ namespace GxPress.Api.AppControllers
         {
             return await friendsRepository.DeleteAsync(request.UserIds, _loginContext.AccountId);
         }
+        /// <summary>
+        /// 根据部门ID获取用户
+        /// </summary>
+        /// /// <param name="departentId"></param>
+        /// <returns></returns>
+        [HttpGet("departent/{departentId}")]
+        public async Task<IEnumerable<UserInfoResult>> GetUserInfoByDepartentResult(int departentId)
+        {
+            return await _userService.GetUserInfoByDepartentResult(departentId);
+        }
     }
 }

+ 10 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/UserController.cs

@@ -490,5 +490,15 @@ namespace GxPress.Api.WebControllers
         {
             return await friendsRepository.DeleteAsync(friendsIds, _loginContext.AccountId);
         }
+        /// <summary>
+        /// 根据部门ID获取用户
+        /// </summary>
+        /// /// <param name="departentId"></param>
+        /// <returns></returns>
+        [HttpGet("departent/{departentId}")]
+        public async Task<IEnumerable<UserInfoResult>> GetUserInfoByDepartentResult(int departentId)
+        {
+            return await _userService.GetUserInfoByDepartentResult(departentId);
+        }
     }
 }

+ 10 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/DepartmentUser/DepartmentUserRepository.cs

@@ -42,7 +42,16 @@ namespace GxPress.Repository.Implement.DepartmentUser
         {
             return await _repository.GetAllAsync<int>(Q.Where(nameof(Entity.DepartmentUser.DepartmentId), departmentId).Select(nameof(Entity.DepartmentUser.UserId)));
         }
-         /// <summary>
+        /// <summary>
+        /// 根据部门ID集合获取用户
+        /// </summary>
+        /// <param name="departmentId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> GetUserIdsAsync(IEnumerable<int> departmentIds)
+        {
+            return await _repository.GetAllAsync<int>(Q.WhereIn(nameof(Entity.DepartmentUser.DepartmentId), departmentIds).Select(nameof(Entity.DepartmentUser.UserId)));
+        }
+        /// <summary>
         /// 获取部门下面的所有用户
         /// </summary>
         /// <param name="departmentId"></param>

+ 0 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -529,7 +529,6 @@ namespace GxPress.Repository.Implement
             user.IsPrivateLetter = !user.IsPrivateLetter;
             return await _repository.UpdateAsync(user);
         }
-
         /// <summary>
         /// 通知
         /// </summary>
@@ -543,7 +542,6 @@ namespace GxPress.Repository.Implement
             user.IsNotice = !user.IsNotice;
             return await _repository.UpdateAsync(user);
         }
-
         /// <summary>
         /// 回复
         /// </summary>

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/DepartmentUser/IDepartmentUserRepository.cs

@@ -43,5 +43,11 @@ namespace GxPress.Repository.Interface.DepartmentUser
         /// <param name="userId"></param>
         /// <returns></returns>
         Task<bool> IsExistsAsync(int userId);
+        /// <summary>
+        /// 根据部门ID集合获取用户
+        /// </summary>
+        /// <param name="departmentId"></param>
+        /// <returns></returns>
+        Task<IEnumerable<int>> GetUserIdsAsync(IEnumerable<int> departmentIds);
     }
 }

+ 12 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/UserService.cs

@@ -518,5 +518,17 @@ namespace GxPress.Service.Implement
             var result = await _userRepository.GetSearchUserInfoResults(keyword, userIdsList);
             return result;
         }
+        /// <summary>
+        /// 根据部门ID获取用户
+        /// </summary>
+        /// <param name="departentId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<UserInfoResult>> GetUserInfoByDepartentResult(int departentId)
+        {
+            var departentList = new List<Entity.Department>();
+            var departent = await _departmentRepository.GetDepartmentById(departentId, departentList);
+            var userIds = await departmentUserRepository.GetUserIdsAsync(departent.Select(n => n.Id));
+            return await _userRepository.GetUserInfoResultsAsync(userIds);
+        }
     }
 }

+ 6 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/IUserService.cs

@@ -77,5 +77,11 @@ namespace GxPress.Service.Interface
         /// <param name="userIds"></param>
         /// <returns></returns>
         Task<IEnumerable<UserInfoResult>> GetSearchUserInfoResults(int userId, string keyword);
+        /// <summary>
+        /// 根据部门ID获取用户
+        /// </summary>
+        /// <param name="departentId"></param>
+        /// <returns></returns>
+        Task<IEnumerable<UserInfoResult>> GetUserInfoByDepartentResult(int departentId);
     }
 }