From eaff2518ab6159c360ec2a865b45002b26fdc4cd Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期一, 19 八月 2024 14:25:47 +0800
Subject: [PATCH] 增加资产删除方法报错提醒

---
 Service/HStation.Service.Assets.Core/04-dal/02-postgresql/PumpSeries.cs |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/Service/HStation.Service.Assets.Core/04-dal/02-postgresql/PumpSeries.cs b/Service/HStation.Service.Assets.Core/04-dal/02-postgresql/PumpSeries.cs
new file mode 100644
index 0000000..794a53a
--- /dev/null
+++ b/Service/HStation.Service.Assets.Core/04-dal/02-postgresql/PumpSeries.cs
@@ -0,0 +1,122 @@
+锘縰sing Yw.DAL.PostgreSql;
+
+namespace HStation.DAL.PostgreSql
+{
+    /// <summary>
+    ///
+    /// </summary>
+    public partial class PumpSeries : BaseDAL_Paras_Flags_TagName_Sorter_UseStatus<Entity.PumpSeries>, IPumpSeries
+    {
+        /// <summary>
+        ///
+        /// </summary>
+        public override ConnectionConfig ConnectionConfig
+        {
+            get { return Assets.ConfigHelper.PostgreSqlConnectionConfig; }
+        }
+
+        //鍒犻櫎鎷撳睍
+        public bool DeleteEx(long ID)
+        {
+            if (ID < 0)
+            {
+                return default;
+            }
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                try
+                {
+                    db.BeginTran();
+                    var project = db.Queryable<Entity.PumpSeries>().ToList().Find(x => x.ID == ID);
+                    var result = db.Deleteable(project).ExecuteCommand() > 0;
+                    if (!result)
+                    {
+                        db.RollbackTran();
+                        return default;
+                    }
+                    else
+                    {
+                        var group = db.Queryable<Entity.PumpGroup>().ToList().Find(x => x.PumpSeriesID == project.ID);
+                        if (group != null)
+                        {
+                            var groupresult = db.Deleteable(group).ExecuteCommand() > 0;
+                            if (!groupresult)
+                            {
+                                db.RollbackTran();
+                                return default;
+                            }
+                            else
+                            {
+                                var map = db.Queryable<Entity.PumpGroupAndMainMap>()
+                                .Where(x => x.PumpGroupID == group.ID)
+                                 .ToList();
+                                var listid = db.Queryable<Entity.PumpGroupAndMainMap>()
+                                .Where(x => x.PumpGroupID == group.ID)
+                                .Select(x => x.PumpMainID)
+                                .ToList();
+                                if (map.Count > 0)
+                                {
+                                    var Modelresult = db.Deleteable(map).ExecuteCommand() > 0;
+                                    if (!Modelresult)
+                                    {
+                                        db.RollbackTran();
+                                        return default;
+                                    }
+                                    else
+                                    {
+                                        var main = db.Queryable<Entity.PumpMain>().ToList();
+                                        foreach (var item in main)
+                                        {
+                                            if (item.PumpSeriesID == project.ID)
+                                            {
+                                                listid.Add(item.ID);
+                                            }
+                                        }
+                                        var mainresult = db.Deleteable<Entity.PumpMain>()
+                                        .In(x => x.ID, listid)
+                                        .ExecuteCommand() > 0;
+                                        if (!mainresult)
+                                        {
+                                            db.RollbackTran();
+                                            return default;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            var listid = new List<long>();
+                            var main = db.Queryable<Entity.PumpMain>().ToList();
+                            foreach (var item in main)
+                            {
+                                if (item.PumpSeriesID == project.ID)
+                                {
+                                    listid.Add(item.ID);
+                                }
+                            }
+                            if (listid.Count > 0)
+                            {
+                                var mainresult = db.Deleteable<Entity.PumpMain>()
+                                .In(x => x.ID, listid)
+                                .ExecuteCommand() > 0;
+                                if (!mainresult)
+                                {
+                                    db.RollbackTran();
+                                    return default;
+                                }
+                            }
+                        }
+                        db.CommitTran();
+                        return result;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    db.RollbackTran();
+                    throw;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3