namespace Yw.DAL
|
{
|
/// <summary>
|
/// 泵曲线映射
|
/// </summary>
|
public partial class PumpCurveMapping : BaseDAL_Sorter<Entity.PumpCurveMapping>
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConfigHelper.DefaultConnectionConfig; }
|
}
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public override long Insert(Entity.PumpCurveMapping entity)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
|
if (entity.ID < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
if (entity.IsWorking)
|
{
|
db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == false)
|
.Where(x => x.PumpID == entity.PumpID && x.ID != entity.ID).ExecuteCommandHasChange();
|
}
|
db.CommitTran();
|
return entity.ID;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 插入拓展
|
/// </summary>
|
public long InsertEx(Entity.PumpCurve curveEntity, Entity.PumpCurveMapping mappingEntity)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var curveId = db.Insertable(curveEntity).ExecuteReturnSnowflakeId();
|
if (curveId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
mappingEntity.CurveID = curveId;
|
mappingEntity.ID = db.Insertable(mappingEntity).ExecuteReturnSnowflakeId();
|
if (mappingEntity.ID < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
if (mappingEntity.IsWorking)
|
{
|
db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == false)
|
.Where(x => x.PumpID == mappingEntity.PumpID && x.ID != mappingEntity.ID).ExecuteCommandHasChange();
|
}
|
db.CommitTran();
|
return mappingEntity.ID;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public override bool Update(Entity.PumpCurveMapping entity)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var bol = db.Updateable(entity).ExecuteCommandHasChange();
|
if (!bol)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
|
if (entity.IsWorking)
|
{
|
db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == false)
|
.Where(x => x.PumpID == entity.PumpID && x.ID != entity.ID).ExecuteCommandHasChange();
|
}
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 更新拓展
|
/// </summary>
|
public bool UpdateEx(Entity.PumpCurve curveEntity, Entity.PumpCurveMapping mappingEntity)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var bol = db.Updateable(curveEntity).ExecuteCommandHasChange();
|
if (!bol)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
bol = db.Updateable(mappingEntity).ExecuteCommandHasChange();
|
if (!bol)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
if (mappingEntity.IsWorking)
|
{
|
db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == false)
|
.Where(x => x.PumpID == mappingEntity.PumpID && x.ID != mappingEntity.ID).ExecuteCommandHasChange();
|
}
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取
|
/// </summary>
|
public List<Entity.PumpCurveMapping> GetByPumpID(long PumpID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.PumpCurveMapping>()
|
.Where(x => x.PumpID == PumpID)
|
.OrderBy(x => x.SortCode).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 PumpIds 获取
|
/// </summary>
|
public List<Entity.PumpCurveMapping> GetByPumpIds(List<long> PumpIds)
|
{
|
if (PumpIds == null || PumpIds.Count < 1)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.PumpCurveMapping>()
|
.Where(x => PumpIds.Contains(x.PumpID))
|
.OrderBy(x => x.SortCode).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 CurveID 获取
|
/// </summary>
|
public List<Entity.PumpCurveMapping> GetByCurveID(long CurveID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.PumpCurveMapping>()
|
.Where(x => x.CurveID == CurveID)
|
.OrderBy(x => x.SortCode).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 更新 OtherName
|
/// </summary>
|
public bool UpdateOtherName(long ID, string OtherName)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.OtherName == OtherName)
|
.Where(x => x.ID == ID)
|
.ExecuteCommandHasChange();
|
}
|
}
|
|
/// <summary>
|
/// 更新 IsWorking
|
/// </summary>
|
public bool UpdateIsWorking(long ID, bool IsWorking)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == IsWorking)
|
.Where(x => x.ID == ID)
|
.ExecuteCommandHasChange();
|
}
|
}
|
|
/// <summary>
|
/// 设置工作曲线
|
/// </summary>
|
public bool SetWorkingCurve(long ID, long PumpID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var bol = db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == true)
|
.Where(x => x.ID == ID)
|
.ExecuteCommandHasChange();
|
if (!bol)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
db.Updateable<Entity.PumpCurveMapping>()
|
.SetColumns(x => x.IsWorking == false)
|
.Where(x => x.PumpID == PumpID && x.ID != ID).ExecuteCommandHasChange();
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 通过 PumpID 删除
|
/// </summary>
|
public bool DeleteByPumpID(long PumpID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.PumpCurveMapping>()
|
.Where(x => x.PumpID == PumpID)
|
.ExecuteCommandHasChange();
|
}
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|