diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application.Contracts/Dtos/ChatMessageGetListInput.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application.Contracts/Dtos/ChatMessageGetListInput.cs new file mode 100644 index 00000000..78dbd87c --- /dev/null +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application.Contracts/Dtos/ChatMessageGetListInput.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.ChatHub.Domain.Shared.Enums; + +namespace Yi.Framework.ChatHub.Application.Contracts.Dtos +{ + public class ChatMessageGetListInput + { + public MessageTypeEnum? MessageType { get; set; } + + /// + /// 接收者(用户id、群组id) + /// + public Guid? ReceiveId { get; set; } + + /// + /// 发送者的用户id + /// + public Guid? SendUserId { get; set; } + + /// + /// 开始时间 + /// + public DateTime? StartTime { get; set; } + + /// + /// 结束时间 + /// + public DateTime? EndTime { get; set; } + } +} diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application/Services/ChatMessageService.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application/Services/ChatMessageService.cs index 0bcddfe1..258419ec 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application/Services/ChatMessageService.cs +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Application/Services/ChatMessageService.cs @@ -3,11 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Services; +using Volo.Abp.EventBus.Local; +using Yi.Framework.Bbs.Domain.Shared.Etos; using Yi.Framework.ChatHub.Application.Contracts.Dtos; using Yi.Framework.ChatHub.Domain.Managers; +using Yi.Framework.ChatHub.Domain.Shared.Enums; using Yi.Framework.ChatHub.Domain.Shared.Model; namespace Yi.Framework.ChatHub.Application.Services @@ -15,7 +19,8 @@ namespace Yi.Framework.ChatHub.Application.Services public class ChatMessageService : ApplicationService { private UserMessageManager _userMessageManager; - public ChatMessageService(UserMessageManager userMessageManager) { _userMessageManager = userMessageManager; } + private ILocalEventBus _localEventBus; + public ChatMessageService(UserMessageManager userMessageManager, ILocalEventBus localEventBus) { _userMessageManager = userMessageManager; _localEventBus = localEventBus; } /// /// 发送个人消息 /// @@ -24,7 +29,10 @@ namespace Yi.Framework.ChatHub.Application.Services [Authorize] public async Task SendPersonalMessageAsync(PersonalMessageInputDto input) { - await _userMessageManager.SendMessageAsync(MessageContext.CreatePersonal(input.Content, input.UserId,CurrentUser.Id!.Value)); ; + var mesageContext = MessageContext.CreatePersonal(input.Content, input.UserId, CurrentUser.Id!.Value); + await _userMessageManager.SendMessageAsync(mesageContext); + + await _userMessageManager.CreateMessageStoreAsync(mesageContext); } @@ -36,8 +44,58 @@ namespace Yi.Framework.ChatHub.Application.Services [Authorize] public async Task SendGroupMessageAsync(GroupMessageInputDto input) { - await _userMessageManager.SendMessageAsync(MessageContext.CreateAll(input.Content, CurrentUser.Id!.Value)); ; + //领域调用,群主消息调用bbs领域 + //如果钱钱不足,将自动断言 + await _localEventBus.PublishAsync(new MoneyChangeEventArgs { UserId = CurrentUser.Id.Value, Number = -1 }); + + var mesageContext = MessageContext.CreateAll(input.Content, CurrentUser.Id!.Value); + await _userMessageManager.SendMessageAsync(mesageContext); + + await _userMessageManager.CreateMessageStoreAsync(mesageContext); + } + + /// + /// 查询消息 + /// + /// + /// + [Authorize] + [RemoteService(IsEnabled = false)] + public async Task> GetListAsync(ChatMessageGetListInput input) + { + var entities = await _userMessageManager._repository._DbQueryable + .WhereIF(input.MessageType is not null, x => x.MessageType == input.MessageType) + .WhereIF(input.ReceiveId is not null, x => x.ReceiveId == input.ReceiveId) + .WhereIF(input.SendUserId is not null, x => x.SendUserId == input.SendUserId) + .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) + .OrderBy(x => x.CreationTime) + .ToListAsync(); + var output = entities.Adapt>(); + return output; + } + + /// + /// 获取用户自己的消息 + /// + /// + [Authorize] + [HttpGet("chat-message/account")] + public async Task> GetAccountMessageListAsync() + { + //默认显示1个月的个人数据 + var userId = CurrentUser.Id!.Value; + //3个类型数据 + var entities = await _userMessageManager._repository._DbQueryable + .Where(x => x.MessageType == MessageTypeEnum.All + || x.ReceiveId == userId + || x.SendUserId == userId + ) + .Where(x => x.CreationTime >= DateTime.Now.AddDays(-30)) + .OrderBy(x => x.CreationTime) + .ToListAsync(); + var output = entities.Adapt>(); + return output; } } } diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Enums/MessageTypeEnum.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Enums/MessageTypeEnum.cs new file mode 100644 index 00000000..85d16e35 --- /dev/null +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Enums/MessageTypeEnum.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.ChatHub.Domain.Shared.Enums +{ + public enum MessageTypeEnum + { + + + Personal, + Group, + All + + } +} diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Model/MessageContext.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Model/MessageContext.cs index 6cc75c70..f95b771b 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Model/MessageContext.cs +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Model/MessageContext.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; +using Yi.Framework.ChatHub.Domain.Shared.Enums; namespace Yi.Framework.ChatHub.Domain.Shared.Model { @@ -11,12 +12,12 @@ namespace Yi.Framework.ChatHub.Domain.Shared.Model { public static MessageContext CreatePersonal(string content, Guid userId,Guid sendUserId) { - return new MessageContext() { MessageType = MessageType.Personal, Content = content, ReceiveId = userId ,SendUserId= sendUserId }; + return new MessageContext() { MessageType = MessageTypeEnum.Personal, Content = content, ReceiveId = userId ,SendUserId= sendUserId }; } public static MessageContext CreateAll(string content, Guid sendUserId) { - return new MessageContext() { MessageType = MessageType.All, Content = content, SendUserId = sendUserId }; + return new MessageContext() { MessageType = MessageTypeEnum.All, Content = content, SendUserId = sendUserId }; } @@ -24,7 +25,7 @@ namespace Yi.Framework.ChatHub.Domain.Shared.Model /// 消息类型 /// [JsonConverter(typeof(JsonStringEnumConverter))] - public MessageType MessageType { get; set; } + public MessageTypeEnum MessageType { get; set; } /// /// 接收者(用户id、群组id) /// @@ -38,14 +39,8 @@ namespace Yi.Framework.ChatHub.Domain.Shared.Model /// 消息内容 /// public string Content { get; set; } - + public DateTime CreationTime { get;protected set; }=DateTime.Now; } - public enum MessageType - { - Personal, - Group, - All - } } diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Yi.Framework.ChatHub.Domain.Shared.csproj b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Yi.Framework.ChatHub.Domain.Shared.csproj index f5a0fbe6..6c143959 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Yi.Framework.ChatHub.Domain.Shared.csproj +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/Yi.Framework.ChatHub.Domain.Shared.csproj @@ -1,7 +1,6 @@ - @@ -9,4 +8,8 @@ + + + + diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/YiFrameworkChatHubDomainSharedModule.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/YiFrameworkChatHubDomainSharedModule.cs index b2e289c3..e4b3d581 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/YiFrameworkChatHubDomainSharedModule.cs +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain.Shared/YiFrameworkChatHubDomainSharedModule.cs @@ -1,9 +1,12 @@ using Volo.Abp.Domain; +using Yi.Framework.Bbs.Domain.Shared; namespace Yi.Framework.ChatHub.Domain.Shared { [DependsOn( - typeof(AbpDddDomainSharedModule))] + typeof(AbpDddDomainSharedModule), + + typeof(YiFrameworkBbsDomainSharedModule))] public class YiFrameworkChatHubDomainSharedModule : AbpModule { diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Entities/MessageEntity.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Entities/MessageEntity.cs new file mode 100644 index 00000000..073608ea --- /dev/null +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Entities/MessageEntity.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; +using Yi.Framework.ChatHub.Domain.Shared.Enums; +using Yi.Framework.ChatHub.Domain.Shared.Model; + +namespace Yi.Framework.ChatHub.Domain.Entities +{ + [SugarTable("YiMessage")] + [SugarIndex($"index_{nameof(MessageEntity)}", + nameof(ReceiveId), OrderByType.Asc, + nameof(SendUserId), OrderByType.Asc, + nameof(CreationTime), OrderByType.Asc)] + public class MessageEntity : Entity, IHasCreationTime + { + public static MessageContext CreatePersonal(string content, Guid userId, Guid sendUserId) + { + return new MessageContext() { MessageType = MessageTypeEnum.Personal, Content = content, ReceiveId = userId, SendUserId = sendUserId }; + } + + public static MessageContext CreateAll(string content, Guid sendUserId) + { + return new MessageContext() { MessageType = MessageTypeEnum.All, Content = content, SendUserId = sendUserId }; + } + + + public string Content { get; set; } + public MessageTypeEnum MessageType { get; set; } + /// + /// 接收者(用户id、群组id) + /// + public Guid? ReceiveId { get; set; } + + /// + /// 发送者的用户id + /// + public Guid SendUserId { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreationTime { get; protected set; } + } +} diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/UserMessageManager.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/UserMessageManager.cs index eba80b5e..d0a52bde 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/UserMessageManager.cs +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/UserMessageManager.cs @@ -1,22 +1,29 @@ -using FreeRedis; +using System.Security.AccessControl; +using FreeRedis; using Mapster; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Options; using Volo.Abp.Caching; +using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Services; +using Yi.Framework.ChatHub.Domain.Entities; using Yi.Framework.ChatHub.Domain.Shared.Caches; using Yi.Framework.ChatHub.Domain.Shared.Consts; +using Yi.Framework.ChatHub.Domain.Shared.Enums; using Yi.Framework.ChatHub.Domain.Shared.Model; using Yi.Framework.ChatHub.Domain.SignalRHubs; +using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.ChatHub.Domain.Managers { public class UserMessageManager : DomainService { private IHubContext _hubContext; - public UserMessageManager(IHubContext hubContext) + public ISqlSugarRepository _repository; + public UserMessageManager(IHubContext hubContext, ISqlSugarRepository repository) { _hubContext = hubContext; + _repository = repository; } /// /// 使用懒加载防止报错 @@ -28,17 +35,17 @@ namespace Yi.Framework.ChatHub.Domain.Managers { switch (context.MessageType) { - case MessageType.Personal: - var userModel =await GetUserAsync(context.ReceiveId.Value); + case MessageTypeEnum.Personal: + var userModel = await GetUserAsync(context.ReceiveId.Value); if (userModel is not null) { await _hubContext.Clients.Client(userModel.ClientId).SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType, context); } break; - case MessageType.Group: + case MessageTypeEnum.Group: throw new NotImplementedException(); break; - case MessageType.All: + case MessageTypeEnum.All: await _hubContext.Clients.All.SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType, context); break; default: @@ -47,6 +54,12 @@ namespace Yi.Framework.ChatHub.Domain.Managers } + + public async Task CreateMessageStoreAsync(MessageContext context) + { + await _repository.InsertAsync(context.Adapt()); + } + public async Task> GetAllUserAsync() { var key = new ChatOnlineUserCacheKey(CacheKeyPrefix); @@ -57,7 +70,7 @@ namespace Yi.Framework.ChatHub.Domain.Managers public async Task GetUserAsync(Guid userId) { var key = new ChatOnlineUserCacheKey(CacheKeyPrefix); - var cacheUser = System.Text.Json.JsonSerializer.Deserialize < ChatOnlineUserCacheItem >( await RedisClient.HGetAsync(key.GetKey(), key.GetField(userId))); + var cacheUser = System.Text.Json.JsonSerializer.Deserialize(await RedisClient.HGetAsync(key.GetKey(), key.GetField(userId))); return cacheUser; } } diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Yi.Framework.ChatHub.Domain.csproj b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Yi.Framework.ChatHub.Domain.csproj index 665f37cf..f4b49527 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Yi.Framework.ChatHub.Domain.csproj +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Yi.Framework.ChatHub.Domain.csproj @@ -2,6 +2,7 @@ + @@ -16,7 +17,6 @@ - diff --git a/Yi.Bbs.Vue3/src/apis/chatMessageApi.js b/Yi.Bbs.Vue3/src/apis/chatMessageApi.js index 3d820226..517dac85 100644 --- a/Yi.Bbs.Vue3/src/apis/chatMessageApi.js +++ b/Yi.Bbs.Vue3/src/apis/chatMessageApi.js @@ -15,4 +15,10 @@ export function sendGroupMessage(data) { data }); } + export function getAccountList() { + return request({ + url: "/chat-message/account", + method: "get" + }); + } \ No newline at end of file diff --git a/Yi.Bbs.Vue3/src/hubs/chatHub.js b/Yi.Bbs.Vue3/src/hubs/chatHub.js index e069b672..2441973f 100644 --- a/Yi.Bbs.Vue3/src/hubs/chatHub.js +++ b/Yi.Bbs.Vue3/src/hubs/chatHub.js @@ -20,7 +20,10 @@ const receiveMsg = (connection) => { }); }; -export default () => { +export function start(){ signalR.start(`chat`, receiveMsg); } +export function close(){ + signalR.SR.stop(); +} diff --git a/Yi.Bbs.Vue3/src/layout/ChatLayout.vue b/Yi.Bbs.Vue3/src/layout/ChatLayout.vue index 0b96217d..c26fa647 100644 --- a/Yi.Bbs.Vue3/src/layout/ChatLayout.vue +++ b/Yi.Bbs.Vue3/src/layout/ChatLayout.vue @@ -5,12 +5,14 @@ \ No newline at end of file diff --git a/Yi.Bbs.Vue3/src/views/home/Index.vue b/Yi.Bbs.Vue3/src/views/home/Index.vue index eb8a6420..1c79f1f5 100644 --- a/Yi.Bbs.Vue3/src/views/home/Index.vue +++ b/Yi.Bbs.Vue3/src/views/home/Index.vue @@ -2,9 +2,13 @@ + + 点击前往-最新上线《聊天室》 ,探索更多可能,结交更多朋友,闭上眼睛,聆听名刀破碎的声音 + + { router.push("/activity/sign"); @@ -451,4 +457,30 @@ const onClickAccessLog = async () => { height: 500px; } } +//走马灯,聊天室链接 +.chat-hub +{ + background-color: #E6A23C; + color: #ffffff; + margin-bottom: 10px; + width: 100%; + overflow: hidden; + white-space: nowrap; + box-sizing: border-box; + span{ + color: red; + } + p { + cursor: pointer; + display: inline-block; + padding-left: 100%; + animation: marquee 20s linear infinite; +} +} + +@keyframes marquee { + 0% { transform: translateX(0); } + 100% { transform: translateX(-100%); } +} +
点击前往-最新上线《聊天室》 ,探索更多可能,结交更多朋友,闭上眼睛,聆听名刀破碎的声音