You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.3 KiB


using Furion.DependencyInjection;
using Furion.DynamicApiController;
using GDZZ.Core.Entity;
using GDZZ.Core.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using SqlSugar;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GDZZ.Core.Service;
/// <summary>
/// 在线用户服务
/// </summary>
[ApiDescriptionSettings(Name = "OnlineUser", Order = 100)]
public class SysOnlineUserService : ISysOnlineUserService, IDynamicApiController, ITransient
{
private readonly ISysCacheService _sysCacheService;
private readonly SqlSugarRepository<OnlineUser> _sysOnlineUerRep; // 在线用户表仓储
private readonly IHubContext<ChatHub, IChatClient> _chatHubContext;
public SysOnlineUserService(ISysCacheService sysCacheService
,SqlSugarRepository<OnlineUser> sysOnlineUerRep
, IHubContext<ChatHub, IChatClient> chatHubContext)
{
_sysCacheService = sysCacheService;
_sysOnlineUerRep = sysOnlineUerRep;
_chatHubContext = chatHubContext;
}
/// <summary>
/// 获取在线用户信息
/// </summary>
/// <returns></returns>
[HttpGet("/sysOnlineUser/list")]
public async Task<dynamic> List([FromQuery] PageInputBase input)
{
var list = await _sysOnlineUerRep.AsQueryable().ToPagedListAsync(input.PageNo, input.PageSize);
return list.XnPagedResult();
}
2 years ago
/// <summary>
/// 强制下线
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpPost("/sysOnlineUser/forceExist")]
[NonValidation]
public async Task ForceExist(OnlineUser user) {
await _chatHubContext.Clients.Client(user.ConnectionId).ForceExist("111");
await _sysOnlineUerRep.DeleteAsync(user);
}
2 years ago
/// <summary>
/// 推送通知
/// </summary>
/// <param name="notice"></param>
/// <param name="userIds"></param>
/// <returns></returns>
[NonAction]
public async Task PushNotice(SysNotice notice,List<long> userIds)
{
var userList = _sysOnlineUerRep.Where(m => userIds.Contains(m.UserId)).ToList();
if (userList.Any()) {
foreach (var item in userList)
{
await _chatHubContext.Clients.Client(item.ConnectionId).AppendNotice(notice);
}
}
}
2 years ago
2 years ago
}