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.
136 lines
5.0 KiB
136 lines
5.0 KiB
using Znyc.CloudCar.Auth.HttpContextUser;
|
|
using Znyc.CloudCar.IRepository.Audit;
|
|
using Znyc.CloudCar.IRepository.Message;
|
|
using Znyc.CloudCar.IServices.CaChe;
|
|
using Znyc.CloudCar.IServices.Message;
|
|
using Znyc.CloudCar.Model.Dtos.Message;
|
|
using Znyc.CloudCar.Model.ViewModels.ReportsCallBack;
|
|
|
|
namespace Znyc.CloudCar.Services.Message
|
|
{
|
|
/// <summary>
|
|
/// 消息通知服务
|
|
/// </summary>
|
|
public class MessageService : IMessageService
|
|
{
|
|
private readonly IMessageRepository _messageRepository;
|
|
private readonly IHttpContextUser _httpContextUser;
|
|
private readonly ICacheService _cacheService;
|
|
private readonly IAuditRepository _auditRepository;
|
|
private readonly IMessageLogRepository _messageLogRepository;
|
|
|
|
public MessageService(
|
|
IMessageRepository messageRepository,
|
|
IHttpContextUser httpContextUser,
|
|
ICacheService cacheService,
|
|
IAuditRepository auditRepository,
|
|
IMessageLogRepository messageLogRepository
|
|
)
|
|
{
|
|
_messageRepository = messageRepository;
|
|
_httpContextUser = httpContextUser;
|
|
_cacheService = cacheService;
|
|
_auditRepository = auditRepository;
|
|
_messageLogRepository = messageLogRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询消息通知列表
|
|
/// </summary>
|
|
/// <param name="currentPage"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public async Task<ResponseOutput> PageAsync(int currentPage, int pageSize)
|
|
{
|
|
var messageLogs = await _messageLogRepository.Select
|
|
.Where(x => x.ReceiverId == _httpContextUser.Id)
|
|
.ToListAsync(x => x.MessageId);
|
|
var messageList = await _messageRepository.Select
|
|
.Where(x => messageLogs.Contains(x.Id))
|
|
.Count(out long total)
|
|
.OrderByDescending(x => x.CreatedTime)
|
|
.Page(currentPage, pageSize)
|
|
.ToListAsync<MessageListOutput>();
|
|
|
|
var data = new PageOutput<MessageListOutput>
|
|
{
|
|
List = messageList,
|
|
Total = total
|
|
};
|
|
ResponseOutput response = new ResponseOutput()
|
|
{
|
|
Successed = true,
|
|
Data = data
|
|
};
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 已读消息记录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<ResponseOutput> UpdateAsync()
|
|
{
|
|
await _messageLogRepository.Select
|
|
.InnerJoin(x => x.MessageId == x.MessageEntity.Id)
|
|
.Where(x => x.State == 0 && x.ReceiverId == _httpContextUser.Id)
|
|
.ToUpdate()
|
|
.Set(x => x.State, 1)
|
|
.ExecuteAffrowsAsync();
|
|
await _cacheService.RemoveUnreadMessageAsync(_httpContextUser.Id);
|
|
ResponseOutput response = new ResponseOutput()
|
|
{
|
|
Successed = true
|
|
};
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 未读提示
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<ResponseOutput> UnreadMessage()
|
|
{
|
|
var unreadMessageDictionary = await _cacheService.GetUnreadMessageAsync(245971643547717);
|
|
if (unreadMessageDictionary.Count == 0)
|
|
{
|
|
//消息列表
|
|
List<MessageListOutput> messages = await _messageLogRepository.Select
|
|
.InnerJoin(x => x.MessageId == x.MessageEntity.Id)
|
|
.Where(x => x.ReceiverId == _httpContextUser.Id && x.State == 0)
|
|
.ToListAsync<MessageListOutput>();
|
|
|
|
//审核失败
|
|
int auditFailCount = (await _auditRepository.GetAuditFailListAsync(_httpContextUser.Id)).Count;
|
|
unreadMessageDictionary.Add("MessageCount", messages.Count());
|
|
unreadMessageDictionary.Add("AuditFailCount", auditFailCount);
|
|
await _cacheService.SetUnreadMessageAsync(_httpContextUser.Id, unreadMessageDictionary);
|
|
}
|
|
// unreadMessageOutput = JsonConvert.DeserializeObject<UnreadMessageOutput>(JsonConvert.SerializeObject(unreadMessageDictionary));
|
|
ResponseOutput response = new ResponseOutput()
|
|
{
|
|
Data = unreadMessageDictionary,
|
|
Successed = true,
|
|
Code = 1
|
|
};
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取新用户滚动播放列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<ResponseOutput> GetRegistUserListAsync()
|
|
{
|
|
List<string> list = await _cacheService.GetRegistUserListAsync(0, 15);
|
|
ResponseOutput response = new ResponseOutput()
|
|
{
|
|
Data = list,
|
|
Successed = true,
|
|
Code = 1
|
|
};
|
|
return response;
|
|
}
|
|
}
|
|
}
|
|
|