public Page <Sys_Role> GetList(int pageIndex, int pageSize, string keyWord) { var condition = FreeSql.Select <Sys_Role>() .Where(t => t.DeleteMark == false) .WhereIf(!string.IsNullOrEmpty(keyWord), t => t.Name.Contains(keyWord) || t.EnCode.Contains(keyWord)) .From <Sys_Organize>((r, o) => r.LeftJoin(a => a.OrganizeId == o.Id)) .LeftJoin <Sys_Organize>((r, o) => r.OrganizeId == o.Id); var total = condition.Count(); var items = condition.OrderBy((a, b) => a.SortCode) .ToList((a, b) => new Sys_Role { AllowEdit = a.AllowEdit, CreateTime = a.CreateTime, CreateUser = a.CreateUser, DeleteMark = a.DeleteMark, EnCode = a.EnCode, Id = a.Id, IsEnabled = a.IsEnabled, ModifyTime = a.ModifyTime, ModifyUser = a.ModifyUser, Name = a.Name, OrganizeId = a.OrganizeId, Remark = a.Remark, SortCode = a.SortCode, Type = a.Type, DeptName = b.FullName }); return(new Page <Sys_Role> { Items = items, TotalItems = total }); }
public async Task <long> GetMessageSessionById(long messageId) { return(await FreeSql.Select <im_chat_message>().Where(x => x.MessageId == messageId) .ToOneAsync(x => x.SessionId)); ; }
/// <summary> /// 获取包含用户Id列表的群组信息 /// </summary> /// <param name="sessionId"></param> /// <returns></returns> public async Task <DTO_UserSession> GetSessionInfoById(long sessionId) { var s = await FreeSql.Select <im_chat_session>().Where(x => x.SessionId == sessionId).ToOneAsync <DTO_UserSession>(); s.SessionUserIds = await GetSessionUserIds(sessionId); return(s); }
/// <summary> /// 获取用户相关连的会话列表 /// </summary> /// <param name="userId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public async Task <IPagedList <DTO_UserSession> > GetUserSessions(string userId, int pageIndex = 1, int pageSize = 20) { var query = FreeSql.Select <im_chat_session, im_chat_userInSession, im_chat_message>() .InnerJoin((x1, x2, x3) => x1.SessionId == x2.SessionId) .LeftJoin((x1, x2, x3) => x1.LastMessageId == x3.MessageId) .Where((x1, x2, x3) => x2.UserId == userId); var count = await query.CountAsync(); if (count <= 0) { return(VM_PagedList <DTO_UserSession> .Empty(pageIndex, pageSize)); } var t = await query .OrderBy((x1, x2, x3) => x2.Order) .OrderByDescending((x1, x2, x3) => x1.LastActivityDt) .Skip((pageIndex - 1) * pageSize) .Take(pageSize) .ToListAsync <DTO_UserSession>((x1, x2, x3) => new DTO_UserSession() { SessionId = x1.SessionId, Name = x1.Name, ContentType = x3 == null?null:(int?)x3.ContentType, LastMessageContent = x3 == null?"":x3.Content, CreateDt = x1.CreateDt, CreateUserId = x1.CreateUserId, ExtData = x1.ExtData, HeaderImageUrl = x1.HeaderImageUrl, IsPublic = x1.IsPublic, LastMessageId = x1.LastMessageId, Type = x1.Type }); if (t.HasData()) { var sessionIds = t.Select(x => x.SessionId).ToArrayEx(); var mappingIDs = await FreeSql.Select <im_chat_userInSession>() .Where(x => sessionIds.Contains(x.SessionId)).ToListAsync(x => new { x.SessionId, x.UserId }); foreach (var session in t) { session.SessionUserIds = mappingIDs.Where(x => x.SessionId == session.SessionId) .Select(x => x.UserId); } //FreeSql.Select<im_chat_userMessageStatus,im_chat_message>() // .InnerJoin((x1,x2)=>x1.SessionId==x2.SessionId) // .Where((x1,x2)=>x1.UserId==userId) // .GroupBy((x1,x2)=>x2.SessionId) // .Having((x1,x2)=> x1.Value.Item2.MessageId> x1.Value.Item1.LastReadMessageId) } return(new VM_PagedList <DTO_UserSession>(t, pageIndex, pageSize, (int)count)); }
public void GetComments() { dynamic comments = FreeSql.Select <Comment>().Include(r => r.UserInfo).From <UserLike>( (z, zzc) => z.LeftJoin(u => u.Id == zzc.SubjectId) //&& zzc.CreateUserId == _currentUser.Id ) .ToList((s, za) => new { comment = s, za.SubjectId }); }
/// <summary> /// 指定用户Id加入session会话中 /// </summary> /// <param name="userId"></param> /// <param name="sessionId"></param> /// <returns></returns> public async Task <ResultReturn> JoinToSession(string userId, long sessionId) { if (!await FreeSql.Select <im_chat_session>().Where(x => x.SessionId == sessionId && x.Type == SessionTypeEnum.Group).AnyAsync()) { return(new FailResultReturn("指定会话不是群组会话,无法加入")); } if (await FreeSql.Select <im_chat_userInSession>().AnyAsync(x => x.SessionId == sessionId && x.UserId == userId)) { return(SuccessResultReturn.Default); } await FreeSql.Insert <im_chat_userInSession>(new im_chat_userInSession() { JoinDt = DateTime.Now, SessionId = sessionId, UserId = userId }).ExecuteInsertedAsync(); return(SuccessResultReturn.Default); }
public Page <Sys_User> GetList(int pageIndex, int pageSize, string keyWord) { var condition = FreeSql.Select <Sys_User>() .Where(t => t.DeleteMark == false) .WhereIf(!string.IsNullOrEmpty(keyWord), t => t.Account.Contains(keyWord) || t.RealName.Contains(keyWord)) .From <Sys_Organize>((u, o) => u.LeftJoin(a => a.DepartmentId == o.Id)); var total = condition.Count(); var items = condition.OrderBy((a, b) => a.SortCode).ToList((a, b) => new Sys_User { Account = a.Account, Address = a.Address, Avatar = a.Avatar, Birthday = a.Birthday, CompanyId = a.CompanyId, CreateTime = a.CreateTime, CreateUser = a.CreateUser, DeleteMark = a.DeleteMark, DepartmentId = a.DepartmentId, Email = a.Email, Gender = a.Gender, Id = a.Id, IsEnabled = a.IsEnabled, MobilePhone = a.MobilePhone, ModifyTime = a.ModifyTime, ModifyUser = a.ModifyUser, NickName = a.NickName, RealName = a.RealName, //RoleId = a.RoleId, Signature = a.Signature, SortCode = a.SortCode, DeptName = b.FullName } ); return(new Page <Sys_User> { Items = items, TotalItems = total }); }
/// <summary> /// 添加一条信息 /// </summary> /// <param name="fromUserId"></param> /// <param name="toSessionId"></param> /// <param name="content"></param> /// <param name="type"></param> /// <param name="contentType"></param> /// <returns></returns> public async Task <long> AddMessage( string fromUserId, long toSessionId, string content, MessageTypeEnum type, MessageContentTypeEnum contentType) { if (!await FreeSql.Select <im_chat_session>().Where(x => x.SessionId == toSessionId).AnyAsync()) { return(-1); } if (!await FreeSql.Select <im_chat_userInSession>().Where(x => x.SessionId == toSessionId && x.UserId == fromUserId).AnyAsync()) { return(-1); } var item = new im_chat_message() { SessionId = toSessionId, SenderId = fromUserId, Content = content, ContentType = contentType, SendDt = DateTime.Now, Type = type }; var messageId = await FreeSql.Insert(item).ExecuteIdentityAsync(); await FreeSql.Update <im_chat_session>() .Where(x => x.SessionId == toSessionId) .Set(x => x.LastActivityDt, DateTime.Now) .Set(x => x.LastMessageId, messageId) .ExecuteUpdatedAsync(); return(messageId); }
/// <summary> /// 拉取历史记录 /// </summary> /// <param name="sessionId">会话Id</param> /// <param name="lastMessageId">上一次拉取的消息Id,如果为-1,则为从最新开始拉取,如果>0,则为最后一条消息id,并从这条消息开始往前拉取</param> /// <returns></returns> public async Task <IReadOnlyList <DTO_SessionMessage> > GetSessionMessage(long sessionId, string userId, long lastMessageId = -1, int takeCount = 20) { if (sessionId == -1 && userId != "") { return(await FreeSql.Select <im_chat_userInSession, im_chat_message, im_chat_session>() .InnerJoin((s, m, se) => s.SessionId == m.SessionId) .Where((s, m, se) => s.UserId == userId) .Where((s, m, se) => m.MessageId > lastMessageId && m.State == 0) .OrderBy((s, m, se) => m.MessageId) .Take(takeCount) .ToListAsync((s, m, se) => new DTO_SessionMessage() { Content = m.State == 99 ? "已撤回的消息" : m.Content, ContentType = m.ContentType, SendDt = m.SendDt, SendUserId = m.SenderId, MessageType = m.Type, State = m.State })); } else { return(await FreeSql.Select <im_chat_message>() .Where(x => x.SessionId == sessionId && x.State == 0) .WhereIf(lastMessageId > 0, x => x.MessageId > lastMessageId) .OrderBy(x => x.MessageId) .Take(takeCount) .ToListAsync(x => new DTO_SessionMessage() { Content = x.State == 99?"已撤回的消息":x.Content, ContentType = x.ContentType, SendDt = x.SendDt, SendUserId = x.SenderId, MessageType = x.Type, State = x.State })); } }
/// <summary> /// 判断指定用户是否在指定会话中 /// </summary> /// <param name="sessionId"></param> /// <param name="userId"></param> /// <returns></returns> public async Task <bool> IsUserExistsInSession(long sessionId, string userId) { return(await FreeSql.Select <im_chat_userInSession>() .Where(x => x.SessionId == sessionId && x.UserId == userId).AnyAsync()); }
/// <summary> /// 获取指定用户的群组Id /// </summary> /// <param name="userId"></param> /// <returns></returns> public async Task <IReadOnlyList <long> > GetUserGroupIDs(string userId) { return(await FreeSql.Select <im_chat_userInSession>().Where(x => x.UserId == userId && x.QuitDt == null) .ToListAsync(x => x.SessionId)); }
/// <summary> /// 获取指定Id会话信息 /// </summary> /// <param name="sessionId"></param> /// <returns></returns> public async Task <im_chat_session> GetSessionById(long sessionId) { return(await FreeSql.Select <im_chat_session>().Where(x => x.SessionId == sessionId).ToOneAsync()); }
/// <summary> /// 获取两个用户的私聊会话id /// </summary> /// <param name="fromUserId"></param> /// <param name="toUserId"></param> /// <returns></returns> public async Task <long> GetToUseIdSessionIdByFromUseId(string fromUserId, string toUserId) { return(await FreeSql.Select <im_chat_session>() .Where(x => x.ExtData.Contains($"{fromUserId},") && x.ExtData.Contains($"{toUserId},")) .ToOneAsync(x => x.SessionId)); }