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 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;
|
var mapId = db.Insertable(mappingEntity).ExecuteReturnSnowflakeId();
|
if (mapId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
db.CommitTran();
|
return mapId;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 批量插入
|
/// </summary>
|
public bool InsertsEx(Dictionary<Entity.PumpCurve, Entity.PumpCurveMapping> dict)
|
{
|
if (dict == null || dict.Count < 1)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
foreach (var item in dict)
|
{
|
var curveId = db.Insertable(item.Key).ExecuteReturnSnowflakeId();
|
if (curveId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
item.Value.CurveID = curveId;
|
var mapId = db.Insertable(item.Value).ExecuteReturnSnowflakeId();
|
if (mapId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 批量插入
|
/// </summary>
|
public List<long> InsertsREx(Dictionary<Entity.PumpCurve, Entity.PumpCurveMapping> dict)
|
{
|
if (dict == null || dict.Count < 1)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var list = new List<long>();
|
foreach (var item in dict)
|
{
|
var curveId = db.Insertable(item.Key).ExecuteReturnSnowflakeId();
|
if (curveId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
item.Value.CurveID = curveId;
|
var mapId = db.Insertable(item.Value).ExecuteReturnSnowflakeId();
|
if (mapId < 1)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
list.Add(mapId);
|
}
|
db.CommitTran();
|
return list;
|
}
|
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>
|
/// 通过 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();
|
}
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|