using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.RedisCache
|
{
|
/// <summary>
|
/// 对接监测流程记录缓存辅助类
|
/// </summary>
|
public class MonitorDataDockingFlowRecordCacheHelper
|
{
|
//标志
|
private const string _flag = "monitor-datadocking-flow";
|
|
//最后一条记录
|
private const string _lastRecord = "last-record";
|
|
//Redis客户端辅助类对象
|
private readonly RedisClientHelper _redisClient = new RedisClientHelper();
|
|
//创建RedisKey
|
private static string CreateRedisKey(long CorpID, long ConfigureID)
|
{
|
return $"{RedisKeyHelper.CreateKey(_flag)}:{CorpID}-{ConfigureID}";
|
}
|
|
#region 最后一条记录
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public void SetLastRecord(Model.MonitorDataDockingFlowRecord model)
|
{
|
if (model == null)
|
return;
|
var redisKey = CreateRedisKey(model.CorpID, model.ConfigureID);
|
_redisClient.HashSetJosn(redisKey, _lastRecord, model);
|
}
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public void SetLastRecord(IEnumerable<Model.MonitorDataDockingFlowRecord> list)
|
{
|
if (list == null || list.Count() < 1)
|
return;
|
foreach (var item in list)
|
{
|
SetLastRecord(item);
|
}
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public Model.MonitorDataDockingFlowRecord GetLastRecord(long CorpID, long ConfigureID)
|
{
|
var redisKey = CreateRedisKey(CorpID, ConfigureID);
|
return _redisClient.HashGetJson<Model.MonitorDataDockingFlowRecord>(redisKey, _lastRecord);
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public List<Model.MonitorDataDockingFlowRecord> GetLastRecord(long CorpID, IEnumerable<long> ConfigureIds)
|
{
|
if (ConfigureIds == null || ConfigureIds.Count() < 1)
|
return default;
|
return ConfigureIds.Select(x => GetLastRecord(CorpID, x)).Where(x => x != null).ToList();
|
}
|
|
|
#endregion
|
|
|
|
}
|
}
|