From 62a273ee755729c9f5aec825fc6adb1076f21ec7 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期二, 07 十一月 2023 11:06:24 +0800
Subject: [PATCH] 初版

---
 Yw.Service.Curve.Core/4-dal/1-pump/PumpCurveMapping.cs |  140 ++++++++++++++++++++++++++++++----------------
 1 files changed, 92 insertions(+), 48 deletions(-)

diff --git a/Yw.Service.Curve.Core/4-dal/1-pump/PumpCurveMapping.cs b/Yw.Service.Curve.Core/4-dal/1-pump/PumpCurveMapping.cs
index 4cac4e9..11cfb94 100644
--- a/Yw.Service.Curve.Core/4-dal/1-pump/PumpCurveMapping.cs
+++ b/Yw.Service.Curve.Core/4-dal/1-pump/PumpCurveMapping.cs
@@ -14,7 +14,40 @@
         }
 
         /// <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)
         {
@@ -30,14 +63,20 @@
                         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
                 {
@@ -48,34 +87,27 @@
         }
 
         /// <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;
@@ -89,39 +121,35 @@
         }
 
         /// <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
                 {
@@ -129,7 +157,6 @@
                     throw;
                 }
             }
-
         }
 
         /// <summary>
@@ -146,6 +173,23 @@
         }
 
         /// <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)

--
Gitblit v1.9.3