🚚移动MessageHub
This commit is contained in:
parent
672fb84871
commit
d2afa84c37
@ -2,11 +2,11 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using SqlSugar;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Hubs;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.ServiceCore.Signalr;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Hubs;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.ServiceCore.Signalr;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
|
||||
@ -5,10 +5,9 @@ using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text.Json.Serialization;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Hubs;
|
||||
using ZR.Common.Cache;
|
||||
using ZR.Infrastructure.WebExtensions;
|
||||
using ZR.ServiceCore.Middleware;
|
||||
using ZR.ServiceCore.Signalr;
|
||||
using ZR.ServiceCore.SqlSugar;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -12,8 +12,4 @@
|
||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.98" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace ZR.Admin.WebApi.Hubs
|
||||
namespace ZR.ServiceCore.Signalr
|
||||
{
|
||||
public class HubsConstant
|
||||
{
|
||||
@ -1,10 +1,12 @@
|
||||
using IPTools.Core;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Model;
|
||||
using IPTools.Core;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Web;
|
||||
using UAParser;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Hubs
|
||||
namespace ZR.ServiceCore.Signalr
|
||||
{
|
||||
/// <summary>
|
||||
/// msghub
|
||||
@ -64,12 +66,12 @@ namespace ZR.Admin.WebApi.Hubs
|
||||
ClientId = clientId ?? Context.ConnectionId
|
||||
};
|
||||
onlineClients.Add(onlineUser);
|
||||
Log.WriteLine(msg: $"{DateTime.Now}:{name},{Context.ConnectionId}连接服务端success,当前已连接{onlineClients.Count}个");
|
||||
Log.WriteLine(msg: $"{name},{Context.ConnectionId}连接服务端success,当前已连接{onlineClients.Count}个");
|
||||
//Clients.All.SendAsync("welcome", $"欢迎您:{name},当前时间:{DateTime.Now}");
|
||||
Clients.Caller.SendAsync(HubsConstant.MoreNotice, SendNotice());
|
||||
Clients.Caller.SendAsync(HubsConstant.ConnId, onlineUser.ConnnectionId);
|
||||
}
|
||||
OnlineUsers? userInfo = GetUserById(userid);
|
||||
OnlineUsers userInfo = GetUserById(userid);
|
||||
if (userInfo == null)
|
||||
{
|
||||
userInfo = new OnlineUsers() { Userid = userid, Name = name, LoginTime = DateTime.Now };
|
||||
@ -105,7 +107,7 @@ namespace ZR.Admin.WebApi.Hubs
|
||||
/// 连接终止时调用。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override Task OnDisconnectedAsync(Exception? exception)
|
||||
public override Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
var user = onlineClients.Where(p => p.ConnnectionId == Context.ConnectionId).FirstOrDefault();
|
||||
if (user != null)
|
||||
@ -120,7 +122,7 @@ namespace ZR.Admin.WebApi.Hubs
|
||||
});
|
||||
|
||||
//累计用户时长
|
||||
OnlineUsers? userInfo = GetUserById(user.Userid);
|
||||
OnlineUsers userInfo = GetUserById(user.Userid);
|
||||
if (userInfo != null)
|
||||
{
|
||||
userInfo.TodayOnlineTime += user?.OnlineTime ?? 0;
|
||||
@ -176,7 +178,7 @@ namespace ZR.Admin.WebApi.Hubs
|
||||
{
|
||||
return onlineClients.Where(p => p.ConnnectionId == connId).FirstOrDefault();
|
||||
}
|
||||
private static OnlineUsers? GetUserById(long userid)
|
||||
private static OnlineUsers GetUserById(long userid)
|
||||
{
|
||||
return users.Where(f => f.Userid == userid).FirstOrDefault();
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
namespace ZR.Admin.WebApi.Hubs
|
||||
namespace ZR.ServiceCore.Signalr
|
||||
{
|
||||
public class OnlineUsers
|
||||
{
|
||||
@ -12,24 +12,24 @@
|
||||
public long Userid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime LoginTime { get; set; }
|
||||
public string? UserIP { get; set; }
|
||||
public string UserIP { get; set; }
|
||||
/// <summary>
|
||||
/// 登录地点
|
||||
/// </summary>
|
||||
public string? Location { get; set; }
|
||||
public string Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户唯一
|
||||
/// </summary>
|
||||
public string? Uuid { get; set; }
|
||||
public string Uuid { get; set; }
|
||||
/// <summary>
|
||||
/// 浏览器
|
||||
/// </summary>
|
||||
public string? Browser { get; set; }
|
||||
public string Browser { get; set; }
|
||||
/// <summary>
|
||||
/// 平台
|
||||
/// </summary>
|
||||
public string? Platform { get; set; } = string.Empty;
|
||||
public string Platform { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// 在线时长
|
||||
/// </summary>
|
||||
Loading…
x
Reference in New Issue
Block a user