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 { /// /// 系统缓存服务 /// public class CacheService : ICacheService, IDynamicApiController, ITransient { private static ICache _redisCache = App.RootServices.GetService(typeof(RedisCache)) as ICache; /// /// /// public CacheService() { } #region 聊天服务 /// /// 获取聊天列表 /// /// [NonAction] public async Task> GetLiveHistoryService(long UserID) { string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}"; return await _redisCache.GetAsync>(cacheKey); } /// /// 设置聊天列表 /// /// [NonAction] public async Task SetLiveHistoryService(long UserID, List liveMessageLists) { string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}"; await _redisCache.SetAsync(cacheKey, liveMessageLists, TimeSpan.FromHours(1)); } /// /// 删除聊天列表 /// /// [NonAction] public async Task DelLiveHistoryService(long UserID) { string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}"; await _redisCache.DelAsync(cacheKey); } #endregion #region 聊天详情 /// /// 获取聊天列表 /// /// [NonAction] public async Task> GetMessage(long UserID,long ChatUserID) { string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}"; return await _redisCache.GetAsync>(cacheKey); } /// /// 获取聊天列表 /// /// [NonAction] public async Task SetMessage(List liveMessages,long UserID,long ChatUserID) { string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}"; await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1)); } /// /// 设置未读数 /// /// 用户未读 /// 聊天室ID /// [NonAction] public async Task SetUnreadAsync(long UserID, long ChatID) { string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}_{ChatID}"; var res = _redisCache.Get(cacheKey); await _redisCache.SetAsync(cacheKey, 1+res); } /// /// 获取未读 /// /// /// /// public async Task GetUnreadAsync(long UserID, long ChatID) { string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}_{ChatID}"; return await _redisCache.GetAsync(cacheKey); } /// /// 获取聊天列表 /// /// [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 GetUserInfoAsync(long UserID) { string cacheKey = SystemConst.MINI_USERINFO + $"{UserID}"; return await _redisCache.GetAsync(cacheKey); } #endregion } }