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.
114 lines
3.6 KiB
114 lines
3.6 KiB
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;
|
|
|
|
/// <summary>
|
|
/// 站点消息
|
|
/// </summary>
|
|
// [Authorize(UserNotifyMessagePermissions.Default)]
|
|
[Authorize]
|
|
[Route($"{MessageConsts.RootPath}user-notify-message")]
|
|
public class UserNotifyMessageService : SfsMessageCrudAppServiceBase<UserNotifyMessage, UserNotifyMessageDto, SfsMessageRequestInputBase, UserNotifyMessageEditInput>
|
|
, IUserNotifyMessageService
|
|
{
|
|
public UserNotifyMessageService(IUserNotifyMessageRepository repository) : base(repository)
|
|
{
|
|
}
|
|
|
|
[HttpGet("list/{userId}")]
|
|
public virtual async Task<List<UserNotifyMessageDto>> 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<UserNotifyMessage>, List<UserNotifyMessageDto>>(entities);
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
[HttpGet("not-read-list/{userId}")]
|
|
public virtual async Task<List<UserNotifyMessageDto>> 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<UserNotifyMessage>, List<UserNotifyMessageDto>>(entities);
|
|
|
|
return dtos;
|
|
}
|
|
|
|
[HttpGet("has-read-list/{userId}")]
|
|
public virtual async Task<List<UserNotifyMessageDto>> 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<UserNotifyMessage>, List<UserNotifyMessageDto>>(entities);
|
|
|
|
return dtos;
|
|
}
|
|
|
|
[HttpGet("count/{userId}")]
|
|
public virtual async Task<int> 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<int> GetNotReadCountAsync(Guid userId)
|
|
{
|
|
var count = await
|
|
(await _repository.GetDbSetAsync().ConfigureAwait(false))
|
|
.Where(p => p.UserId == userId && !p.HasRead)
|
|
.CountAsync().ConfigureAwait(false);
|
|
|
|
return count;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id修改信息为已读
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[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);
|
|
}
|
|
}
|
|
|