From 7a75025880fc509817f0277da7c424febe15faac Mon Sep 17 00:00:00 2001 From: youngq Date: Tue, 25 Feb 2025 15:41:22 +0800 Subject: [PATCH] =?UTF-8?q?1:=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=9B=91=E6=B5=8B=E6=8E=A5=E5=8F=A3i=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E8=81=8A=E5=A4=A9=E4=BB=BB=E7=84=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=A7=E5=90=8D=E7=A7=B0BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WGShare.API/Controllers/AuthController.cs | 21 +++++++++++++++++++++ WGShare.API/Hubs/SessionManageHub.cs | 16 +++++++++++----- WGShare.API/WGShare.API.xml | 7 +++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/WGShare.API/Controllers/AuthController.cs b/WGShare.API/Controllers/AuthController.cs index 25df117..f88eb2c 100644 --- a/WGShare.API/Controllers/AuthController.cs +++ b/WGShare.API/Controllers/AuthController.cs @@ -51,6 +51,27 @@ namespace WGShare.API.Controllers return await _sqlSugar.Queryable().AnyAsync(x => x.IsDelete == false && x.Account == account && x.IsAnonymous == false); } + /// + /// 检查用户是否在线 + /// + /// + /// + [HttpGet("check-online"), AllowAnonymous] + public async Task CheckUserOnline([FromQuery] string account) + { + var user = await _sqlSugar.Queryable().FirstAsync(x => x.IsDelete == false && x.Account == account && x.IsAnonymous == false); + if (user == null) + { + return false; + } + var connectId = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetOnlineUserKey(user.TenantId), user.Id); + if (!string.IsNullOrWhiteSpace(connectId)) + { + return true; + } + return false; + } + /// /// 正常账号登录 /// diff --git a/WGShare.API/Hubs/SessionManageHub.cs b/WGShare.API/Hubs/SessionManageHub.cs index a2905e0..f1f000a 100644 --- a/WGShare.API/Hubs/SessionManageHub.cs +++ b/WGShare.API/Hubs/SessionManageHub.cs @@ -84,7 +84,7 @@ namespace WGShare.API.Hubs { _logger.LogInformation($@"{DateTime.Now} account:{account} 退出以下频道:{string.Join(',', roomNum)}"); if (!string.IsNullOrEmpty(roomNum)) - { + { // 判断是否全员看他,是则移除 var script = $@"local value = redis.call('HGET', KEYS[1], ARGV[1]) if value == ARGV[2] or value == ARGV[3] then @@ -274,12 +274,18 @@ namespace WGShare.API.Hubs { var uname = Context.User?.Claims.FirstOrDefault(x => x.Type == "uname")?.Value; var uid = Context.User?.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; + var tenant = Context.Items["tenant"].ToString(); + + _logger.LogInformation($" {DateTime.Now} 发送消息 uname:{uname} roomNum:{rooNum} msg:{msg}"); - _logger.LogInformation($" {DateTime.Now}发送消息 uname:" + uname); - _logger.LogInformation($" {DateTime.Now}发送消息 roomNum:" + rooNum); - _logger.LogInformation($" {DateTime.Now}发送消息 msg:" + msg); + var userInfo = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(tenant, rooNum), uid); + var userName = uname; + if (userInfo != null) + { + userName = userInfo.UserName; + } - await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, uname, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg); + await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, userName, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg); } /// diff --git a/WGShare.API/WGShare.API.xml b/WGShare.API/WGShare.API.xml index 78bf812..4766f06 100644 --- a/WGShare.API/WGShare.API.xml +++ b/WGShare.API/WGShare.API.xml @@ -11,6 +11,13 @@ + + + 检查用户是否在线 + + + + 正常账号登录