using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Myshipping.Core.Entity;
using Myshipping.Core.Entity.CommonDB;
using Myshipping.Core.Service.Dict.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Myshipping.Core.Service;
///
/// 系统缓存服务
///
[ApiDescriptionSettings(Name = "Cache", Order = 100)]
public class SysCacheService : ISysCacheService, IDynamicApiController, ISingleton
{
private readonly ICache _cache;
private readonly CacheOptions _cacheOptions;
private readonly ILogger _logger;
public SysCacheService(IOptions cacheOptions, ILogger logger, Func resolveNamed)
{
_logger = logger;
_cacheOptions = cacheOptions.Value;
_cache = resolveNamed(_cacheOptions.CacheType.ToString(), default) as ICache;
}
///
/// 获取数据范围缓存(机构Id集合)
///
///
///
public async Task> GetDataScope(long userId)
{
var cacheKey = CommonConst.CACHE_KEY_DATASCOPE + $"{userId}";
return await _cache.GetAsync>(cacheKey);
}
///
/// 获取数据范围缓存(用户Id集合)
///
///
///
public async Task> GetUsersDataScope(long userId)
{
var cacheKey = CommonConst.CACHE_KEY_USERSDATASCOPE + $"{userId}";
return await _cache.GetAsync>(cacheKey);
}
///
/// 缓存数据范围(机构Id集合)
///
///
///
///
[NonAction]
public async Task SetDataScope(long userId, List dataScopes)
{
var cacheKey = CommonConst.CACHE_KEY_DATASCOPE + $"{userId}";
await _cache.SetAsync(cacheKey, dataScopes);
}
///
/// 缓存数据范围(用户Id集合)
///
///
///
///
[NonAction]
public async Task SetUsersDataScope(long userId, List dataScopes)
{
var cacheKey = CommonConst.CACHE_KEY_USERSDATASCOPE + $"{userId}";
await _cache.SetAsync(cacheKey, dataScopes);
}
///
/// 获取菜单缓存
///
///
///
///
public async Task> GetMenu(long userId, string appCode)
{
var cacheKey = CommonConst.CACHE_KEY_MENU + $"{userId}-{appCode}";
return await _cache.GetAsync>(cacheKey);
}
///
/// 缓存菜单
///
///
///
///
///
[NonAction]
public async Task SetMenu(long userId, string appCode, List menus)
{
var cacheKey = CommonConst.CACHE_KEY_MENU + $"{userId}-{appCode}";
await _cache.SetAsync(cacheKey, menus);
}
///
/// 获取权限缓存(按钮)
///
///
///
public async Task> GetPermission(long userId)
{
var cacheKey = CommonConst.CACHE_KEY_PERMISSION + $"{userId}";
return await _cache.GetAsync>(cacheKey);
}
///
/// 缓存权限
///
///
///
///
[NonAction]
public async Task SetPermission(long userId, List permissions)
{
var cacheKey = CommonConst.CACHE_KEY_PERMISSION + $"{userId}";
await _cache.SetAsync(cacheKey, permissions);
}
///
/// 获取所有缓存关键字
///
///
public List GetAllCacheKeys()
{
var cacheItems = _cache.GetAllKeys();
if (cacheItems == null) return new List();
return cacheItems.Where(u => !u.ToString().StartsWith("mini-profiler")).Select(u => u).ToList();
}
///
/// 获取所有按钮权限
///
///
public async Task> GetAllPermission()
{
var cacheKey = CommonConst.CACHE_KEY_ALLPERMISSION;
return await _cache.GetAsync>(cacheKey);
}
///
/// 设置所有按钮权限
///
///
///
public async Task SetAllPermission(List permissions)
{
var cacheKey = CommonConst.CACHE_KEY_ALLPERMISSION;
await _cache.SetAsync(cacheKey, permissions);
}
///
/// 删除指定关键字缓存
///
///
///
[NonAction]
public bool Del(string key)
{
_cache.Del(key);
return true;
}
///
/// 删除指定关键字缓存
///
///
///
public Task DelAsync(string key)
{
_cache.DelAsync(key);
return Task.FromResult(true);
}
///
/// 删除某特征关键字缓存
///
///
///
public Task DelByPatternAsync(string key)
{
_cache.DelByPatternAsync(key);
return Task.FromResult(true);
}
///
/// 设置缓存
///
///
///
///
[NonAction]
public bool Set(string key, object value)
{
return _cache.Set(key, value);
}
///
/// 设置缓存
///
///
///
///
public async Task SetAsync(string key, object value)
{
return await _cache.SetAsync(key, value);
}
///
/// 设置缓存,并带有过期时间
///
///
///
///
///
public async Task SetTimeoutAsync(string key, object value, TimeSpan ts)
{
return await _cache.SetAsync(key, value, ts);
}
///
/// 获取缓存
///
///
///
[NonAction]
public string Get(string key)
{
return _cache.Get(key);
}
///
/// 获取缓存
///
///
///
public async Task GetAsync(string key)
{
return await _cache.GetAsync(key);
}
///
/// 获取缓存
///
///
///
///
[NonAction]
public T Get(string key)
{
return _cache.Get(key);
}
///
/// 获取缓存
///
///
///
///
public Task GetAsync(string key)
{
return _cache.GetAsync(key);
}
///
/// 检查给定 key 是否存在
///
/// 键
///
[NonAction]
public bool Exists(string key)
{
return _cache.Exists(key);
}
///
/// 检查给定 key 是否存在
///
/// 键
///
public Task ExistsAsync(string key)
{
return _cache.ExistsAsync(key);
}
#region 公共库缓存
///
/// 获取公共库 船公司
///
///
public Task> GetAllCodeCarrier()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_CARRIER);
}
///
/// 获取公共库 船名
///
///
public Task> GetAllCodeVessel()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_VESSEL);
}
///
/// 获取公共库 船代
///
///
public Task> GetAllCodeForwarder()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER);
}
///
/// 获取公共库 场站
///
///
public Task> GetAllCodeYard()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_YARD);
}
///
/// 获取公共库 起始港
///
///
public Task> GetAllCodePortLoad()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_PORTLOAD);
}
///
/// 获取公共库 目的港
///
///
public Task> GetAllCodePort()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_PORT);
}
///
/// 获取公共库 包装
///
///
public Task> GetAllCodePackage()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_PACKAGE);
}
///
/// 获取公共库 运输方式
///
///
public Task> GetAllCodeService()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_SERVICE);
}
///
/// 获取公共库 箱型
///
///
public Task> GetAllCodeCtn()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_CTN);
}
///
/// 获取公共库 付费方式
///
///
public Task> GetAllCodeFrt()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_FRT);
}
///
/// 获取公共库 航线
///
///
public Task> GetAllCodeLane()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_LANE);
}
///
/// 设置公共库 航线与港口的的关系表
///
///
public Task> GetAllRelaPortCarrierLane()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_LANE_PORT);
}
///
/// 获取公共库 国家
///
///
public Task> GetAllCodeCountry()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_COUNTRY);
}
///
/// 获取公共库 箱型映射
///
///
public Task> GetAllMappingCtn()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CTN);
}
///
/// 获取公共库 船司映射
///
///
public Task> GetAllMappingCarrier()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CARRIER);
}
///
/// 获取公共库 费用方式映射
///
///
public Task> GetAllMappingFrt()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_FRT);
}
///
/// 获取公共库 船名映射
///
///
public Task> GetAllMappingVessel()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_VESSEL);
}
///
/// 获取公共库 场站映射
///
///
public Task> GetAllMappingYard()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_YARD);
}
///
/// 获取公共库 船代映射
///
///
public Task> GetAllMappingForwarder()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_FORWARDER);
}
///
/// 设置公共库 船公司
///
///
public Task SetAllCodeCarrier(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_CARRIER, list);
}
///
/// 设置公共库 船名
///
///
public Task SetAllCodeVessel(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_VESSEL, list.ToJsonString());
}
///
/// 设置公共库 船代
///
///
public Task SetAllCodeForwarder(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER, list);
}
///
/// 设置公共库 场站
///
///
public Task SetAllCodeYard(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_YARD, list);
}
///
/// 设置公共库 起始港
///
///
public Task SetAllCodePortLoad(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_PORTLOAD, list);
}
///
/// 设置公共库 目的港
///
///
public Task SetAllCodePort(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_PORT, list);
}
///
/// 设置公共库 包装
///
///
public Task SetAllCodePackage(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_PACKAGE, list);
}
///
/// 设置公共库 运输方式
///
///
public Task SetAllCodeService(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_SERVICE, list);
}
///
/// 设置公共库 箱型
///
///
public Task SetAllCodeCtn(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_CTN, list);
}
///
/// 设置公共库 付费方式
///
///
public Task SetAllCodeFrt(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_FRT, list);
}
///
/// 设置公共库 航线
///
///
public Task SetAllCodeLane(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_LANE, list);
}
///
/// 设置公共库 航线与港口的的关系表
///
///
public Task SetAllRelaPortCarrierLane(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_LANE_PORT, list);
}
///
/// 设置公共库 国家
///
///
public Task SetAllCodeCountry(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_COUNTRY, list);
}
///
/// 设置公共库 箱型映射
///
///
public Task SetAllMappingCtn(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CTN, list);
}
///
/// 设置公共库 船司映射
///
///
public Task SetAllMappingCarrier(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CARRIER, list);
}
///
/// 设置公共库 费用方式映射
///
///
public Task SetAllMappingFrt(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_FRT, list);
}
///
/// 设置公共库 船名映射
///
///
public Task SetAllMappingVessel(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_VESSEL, list);
}
///
/// 设置公共库 场站映射
///
///
public Task SetAllMappingYard(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_YARD, list);
}
///
/// 设置公共库 船代映射
///
///
public Task SetAllMappingForwarder(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_FORWARDER, list);
}
///
/// 设置公共库 起始港映射
///
///
public Task SetAllMappingPortLoad(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PORTLOAD, list);
}
///
/// 获取公共库 起始港映射
///
///
public Task> GetAllMappingPortLoad()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PORTLOAD);
}
///
/// 获取公共库 目的港映射
///
///
public Task> GetAllMappingPort()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PORT);
}
///
/// 设置公共库 目的港映射
///
///
public Task SetAllMappingPort(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PORT, list);
}
///
/// 设置公共库 包装映射
///
///
public Task SetAllMappingPackage(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PACKAGE, list);
}
///
/// 获取公共库 包装映射
///
///
public Task> GetAllMappingPackage()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_PACKAGE);
}
///
/// 获取公共库 运输条款映射
///
///
public Task> GetAllMappingService()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_SERVICE);
}
///
/// 设置公共库 运输条款映射
///
///
public Task SetAllMappingService(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_SERVICE, list);
}
///
/// 获取公共库 签单方式
///
///
public Task> GetAllCodeIssueType()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CODEISSUETYPE);
}
///
/// 设置公共库 签单方式
///
///
public Task SetAllCodeIssueType(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_CODEISSUETYPE, list);
}
///
/// 获取公共库 签单方式映射
///
///
public Task> GetAllMappingIssueType()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_ISSUETYPE);
}
///
/// 设置公共库 签单方式映射
///
///
public Task SetAllMappingIssueType(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_MAPPING_ISSUETYPE, list);
}
#endregion
#region DJY
///
/// 获取租户参数
///
///
public Task> GetAllTenantParam()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_TENANT_PARAM_VALUE);
}
///
/// 设置租户参数
///
///
public Task SetAllTenantParam(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_TENANT_PARAM_VALUE, list);
}
///
/// 获取字典缓存
///
///
public Task> GetAllDictData()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
}
///
/// 设置字典参数
///
///
public Task SetAllDictData(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA, list);
}
///
/// 获取EDI参数
///
///
public Task> GetAllEdiSetting()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_DJY_EDI_SETTING);
}
///
/// 设置EDI参数
///
///
public Task SetAllEdiSetting(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_DJY_EDI_SETTING, list);
}
///
/// 更新配置缓存
///
///
public Task SetAllSysConfig(List list)
{
return _cache.SetAsync(CommonConst.DJY_CONST, list);
}
///
/// 获取配置缓存
///
///
public async Task> GetAllSysConfig()
{
return await _cache.GetAsync>(CommonConst.DJY_CONST);
}
///
/// 获取公共库 城市信息
///
///
public Task> GetAllCodeCity()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_CITY);
}
///
/// 获取公共库 城市信息
///
///
public Task> GetAllCodeProvince()
{
return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_PROVINCE);
}
///
/// 设置公共库 城市信息
///
///
public Task SetAllCodeCity(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_CITY, list);
}
///
/// 设置公共库 城市信息
///
///
public Task SetAllCodeProvince(List list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_PROVINCE, list);
}
#endregion
}