You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.6 KiB
C#

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<IRedisService>();
}
/// <summary>
/// 获取缓存数据
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="cacheCategory">缓存key枚举</param>
/// <param name="systemKey">缓存系统KEY</param>
/// <returns>返回列表</returns>
public async Task<DataResult<List<T>>> GetAllCommonCodeFromCache<T>(SysCacheCategoryEnum cacheCategory, string systemKey)
{
var currVal =_redisService.GetValue<List<T>>($"{cacheCategory.ToString()}_{systemKey}");
if (currVal == null)
return DataResult<List<T>>.FailedData(new List<T>());
return DataResult<List<T>>.Success(currVal);
}
/// <summary>
/// 设置缓存
/// </summary>
/// <param name="cacheObj">被缓存的详情</param>
/// <param name="cacheCategory">缓存类型枚举</param>
/// <param name="systemKey">缓存系统KEY</param>
/// <param name="outSecond">超期时间(毫米)</param>
/// <returns></returns>
public async Task<DataResult<string>> 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<string>.Success(string.Empty);
}
/// <summary>
/// 清除缓存
/// </summary>
/// <param name="cacheCategory">缓存类型枚举</param>
/// <param name="systemKey">缓存系统KEY</param>
/// <returns></returns>
public async Task<DataResult> RemoveCache(SysCacheCategoryEnum cacheCategory, string systemKey)
{
_redisService.DeleteKey($"{cacheCategory.ToString()}_{systemKey}");
return DataResult.Successed(MultiLanguageConst.RemoveCacheSucc);
}
}
public enum SysCacheCategoryEnum
{
/// <summary>
/// 船名基础信息
/// </summary>
[Description("船名基础信息")]
CommonCodeVessel,
/// <summary>
/// 港口基础信息
/// </summary>
[Description("港口基础信息")]
CommonCodePort,
/// <summary>
/// 包装基础信息
/// </summary>
[Description("包装基础信息")]
CommonCodePackage,
/// <summary>
/// 运输条款基础信息
/// </summary>
[Description("运输条款基础信息")]
CommonCodeService,
/// <summary>
/// 集装箱型基础信息
/// </summary>
[Description("集装箱型基础信息")]
CommonCodeCtn,
/// <summary>
/// 付费方式基础信息
/// </summary>
[Description("付费方式基础信息")]
CommonCodeFrt,
/// <summary>
/// 国家基础信息
/// </summary>
[Description("国家基础信息")]
CommonCodeCountry,
/// <summary>
4 months ago
/// 航线基础信息
/// </summary>
[Description("航线基础信息")]
CommonCodeLanes,
/// <summary>
/// 签单方式基础信息
/// </summary>
[Description("签单方式基础信息")]
CommonCodeIssueType,
/// <summary>
/// 场站映射信息
/// </summary>
[Description("场站映射信息")]
CommonMappingYard,
/// <summary>
/// 集装箱型映射信息
/// </summary>
[Description("集装箱型映射信息")]
CommonMappingCtn,
/// <summary>
/// 船公司映射信息
/// </summary>
[Description("船公司映射信息")]
CommonMappingCarrier,
/// <summary>
/// 付费方式映射
/// </summary>
[Description("付费方式映射")]
CommonMappingFrt,
/// <summary>
/// 船名映射
/// </summary>
[Description("船名映射")]
CommonMappingVessel,
/// <summary>
/// 船代映射
/// </summary>
[Description("船代映射")]
CommonMappingForwarder,
/// <summary>
/// 港口映射
/// </summary>
[Description("港口映射")]
CommonMappingPort,
/// <summary>
/// 签单方式映射
/// </summary>
[Description("签单方式映射")]
4 months ago
CommonMappingIssueType,
/// <summary>
/// 任务分配设置
/// </summary>
[Description("任务分配设置")]
TaskAllocationtSet,
}
}