李昊 4 vuotta sitten
vanhempi
commit
3e24427b45

+ 9 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/DepartmentUser/DepartmentUserRepository.cs

@@ -149,5 +149,14 @@ namespace GxPress.Repository.Implement.DepartmentUser
             }
             return true;
         }
+        /// <summary>
+        /// 根据用户id获取所在部门
+        /// </summary>
+        /// <param name="userIds"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<Entity.DepartmentUser>> GetDepartmentUsersByUserIdsAsync(IEnumerable<int> userIds)
+        {
+            return await _repository.GetAllAsync(Q.WhereIn(nameof(Entity.DepartmentUser.UserId), userIds));
+        }
     }
 }

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

@@ -55,5 +55,11 @@ namespace GxPress.Repository.Interface.DepartmentUser
         /// <param name="departmentIds"></param>
         /// <returns></returns>
         Task<IEnumerable<int>> GetUserIdsByDepartmentIdsAsync(IEnumerable<int> departmentIds);
+         /// <summary>
+        /// 根据用户id获取所在部门
+        /// </summary>
+        /// <param name="userIds"></param>
+        /// <returns></returns>
+        Task<IEnumerable<Entity.DepartmentUser>> GetDepartmentUsersByUserIdsAsync(IEnumerable<int> userIds);
     }
 }

+ 11 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/AdminVerify/AdminVerifyInsetService.cs

@@ -7,6 +7,7 @@ using GxPress.Entity;
 using GxPress.EnumConst;
 using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.AdminVerify;
+using GxPress.Repository.Interface.DepartmentUser;
 using GxPress.Request.App.AdminVerify;
 using GxPress.Request.App.Middle;
 using GxPress.Service.Interface.AdminVerify;
@@ -24,9 +25,10 @@ namespace GxPress.Service.Implement.AdminVerify
         private readonly IGroupChatRepository _groupChatRepository;
         private readonly IMiddleRepository _middleRepository;
         private readonly IGroupUserRepository _groupUserRepository;
+        private readonly IDepartmentUserRepository departmentUserRepository;
         public AdminVerifyInsetService(IAdminVerifyRepository adminVerifyRepository, IUserRepository userRepository,
             IDepartmentRepository departmentRepository, IMiddleService middleService, IGroupRepository groupRepository,
-            IGroupChatRepository groupChatRepository, IMiddleRepository middleRepository, IGroupUserRepository groupUserRepository)
+            IGroupChatRepository groupChatRepository, IMiddleRepository middleRepository, IGroupUserRepository groupUserRepository, IDepartmentUserRepository departmentUserRepository)
         {
             _adminVerifyRepository = adminVerifyRepository;
             _userRepository = userRepository;
@@ -36,6 +38,7 @@ namespace GxPress.Service.Implement.AdminVerify
             _groupChatRepository = groupChatRepository;
             _middleRepository = middleRepository;
             _groupUserRepository = groupUserRepository;
+            this.departmentUserRepository = departmentUserRepository;
         }
 
         /// <summary>
@@ -50,7 +53,8 @@ namespace GxPress.Service.Implement.AdminVerify
             var userDto = await _userRepository.GetAsync(request.UserId);
             //获取员工所有信息
             var users = await _userRepository.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), request.UserIds));
-            var departments = await _departmentRepository.GetAllAsync(Q.WhereIn(nameof(Entity.Department.Id), users.Select(n => n.DepartmentId)));
+            var departmentUsers = await departmentUserRepository.GetDepartmentUsersByUserIdsAsync(request.UserIds);
+            var departments = await _departmentRepository.GetAllAsync(Q.WhereIn(nameof(Entity.Department.Id), departmentUsers.Select(n => n.DepartmentId)));
             foreach (var userId in request.UserIds)
             {
                 var adminVerify = new Entity.AdminVerify();
@@ -59,7 +63,11 @@ namespace GxPress.Service.Implement.AdminVerify
                 var user = users.FirstOrDefault(n => n.Id == userId);
                 if (user == null)
                     continue;
-                var department = departments.FirstOrDefault(n => n.Id == user.DepartmentId);
+                var department = new Entity.Department();
+                if (departmentUsers.FirstOrDefault(n => n.UserId == user.Id) != null)
+                {
+                    department = departments.FirstOrDefault(m => m.Id == departmentUsers.FirstOrDefault(n => n.UserId == user.Id).DepartmentId);
+                }
                 var group = await _groupRepository.GetAsync(request.SourceId);
                 //查询是否存在
                 adminVerify = await _adminVerifyRepository.GetAsync(Q.Where(nameof(Entity.AdminVerify.AdminId), userId).Where(nameof(Entity.AdminVerify.SourceType), request.SourceType).Where(nameof(Entity.AdminVerify.SourceId), group.Id).WhereIn(nameof(Entity.AdminVerify.DisposeType), new List<int> { 0, 1 }));