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.

110 lines
3.0 KiB

using Furion;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
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>
/// <returns></returns>
[NonAction]
public async Task DelMessage(long UserID, long ChatUserID)
{
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
await _redisCache.DelAsync(cacheKey);
}
#endregion
}
}