lihao 4 years ago
parent
commit
a2df4f30c6

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

@@ -496,5 +496,16 @@ namespace GxPress.Api.AppControllers
         {
             return await _userRepository.GetGroupUserAsync(request);
         }
+
+           /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpGet("group-users")]
+        public async Task<IEnumerable<GroupUserListResult>> GetGroupUsersAsync([FromQuery] GroupUserFindRequest request)
+        {
+            return await _userRepository.GetGroupUsersAsync(request);
+        }
     }
 }

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

@@ -1133,5 +1133,38 @@ namespace GxPress.Repository.Implement
             }
             return result;
         }
+
+        /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<GroupUserListResult>> GetGroupUsersAsync(GroupUserFindRequest request)
+        {
+            var userCount = new SqlKata.Query("tede_user");
+            userCount.Where("Id", ">", 0).AsCount("Id");
+            var query = new SqlKata.Query("tede_user");
+            query.Join("tede_department as a", "a.Id", "tede_user.DepartmentId");
+            query.Join("tede_group_user as b", "b.UserId", "tede_user.Id");
+            query.Where("b.GroupId", "=", request.GroupId);
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                query.Where(n => n.OrWhereLike("tede_user.Name", $"%{request.KeyWord}").OrWhereLike("tede_user.Phone", $"%{request.KeyWord}").OrWhereLike("tede_user.Email", $"%{request.KeyWord}"));
+            if (request.TypeId == 1)
+                query.WhereIn("b.GroupUserRoleId", new List<int> { 1, 2 });
+            if (request.TypeId == 2)
+                query.Where("b.GroupUserRoleId", 3);
+            query.Select(
+                     "b.{Id, GroupUserRoleId, CreatedDate,GroupId}",
+                     "tede_user.{Id AS UserId, Name, AvatarUrl,Email,ImId}",
+                     "a.{Name AS DepartmentName}");
+            query.Select(userCount, "UserCount");
+            var result = await _repository.GetAllAsync<GroupUserListResult>(query);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.Email = string.IsNullOrEmpty(item.Email) ? string.Empty : item.Email;
+            }
+            return result;
+        }
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IUserRepository.cs

@@ -278,5 +278,11 @@ namespace GxPress.Repository.Interface
         /// <param name="request"></param>
         /// <returns></returns>
         Task<IEnumerable<GroupUserListResult>> GetGroupUserAsync(GroupUserFindRequest request);
+        /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+         Task<IEnumerable<GroupUserListResult>> GetGroupUsersAsync(GroupUserFindRequest request);
     }
 }