From 41a59b8098446c595ce42d78a279123a4bfa6795 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期五, 12 八月 2022 14:38:20 +0800
Subject: [PATCH] 增加 泵曲线映射批量操作接口

---
 DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs b/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs
index 56261ac..6408ce4 100644
--- a/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs
+++ b/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs
@@ -279,6 +279,62 @@
         }
 
 
+        /// <summary>
+        /// 閫氳繃  CurveID 璁剧疆
+        /// </summary>
+        public bool SetOfObject(long CorpID,  long CurveID,  List<Entity.PumpCurveMapping> list)
+        {
+            if (list == null || list.Count() < 1)
+            {
+                using (var db = new SqlSugarClient(ConnectionConfig))
+                {
+                    return db.Deleteable<Entity.PumpCurveMapping>()
+                        .Where(x => x.CorpID == CorpID && x.CurveID == CurveID)
+                        .ExecuteCommand() > 0;
+                }
+            }
+
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                try
+                {
+                    db.BeginTran();
+                    var add_list = list.Where(x => x.ID < 1).ToList();
+                    var update_list = list.Where(x => x.ID > 0).ToList();
+                    var ids_exist = update_list.Select(x => x.ID).Distinct().ToList();
+                    db.Deleteable<Entity.PumpCurveMapping>().Where(x => x.CorpID == CorpID && x.CurveID == CurveID && !ids_exist.Contains(x.ID)).ExecuteCommand(); 
+                    if (add_list.Count > 0)
+                    {
+                        var result = db.Insertable(add_list).ExecuteReturnSnowflakeIdList().Count > 0;
+                        if (!result)
+                        {
+                            db.RollbackTran();
+                            return default;
+                        }
+                    }
+                    if (update_list.Count > 0)
+                    {
+                        var result = db.Updateable(update_list).ExecuteCommand() > 0;
+                        if (!result)
+                        {
+                            db.RollbackTran();
+                            return default;
+                        }
+                    } 
+
+                    db.CommitTran();
+                    return true;
+                }
+                catch
+                {
+                    db.RollbackTran();
+                    throw;
+                }
+
+            }
+        }
+
+
 
 
 

--
Gitblit v1.9.3