李昊 преди 4 години
родител
ревизия
964cc396b7

+ 2 - 0
gx_api/GxPress/Model/GxPress.EnumConst/AllTypeConst.cs

@@ -111,6 +111,8 @@ namespace GxPress.EnumConst
     /// /// </summary>
     public enum UserlinkConst
     {
+        [Description("用户")]
+        User = 0,
         [Description("单位通讯录")]
         Work = 1,
         [Description("系统通讯录")]

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

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

+ 7 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/DepartmentUser/IDepartmentUserRepository.cs

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

+ 24 - 9
gx_api/GxPress/Service/GxPress.Service.Implement/UserMiddle/UserMiddleService.cs

@@ -7,6 +7,10 @@ using System.Threading.Tasks;
 using GxPress.Repository.Interface;
 using Datory;
 using System.Linq;
+using GxPress.EnumConst;
+using GxPress.Repository.Interface.DepartmentUser;
+using GxPress.Repository.Interface.Friends;
+
 namespace GxPress.Service.Implement.UserMiddle
 {
     public class UserMiddleService : IUserMiddleService
@@ -18,7 +22,9 @@ namespace GxPress.Service.Implement.UserMiddle
         private readonly IDepartmentRepository _departmentRepository;
         private readonly IGroupChatUserRepository groupChatUserRepository;
         private readonly IGroupUserRepository groupUserRepository;
-        public UserMiddleService(IUserMiddleRepository userMiddleRepository, IUserRepository userRepository, IAddressBookGroupUserRepository addressBookGroupUserRepository, IDepartmentRepository departmentRepository, IAddressBookGroupRepository addressBookGroupRepository, IGroupChatUserRepository groupChatUserRepository, IGroupUserRepository groupUserRepository)
+        private readonly IDepartmentUserRepository departmentUserRepository;
+        private readonly IFriendsRepository friendsRepository;
+        public UserMiddleService(IUserMiddleRepository userMiddleRepository, IUserRepository userRepository, IAddressBookGroupUserRepository addressBookGroupUserRepository, IDepartmentRepository departmentRepository, IAddressBookGroupRepository addressBookGroupRepository, IGroupChatUserRepository groupChatUserRepository, IGroupUserRepository groupUserRepository, IDepartmentUserRepository departmentUserRepository, IFriendsRepository friendsRepository)
         {
             _userMiddleRepoitory = userMiddleRepository;
             _userRepoitory = userRepository;
@@ -27,6 +33,8 @@ namespace GxPress.Service.Implement.UserMiddle
             _addressBookGroupRepository = addressBookGroupRepository;
             this.groupChatUserRepository = groupChatUserRepository;
             this.groupUserRepository = groupUserRepository;
+            this.departmentUserRepository = departmentUserRepository;
+            this.friendsRepository = friendsRepository;
         }
         /// <summary>
         /// 添加用户中间表
@@ -99,28 +107,30 @@ namespace GxPress.Service.Implement.UserMiddle
 
             foreach (var userMiddle in userMiddles)
             {
-                if (userMiddle.SourceType != 0)
+                if (userMiddle.SourceType != UserlinkConst.User.GetHashCode())
                 {
-                    if (userMiddle.SourceType == 1)
+                    if (userMiddle.SourceType == UserlinkConst.Work.GetHashCode())
                     {
                         if (userMiddle.SourceId == 0)
                             //获取所有用户
-                            userIds.AddRange(await _userRepoitory.GetAllIntsAsync(Q.Select(nameof(Entity.User.Id)).Where(nameof(Entity.User.Id), ">", 0)));
+                            userIds.AddRange(await departmentUserRepository.GetUserIdsByUserIdAsync(userId));
                         else
                         {
                             //递归获取部门
                             var departments = new List<Entity.Department>();
                             departments = await _departmentRepository.GetDepartmentById(userMiddle.SourceId, departments);
-                            userIds.AddRange(await _userRepoitory.GetAllIntsAsync(Q.WhereIn(nameof(Entity.User.DepartmentId), departments.Select(n => n.Id))));
+                            //获取部门用户
+                            userIds.AddRange(await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id)));
                         }
                     }
-                    if (userMiddle.SourceType == 2)
+                    //系统
+                    if (userMiddle.SourceType == UserlinkConst.System.GetHashCode())
                     {
                         /// <summary>
                         /// 我的小组
                         /// </summary>
                         /// <value></value>
-                        if (userMiddle.SourceTypeValue == 1)
+                        if (userMiddle.SourceTypeValue == UserlinkConst.MyGroup.GetHashCode())
                         {
                             if (userMiddle.SourceId == 0)
                             {
@@ -136,7 +146,7 @@ namespace GxPress.Service.Implement.UserMiddle
                         /// 我的群聊
                         /// </summary>
                         /// <value></value>
-                        if (userMiddle.SourceTypeValue == 2)
+                        if (userMiddle.SourceTypeValue == UserlinkConst.MyGroupChat.GetHashCode())
                         {
                             if (userMiddle.SourceId == 0)
                             {
@@ -149,7 +159,7 @@ namespace GxPress.Service.Implement.UserMiddle
                             }
                         }
                     }
-                    if (userMiddle.SourceType == 3)
+                    if (userMiddle.SourceType == UserlinkConst.My.GetHashCode())
                     {
                         if (userMiddle.SourceId == 0)
                         {
@@ -164,6 +174,11 @@ namespace GxPress.Service.Implement.UserMiddle
                             userIds.AddRange(addressBookGroupUsers.Select(n => n.UserId).ToList());
                         }
                     }
+                    if (userMiddle.SourceType == UserlinkConst.Other.GetHashCode())
+                    {
+                        if (userMiddle.SourceId == 0)
+                            userIds.AddRange(await friendsRepository.GetFriendsIdsAsync(userId, 0));
+                    }
                 }
             }
             if (userIds.Count() > 0)