namespace Yw.RedisCache
|
{
|
/// <summary>
|
/// 指标健康评价记录缓存辅助类
|
/// </summary>
|
public class HealthMultiItemEvaluationRecordCacheHelper
|
{
|
//健康结果记录
|
private const string _flag = "health-multi-item-evaluation-record";
|
|
//最后一条记录
|
private const string _lastRecord = "last-record";
|
|
//Redis客户端辅助类对象
|
private readonly RedisClientHelper _redisClient = new();
|
|
//获取 RedisKey
|
private static string CreateRedisKey(long BindingID, long ItemID)
|
{
|
return $"{RedisKeyHelper.CreateKey(_flag)}:{BindingID}-{ItemID}";
|
}
|
|
|
#region 记录
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public bool SetLastRecord(Model.HealthMultiItemEvaluationRecord model)
|
{
|
if (model == null)
|
return false;
|
string redisKey = CreateRedisKey(model.BindingID, model.ItemID);
|
var hashKey = _lastRecord;
|
_redisClient.HashSetJosn(redisKey, hashKey, model);
|
return true;
|
}
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public bool SetLastRecord(IEnumerable<Model.HealthMultiItemEvaluationRecord> list)
|
{
|
if (list == null || !list.Any())
|
return false;
|
foreach (var item in list)
|
{
|
var bol = SetLastRecord(item);
|
if (!bol)
|
return false;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public Model.HealthMultiItemEvaluationRecord GetLastRecord(long BindingID, long ItemID)
|
{
|
var redisKey = CreateRedisKey(BindingID, ItemID);
|
var hashKey = _lastRecord;
|
return _redisClient.HashGetJson<Model.HealthMultiItemEvaluationRecord>(redisKey, hashKey);
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public List<Model.HealthMultiItemEvaluationRecord> GetLastRecord(long BindingID, IEnumerable<long> ItemIds)
|
{
|
if (ItemIds == null || !ItemIds.Any())
|
return default;
|
return ItemIds.ToList().Select(x => GetLastRecord(BindingID, x)).Where(x => x != null).ToList();
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public List<Model.HealthMultiItemEvaluationRecord> GetLastRecord(IEnumerable<KeyValuePair<long, long>> list)
|
{
|
if (list == null || !list.Any())
|
return default;
|
return list.ToList().Select(x => GetLastRecord(x.Key, x.Value)).Where(x => x != null).ToList();
|
}
|
|
/// <summary>
|
/// 删除最后一条记录
|
/// </summary>
|
public void DeleteLastRecord(long BindingID, long ItemID)
|
{
|
var redisKey = CreateRedisKey(BindingID, ItemID);
|
var hasKey = _lastRecord;
|
_redisClient.HashDelete(redisKey, hasKey);
|
}
|
|
#endregion
|
}
|
}
|