using Furion.DependencyInjection; using Furion.DynamicApiController; using Myshipping.Core.Entity; using Myshipping.Core.Service; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using SqlSugar; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Myshipping.Core.Service; /// /// 在线用户服务 /// [ApiDescriptionSettings(Name = "OnlineUser", Order = 100)] public class SysOnlineUserService : ISysOnlineUserService, IDynamicApiController, ITransient { private readonly ISysCacheService _sysCacheService; private readonly SqlSugarRepository _sysOnlineUerRep; // 在线用户表仓储 private readonly IHubContext _chatHubContext; public SysOnlineUserService(ISysCacheService sysCacheService ,SqlSugarRepository sysOnlineUerRep , IHubContext chatHubContext) { _sysCacheService = sysCacheService; _sysOnlineUerRep = sysOnlineUerRep; _chatHubContext = chatHubContext; } /// /// 获取在线用户信息 /// /// [HttpGet("/sysOnlineUser/list")] public async Task List([FromQuery] PageInputBase input) { var list = await _sysOnlineUerRep.AsQueryable().ToPagedListAsync(input.PageNo, input.PageSize); return list.XnPagedResult(); } [HttpPost("/sysOnlineUser/forceExist")] [NonValidation] public async Task ForceExist(OnlineUser user) { await _chatHubContext.Clients.Client(user.ConnectionId).ForceExist("7777777"); await _sysOnlineUerRep.DeleteAsync(user); } [NonAction] public async Task PushNotice(SysNotice notice,List 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); } } } }