using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.RedisCache
|
{
|
/// <summary>
|
/// 监测记录缓存辅助类
|
/// </summary>
|
public class MonitorRecordCacheHelper
|
{
|
public MonitorRecordCacheHelper()
|
{
|
}
|
|
|
|
|
//Redis客户端辅助类对象
|
private readonly RedisClientHelper _redisClient = null;
|
|
|
private static string CreateRedisKey(long monitorPointId)
|
{
|
return $"linux_test:{monitorPointId}";
|
}
|
|
//最后一条记录
|
private const string _lastRecord = "last-record";
|
|
|
#region 最后一条记录
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public void SetLastRecord(Model.MonitorRecord model, out bool redis, out string info)
|
{
|
info = string.Empty;
|
redis = false;
|
var redisKey = CreateRedisKey(model.MonitorPointID);
|
redis = _redisClient.HashSetJosn(redisKey, _lastRecord, model, out info);
|
|
}
|
|
|
/// <summary>
|
/// 设置最后一条记录
|
/// </summary>
|
public void SetLastRecord(IEnumerable<Model.MonitorRecord> list, out string info)
|
{
|
info = "IStation.RedisCache.LinuxTest";
|
if (list == null || list.Count() < 1)
|
return;
|
foreach (var item in list)
|
{
|
SetLastRecord(item,out bool redis,out info);
|
}
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public Model.MonitorRecord GetLastRecord(long monitorPointId)
|
{
|
var redisKey = CreateRedisKey(monitorPointId);
|
return _redisClient.HashGetJson<Model.MonitorRecord>(redisKey, _lastRecord);
|
}
|
|
/// <summary>
|
/// 获取最后一条记录
|
/// </summary>
|
public List<Model.MonitorRecord> GetLastRecord(IEnumerable<long> monitorPointIds)
|
{
|
if (monitorPointIds == null || monitorPointIds.Count() < 1)
|
return default;
|
return monitorPointIds.Select(x => GetLastRecord(x)).Where(x => x != null).ToList();
|
}
|
|
|
#endregion
|
|
|
|
}
|
}
|