using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SqlSugar; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Yi.Framework.Bbs.Application.Contracts.Dtos.Notice; using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Application.Services { public class BbsNoticeService : ApplicationService { private ISqlSugarRepository _repository; public BbsNoticeService(ISqlSugarRepository repository) { _repository = repository; } /// /// 查询用户的消息,需登录 /// /// /// /// [Authorize] public async Task> GetListAsync(BbsNoticeGetListInputVo input) { RefAsync total = 0; var entities = await _repository._DbQueryable.Where(x => x.AcceptUserId == CurrentUser.Id) .OrderByDescending(x => x.CreationTime) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); var output = entities.Adapt>(); return new PagedResultDto(total, output); } /// /// 已读消息,不传guid,代表一键已读,需登录 /// /// [Authorize] [Route("bbs-notice/read/{noticeId?}")] public async Task PutReadAsync(Guid? noticeId) { //一键已读 if (noticeId is null) { await _repository._Db.Updateable() .SetColumns(it => it.IsRead == true) .Where(x => x.AcceptUserId == CurrentUser.Id) .Where(x => x.IsRead == false) .ExecuteCommandAsync(); } //已读一条 else { await _repository._Db.Updateable() .SetColumns(it => it.IsRead == true) .Where(x => x.AcceptUserId == CurrentUser.Id) .Where(x => x.IsRead == false) .Where(x => x.Id == noticeId) .ExecuteCommandAsync(); } } } }