From a60f3ee45a6b86de936d19a122acdfb30570a867 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 17 七月 2024 12:30:49 +0800
Subject: [PATCH] bug修复,优化

---
 Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs |  101 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 95 insertions(+), 6 deletions(-)

diff --git a/Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs b/Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs
index 34a61a1..45f1657 100644
--- a/Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs
+++ b/Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs
@@ -14,20 +14,98 @@
         }
 
         /// <summary>
+        /// 
+        /// </summary>
+        public Entity.RunAnalyConfigure GetByObjectTypeAndObjectID(string ObjectType, long ObjectID)
+        {
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                return db.Queryable<Entity.RunAnalyConfigure>()
+                        .Where(x => x.ObjectType == ObjectType && x.ObjectID == ObjectID)
+                        .First();
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public long InsertOrUpdate(Entity.RunAnalyConfigurePure pure)
+        {
+            if (pure == null)
+            {
+                return default;
+            }
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                try
+                {
+                    db.BeginTran();
+                    var entity = db.Queryable<Entity.RunAnalyConfigure>()
+                        .Where(x => x.ObjectType == pure.ObjectType && x.ObjectID == pure.ObjectID)
+                        .First();
+                    if (entity == null)
+                    {
+                        entity = new Entity.RunAnalyConfigure(pure);
+                    }
+                    else
+                    {
+                        entity.Reset(pure);
+                    }
+
+                    if (entity.ID < 1)
+                    {
+                        entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
+                        if (entity.ID < 1)
+                        {
+                            db.RollbackTran();
+                            return default;
+                        }
+                    }
+                    else
+                    {
+                        var bol = db.Updateable(entity).ExecuteCommandHasChange();
+                        if (!bol)
+                        {
+                            db.RollbackTran();
+                            return default;
+                        }
+                    }
+                    return entity.ID;
+                }
+                catch
+                {
+                    db.RollbackTran();
+                    throw;
+                }
+            }
+        }
+
+        /// <summary>
         /// 璁剧疆
         /// </summary>
-        public bool Set(List<Entity.RunAnalyConfigure> entityList)
+        public bool Set(List<Entity.RunAnalyConfigurePure> pureList)
         {
             using (var db = new SqlSugarClient(ConnectionConfig))
             {
                 try
                 {
                     db.BeginTran();
-                    var ids = new List<long>();
-                    if (entityList != null && entityList.Count > 0)
+                    if (pureList != null && pureList.Count > 0)
                     {
-                        foreach (var entity in entityList)
+                        foreach (var pure in pureList)
                         {
+                            var entity = db.Queryable<Entity.RunAnalyConfigure>()
+                                .Where(x => x.ObjectType == pure.ObjectType && x.ObjectID == pure.ObjectID)
+                                .First();
+                            if (entity == null)
+                            {
+                                entity = new Entity.RunAnalyConfigure(pure);
+                            }
+                            else
+                            {
+                                entity.Reset(pure);
+                            }
+
                             if (entity.ID < 1)
                             {
                                 entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
@@ -46,11 +124,9 @@
                                     return false;
                                 }
                             }
-                            ids.Add(entity.ID);
                         }
                     }
 
-                    db.Deleteable<Entity.RunAnalyConfigure>().Where(x => !ids.Contains(x.ID)).ExecuteCommandHasChange();
                     db.CommitTran();
                     return true;
                 }
@@ -62,5 +138,18 @@
             }
         }
 
+        /// <summary>
+        /// 閫氳繃 ObjectType 鍜� ObjectID 鍒犻櫎
+        /// </summary>
+        public bool DeleteByObjectTypeAndObjectID(string ObjectType, long ObjectID)
+        {
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                return db.Deleteable<Entity.RunAnalyConfigure>()
+                    .Where(x => x.ObjectType == ObjectType && x.ObjectID == ObjectID)
+                    .ExecuteCommandHasChange();
+            }
+        }
+
     }
 }

--
Gitblit v1.9.3