using DS.Module.Core; using DS.Module.RedisModule; using DS.WMS.Core.Code.Entity; using DS.WMS.Core.Code.Interface; using DS.WMS.Core.Sys.Interface; using LanguageExt; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NPOI.SS.Formula.Functions; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DS.WMS.Core.Sys.Method { public class SysCacheService : ISysCacheService { private readonly IServiceProvider _serviceProvider; private readonly IRedisService _redisService; public SysCacheService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _redisService = _serviceProvider.GetRequiredService(); } /// /// 获取缓存数据 /// /// 数据类型 /// 缓存key枚举 /// 缓存系统KEY /// 返回列表 public async Task>> GetAllCommonCodeFromCache(SysCacheCategoryEnum cacheCategory, string systemKey) { var currVal =_redisService.GetValue>($"{cacheCategory.ToString()}_{systemKey}"); if (currVal == null) return DataResult>.FailedData(new List()); return DataResult>.Success(currVal); } /// /// 设置缓存 /// /// 被缓存的详情 /// 缓存类型枚举 /// 缓存系统KEY /// 超期时间(毫米) /// public async Task> SetCommonCode(object cacheObj, SysCacheCategoryEnum cacheCategory, string systemKey, int outSecond = 0) { if (outSecond > 0) _redisService.SetValue($"{cacheCategory.ToString()}_{systemKey}", JsonConvert.SerializeObject(cacheObj), outSecond); _redisService.SetValue($"{cacheCategory.ToString()}_{systemKey}", JsonConvert.SerializeObject(cacheObj)); return DataResult.Success(string.Empty); } /// /// 清除缓存 /// /// 缓存类型枚举 /// 缓存系统KEY /// public async Task RemoveCache(SysCacheCategoryEnum cacheCategory, string systemKey) { _redisService.DeleteKey($"{cacheCategory.ToString()}_{systemKey}"); return DataResult.Successed(MultiLanguageConst.RemoveCacheSucc); } } public enum SysCacheCategoryEnum { /// /// 船名基础信息 /// [Description("船名基础信息")] CommonCodeVessel, /// /// 港口基础信息 /// [Description("港口基础信息")] CommonCodePort, /// /// 包装基础信息 /// [Description("包装基础信息")] CommonCodePackage, /// /// 运输条款基础信息 /// [Description("运输条款基础信息")] CommonCodeService, /// /// 集装箱型基础信息 /// [Description("集装箱型基础信息")] CommonCodeCtn, /// /// 付费方式基础信息 /// [Description("付费方式基础信息")] CommonCodeFrt, /// /// 国家基础信息 /// [Description("国家基础信息")] CommonCodeCountry, /// /// 航线基础信息 /// [Description("航线基础信息")] CommonCodeLanes, /// /// 场站映射信息 /// [Description("场站映射信息")] CommonMappingYard, /// /// 集装箱型映射信息 /// [Description("集装箱型映射信息")] CommonMappingCtn, /// /// 船公司映射信息 /// [Description("船公司映射信息")] CommonMappingCarrier, /// /// 付费方式映射 /// [Description("付费方式映射")] CommonMappingFrt, /// /// 船名映射 /// [Description("船名映射")] CommonMappingVessel, /// /// 船代映射 /// [Description("船代映射")] CommonMappingForwarder, /// /// 港口映射 /// [Description("港口映射")] CommonMappingPort } }