|
@@ -0,0 +1,156 @@
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Dapper;
|
|
|
+using Datory;
|
|
|
+using GxPress.Common.Tools;
|
|
|
+using GxPress.EnumConst;
|
|
|
+using GxPress.Result.Chat;
|
|
|
+using GxPress.Service.Interface;
|
|
|
+using GxPress.Service.Interface.Chat;
|
|
|
+
|
|
|
+namespace GxPress.Service.Implement.Chat
|
|
|
+{
|
|
|
+ public class ChatSearchService : IChatSearchService
|
|
|
+ {
|
|
|
+ private readonly IUserService userService;
|
|
|
+ public ChatSearchService(IUserService userService)
|
|
|
+ {
|
|
|
+ this.userService = userService;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 搜索单聊
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="keyWord"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<IEnumerable<ChatSearchResult>> GetChatSearchAsync(string keyWord, int userId)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(keyWord))
|
|
|
+ return new List<ChatSearchResult>();
|
|
|
+ var chatConstValue = AllTypeConst.Wechat.GetHashCode();
|
|
|
+ string sqlStr = string.Empty;
|
|
|
+ if (!string.IsNullOrEmpty(keyWord))
|
|
|
+ sqlStr += $" and c.Name like '%{keyWord}%'";
|
|
|
+ var sql = $@"SELECT
|
|
|
+ c.Id, c.Name,c.Phone as ImId,c.AvatarUrl,b.LastModifiedDate
|
|
|
+ FROM
|
|
|
+ tede_middle a
|
|
|
+ INNER JOIN
|
|
|
+ tede_often_contact b ON a.middleId = b.Id
|
|
|
+ INNER JOIN
|
|
|
+ tede_user c ON c.Id = b.ContactUserId
|
|
|
+ WHERE
|
|
|
+ a.FolderType = {chatConstValue} AND a.UserId = {userId}
|
|
|
+ AND a.IsDelete = 0
|
|
|
+ AND b.ChatType = 1 {sqlStr}";
|
|
|
+ var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
|
|
|
+ var connection = database.GetConnection();
|
|
|
+ var result = await connection.QueryAsync<ChatSearchResult>(sql);
|
|
|
+ foreach (var item in result)
|
|
|
+ {
|
|
|
+ item.TypeValue = 1;
|
|
|
+ item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 搜索信源文件夹
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="keyWord"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<IEnumerable<ChatSearchResult>> GetChatFolderNameSearchAsync(string keyWord, int userId)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(keyWord))
|
|
|
+ return new List<ChatSearchResult>();
|
|
|
+ var chatConstValue = AllTypeConst.Wechat.GetHashCode();
|
|
|
+ string sqlStr = string.Empty;
|
|
|
+ if (!string.IsNullOrEmpty(keyWord))
|
|
|
+ sqlStr += $" and a.FolderName like '%{keyWord}%'";
|
|
|
+ var sql = $@"SELECT
|
|
|
+ a.Id,a.FolderName as Name,a.LastModifiedDate
|
|
|
+ FROM
|
|
|
+ tede_middle a
|
|
|
+ WHERE
|
|
|
+ a.FolderType = {chatConstValue} AND a.UserId = {userId}
|
|
|
+ AND a.IsDelete = 0
|
|
|
+ AND a.AttributeValue = 2 {sqlStr}";
|
|
|
+ var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
|
|
|
+ var connection = database.GetConnection();
|
|
|
+ var result = await connection.QueryAsync<ChatSearchResult>(sql);
|
|
|
+ foreach (var item in result)
|
|
|
+ {
|
|
|
+ item.TypeValue = 3;
|
|
|
+ item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 搜索信源群聊
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="keyWord"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<IEnumerable<ChatSearchResult>> GetGroupChatNameSearchAsync(string keyWord, int userId)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(keyWord))
|
|
|
+ return new List<ChatSearchResult>();
|
|
|
+ var chatConstValue = AllTypeConst.Wechat.GetHashCode();
|
|
|
+ string sqlStr = string.Empty;
|
|
|
+ if (!string.IsNullOrEmpty(keyWord))
|
|
|
+ sqlStr += $" AND d.Name LIKE '%{keyWord}%'";
|
|
|
+ var sql = $@"SELECT
|
|
|
+ d.Id,
|
|
|
+ d.Name,
|
|
|
+ d.AvatarUrl,
|
|
|
+ d.GroupChatImId AS ImId,
|
|
|
+ d.CreatedDate AS LastModifiedDate
|
|
|
+ FROM
|
|
|
+ tede_middle a
|
|
|
+ INNER JOIN
|
|
|
+ tede_often_contact b ON a.middleId = b.Id
|
|
|
+ INNER JOIN
|
|
|
+ tede_group_chat d ON d.GroupChatImId = b.ContactUserId
|
|
|
+ WHERE
|
|
|
+ a.FolderType = {chatConstValue} AND a.UserId ={userId}
|
|
|
+ AND a.IsDelete = 0
|
|
|
+ AND b.ChatType = 2
|
|
|
+ {sqlStr}
|
|
|
+ ORDER BY d.CreatedDate DESC;";
|
|
|
+ var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
|
|
|
+ var connection = database.GetConnection();
|
|
|
+ var result = await connection.QueryAsync<ChatSearchResult>(sql);
|
|
|
+ foreach (var item in result)
|
|
|
+ {
|
|
|
+ item.TypeValue = 2;
|
|
|
+ item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 查询好友
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="keyWord"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<IEnumerable<ChatSearchResult>> GetFriendUserInfoResult(string keyWord, int userId)
|
|
|
+ {
|
|
|
+ var users = await userService.GetFriendUserInfoResult(userId, keyWord);
|
|
|
+ var result = new List<ChatSearchResult>();
|
|
|
+ foreach (var item in users)
|
|
|
+ {
|
|
|
+ result.Add(new ChatSearchResult
|
|
|
+ {
|
|
|
+ Id = item.Id,
|
|
|
+ Name = item.Name,
|
|
|
+ AvatarUrl = item.AvatarUrl,
|
|
|
+ DepartmentName = item.DepartmentName,
|
|
|
+ ImId = item.Phone
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|