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