|
|
|
|
using Furion;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using GDZZ.Application.Entity;
|
|
|
|
|
using GDZZ.Application.Enum;
|
|
|
|
|
using GDZZ.Core;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application.Help
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 系统缓存服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CacheService : ICacheService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private static ICache _redisCache = App.RootServices.GetService(typeof(RedisCache)) as ICache;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CacheService() { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 聊天服务
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task<List<LiveHistoryLists>> GetLiveHistoryService(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
|
|
|
|
|
return await _redisCache.GetAsync<List<LiveHistoryLists>>(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task SetLiveHistoryService(long UserID, List<LiveHistoryLists> liveMessageLists)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
|
|
|
|
|
await _redisCache.SetAsync(cacheKey, liveMessageLists, TimeSpan.FromHours(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task DelLiveHistoryService(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
|
|
|
|
|
await _redisCache.DelAsync(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 聊天详情
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task<List<LiveMessageList>> GetMessage(long UserID,long ChatUserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
|
|
|
|
|
return await _redisCache.GetAsync<List<LiveMessageList>>(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task SetMessage(List<LiveMessageList> liveMessages,long UserID,long ChatUserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
|
|
|
|
|
await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置未读数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="UserID"></param>
|
|
|
|
|
/// <param name="ChatUserID"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task SetUnreadAsync(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}";
|
|
|
|
|
var res = _redisCache.Get<int>(cacheKey);
|
|
|
|
|
await _redisCache.SetAsync(cacheKey, 1+res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> GetUnreadAsync(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}";
|
|
|
|
|
return _redisCache.Get<int>(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task UpUnreadAsync(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}";
|
|
|
|
|
await _redisCache.SetAsync(cacheKey, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取聊天列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public async Task DelMessage(long UserID, long ChatUserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
|
|
|
|
|
await _redisCache.DelAsync(cacheKey);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 用户服务
|
|
|
|
|
|
|
|
|
|
public async Task SetUserInfoAsync(AuthUserOut authUserOut, long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.MINI_USERINFO + $"{UserID}";
|
|
|
|
|
await _redisCache.SetAsync(cacheKey, authUserOut, TimeSpan.FromDays(1));
|
|
|
|
|
}
|
|
|
|
|
public async Task<AuthUserOut> GetUserInfoAsync(long UserID)
|
|
|
|
|
{
|
|
|
|
|
string cacheKey = SystemConst.MINI_USERINFO + $"{UserID}";
|
|
|
|
|
return await _redisCache.GetAsync<AuthUserOut>(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|