| | |
| | | } |
| | | |
| | | /// <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) |
| | | { |
| | |
| | | return default; |
| | | } |
| | | mappingEntity.CurveID = curveId; |
| | | var mapId = db.Insertable(mappingEntity).ExecuteReturnSnowflakeId(); |
| | | if (mapId < 1) |
| | | 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 mapId; |
| | | return mappingEntity.ID; |
| | | } |
| | | catch |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 批量插入 |
| | | /// 更新一条 |
| | | /// </summary> |
| | | public bool InsertsEx(Dictionary<Entity.PumpCurve, Entity.PumpCurveMapping> dict) |
| | | public override bool Update(Entity.PumpCurveMapping entity) |
| | | { |
| | | if (dict == null || dict.Count < 1) |
| | | { |
| | | return default; |
| | | } |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | foreach (var item in dict) |
| | | var bol = db.Updateable(entity).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | 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.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; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 批量插入 |
| | | /// 更新拓展 |
| | | /// </summary> |
| | | public List<long> InsertsREx(Dictionary<Entity.PumpCurve, Entity.PumpCurveMapping> dict) |
| | | public bool UpdateEx(Entity.PumpCurve curveEntity, Entity.PumpCurveMapping mappingEntity) |
| | | { |
| | | 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 bol = db.Updateable(curveEntity).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | 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.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 list; |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <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) |