1:新增用户在线监测接口i

2.修复用户修改名称后,聊天任然使用旧名称BUG
This commit is contained in:
youngq 2025-02-25 15:41:22 +08:00
parent 484ab104ab
commit 7a75025880
3 changed files with 39 additions and 5 deletions

View File

@ -51,6 +51,27 @@ namespace WGShare.API.Controllers
return await _sqlSugar.Queryable<User>().AnyAsync(x => x.IsDelete == false && x.Account == account && x.IsAnonymous == false);
}
/// <summary>
/// 检查用户是否在线
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
[HttpGet("check-online"), AllowAnonymous]
public async Task<bool> CheckUserOnline([FromQuery] string account)
{
var user = await _sqlSugar.Queryable<User>().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;
}
/// <summary>
/// 正常账号登录
/// </summary>

View File

@ -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);
_logger.LogInformation($" {DateTime.Now}发送消息 roomNum" + rooNum);
_logger.LogInformation($" {DateTime.Now}发送消息 msg" + msg);
_logger.LogInformation($" {DateTime.Now} 发送消息 uname{uname} roomNum{rooNum} msg{msg}");
await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, uname, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg);
var userInfo = RedisHelper.Instance.HGet<ChannelUserInfo>(RedisKeyConstant.SessionManage.GetChannelUserKey(tenant, rooNum), uid);
var userName = uname;
if (userInfo != null)
{
userName = userInfo.UserName;
}
await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, userName, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg);
}
/// <summary>

View File

@ -11,6 +11,13 @@
<param name="account"></param>
<returns></returns>
</member>
<member name="M:WGShare.API.Controllers.AuthController.CheckUserOnline(System.String)">
<summary>
检查用户是否在线
</summary>
<param name="account"></param>
<returns></returns>
</member>
<member name="M:WGShare.API.Controllers.AuthController.Login(WGShare.Domain.DTOs.Login.UserLoginDTO)">
<summary>
正常账号登录