using BBWY.Common.Models;
using BBWY.Server.Model.Db;
using Microsoft.Extensions.Caching.Memory;
using System;
namespace BBWY.Server.Business
{
public class YunDingBusiness : IDenpendency
{
private IMemoryCache memoryCache;
private IFreeSql fsql;
private TimeSpan expirationTimeSpan = TimeSpan.FromDays(500);
public YunDingBusiness(IMemoryCache memoryCache, IFreeSql fsql)
{
this.memoryCache = memoryCache;
this.fsql = fsql;
}
///
/// 创建云鼎Key
///
public void CreateKey()
{
var key = Guid.NewGuid().ToString();
memoryCache.Set("YunDingKey", key, expirationTimeSpan);
fsql.Update(1).Set(k => k.YunDingKey, key).ExecuteAffrows();
}
///
/// 刷新云鼎Key
///
public void RefreshKey()
{
var yundingKey = fsql.Select(1).ToOne();
memoryCache.Set("YunDingKey", yundingKey.YunDingKey, expirationTimeSpan);
}
///
/// 读取云鼎Key
///
///
public string GetKey()
{
return memoryCache.Get("YunDingKey");
}
}
}