using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.RedisCache
{
///
///
///
public class EtaRealRecord
{
private const string _flag = "eta-real-record";//标志
private const string _lastRecord = "last-record";//最后一条记录
private const string _lastNormalRecord = "last-normal-record";//最后一条正常记录
private const string _lastAbnormalRecord = "last-abnormal-record";//最后一条不正常记录
private const string _lastRunRecord = "last-run-record";//最后一次运行记录
private const string _lastShutRecord = "last-shut-record";//最后一次停机记录
//Redis客户端辅助类对象
private readonly RedisClientHelper _redisClient = new RedisClientHelper();
//创建RedisKey
private static string CreateRedisKey(long CorpID, string ObjectType, long ObjectID)
{
return $"{RedisKeyHelper.CreateKey(_flag)}:{CorpID}:{ObjectType}-{ObjectID}";
}
#region Single
///
/// 设置最后一条记录
///
public void SetLastSingleRecord(Model.EtaSingleRealRecordPure model)
{
if (model == null)
return;
SetLastRecord(model);
var redisKey= CreateRedisKey(model.CorpID, model.ObjectType, model.ObjectID);
if (model.RSa == RunStatus.Run)
{
_redisClient.HashSetJosn(redisKey, _lastRunRecord, model);
}
else
{
_redisClient.HashSetJosn(_lastRecord, _lastShutRecord, model);
}
}
///
/// 设置最后一条记录
///
public void SetLastSingleRecord(IEnumerable list)
{
list?.ToList().ForEach(x => SetLastSingleRecord(x));
}
///
/// 获取最后一条记录
///
public Model.EtaSingleRealRecordPure GetLastSingleRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条记录
///
public List GetLastSingleRecord(long CorpID,string ObjectType,IEnumerable ObjectIds)
{
return GetLastRecord(CorpID,ObjectType,ObjectIds);
}
///
/// 获取最后一条记录
///
public List GetLastSingleRecord(long CorpID, IEnumerable> list)
{
return GetLastRecord(CorpID,list);
}
///
/// 获取最后一条正常记录
///
public Model.EtaSingleRealRecordPure GetLastNormalSingleRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastNormalRecord(CorpID, ObjectType,ObjectID);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalSingleRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastNormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalSingleRecord(long CorpID, IEnumerable> list)
{
return GetLastNormalRecord(CorpID,list);
}
///
/// 获取最后一条不正常记录
///
public Model.EtaSingleRealRecordPure GetLastAbnormalSingleRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalSingleRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalSingleRecord(long CorpID, IEnumerable> list)
{
return GetLastAbnormalRecord(CorpID, list);
}
///
/// 获取最后一条开机记录
///
public Model.EtaSingleRealRecordPure GetLastRunSingleRecord(long CorpID, string ObjectType, long ObjectID)
{
var redisKey = CreateRedisKey(CorpID,ObjectType,ObjectID);
return _redisClient.HashGetJson(redisKey,_lastRunRecord);
}
///
/// 获取最后一条开机记录
///
public List GetLastRunSingleRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastRunSingleRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条开机记录
///
public List GetLastRunSingleRecord(long CorpID, IEnumerable> list)
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastRunSingleRecord(CorpID, x.Key,x.Value)).Where(x => x != null).ToList();
}
///
/// 获取最后一条停机记录
///
public Model.EtaSingleRealRecordPure GetLastShutSingleRecord(long CorpID, string ObjectType, long ObjectID)
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastShutRecord);
}
///
/// 获取最后一条停机记录
///
public List GetLastShutSingleRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastShutSingleRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条停机记录
///
public List GetLastShutSingleRecord(long CorpID, IEnumerable> list)
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastShutSingleRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
#endregion
#region Multi
///
/// 设置最后一条记录
///
public void SetLastMultiRecord(Model.EtaMultiRealRecordPure model)
{
if (model == null)
return;
SetLastRecord(model);
var redisKey = CreateRedisKey(model.CorpID, model.ObjectType, model.ObjectID);
if (model.RunningCount>0 )
{
_redisClient.HashSetJosn(redisKey, _lastRunRecord, model);
}
else
{
_redisClient.HashSetJosn(_lastRecord, _lastShutRecord, model);
}
}
///
/// 设置最后一条记录
///
public void SetLastMultiRecord(IEnumerable list)
{
list?.ToList().ForEach(x => SetLastMultiRecord(x));
}
///
/// 获取最后一条记录
///
public Model.EtaMultiRealRecordPure GetLastMultiRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条记录
///
public List GetLastMultiRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条记录
///
public List GetLastMultiRecord(long CorpID, IEnumerable> list)
{
return GetLastRecord(CorpID, list);
}
///
/// 获取最后一条正常记录
///
public Model.EtaMultiRealRecordPure GetLastNormalMultiRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastNormalRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalMultiRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastNormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalMultiRecord(long CorpID, IEnumerable> list)
{
return GetLastNormalRecord(CorpID, list);
}
///
/// 获取最后一条不正常记录
///
public Model.EtaMultiRealRecordPure GetLastAbnormalMultiRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalMultiRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalMultiRecord(long CorpID, IEnumerable> list)
{
return GetLastAbnormalRecord(CorpID, list);
}
///
/// 获取最后一条开机记录
///
public Model.EtaMultiRealRecordPure GetLastRunMultiRecord(long CorpID, string ObjectType, long ObjectID)
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastRunRecord);
}
///
/// 获取最后一条开机记录
///
public List GetLastRunMultiRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastRunMultiRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条开机记录
///
public List GetLastRunMultiRecord(long CorpID, IEnumerable> list)
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastRunMultiRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
///
/// 获取最后一条停机记录
///
public Model.EtaMultiRealRecordPure GetLastShutMultiRecord(long CorpID, string ObjectType, long ObjectID)
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastShutRecord);
}
///
/// 获取最后一条停机记录
///
public List GetLastShutMultiRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastShutMultiRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条停机记录
///
public List GetLastShutMultiRecord(long CorpID, IEnumerable> list)
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastShutMultiRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
#endregion
#region Logic
///
/// 设置最后一条记录
///
public void SetLastLogicRecord(Model.EtaLogicRealRecordPure model)
{
SetLastRecord(model);
}
///
/// 设置最后一条记录
///
public void SetLastLogicRecord(IEnumerable list)
{
list?.ToList().ForEach(x => SetLastLogicRecord(x));
}
///
/// 获取最后一条记录
///
public Model.EtaLogicRealRecordPure GetLastLogicRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条记录
///
public List GetLastLogicRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条记录
///
public List GetLastLogicRecord(long CorpID, IEnumerable> list)
{
return GetLastRecord(CorpID, list);
}
///
/// 获取最后一条正常记录
///
public Model.EtaLogicRealRecordPure GetLastNormalLogicRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastNormalRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalLogicRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastNormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalLogicRecord(long CorpID, IEnumerable> list)
{
return GetLastNormalRecord(CorpID, list);
}
///
/// 获取最后一条不正常记录
///
public Model.EtaLogicRealRecordPure GetLastAbnormalLogicRecord(long CorpID, string ObjectType, long ObjectID)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectID);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalLogicRecord(long CorpID, string ObjectType, IEnumerable ObjectIds)
{
return GetLastAbnormalRecord(CorpID, ObjectType, ObjectIds);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalLogicRecord(long CorpID, IEnumerable> list)
{
return GetLastAbnormalRecord(CorpID, list);
}
#endregion
#region 最后一条记录
///
/// 设置最后一条记录
///
public void SetLastRecord(T t) where T : Model.EtaBasicRealRecord
{
if (t == null)
return;
var redisKey = CreateRedisKey(t.CorpID, t.ObjectType, t.ObjectID);
_redisClient.HashSetJosn(redisKey, _lastRecord, t);
if (t.AnalyStatus == Model.Eta.eAnalyStatus.Normal)
{
_redisClient.HashSetJosn(redisKey, _lastNormalRecord, t);
}
else
{
_redisClient.HashSetJosn(redisKey, _lastAbnormalRecord, t);
}
}
///
/// 设置最后一条记录
///
public void SetLastRecord(IEnumerable list) where T : Model.EtaBasicRealRecord
{
if (list == null || list.Count() < 1)
return;
foreach (var item in list)
{
SetLastRecord(item);
}
}
///
/// 获取最后一条记录
///
public T GetLastRecord(long CorpID, string ObjectType, long ObjectID) where T : Model.EtaBasicRealRecord
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastRecord);
}
///
/// 获取最后一条记录
///
public List GetLastRecord(long CorpID, string ObjectType, IEnumerable ObjectIds) where T : Model.EtaBasicRealRecord
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x=>GetLastRecord(CorpID,ObjectType,x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条记录
///
public List GetLastRecord(long CorpID, IEnumerable> list) where T : Model.EtaBasicRealRecord
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
///
/// 获取最后一条正常记录
///
public T GetLastNormalRecord(long CorpID, string ObjectType, long ObjectID) where T : Model.EtaBasicRealRecord
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastNormalRecord);
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalRecord(long CorpID, string ObjectType, IEnumerable ObjectIds) where T : Model.EtaBasicRealRecord
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastNormalRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条正常记录
///
public List GetLastNormalRecord(long CorpID, IEnumerable> list) where T : Model.EtaBasicRealRecord
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastNormalRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
///
/// 获取最后一条不正常记录
///
public T GetLastAbnormalRecord(long CorpID, string ObjectType, long ObjectID) where T : Model.EtaBasicRealRecord
{
var redisKey = CreateRedisKey(CorpID, ObjectType, ObjectID);
return _redisClient.HashGetJson(redisKey, _lastAbnormalRecord);
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalRecord(long CorpID, string ObjectType, IEnumerable ObjectIds) where T : Model.EtaBasicRealRecord
{
if (ObjectIds == null || ObjectIds.Count() < 1)
return default;
return ObjectIds.Select(x => GetLastAbnormalRecord(CorpID, ObjectType, x)).Where(x => x != null).ToList();
}
///
/// 获取最后一条不正常记录
///
public List GetLastAbnormalRecord(long CorpID, IEnumerable> list) where T : Model.EtaBasicRealRecord
{
if (list == null || list.Count() < 1)
return default;
return list.Select(x => GetLastAbnormalRecord(CorpID, x.Key, x.Value)).Where(x => x != null).ToList();
}
#endregion
}
}