From bdbfc1045c94e23c74cf9c6f98b0b4f9b0ca0d00 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期五, 24 一月 2025 08:27:00 +0800
Subject: [PATCH] 删除多余的文件

---
 StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs |  241 +++++++++++++++++++++--------------------------
 1 files changed, 108 insertions(+), 133 deletions(-)

diff --git a/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs b/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs
index 8ccf411..95503d6 100644
--- a/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs
+++ b/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs
@@ -1,6 +1,7 @@
 锘縰sing MES.Service.DB;
 using MES.Service.Dto.webApi;
 using MES.Service.Modes;
+using MES.Service.util;
 using SqlSugar;
 
 namespace MES.Service.service.BasicData;
@@ -16,15 +17,15 @@
             switch (unit.Type)
             {
                 case "0":
-                    if (UpdateSupplierStatus(db, entity.Id, "A"))
+                    if (UpdateSupplierStatus(db, entity, "A"))
                         return 1;
                     break;
                 case "1":
-                    if (UpdateSupplierStatus(db, entity.Id, "B"))
+                    if (UpdateSupplierStatus(db, entity, "B"))
                         return 1;
                     break;
                 case "3":
-                    if (DeleteSupplier(entity.Id))
+                    if (DeleteSupplier(entity))
                         return 1;
                     break;
                 case "2":
@@ -43,111 +44,16 @@
 
     public bool SaveList(List<ErpSupplier> suppliers)
     {
-        var list = suppliers.Select(GetMesSupplier).ToList();
-        var groupBy = list.GroupBy(s => s.Type)
-            .ToDictionary(g => g.Key, g => g.ToList());
-
-        return UseTransaction(db =>
-        {
-            foreach (var supplierGroup in groupBy)
-                switch (supplierGroup.Key)
-                {
-                    case "0":
-                        if (!UpdateSupplierStatusBatch(db, supplierGroup.Value,
-                                "A"))
-                            throw new NotImplementedException("鍚敤澶辫触");
-                        break;
-                    case "1":
-                        if (!UpdateSupplierStatusBatch(db, supplierGroup.Value,
-                                "B"))
-                            throw new NotImplementedException("绂佺敤澶辫触");
-                        break;
-                    
-                    case "3":
-                        if (!DeleteSupplierBatch(db, supplierGroup.Value))
-                            throw new NotImplementedException("鍒犻櫎澶辫触");
-                        break;
-                    case "2":
-                    case "4":
-                        if (!InsertOrUpdateBatch(db, supplierGroup.Value))
-                            throw new NotImplementedException("鍚屾澶辫触");
-                        break;
-                    default:
-                        throw new ArgumentNullException(
-                            $"type娌℃湁{supplierGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�");
-                }
-
-            return 1;
-        }) > 0;
+        var result = suppliers.Select(Save).ToList();
+        return result.All(b => b);
     }
 
-    private bool UpdateSupplierStatus(SqlSugarScope db, decimal supplierId,
+    private bool UpdateSupplierStatus(SqlSugarScope db,
+        List<MesSupplier> supplierId,
         string status)
     {
-        var result = db.Updateable<MesSupplier>()
-            .SetColumns(s => s.Fforbidstatus == status)
-            .Where(s => s.Id == supplierId).ExecuteCommand();
+        var ids = supplierId.Select(it => it.Id).ToArray();
 
-        if (result > 0)
-            return true;
-
-        throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
-    }
-
-    private bool InsertSupplier(SqlSugarScope db, MesSupplier entity)
-    {
-        var insert = db.Insertable(entity).ExecuteCommand();
-        if (insert > 0)
-            return true;
-
-        throw new NotImplementedException("鎻掑叆澶辫触");
-    }
-
-    private bool DeleteSupplier(decimal supplierId)
-    {
-        if (base.DeleteById(supplierId)) return true;
-
-        throw new NotImplementedException("鍒犻櫎澶辫触");
-    }
-
-    private MesSupplier GetMesSupplier(ErpSupplier supplier)
-    {
-        return new MesSupplier
-        {
-            Id = Convert.ToDecimal(supplier.Id),
-            SuppNo = supplier.FNumber,
-            SuppSname = supplier.FShortName,
-            SuppName = supplier.FName,
-            Lxr = supplier.FContact,
-            Telf1 = supplier.FTel,
-            Fstaffid = supplier.FStaffId,
-            /// <summary>
-            /// 鎺ュ彛瀛楁璋冩暣锛氭爣鍑嗙増鎺ュ彛鏂板 ERP鍗曟嵁鐘舵�� 瀛楁銆�
-            /// </summary>
-            /// <remarks>
-            /// 淇敼浜猴細<姹犲崡楠�>
-            /// 淇敼鏃ユ湡锛�<2024-12-28>
-            /// 淇敼璇存槑锛�
-            /// - 鍘熶唬鐮侊細绌�
-            /// - 淇敼鍚庯細    
-            ///FDOCUMENTSTATUS = supplier.FDocumentStatus,
-            /// </remarks>
-            FDOCUMENTSTATUS = supplier.FDocumentStatus,
-
-            Fforbidstatus = supplier.FForbidStatus,
-            CreateDate = DateTime.Now,
-            CreateOrg= Convert.ToDecimal(supplier.FCreateOrgId),
-            UseOrg= Convert.ToDecimal(supplier.FUseOrgId),
-            Remark=supplier.fremarks,
-            Company = "1000",
-            Factory = "1000"
-        };
-    }
-
-    private bool UpdateSupplierStatusBatch(SqlSugarScope db,
-        List<MesSupplier> supplierList, string status)
-    {
-        var ids = supplierList.Select(it => it.Id).ToArray();
         var result = db.Updateable<MesSupplier>()
             .SetColumns(s => s.Fforbidstatus == status)
             .Where(s => ids.Contains(s.Id)).ExecuteCommand();
@@ -158,25 +64,108 @@
         throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
     }
 
-    private bool InsertSupplierBatch(SqlSugarScope db,
-        List<MesSupplier> supplierList)
+    private bool DeleteSupplier(List<MesSupplier> supplierId)
     {
-        var insertRange = db.Insertable(supplierList).ExecuteCommand();
-        if (insertRange > 0)
-            return true;
+        // 鎻愬彇鎵�鏈夐渶瑕佺殑 MesId 缁勫悎 
+        var ids = supplierId.Select(customer => customer.Id.ToString())
+            .ToList();
+        
+        // 浣跨敤杩欎簺 MesId 鍘绘煡璇� MesLinkU9 琛紝鎵惧埌瀵瑰簲鐨� U9Id
+        var u9Ids = Db.Queryable<MesLinkU9>()
+            .Where(u =>
+                ids.Contains(u.MesId) && u.TableType == "MES_SUPPLIER")
+            .Select(u => u.U9Id)
+            .Distinct() // 搴旂敤 Distinct 鍘婚噸
+            .ToList();
 
-        throw new NotImplementedException("鎻掑叆澶辫触");
+        // 鏍规嵁 U9Id 鎵惧埌鎵�鏈夊搴旂殑 MesId锛岃繘琛屽垹闄�
+        // 娉ㄦ剰锛氳繖閲屽亣璁炬偍纭疄鎯宠鍒犻櫎杩欎簺璁板綍銆傚鏋滀笉纭畾锛岃鍏堟煡璇互楠岃瘉缁撴灉銆�
+        var idsToDelete = Db.Queryable<MesLinkU9>()
+            .Where(u => u9Ids.Contains(u.U9Id) && u.TableType == "MES_SUPPLIER")
+            .Select(u => u.MesId)
+            .Distinct() // 搴旂敤 Distinct 鍘婚噸
+            .ToList();
+
+
+        //浠ヤ笂鏂规硶鍙互鑰冭檻浼樺寲锛屽皢U9id鎵句釜鏂板缓瀛楁瀛樺湪MES_CUSTOMER涓紝灏卞彲浠ュ皯涓�姝ユ煡璇簡銆�
+
+        var deleteByIds = Db.Deleteable<MesSupplier>().In(idsToDelete)
+            .ExecuteCommand();
+        // if (deleteByIds > 0)
+        //     return true;
+        return true;
+        //throw new NotImplementedException("鍒犻櫎澶辫触");
     }
 
-    private bool DeleteSupplierBatch(SqlSugarScope db,
-        List<MesSupplier> supplierList)
+    private List<MesSupplier> GetMesSupplier(ErpSupplier supplier)
     {
-        var ids = supplierList.Select(it => it.Id).ToArray();
-        var deleteByIds = db.Deleteable<MesSupplier>().In(ids).ExecuteCommand();
-        if (deleteByIds > 0)
-            return true;
+        List<MesSupplier> list = new();
+        foreach (var se in supplier.FUseOrgId)
+        {
+            var exists = Db.Queryable<MesLinkU9>().Any(u =>
+                u.U9Id == supplier.Id && u.OrgId == se.FUseOrgId &&
+                u.TableType == "MES_SUPPLIER");
 
-        throw new NotImplementedException("鍒犻櫎澶辫触");
+            decimal mesId = 0;
+            if (exists)
+            {
+                //鑾峰彇mesid
+                mesId = Convert.ToDecimal(Db.Queryable<MesLinkU9>()
+                    .Where(u =>
+                        u.U9Id == supplier.Id && u.OrgId == se.FUseOrgId &&
+                        u.TableType == "MES_SUPPLIER")
+                    .Select(u => u.MesId) // 閫夋嫨 MesId 瀛楁
+                    .First());
+            }
+            else
+            {
+                mesId = GetSeqUtil.GetSeq("SEQ_BASEINFO_ID");
+                var entity = new MesLinkU9
+                {
+                    CreateDate = DateTime.Now,
+                    MesId = mesId.ToString(),
+                    U9Id = supplier.Id,
+                    OrgId = se.FUseOrgId,
+                    TableType = "MES_SUPPLIER"
+                };
+                Db.Insertable(entity).ExecuteCommand();
+            }
+
+            var mesSupplier = new MesSupplier
+            {
+                Id = mesId,
+                SuppNo = supplier.FNumber,
+                SuppSname = supplier.FShortName,
+                SuppName = supplier.FName,
+                Lxr = supplier.FContact,
+                Telf1 = supplier.FTel,
+                Fstaffid = supplier.FStaffId,
+                /// <summary>
+                /// 鎺ュ彛瀛楁璋冩暣锛氭爣鍑嗙増鎺ュ彛鏂板 ERP鍗曟嵁鐘舵�� 瀛楁銆�
+                /// </summary>
+                /// <remarks>
+                /// 淇敼浜猴細<姹犲崡楠�>
+                /// 淇敼鏃ユ湡锛�<2024-12-28>
+                /// 淇敼璇存槑锛�
+                /// - 鍘熶唬鐮侊細绌�
+                /// - 淇敼鍚庯細    
+                ///FDOCUMENTSTATUS = supplier.FDocumentStatus,
+                /// </remarks>
+                DocumentStatus = supplier.FDocumentStatus,
+                Fforbidstatus = supplier.FForbidStatus,
+                CreateDate = DateTime.Now,
+                //CreateOrg= Convert.ToDecimal(supplier.FCreateOrgId),
+                UseOrg = se.FUseOrgId,
+                //Remark=supplier.fremarks,
+                PrivateDescSeg = supplier.PrivateDescSeg,
+                Company = "1000",
+                Factory = "1000"
+            };
+
+            list.Add(mesSupplier);
+        }
+
+        return list;
     }
 
     /// <summary>
@@ -208,25 +197,11 @@
     //    return false;
     //}
     ///鏂颁唬鐮�
-    private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity)
+    private bool InsertOrUpdate(SqlSugarScope db, List<MesSupplier> entity)
     {
-        db.Deleteable<MesSupplier>()
-            .Where(s => s.Id == entity.Id)
-            .ExecuteCommand();
-
+        DeleteSupplier(entity);
+         
         var insert = db.Insertable(entity).ExecuteCommand();
         return insert > 0;
-    }
-
-
-
-    private bool InsertOrUpdateBatch(SqlSugarScope db,
-        List<MesSupplier> supplierList)
-    {
-        foreach (var entity in supplierList)
-            if (!InsertOrUpdate(db, entity))
-                return false;
-
-        return true;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3