lihao 4 years ago
parent
commit
a3754b76fd

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

@@ -17,10 +17,13 @@ using GxPress.EnumConst;
 using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Friends;
 using GxPress.Request;
+using GxPress.Request.App.GroupUser;
 using GxPress.Request.App.User;
 using GxPress.Request.User;
 using GxPress.Request.UserMiddle;
 using GxPress.Result.App.FileLibrary;
+using GxPress.Result.App.Group;
+using GxPress.Result.App.GroupUser;
 using GxPress.Result.App.User;
 using GxPress.Result.User;
 using GxPress.Service.Interface;
@@ -483,5 +486,15 @@ namespace GxPress.Api.AppControllers
         {
             return await _userService.GetFriendUserInfoResult(_loginContext.AccountId, keyWord);
         }
+        /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpGet("group-user")]
+        public async Task<IEnumerable<GroupUserListResult>> GetGroupUserAsync([FromQuery] GroupUserFindRequest request)
+        {
+            return await _userRepository.GetGroupUserAsync(request);
+        }
     }
 }

+ 10 - 4
gx_api/GxPress/Model/GxPress.Request/App/GroupUser/GroupUserFindRequest.cs

@@ -1,7 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
 namespace GxPress.Request.App.GroupUser
 {
     /// <summary>
@@ -13,5 +9,15 @@ namespace GxPress.Request.App.GroupUser
         /// 小组ID
         /// </summary>
         public int GroupId { get; set; }
+        /// <summary>
+        /// 2 普通 1 主要
+        /// </summary>
+        /// <value></value>
+        public int TypeId { get; set; }
+        /// <summary>
+        /// 搜索关键字
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
     }
 }

+ 10 - 1
gx_api/GxPress/Model/GxPress.Result/App/GroupUser/GroupUserListResult.cs

@@ -43,6 +43,15 @@ namespace GxPress.Result.App.GroupUser
         /// 创建时间
         /// </summary>
         public DateTime? CreatedDate { get; set; }
-
+        /// <summary>
+        ///环信
+        /// </summary>
+        /// <value></value>
+        public string ImId { get; set; }
+        /// <summary>
+        /// 邮箱
+        /// </summary>
+        /// <value></value>
+        public string Email { get; set; }
     }
 }

+ 6 - 12
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -255,24 +255,18 @@ namespace GxPress.Repository.Implement
             if (!string.IsNullOrEmpty(groupDetail.HistoryAvatarUrl))
                 groupDetail.HistoryAvatarUrl = StringUtils.AddDomain(groupDetail.HistoryAvatarUrl);
             var sql =
-                $@"SELECT a.*,b.Name,b.AvatarUrl,c.Name  FROM tede_group_user a 
+                $@"SELECT a.Id,a.GroupUserRoleId,a.CreatedDate,a.GroupId,b.Id as UserId,b.Name,b.AvatarUrl,b.Email,b.ImId,c.Name as DepartmentName  FROM tede_group_user a 
                 inner join tede_user b on a.UserId=b.Id 
                 inner join tede_department c on b.DepartmentId=c.Id 
-                where a.GroupId=@groupId order by a.GroupUserRoleId";
+                where a.GroupId={request.GroupId} order by a.GroupUserRoleId";
             var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);
             var connection = database.GetConnection();
             var result =
                 await connection
-                    .QueryAsync<GroupUserListResult, User, Department, GroupUserListResult>(sql,
-                        (groupUserListResult, user, department) =>
-                        {
-                            groupUserListResult.DepartmentName = department.Name;
-                            groupUserListResult.Name = user.Name;
-                            groupUserListResult.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
-                            return groupUserListResult;
-                        }, new { groupId = request.GroupId }, splitOn: "Name");
-
+                    .QueryAsync<GroupUserListResult>(sql);
+            foreach (var item in result)
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
             var groupDetailResult = _mapper.Map<GroupDetailResult>(groupDetail);
             groupDetailResult.GroupUserListResult = result;
             var groupUser = await _groupUserRepository.GetAsync(Q.Where(nameof(GroupUser.UserId), request.UserId)
@@ -730,6 +724,6 @@ namespace GxPress.Repository.Implement
             }
             return result;
         }
-       
+
     }
 }

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

@@ -26,6 +26,8 @@ using GxPress.Result.App.User;
 using GxPress.Result.Job;
 using GxPress.Common.Http;
 using GxPress.Repository.Interface.DepartmentUser;
+using GxPress.Request.App.GroupUser;
+using GxPress.Result.App.GroupUser;
 
 namespace GxPress.Repository.Implement
 {
@@ -1081,5 +1083,55 @@ namespace GxPress.Repository.Implement
             var result = await connection.ExecuteScalarAsync<int>(sql);
             return result;
         }
+        /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<GroupUserListResult>> GetGroupUserAsync(GroupUserFindRequest request)
+        {
+            string sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                sqlStr += $@" AND (b.Name LIKE '%{request.KeyWord}%'
+               OR b.Phone LIKE '%{request.KeyWord}%'
+               OR b.Email LIKE '%{request.KeyWord}%')";
+            }
+            if (request.TypeId == 1)
+                sqlStr += " AND a.GroupUserRoleId IN (1,2)";
+            if (request.TypeId == 2)
+                sqlStr += " AND a.GroupUserRoleId=3";
+            string sql = $@"SELECT 
+                            a.Id,
+                            a.GroupUserRoleId,
+                            a.CreatedDate,
+                            a.GroupId,
+                            b.Id AS UserId,
+                            b.Name,
+                            b.AvatarUrl,
+                            b.Email,
+                            b.ImId,
+                            c.Name AS DepartmentName
+                        FROM
+                            tede_group_user a
+                                INNER JOIN
+                            tede_user b ON a.UserId = b.Id
+                                INNER JOIN
+                            tede_department c ON b.DepartmentId = c.Id
+                        WHERE
+                            a.GroupId = {request.GroupId}
+                               {sqlStr}
+                        ORDER BY a.GroupUserRoleId";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<GroupUserListResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.Email = string.IsNullOrEmpty(item.Email) ? string.Empty : item.Email;
+            }
+            return result;
+        }
     }
 }

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

@@ -8,6 +8,9 @@ using Datory;
 using GxPress.Result.App.User;
 using GxPress.Result.Job;
 using SqlKata;
+using GxPress.Result.App.Group;
+using GxPress.Request.App.GroupUser;
+using GxPress.Result.App.GroupUser;
 
 namespace GxPress.Repository.Interface
 {
@@ -269,5 +272,11 @@ namespace GxPress.Repository.Interface
         /// <param name="userId"></param>
         /// <returns></returns>
         Task<int> GetUserUReadFlowTodoCountAsync(int userId);
+        /// <summary>
+        /// 获取小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<IEnumerable<GroupUserListResult>> GetGroupUserAsync(GroupUserFindRequest request);
     }
 }