namespace HStation.Service
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class XhsPumpPhartMapping
|
{
|
#region Cache
|
|
//获取缓存
|
private static List<Model.XhsPumpPhartMapping> GetCache()
|
{
|
var all = XhsPumpPhartMappingCacheHelper.GetSet(() =>
|
{
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetAll();
|
var modelList = Entity2Models(entityList);
|
if (modelList == null)
|
{
|
modelList = new List<Model.XhsPumpPhartMapping>();
|
}
|
return modelList;
|
}, Yw.Service.ConfigHelper.CacheKeepTime, Yw.Service.ConfigHelper.CacheRandomTime);
|
return all;
|
}
|
|
//通过 ID 更新缓存
|
internal static Model.XhsPumpPhartMapping UpdateCache(long ID)
|
{
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityDb = dal.GetByID(ID);
|
var modelDb = Entity2Model(entityDb);
|
var all = GetCache();
|
var model = all.Find(x => x.ID == ID);
|
if (model == null)
|
{
|
all.Add(modelDb);
|
}
|
else
|
{
|
model.Reset(modelDb);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
return modelDb;
|
}
|
|
//通过 Ids 更新缓存
|
private static void UpdateCache(List<long> Ids)
|
{
|
if (Ids == null || Ids.Count < 1)
|
return;
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetByIds(Ids);
|
var modelList = Entity2Models(entityList);
|
var all = GetCache();
|
all.RemoveAll(x => Ids.Contains(x.ID));
|
if (modelList != null && modelList.Count > 0)
|
{
|
all.AddRange(modelList);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 PumpID 更新缓存
|
internal static void UpdateCacheByPumpID(long PumpID)
|
{
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetByPumpID(PumpID);
|
var modelList = Entity2Models(entityList);
|
var all = GetCache();
|
all.RemoveAll(x => x.PumpID == PumpID);
|
if (modelList != null && modelList.Count > 0)
|
{
|
all.AddRange(modelList);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 PumpIds 更新缓存
|
internal static void UpdateCacheByPumpIds(List<long> PumpIds)
|
{
|
if (PumpIds == null || PumpIds.Count < 1)
|
{
|
return;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetByPumpIds(PumpIds);
|
var modelList = Entity2Models(entityList);
|
var all = GetCache();
|
all.RemoveAll(x => PumpIds.Contains(x.PumpID));
|
if (modelList != null && modelList.Count > 0)
|
{
|
all.AddRange(modelList);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 DiagramID 更新缓存
|
internal static void UpdateCacheByDiagramID(long DiagramID)
|
{
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetByDiagramID(DiagramID);
|
var modelList = Entity2Models(entityList);
|
var all = GetCache();
|
all.RemoveAll(x => x.DiagramID == DiagramID);
|
if (modelList != null && modelList.Count > 0)
|
{
|
all.AddRange(modelList);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 DiagramIds 更新缓存
|
internal static void UpdateCacheByDiagramIds(List<long> DiagramIds)
|
{
|
if (DiagramIds == null || DiagramIds.Count < 1)
|
{
|
return;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var entityList = dal.GetByDiagramIds(DiagramIds);
|
var modelList = Entity2Models(entityList);
|
var all = GetCache();
|
all.RemoveAll(x => DiagramIds.Contains(x.DiagramID));
|
if (modelList != null && modelList.Count > 0)
|
{
|
all.AddRange(modelList);
|
}
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//移除缓存
|
private static void RemoveCache(long ID)
|
{
|
var all = GetCache();
|
all.RemoveAll(x => x.ID == ID);
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 PumpID 移除缓存
|
internal static void RemoveCacheByPumpID(long PumpID)
|
{
|
var all = GetCache();
|
all.RemoveAll(x => x.PumpID == PumpID);
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
//通过 DiagramID 移除缓存
|
internal static void RemoveCacheByDiagramID(long DiagramID)
|
{
|
var all = GetCache();
|
all.RemoveAll(x => x.DiagramID == DiagramID);
|
XhsPumpPhartMappingCacheHelper.Trigger();
|
}
|
|
/// <summary>
|
/// 发布缓存
|
/// </summary>
|
public static void PublishCache(string key)
|
{
|
XhsPumpPhartMappingCacheHelper.Publish(key);
|
}
|
|
#endregion
|
|
#region Query
|
|
#region general
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetAll()
|
{
|
var all = GetCache();
|
return all.OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public Model.XhsPumpPhartMapping GetByID(long ID)
|
{
|
var all = GetAll();
|
return all.Find(x => x.ID == ID);
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetByIds(List<long> Ids)
|
{
|
if (Ids == null || Ids.Count < 1)
|
{
|
return default;
|
}
|
var all = GetAll();
|
return all.Where(x => Ids.Contains(x.ID)).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetByPumpID(long PumpID)
|
{
|
var all = GetAll();
|
var list = all.Where(x => x.PumpID == PumpID).OrderBy(x => x.SortCode).ToList();
|
return list;
|
}
|
|
/// <summary>
|
/// 通过 PumpIds 获取
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetByPumpIds(List<long> PumpIds)
|
{
|
if (PumpIds == null || PumpIds.Count < 1)
|
{
|
return default;
|
}
|
var all = GetAll();
|
return all.Where(x => PumpIds.Contains(x.PumpID)).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取默认
|
/// </summary>
|
public Model.XhsPumpPhartMapping GetDefaultByPumpID(long PumpID)
|
{
|
var all = GetByPumpID(PumpID);
|
if (all == null || all.Count < 1)
|
{
|
return default;
|
}
|
var model = all.OrderBy(x => x.Importance).LastOrDefault();
|
return model;
|
}
|
|
/// <summary>
|
/// 通过 DiagramID 获取
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetByDiagramID(long DiagramID)
|
{
|
var all = GetAll();
|
return all.Where(x => x.DiagramID == DiagramID).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 通过 DiagramIds 获取
|
/// </summary>
|
public List<Model.XhsPumpPhartMapping> GetByDiagramIds(List<long> DiagramIds)
|
{
|
if (DiagramIds == null || DiagramIds.Count < 1)
|
{
|
return default;
|
}
|
var all = GetAll();
|
return all.Where(x => DiagramIds.Contains(x.DiagramID)).OrderBy(x => x.SortCode).ToList();
|
}
|
|
/// <summary>
|
/// 获取最大排序码
|
/// </summary>
|
public int GetMaxSortCode(long PumpID)
|
{
|
var all = GetByPumpID(PumpID);
|
if (all == null || all.Count < 1)
|
{
|
return 0;
|
}
|
return all.Max(x => x.SortCode);
|
}
|
|
#endregion
|
|
#region tuple
|
|
/// <summary>
|
/// 通过 PumpID 获取Tuple
|
/// </summary>
|
public List<Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>> GetTupleByPumpID
|
(long PumpID, eDiagramType? DiagramType = null, List<eGraphType> GraphTypeList = null)
|
{
|
var allMappingList = GetByPumpID(PumpID);
|
if (allMappingList == null || allMappingList.Count < 1)
|
{
|
return default;
|
}
|
var allDiagramIds = allMappingList.Select(x => x.DiagramID).Distinct().ToList();
|
var allDiagramList = new HStation.Service.XhsPhartDiagram().GetByIds(allDiagramIds);
|
if (DiagramType.HasValue)
|
{
|
allDiagramList = allDiagramList?.Where(x => x.DiagramType == (int)DiagramType.Value).ToList();
|
}
|
if (allDiagramList == null || allDiagramList.Count < 1)
|
{
|
return default;
|
}
|
allDiagramIds = allDiagramList.Select(x => x.ID).ToList();
|
var allGraphList = new HStation.Service.XhsPhartGraph().GetByDiagramIds(allDiagramIds);
|
if (GraphTypeList != null && GraphTypeList.Count > 0)
|
{
|
allGraphList = allGraphList?.Where(x => GraphTypeList.Contains((eGraphType)x.GraphType)).ToList();
|
}
|
var vmList = new List<Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>>();
|
foreach (var mapping in allMappingList)
|
{
|
var diagram = allDiagramList.Find(x => x.ID == mapping.DiagramID);
|
if (diagram == null)
|
{
|
continue;
|
}
|
var graphList = allGraphList?.Where(x => x.DiagramID == mapping.DiagramID).ToList();
|
var vm = new Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>(mapping, diagram, graphList);
|
vmList.Add(vm);
|
}
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取Tuple
|
/// </summary>
|
public Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>> GetTupleByID
|
(long ID, eDiagramType? DiagramType = null, List<eGraphType> GraphTypeList = null)
|
{
|
var mapping = GetByID(ID);
|
if (mapping == null)
|
{
|
return default;
|
}
|
var diagram = new HStation.Service.XhsPhartDiagram().GetByID(mapping.DiagramID);
|
if (diagram == null)
|
{
|
return default;
|
}
|
if (DiagramType.HasValue)
|
{
|
if (diagram.DiagramType != (int)DiagramType.Value)
|
{
|
return default;
|
}
|
}
|
var graphList = new HStation.Service.XhsPhartGraph().GetByDiagramID(diagram.ID);
|
if (GraphTypeList != null && GraphTypeList.Count > 0)
|
{
|
graphList = graphList?.Where(x => GraphTypeList.Contains((eGraphType)x.GraphType)).ToList();
|
}
|
var vm = new Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>(mapping, diagram, graphList);
|
return vm;
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取Tuple
|
/// </summary>
|
public List<Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>> GetTupleByIds
|
(List<long> Ids, eDiagramType? DiagramType = null, List<eGraphType> GraphTypeList = null)
|
{
|
if (Ids == null || Ids.Count < 1)
|
{
|
return default;
|
}
|
var allMappingList = GetByIds(Ids);
|
if (allMappingList == null || allMappingList.Count < 1)
|
{
|
return default;
|
}
|
var allDiagramIds = allMappingList.Select(x => x.DiagramID).Distinct().ToList();
|
var allDiagramList = new HStation.Service.XhsPhartDiagram().GetByIds(allDiagramIds);
|
if (DiagramType.HasValue)
|
{
|
allDiagramList = allDiagramList?.Where(x => x.DiagramType == (int)DiagramType.Value).ToList();
|
}
|
if (allDiagramList == null || allDiagramList.Count < 1)
|
{
|
return default;
|
}
|
allDiagramIds = allDiagramList.Select(x => x.ID).ToList();
|
var allGraphList = new HStation.Service.XhsPhartGraph().GetByDiagramIds(allDiagramIds);
|
if (GraphTypeList != null && GraphTypeList.Count > 0)
|
{
|
allGraphList = allGraphList?.Where(x => GraphTypeList.Contains((eGraphType)x.GraphType)).ToList();
|
}
|
var vmList = new List<Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>>();
|
foreach (var mapping in allMappingList)
|
{
|
var diagram = allDiagramList.Find(x => x.ID == mapping.DiagramID);
|
if (diagram == null)
|
{
|
continue;
|
}
|
var graphList = allGraphList?.Where(x => x.DiagramID == mapping.DiagramID).ToList();
|
var vm = new Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>(mapping, diagram, graphList);
|
vmList.Add(vm);
|
}
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取默认Tuple
|
/// </summary>
|
public Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>> GetTupleDefaultByPumpID
|
(long PumpID, eDiagramType? DiagramType = null, List<eGraphType> GraphTypeList = null)
|
{
|
var allMappingList = GetByPumpID(PumpID);
|
if (allMappingList == null || allMappingList.Count < 1)
|
{
|
return default;
|
}
|
var allDiagramIds = allMappingList.Select(x => x.DiagramID).Distinct().ToList();
|
var allDiagramList = new HStation.Service.XhsPhartDiagram().GetByIds(allDiagramIds);
|
if (DiagramType.HasValue)
|
{
|
allDiagramList = allDiagramList?.Where(x => x.DiagramType == (int)DiagramType.Value).ToList();
|
}
|
if (allDiagramList == null || allDiagramList.Count < 1)
|
{
|
return default;
|
}
|
|
var mapping = (from x in allMappingList
|
join y in allDiagramList
|
on x.DiagramID equals y.ID
|
orderby x.Importance descending
|
select x).FirstOrDefault();
|
if (mapping == null)
|
{
|
return default;
|
}
|
var diagram = allDiagramList.Find(x => x.ID == mapping.DiagramID);
|
var graphList = new HStation.Service.XhsPhartGraph().GetByDiagramID(mapping.DiagramID);
|
if (GraphTypeList != null && GraphTypeList.Count > 0)
|
{
|
graphList = graphList?.Where(x => GraphTypeList.Contains((eGraphType)x.GraphType)).ToList();
|
}
|
var vm = new Tuple<Model.XhsPumpPhartMapping, Model.XhsPhartDiagram, List<Model.XhsPhartGraph>>(mapping, diagram, graphList);
|
return vm;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public long Insert(Model.XhsPumpPhartMapping model)
|
{
|
if (model == null)
|
{
|
return default;
|
}
|
var entity = Model2Entity(model);
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var id = dal.Insert(entity);
|
if (id > 0)
|
{
|
UpdateCacheByPumpID(model.PumpID);
|
}
|
return id;
|
}
|
|
/// <summary>
|
/// 插入拓展
|
/// </summary>
|
public long InsertEx(Model.XhsPumpPhartMapping mapping, Model.XhsPhartDiagram diagram, List<Model.XhsPhartGraph> graphList)
|
{
|
if (mapping == null)
|
{
|
return default;
|
}
|
var entityMapping = Model2Entity(mapping);
|
var entityDiagram = XhsPhartDiagram.Model2Entity(diagram);
|
var entityGraphList = XhsPhartGraph.Model2Entities(graphList);
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var id = dal.InsertEx(entityMapping, entityDiagram, entityGraphList);
|
if (id > 0)
|
{
|
UpdateCache(id);
|
mapping = GetByID(id);
|
if (diagram != null)
|
{
|
XhsPhartDiagram.UpdateCache(mapping.DiagramID);
|
}
|
if (graphList != null && graphList.Count > 0)
|
{
|
XhsPhartGraph.UpdateCacheByDiagramID(mapping.DiagramID);
|
}
|
}
|
return id;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public bool Update(Model.XhsPumpPhartMapping model)
|
{
|
if (model == null)
|
{
|
return false;
|
}
|
var entity = Model2Entity(model);
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.Update(entity);
|
if (bol)
|
{
|
UpdateCacheByPumpID(model.PumpID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新拓展
|
/// </summary>
|
public bool UpdateEx(Model.XhsPumpPhartMapping mapping, Model.XhsPhartDiagram diagram, List<Model.XhsPhartGraph> graphList)
|
{
|
if (mapping == null)
|
{
|
return default;
|
}
|
var entityMapping = Model2Entity(mapping);
|
var entityDiagram = XhsPhartDiagram.Model2Entity(diagram);
|
var entityGraphList = XhsPhartGraph.Model2Entities(graphList);
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.UpdateEx(entityMapping, entityDiagram, entityGraphList);
|
if (bol)
|
{
|
UpdateCache(mapping.ID);
|
if (diagram != null)
|
{
|
XhsPhartDiagram.UpdateCache(mapping.DiagramID);
|
}
|
if (graphList != null && graphList.Count > 0)
|
{
|
XhsPhartGraph.UpdateCacheByDiagramID(mapping.DiagramID);
|
}
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
public bool UpdateSortCode(long ID, int SortCode)
|
{
|
if (ID < 1)
|
{
|
return default;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.UpdateSortCode(ID, SortCode);
|
if (bol)
|
{
|
UpdateCache(ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
public bool UpdateSorter(List<Yw.Model.Sorter> sorters)
|
{
|
if (sorters == null || sorters.Count < 1)
|
{
|
return default;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.UpdateSorter(sorters.ToEntityList());
|
if (bol)
|
{
|
UpdateCache(sorters.Select(x => x.ID).ToList());
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 OtherName
|
/// </summary>
|
public bool UpdateOtherName(long ID, string OtherName)
|
{
|
if (ID < 1)
|
{
|
return default;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.UpdateOtherName(ID, OtherName);
|
if (bol)
|
{
|
UpdateCache(ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 Importance
|
/// </summary>
|
public bool UpdateImportance(long ID, int Importance)
|
{
|
if (ID < 1)
|
{
|
return default;
|
}
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.UpdateImportance(ID, Importance);
|
if (bol)
|
{
|
UpdateCache(ID);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
#region Exist
|
|
/// <summary>
|
/// 通过 PumpID 判断是否存在
|
/// </summary>
|
public bool IsExistByPumpID(long PumpID)
|
{
|
var all = GetAll();
|
if (all == null || all.Count < 1)
|
{
|
return false;
|
}
|
return all.Exists(x => x.PumpID == PumpID);
|
}
|
|
/// <summary>
|
/// 通过 DiagramID 判断是否存在
|
/// </summary>
|
public bool IsExistByDiagramID(long DiagramID)
|
{
|
var all = GetAll();
|
if (all == null || all.Count < 1)
|
{
|
return false;
|
}
|
return all.Exists(x => x.DiagramID == DiagramID);
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
public bool DeleteByID(long ID, out string Msg)
|
{
|
Msg = string.Empty;
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.DeleteByID(ID);
|
if (bol)
|
{
|
RemoveCache(ID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 通过 PumpID 删除
|
/// </summary>
|
public bool DeleteByPumpID(long PumpID, out string Msg)
|
{
|
Msg = string.Empty;
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.DeleteByPumpID(PumpID);
|
if (bol)
|
{
|
RemoveCacheByPumpID(PumpID);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 通过 DiagramID 删除
|
/// </summary>
|
public bool DeleteByDiagramID(long DiagramID, out string Msg)
|
{
|
Msg = string.Empty;
|
var dal = DALCreateHelper.CreateDAL<HStation.DAL.IXhsPumpPhartMapping>();
|
var bol = dal.DeleteByDiagramID(DiagramID);
|
if (bol)
|
{
|
RemoveCacheByDiagramID(DiagramID);
|
XhsPhartDiagram.RemoveCache(DiagramID);
|
XhsPhartGraph.RemoveCacheByDiagramID(DiagramID);
|
}
|
return bol;
|
}
|
|
|
#endregion
|
|
}
|
}
|