李昊 4 years ago
parent
commit
e6f41fe042

+ 13 - 9
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -990,15 +990,19 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<IEnumerable<UserInfoResult>> GetUserInfoNoFriendsResults(string keyword, IEnumerable<int> userIds)
         {
-            var query = Q.NewQuery();
-            if (!string.IsNullOrEmpty(keyword))
-            {
-                query.OrWhereLike(nameof(User.Name), $"%{keyword}%");
-                query.OrWhereLike(nameof(User.Email), $"%{keyword}%");
-                query.OrWhereLike(nameof(User.Phone), $"%{keyword}%");
-            }
-            query.WhereNotIn(nameof(User.Id), userIds);
-            return await _repository.GetAllAsync<UserInfoResult>(query);
+            userIds = userIds.Distinct();
+            var sqlStr = "";
+            foreach (var item in userIds)
+                sqlStr += $"{item},";
+            sqlStr = sqlStr.Remove(sqlStr.Length - 1, 1);
+            var sql = $@"select * from tede_user where id not in({sqlStr}) and (Name like '%{keyword}%' or phone like '%{keyword}%' or Email like '%{keyword}%')";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<UserInfoResult>(sql);
+            foreach (var item in result)
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+            return result;
         }
     }
 }

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

@@ -497,8 +497,6 @@ namespace GxPress.Service.Implement
                 //获取部门数据
                 userIdsList.AddRange(await departmentUserRepository.GetUserIdsAsync());
             var result = await _userRepository.GetUserInfoNoFriendsResults(keyword, userIdsList);
-            foreach (var item in result)
-                item.AvatarUrl = StringUtils.AddDomain(item.AvatarUrl);
             return result;
         }
     }