diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/NoticeService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/NoticeService.cs index bcc276bc..dc77fbac 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/NoticeService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/NoticeService.cs @@ -1,8 +1,11 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; using SqlSugar; using Volo.Abp.Application.Dtos; using Yi.Framework.Ddd.Application; using Yi.Framework.Rbac.Application.Contracts.Dtos.Notice; using Yi.Framework.Rbac.Application.Contracts.IServices; +using Yi.Framework.Rbac.Application.SignalRHubs; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.SqlSugarCore.Abstractions; @@ -15,8 +18,10 @@ namespace Yi.Framework.Rbac.Application.Services INoticeService { private ISqlSugarRepository _repository; - public NoticeService(ISqlSugarRepository repository) : base(repository) + private IHubContext _hubContext; + public NoticeService(ISqlSugarRepository repository, IHubContext hubContext) : base(repository) { + _hubContext = hubContext; _repository = repository; } @@ -29,11 +34,37 @@ namespace Yi.Framework.Rbac.Application.Services { RefAsync total = 0; - var entities = await _repository._DbQueryable.WhereIF(input.Type is not null, x => x.Type==input.Type) + var entities = await _repository._DbQueryable.WhereIF(input.Type is not null, x => x.Type == input.Type) .WhereIF(!string.IsNullOrEmpty(input.Title), x => x.Title!.Contains(input.Title!)) .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); return new PagedResultDto(total, await MapToGetListOutputDtosAsync(entities)); } + + + + /// + /// 发送在线消息 + /// + /// + [HttpPost("notice/online/{id}")] + public async Task SendOnlineAsync([FromRoute] Guid id) + { + var entity = await _repository._DbQueryable.FirstAsync(x => x.Id == id); + await _hubContext.Clients.All.SendAsync("ReceiveNotice", entity.Type.ToString(), entity.Title, entity.Content); + } + /// + /// 发送离线消息 + /// + /// + [HttpPost("notice/offline/{id}")] + public async Task SendOfflineAsync([FromRoute] Guid id) + { + //先发送一个在线 + await SendOnlineAsync(id); + + //然后将所有用户和通知id进行保留记录,判断是否已读还是未读 + //在首次请求返回全部未读的通知给前端即可 + } } } diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db b/Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db deleted file mode 100644 index 89ecce23..00000000 Binary files a/Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db and /dev/null differ diff --git a/Yi.Bbs.Vue3/src/App.vue b/Yi.Bbs.Vue3/src/App.vue index 85ca157a..76c23713 100644 --- a/Yi.Bbs.Vue3/src/App.vue +++ b/Yi.Bbs.Vue3/src/App.vue @@ -7,6 +7,7 @@