From b826e3716742abba49ab2a851b943ea8328db66e Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 24 十二月 2024 11:19:45 +0800
Subject: [PATCH] 水池匹配修改

---
 BLL/HStation.BLL.Assets.Core/03-localclient/06-Elbow/AssetsElbowSeries.cs |  154 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 123 insertions(+), 31 deletions(-)

diff --git a/BLL/HStation.BLL.Assets.Core/03-localclient/06-Elbow/AssetsElbowSeries.cs b/BLL/HStation.BLL.Assets.Core/03-localclient/06-Elbow/AssetsElbowSeries.cs
index dca9ee7..5142b5c 100644
--- a/BLL/HStation.BLL.Assets.Core/03-localclient/06-Elbow/AssetsElbowSeries.cs
+++ b/BLL/HStation.BLL.Assets.Core/03-localclient/06-Elbow/AssetsElbowSeries.cs
@@ -1,9 +1,7 @@
-锘縰sing Yw.Dto;
-
-namespace HStation.CAL.LocalClient
+锘縩amespace HStation.CAL.LocalClient
 {
     /// <summary>
-    /// 鎶ヨ绛夌骇
+    /// 鎹㈢儹鍣ㄧ郴鍒�
     /// </summary>
     public class AssetsElbowSeries : IAssetsElbowSeries
     {
@@ -51,6 +49,8 @@
 
         #endregion Query
 
+
+
         #region Insert
 
         /// <summary>
@@ -60,8 +60,26 @@
         {
             return await Task.Factory.StartNew(() =>
             {
+                var parentIds = new List<long>();
+                if (input.ParentID > 0)
+                {
+                    var parent = _service.GetByID(input.ParentID);
+                    if (parent == null)
+                    {
+                        throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ParentID:{input.ParentID} 鏁版嵁涓嶅瓨鍦�");
+                    }
+                    parentIds = TreeParentIdsHelper.GetChildParentIds(parent.ID, parent.ParentIds);
+                }
+                if (!string.IsNullOrEmpty(input.TagName))
+                {
+                    if (_service.IsExistTagName(input.TagName))
+                    {
+                        throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"TagName:{input.TagName} 鏍囪宸插瓨鍦�");
+                    }
+                }
                 var model = input.Adapt<AddAssetsElbowSeriesInput, Model.AssetsElbowSeries>();
-                model.SortCode = _service.GetMaxSortCode() + 1;
+                model.ParentIds = parentIds;
+                model.SortCode = _service.GetMaxSortCode(input.ParentID) + 1;
                 var id = _service.Insert(model);
                 return id;
             });
@@ -74,13 +92,7 @@
         {
             return await Task.Factory.StartNew(() =>
             {
-                var list = inputList.Select(x => x.Adapt<AddAssetsElbowSeriesInput, Model.AssetsElbowSeries>()).ToList();
-                list.ForEach(x =>
-                {
-                    x.SortCode = _service.GetMaxSortCode() + 1 + list.IndexOf(x);
-                });
-                var bol = _service.Inserts(list);
-                return bol;
+                return false;
             });
         }
 
@@ -111,7 +123,13 @@
                 {
                     throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 鏁版嵁涓嶅瓨鍦�");
                 }
-
+                if (!string.IsNullOrEmpty(input.TagName))
+                {
+                    if (_service.IsExistTagNameExceptID(input.TagName, input.ID))
+                    {
+                        throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"TagName:{input.TagName} 鏍囪宸插瓨鍦�");
+                    }
+                }
                 var rhs = new Model.AssetsElbowSeries(model);
                 input.Adapt(rhs);
                 var bol = _service.Update(rhs);
@@ -126,13 +144,7 @@
         {
             return await Task.Factory.StartNew(() =>
             {
-                if (inputList == null || inputList.Count < 1)
-                {
-                    return false;
-                }
-                var list = inputList.Select(x => x.Adapt<UpdateAssetsElbowSeriesInput, Model.AssetsElbowSeries>()).ToList();
-                var bol = _service.Updates(list);
-                return bol;
+                return false;
             });
         }
 
@@ -140,17 +152,6 @@
         /// 澶ф壒閲忔洿鏂�
         /// </summary>
         public async Task<bool> BulkUpdates(List<UpdateAssetsElbowSeriesInput> list)
-        {
-            return await Task.Factory.StartNew(() =>
-            {
-                return false;
-            });
-        }
-
-        /// <summary>
-        /// 鏇存柊缂栫爜
-        /// </summary>
-        public async Task<bool> UpdateCode(long ID, string Code)
         {
             return await Task.Factory.StartNew(() =>
             {
@@ -179,6 +180,61 @@
             {
                 var list = inputList.Select(x => x.Adapt<Yw.Model.Sorter>()).ToList();
                 var bol = _service.UpdateSorter(list);
+                return bol;
+            });
+        }
+
+        /// <summary>
+        /// 鏇存柊鏍戞帓搴忕爜
+        /// </summary>
+        public async Task<bool> UpdateTreeSortCode(long ID, long ParentID, int SortCode)
+        {
+            return await Task.Factory.StartNew(() =>
+            {
+                var model = _service.GetByID(ID);
+                if (model == null)
+                {
+                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{ID} 鏁版嵁涓嶅瓨鍦�");
+                }
+                var parentIds = new List<long>();
+                if (ParentID > 0)
+                {
+                    var parent = _service.GetByID(ParentID);
+                    if (parent == null)
+                    {
+                        throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ParentID:{ParentID} 鏁版嵁涓嶅瓨鍦�");
+                    }
+                    parentIds = TreeParentIdsHelper.GetChildParentIds(parent.ID, parent.ParentIds);
+                }
+                var sorterList = new List<Yw.Model.TreeSorter>()
+                {
+                    new Yw.Model.TreeSorter()
+                    {
+                        ID=ID,
+                        ParentIds=parentIds,
+                        SortCode=SortCode
+                    }
+                };
+                if (TreeParentIdsHelper.ToString(parentIds) != TreeParentIdsHelper.ToString(model.ParentIds))
+                {
+                    var children = _service.GetChildrenByID(ID);
+                    if (children != null && children.Count > 0)
+                    {
+                        foreach (var item in children)
+                        {
+                            var itemParent = sorterList.Find(x => x.ID == item.ParentIds.Last());
+                            var itemParentIds = TreeParentIdsHelper.GetChildParentIds(itemParent.ID, itemParent.ParentIds);
+                            var sorter = new Yw.Model.TreeSorter()
+                            {
+                                ID = item.ID,
+                                ParentIds = itemParentIds,
+                                SortCode = item.SortCode
+                            };
+                            sorterList.Add(sorter);
+                        }
+                    }
+                }
+                var bol = _service.UpdateTreeSorter(sorterList);
                 return bol;
             });
         }
@@ -214,12 +270,47 @@
         {
             return await Task.Factory.StartNew(() =>
             {
+                if (!string.IsNullOrEmpty(TagName))
+                {
+                    if (_service.IsExistTagNameExceptID(TagName, ID))
+                    {
+                        throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"TagName:{TagName}", "鏍囪鍚嶇О宸插瓨鍦�");
+                    }
+                }
                 var bol = _service.UpdateTagName(ID, TagName);
                 return bol;
             });
         }
 
         #endregion Update
+
+        #region Exist
+
+        /// <summary>
+        ///
+        /// </summary>
+        public async Task<bool> IsExistTagName(string TagName)
+        {
+            return await Task.Factory.StartNew(() =>
+            {
+                var bol = _service.IsExistTagName(TagName);
+                return bol;
+            });
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        public async Task<bool> IsExistTagNameExceptID(string TagName, long ExceptID)
+        {
+            return await Task.Factory.StartNew(() =>
+            {
+                var bol = _service.IsExistTagNameExceptID(TagName, ExceptID);
+                return bol;
+            });
+        }
+
+        #endregion Exist
 
         #region Delete
 
@@ -263,5 +354,6 @@
         }
 
         #endregion Delete
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3