namespace Yw.Service
{
///
///
///
public class PumpCurveExMapping
{
///
/// 通过 PumpID 获取
///
public List> 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(x, y)).ToList();
}
///
/// 通过 ID 获取
///
public Tuple 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(mapping, curve);
}
///
/// 通过 Ids 获取
///
public List> GetByIds(List 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(x, y)).ToList();
}
///
/// 通过 PumpID 获取工作曲线
///
public Tuple 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(mapping, curve);
}
///
/// 通过 PumpID 获取默认曲线
///
public Tuple 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(mapping, curve);
}
#region Insert
///
/// 插入一条
///
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
///
/// 更新一条
///
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
}
}