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