using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Service
|
{
|
/// <summary>
|
/// 测点
|
/// </summary>
|
public partial class MonitorPoint
|
{
|
#region Cache
|
|
//通过 CorpID 更新缓存
|
internal List<Model.MonitorPoint> GetCorpCache(long CorpID)
|
{
|
var all = MonitorPointCacheHelper.GetSet(CorpID, () =>
|
{
|
var dal=new DAL.MonitorPoint();
|
var entity_list = dal.GetByCorpID(CorpID);
|
var model_list = Entity2Models(entity_list);
|
if (model_list == null)
|
{
|
model_list = new List<Model.MonitorPoint>();
|
}
|
return model_list;
|
}, ConfigHelper.CacheKeepTime, ConfigHelper.CacheRandomTime);
|
return all;
|
}
|
|
//通过 ID 更新缓存
|
internal void UpdateCorpCache(long CorpID, long ID)
|
{
|
var dal=new DAL.MonitorPoint();
|
var entity_ds = dal.GetByID(CorpID, ID);
|
var model_ds = Entity2Model(entity_ds);
|
var all = GetCorpCache(CorpID);
|
var model = all.Find(x => x.ID == ID);
|
if (model == null)
|
{
|
all.Add(model_ds);
|
}
|
else
|
{
|
model.Reset(model_ds);
|
}
|
}
|
|
//通过 Ids 更新缓存
|
internal void UpdateCorpCache(long CorpID, List<long> Ids)
|
{
|
if (Ids == null || Ids.Count() < 1)
|
return;
|
var dal=new DAL.MonitorPoint();
|
var entity_list = dal.GetByIds(CorpID, Ids);
|
var model_list = Entity2Models(entity_list);
|
var all = GetCorpCache(CorpID);
|
all.RemoveAll(x => Ids.Contains(x.ID));
|
if (model_list != null && model_list.Count > 0)
|
{
|
all.AddRange(model_list);
|
}
|
}
|
|
//通过 ID 移除缓存
|
internal void RemoveCorpCache(long CorpID, long ID)
|
{
|
var all = GetCorpCache(CorpID);
|
all.RemoveAll(x => x.ID == ID);
|
}
|
|
#endregion
|
|
#region Query
|
|
#region 测点
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByCorpID(long CorpID)
|
{
|
var all = GetCorpCache(CorpID);
|
return all.OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public Model.MonitorPoint GetByID(long CorpID, long ID)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Find(x => x.ID == ID);
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByIds(long CorpID, List<long> Ids)
|
{
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => Ids.Contains(x.ID)).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByIds(long CorpID, List<long> Ids, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => Ids.Contains(x.ID)&&x.MonitorType==MonitorType&&x.CronType==CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID, Model.eMonitorType MonitorType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID && x.MonitorType == MonitorType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID,Model.eMonitorType MonitorType,Model.Monitor.eCronType CronType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID&&x.MonitorType== MonitorType&&x.CronType==CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID, Model.Monitor.eCronType CronType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID && x.CronType == CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongIds 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByBelongTypeAndBelongIds(long CorpID, string BelongType, List<long> BelongIds)
|
{
|
if (BelongIds == null || BelongIds.Count() < 1)
|
return default;
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.BelongType == BelongType && BelongIds.Contains(x.BelongID)).OrderBy(x=>x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByGroupID(long CorpID,long GroupID)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x =>x.GroupID == GroupID).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByGroupID
|
(long CorpID, long GroupID, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.GroupID == GroupID && x.MonitorType == MonitorType && x.CronType == CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 GroupIds 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByGroupIds(long CorpID, IEnumerable<long> GroupIds)
|
{
|
if (GroupIds == null || GroupIds.Count() < 1)
|
return default;
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => GroupIds.Contains(x.GroupID)).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 GroupIds 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByGroupIds(long CorpID, IEnumerable<long> GroupIds,Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
if (GroupIds == null || GroupIds.Count() < 1)
|
return default;
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => GroupIds.Contains(x.GroupID)&&x.MonitorType==MonitorType&&x.CronType==CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByMonitorTypeAndCronType
|
(long CorpID, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.MonitorType == MonitorType && x.CronType == CronType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByMonitorTypeAndCronType
|
(IEnumerable<long> CorpIds, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
if (CorpIds == null || CorpIds.Count() < 1)
|
return default;
|
return CorpIds.SelectMany(x => GetByMonitorTypeAndCronType(x, MonitorType, CronType)).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 和 SourceType 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByMonitorTypeAndCronTypeAndSourceType
|
(long CorpID, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType, Model.Monitor.eSourceType SourceType)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Where(x => x.MonitorType == MonitorType && x.CronType == CronType && x.SourceType == SourceType).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 和 SourceType 获取
|
/// </summary>
|
public List<Model.MonitorPoint> GetByMonitorTypeAndCronTypeAndSourceType
|
(IEnumerable<long> CorpIds, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType, Model.Monitor.eSourceType SourceType)
|
{
|
if (CorpIds == null || CorpIds.Count() < 1)
|
return default;
|
return CorpIds.SelectMany(x => GetByMonitorTypeAndCronTypeAndSourceType(x, MonitorType,CronType, SourceType)).ToList();
|
}
|
|
|
#endregion
|
|
#region 测点+信号列表
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByCorpID(long CorpID)
|
{
|
var monitor_list = GetByCorpID(CorpID);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
var monitor_list = GetByBelongTypeAndBelongID(CorpID,BelongType,BelongID);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongIds 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByBelongTypeAndBelongIds(long CorpID, string BelongType, List<long> BelongIds)
|
{
|
var monitor_list = GetByBelongTypeAndBelongIds(CorpID, BelongType, BelongIds);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByGroupID(long CorpID, long GroupID)
|
{
|
var monitor_list = GetByGroupID(CorpID, GroupID);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupIds 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByGroupIds(long CorpID, List<long> GroupIds)
|
{
|
var monitor_list = GetByGroupIds(CorpID, GroupIds);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public Model.MonitorPointExSignalList GetExSignalListByID(long CorpID, long ID)
|
{
|
var monitor = GetByID(CorpID,ID);
|
if (monitor == null)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointID(CorpID,ID);
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
return new Model.MonitorPointExSignalList(monitor,signal_list);
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> GetExSignalListByIds(long CorpID, List<long> Ids)
|
{
|
var monitor_list = GetByIds(CorpID, Ids);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID));
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = monitor_list.Select(x => new Model.MonitorPointExSignalList(x, signal_list.Where(y => y.MonitorPointID == x.ID).OrderBy(y => y.SortCode))).ToList();
|
return vm_list;
|
}
|
|
#endregion
|
|
#region 测点+信号+信号类型
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
var monitor_list = GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
var monitor_list = GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID, MonitorType, CronType);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID, Model.eMonitorType MonitorType)
|
{
|
var monitor_list = GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID, MonitorType);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByBelongTypeAndBelongID
|
(long CorpID, string BelongType, long BelongID, Model.Monitor.eCronType CronType)
|
{
|
var monitor_list = GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID, CronType);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByGroupID(long CorpID, long GroupID)
|
{
|
var monitor_list = GetByGroupID(CorpID, GroupID);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByGroupIds(long CorpID, IEnumerable<long> GroupIds)
|
{
|
if (GroupIds == null || GroupIds.Count() < 1)
|
return default;
|
var monitor_list = GetByGroupIds(CorpID, GroupIds);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByGroupID
|
(long CorpID, long GroupID, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
var monitor_list = GetByGroupID(CorpID, GroupID,MonitorType,CronType);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 GroupID 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByGroupIds
|
(long CorpID, IEnumerable<long> GroupIds, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
if (GroupIds == null || GroupIds.Count() < 1)
|
return default;
|
var monitor_list = GetByGroupIds(CorpID, GroupIds.ToList(), MonitorType, CronType);
|
if (monitor_list == null || monitor_list.Count < 1)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, monitor_list.Select(x => x.ID).ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in monitor_list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 和 SourceType 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByMonitorTypeAndCronTypeAndSourceType
|
(IEnumerable<long> CorpIds, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType, Model.Monitor.eSourceType SourceType)
|
{
|
if (CorpIds == null || CorpIds.Count() < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var CorpId in CorpIds)
|
{
|
var list = GetByMonitorTypeAndCronTypeAndSourceType(CorpId, MonitorType, CronType, SourceType);
|
if (list == null || list.Count < 1)
|
continue;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpId, list.Select(x => x.ID).Distinct().ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
continue;
|
foreach (var item in list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorType 和 CronType 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByMonitorTypeAndCronType
|
(IEnumerable<long> CorpIds, Model.eMonitorType MonitorType, Model.Monitor.eCronType CronType)
|
{
|
if (CorpIds == null || CorpIds.Count() < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var CorpId in CorpIds)
|
{
|
var list = GetByMonitorTypeAndCronType(CorpId, MonitorType, CronType);
|
if (list == null || list.Count < 1)
|
continue;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpId, list.Select(x => x.ID).Distinct().ToList());
|
if (signal_list == null || signal_list.Count < 1)
|
continue;
|
foreach (var item in list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByIds(long CorpID, List<long> Ids)
|
{
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var list = GetByIds(CorpID, Ids);
|
if (list == null || list.Count < 1)
|
return default;
|
var ids = list.Select(x => x.ID).Distinct().ToList();
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, ids);
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取 测点+信号+信号类型
|
/// </summary>
|
public List<Model.MonitorPoint_Signal_SignalType> GetExSignalWithSignalTypeByIds
|
(long CorpID, List<long> Ids,Model.eMonitorType monitorType,Model.Monitor.eCronType cronType)
|
{
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var list = GetByIds(CorpID, Ids,monitorType,cronType);
|
if (list == null || list.Count < 1)
|
return default;
|
var ids = list.Select(x => x.ID).Distinct().ToList();
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointIds(CorpID, ids);
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
var vm_list = new List<Model.MonitorPoint_Signal_SignalType>();
|
foreach (var item in list)
|
{
|
var signals = signal_list.Where(x => x.MonitorPointID == item.ID).OrderBy(x => x.SortCode).ToList();
|
if (signals != null && signals.Count > 0)
|
{
|
var vm = new Model.MonitorPoint_Signal_SignalType(item, signals);
|
vm_list.Add(vm);
|
}
|
}
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取 测点+信号+信号类型
|
/// </summary>
|
public Model.MonitorPoint_Signal_SignalType GetExSignalWithSignalTypeByID(long CorpID, long ID)
|
{
|
var point = GetByID(CorpID, ID);
|
if (point == null)
|
return default;
|
var signal_list = new Signal().GetExSignalTypeByMonitorPointID(CorpID, ID);
|
if (signal_list == null || signal_list.Count < 1)
|
return default;
|
return new Model.MonitorPoint_Signal_SignalType(point, signal_list);
|
}
|
|
|
#endregion
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入
|
/// </summary>
|
public long Insert(Model.MonitorPoint model)
|
{
|
if (model == null)
|
return default;
|
if (model.CorpID < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity = Model2Entity(model);
|
var id = dal.Insert(entity);
|
if (id > 0)
|
{
|
UpdateCorpCache(entity.CorpID, id);
|
}
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
public bool Inserts(List<Model.MonitorPoint> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count != 1 || corpIds[0] < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity_list = Model2Entities(list.ToList());
|
var ids = dal.InsertsR(entity_list);
|
if (ids != null && ids.Count > 0)
|
{
|
UpdateCorpCache(corpIds[0], ids);
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 插入拓展
|
/// </summary>
|
public long InsertEx(Model.MonitorPointExSignalList model)
|
{
|
if (model == null || model.SignalList == null || model.SignalList.Count < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity = Model2Entity(model);
|
var entity_signal_list = Model2Entities(model.SignalList);
|
var id = dal.InsertEx(entity, entity_signal_list);
|
if (id > 0)
|
{
|
UpdateCorpCache(model.CorpID, id);
|
new Signal().UpdateCorpCacheByMonitorPointID(model.CorpID, id);
|
}
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条拓展
|
/// </summary>
|
public bool InsertsEx(List<Model.MonitorPointExSignalList> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count != 1 || corpIds[0] < 1)
|
return default;
|
var dict = new Dictionary<Entity.MonitorPoint, List<Entity.Signal>>();
|
foreach (var item in list)
|
{
|
var entity = Model2Entity(item);
|
var entity_signal_list = Model2Entities(item.SignalList);
|
dict.Add(entity, entity_signal_list);
|
}
|
var dal=new DAL.MonitorPoint();
|
var ids = dal.InsertsREx(dict);
|
if (ids != null && ids.Count > 0)
|
{
|
UpdateCorpCache(corpIds[0], ids);
|
new Signal().UpdateCorpCacheByMonitorPointID(corpIds[0], ids);
|
return true;
|
}
|
return false;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public bool Update(Model.MonitorPoint model)
|
{
|
if (model == null)
|
return default;
|
if (model.CorpID < 1)
|
return default;
|
if (model.ID < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity = Model2Entity(model);
|
var bol = dal.Update(entity);
|
if (bol)
|
{
|
UpdateCorpCache(model.CorpID, model.ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
public bool Updates(List<Model.MonitorPoint> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count != 1 || corpIds[0] < 1)
|
return default;
|
if (list.ToList().Exists(x => x.ID < 1))
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity_list = Model2Entities(list.ToList());
|
var bol = dal.Updates(entity_list);
|
if (bol)
|
{
|
UpdateCorpCache(corpIds[0], list.Select(x => x.ID).ToList());
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新拓展
|
/// </summary>
|
public bool UpdateEx(Model.MonitorPointExSignalList model)
|
{
|
if (model == null)
|
return default;
|
if (model.CorpID < 1)
|
return default;
|
if (model.ID < 1)
|
return default;
|
if (model.SignalList == null || model.SignalList.Count < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var entity = Model2Entity(model);
|
var entity_signal_list = Model2Entities(model.SignalList);
|
var bol = dal.UpdateEx(entity, entity_signal_list);
|
if (bol)
|
{
|
UpdateCorpCache(model.CorpID, model.ID);
|
new Signal().UpdateCorpCacheByMonitorPointID(model.CorpID, model.ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 批量更新拓展
|
/// </summary>
|
public bool UpdatesEx(List<Model.MonitorPointExSignalList> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count != 1 || corpIds[0] < 1)
|
return default;
|
if (list.ToList().Exists(x => x.ID < 1))
|
return default;
|
var dict = new Dictionary<Entity.MonitorPoint, List<Entity.Signal>>();
|
foreach (var item in list)
|
{
|
var entity = Model2Entity(item);
|
var entity_signal_list = Model2Entities(item.SignalList);
|
dict.Add(entity, entity_signal_list);
|
}
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdatesEx(dict);
|
if (bol)
|
{
|
UpdateCorpCache(corpIds[0], list.Select(x => x.ID).ToList());
|
new Signal().UpdateCorpCacheByMonitorPointID(corpIds[0], list.Select(x => x.ID).ToList());
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 GroupID
|
/// </summary>
|
public bool UpdateGroupID(long CorpID, long ID, long GroupID)
|
{
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateGroupID(CorpID, ID, GroupID);
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
public bool UpdateSortCode(long CorpID, long ID, int SortCode)
|
{
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateSortCode(CorpID, ID, SortCode);
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
public bool UpdateSorter(long CorpID, List<Model.Sorter> sorters)
|
{
|
if (sorters == null || sorters.Count() < 1)
|
return default;
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateSorter(CorpID, sorters.ToEntityList());
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, sorters.Select(x => x.ID).ToList());
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新使用状态
|
/// </summary>
|
public bool UpdateUseStatus(long CorpID, long ID, Model.eUseStatus UseStatus)
|
{
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateUseStatus(CorpID, ID, (int)UseStatus);
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 TagName
|
/// </summary>
|
public bool UpdateTagName(long CorpID, long ID, string TagName)
|
{
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateTagName(CorpID, ID, TagName);
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 TerminalId
|
/// </summary>
|
public bool UpdateTerminalId(long CorpID, long ID, string TerminalId)
|
{
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.UpdateTerminalId(CorpID, ID, TerminalId);
|
if (bol)
|
{
|
UpdateCorpCache(CorpID, ID);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
#region Exist
|
|
/// <summary>
|
/// 判断TagName是否存在
|
/// </summary>
|
public bool IsExistTagName(long CorpID, string TagName)
|
{
|
if (string.IsNullOrEmpty(TagName))
|
return default;
|
var all = GetByCorpID(CorpID);
|
if (all == null || all.Count < 1)
|
return default;
|
return all.Exists(x => !string.IsNullOrEmpty(x.TagName) && x.TagName.ToUpper() == TagName.ToUpper());
|
}
|
|
/// <summary>
|
/// 判断TagName是否存在 ExceptID
|
/// </summary>
|
public bool IsExistTagNameExceptID(long CorpID, string TagName, long ExceptID)
|
{
|
if (string.IsNullOrEmpty(TagName))
|
return default;
|
var all = GetByCorpID(CorpID);
|
if (all == null || all.Count < 1)
|
return default;
|
return all.Exists(x => !string.IsNullOrEmpty(x.TagName) && x.TagName.ToUpper() == TagName.ToUpper() && x.ID != ExceptID);
|
}
|
|
/// <summary>
|
/// 通过 GroupID 判断是否存在
|
/// </summary>
|
public bool IsExistByGroupID(long CorpID, long GroupID)
|
{
|
var all = GetByCorpID(CorpID);
|
return all.Exists(x => x.GroupID == GroupID);
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
public bool DeleteByID(long CorpID, long ID, out string Msg)
|
{
|
Msg = string.Empty;
|
if (new MonitorPointMapping().IsExistByMonitorPointID(CorpID, ID))
|
{
|
Msg = "该测点已被关联";
|
return false;
|
}
|
var dal=new DAL.MonitorPoint();
|
var bol = dal.DeleteByID(CorpID, ID);
|
if (bol)
|
{
|
RemoveCorpCache(CorpID, ID);
|
new Signal().RemoveCorpCacheByMonitorPointID(CorpID,ID);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
}
|
}
|