namespace Yw.Service
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class PumpCurveExMapping
|
{
|
/// <summary>
|
/// 通过 PumpID 获取
|
/// </summary>
|
public List<Tuple<Model.PumpCurveMapping, Model.PumpCurve>> GetByPumpID(long PumpID)
|
{
|
var mappingList = new Service.PumpCurveMapping().GetByPumpID(PumpID);
|
if (mappingList == null || mappingList.Count < 1)
|
{
|
return default;
|
}
|
var curveIds = mappingList.Select(x => x.CurveID).Distinct().ToList();
|
var curveList = new Service.PumpCurve().GetByIds(curveIds);
|
return (from x in mappingList
|
join y in curveList
|
on x.CurveID equals y.ID
|
select new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(x, y)).ToList();
|
}
|
|
/// <summary>
|
/// 通过 PumpIds 获取
|
/// </summary>
|
public List<Tuple<Model.PumpCurveMapping, Model.PumpCurve>> GetByPumpIds(List<long> PumpIds)
|
{
|
if (PumpIds == null || PumpIds.Count < 1)
|
{
|
return default;
|
}
|
var mappingList = new Service.PumpCurveMapping().GetByPumpIds(PumpIds);
|
if (mappingList == null || mappingList.Count < 1)
|
{
|
return default;
|
}
|
var curveIds = mappingList.Select(x => x.CurveID).Distinct().ToList();
|
var curveList = new Service.PumpCurve().GetByIds(curveIds);
|
return (from x in mappingList
|
join y in curveList
|
on x.CurveID equals y.ID
|
select new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(x, y)).ToList();
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public Tuple<Model.PumpCurveMapping, Model.PumpCurve> GetByID(long ID)
|
{
|
var mapping = new Service.PumpCurveMapping().GetByID(ID);
|
if (mapping == null)
|
{
|
return default;
|
}
|
var curve = new Service.PumpCurve().GetByID(mapping.CurveID);
|
if (curve == null)
|
{
|
return default;
|
}
|
return new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(mapping, curve);
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public List<Tuple<Model.PumpCurveMapping, Model.PumpCurve>> GetByIds(List<long> Ids)
|
{
|
var mappingList = new Service.PumpCurveMapping().GetByIds(Ids);
|
if (mappingList == null || mappingList.Count < 1)
|
{
|
return default;
|
}
|
var curveIds = mappingList.Select(x => x.CurveID).Distinct().ToList();
|
var curveList = new Service.PumpCurve().GetByIds(curveIds);
|
return (from x in mappingList
|
join y in curveList
|
on x.CurveID equals y.ID
|
select new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(x, y)).ToList();
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取工作曲线
|
/// </summary>
|
public Tuple<Model.PumpCurveMapping, Model.PumpCurve> GetWorkingByPumpID(long PumpID)
|
{
|
var mapping = new Service.PumpCurveMapping().GetWorkingByPumpID(PumpID);
|
if (mapping == null)
|
{
|
return default;
|
}
|
var curve = new Service.PumpCurve().GetByID(mapping.CurveID);
|
if (curve == null)
|
{
|
return default;
|
}
|
return new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(mapping, curve);
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取默认曲线
|
/// </summary>
|
public Tuple<Model.PumpCurveMapping, Model.PumpCurve> GetDefaultByPumpID(long PumpID)
|
{
|
var mapping = new Service.PumpCurveMapping().GetDefaultByPumpID(PumpID);
|
if (mapping == null)
|
{
|
return default;
|
}
|
var curve = new Service.PumpCurve().GetByID(mapping.CurveID);
|
if (curve == null)
|
{
|
return default;
|
}
|
return new Tuple<Model.PumpCurveMapping, Model.PumpCurve>(mapping, curve);
|
}
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public long Insert(Model.PumpCurve curve, Model.PumpCurveMapping mapping)
|
{
|
if (curve == null || mapping == null)
|
{
|
return default;
|
}
|
var curveEntity = PumpCurve.Model2Entity(curve);
|
var mappingEntity = PumpCurveMapping.Model2Entity(mapping);
|
var dal = new DAL.PumpCurveMapping();
|
var id = dal.InsertEx(curveEntity, mappingEntity);
|
if (id > 0)
|
{
|
var rhs = PumpCurveMapping.UpdateCache(id);
|
PumpCurve.UpdateCache(rhs.CurveID);
|
}
|
return id;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public bool Update(Model.PumpCurve curve, Model.PumpCurveMapping mapping)
|
{
|
if (curve == null || mapping == null)
|
{
|
return default;
|
}
|
var curveEntity = PumpCurve.Model2Entity(curve);
|
var mappingEntity = PumpCurveMapping.Model2Entity(mapping);
|
var dal = new DAL.PumpCurveMapping();
|
var bol = dal.UpdateEx(curveEntity, mappingEntity);
|
if (bol)
|
{
|
PumpCurveMapping.UpdateCacheByPumpID(mapping.PumpID);
|
PumpCurve.UpdateCache(curve.ID);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
|
|
}
|
}
|