using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Volo.Abp; using Volo.Abp.Domain.Repositories; using Win_in.Sfs.Message.Application.Contracts; using Win_in.Sfs.Message.Domain; using Win_in.Sfs.Message.Domain.Shared; namespace Win_in.Sfs.Message.Application; /// /// 站点消息 /// // [Authorize(UserNotifyMessagePermissions.Default)] [Authorize] [Route($"{MessageConsts.RootPath}user-notify-message")] public class UserNotifyMessageService : SfsMessageCrudAppServiceBase , IUserNotifyMessageService { public UserNotifyMessageService(IUserNotifyMessageRepository repository) : base(repository) { } [HttpGet("list/{userId}")] public virtual async Task> GetListAsync(Guid userId) { var entities = await (await _repository.GetDbSetAsync().ConfigureAwait(false)) .Where(p => p.UserId == userId) .OrderBy(t => t.HasRead) .ThenByDescending(p => p.Id) .Take(100) .ToListAsync().ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return dtos; } [HttpGet("not-read-list/{userId}")] public virtual async Task> GetNotReadListAsync(Guid userId) { var entities = await (await _repository.GetDbSetAsync().ConfigureAwait(false)) .Where(p => p.UserId == userId && !p.HasRead) .OrderByDescending(p => p.Id) .Take(100) .ToListAsync().ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return dtos; } [HttpGet("has-read-list/{userId}")] public virtual async Task> GetHasReadListAsync(Guid userId) { var entities = await (await _repository.GetDbSetAsync().ConfigureAwait(false)) .Where(p => p.UserId == userId && p.HasRead) .OrderByDescending(p => p.Id) .Take(100) .ToListAsync().ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return dtos; } [HttpGet("count/{userId}")] public virtual async Task GetCountAsync(Guid userId) { var count = await (await _repository.GetDbSetAsync().ConfigureAwait(false)) .Where(p => p.UserId == userId) .CountAsync().ConfigureAwait(false); return count; } [HttpGet("not-read-count/{userId}")] public virtual async Task GetNotReadCountAsync(Guid userId) { var count = await (await _repository.GetDbSetAsync().ConfigureAwait(false)) .Where(p => p.UserId == userId && !p.HasRead) .CountAsync().ConfigureAwait(false); return count; } /// /// 根据id修改信息为已读 /// /// /// [HttpPost("read/{id}")] public virtual async Task ReadAsync(Guid id) { var entity = await _repository.GetAsync(id).ConfigureAwait(false); Check.NotNull(entity, EntityClassName); entity.HasRead = true; entity.ReadTime = Clock.Now; await _repository.UpdateAsync(entity).ConfigureAwait(false); } }