From 8d771316d68f1523bcdf30c97d3a55107cb5ae56 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期四, 04 九月 2025 10:53:31 +0800 Subject: [PATCH] 111 --- MES.Service/service/BasicData/MesSupplierManager.cs | 59 ++++++++++++++++++++++------------------------------------- 1 files changed, 22 insertions(+), 37 deletions(-) diff --git a/MES.Service/service/BasicData/MesSupplierManager.cs b/MES.Service/service/BasicData/MesSupplierManager.cs index 022fb52..6a1aa6a 100644 --- a/MES.Service/service/BasicData/MesSupplierManager.cs +++ b/MES.Service/service/BasicData/MesSupplierManager.cs @@ -43,41 +43,15 @@ 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 => + if (suppliers == null || !suppliers.Any()) { - 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}杩欎釜绫诲瀷鐨勫弬鏁�"); - } + Console.WriteLine("璀﹀憡: 浼犲叆鐨勫垪琛ㄤ负绌�"); + return false; + } - return 1; - }) > 0; + // 閫愭潯澶勭悊锛屽叏閮ㄦ垚鍔熸墠杩斿洖true锛堜簨鍔″唴鎵归噺澶勭悊鏇翠紭锛屾澶勪繚鎸佸師鏈夐�昏緫锛� + var result = suppliers.Select(Save).ToList(); + return result.All(b => b); } private bool UpdateSupplierStatus(SqlSugarScope db, decimal supplierId, @@ -114,11 +88,11 @@ private MesSupplier GetMesSupplier(ErpSupplier supplier) { - return new MesSupplier + var entity = new MesSupplier { - Id = string.IsNullOrEmpty(supplier.Id) - ? DateTimeOffset.UtcNow.ToUnixTimeSeconds() - : Convert.ToDecimal(supplier.Id), + // Id = string.IsNullOrEmpty(supplier.Id) + // ? DateTimeOffset.UtcNow.ToUnixTimeSeconds() + // : Convert.ToDecimal(supplier.Id), Type = supplier.Type, SuppNo = supplier.FNumber, SuppSname = supplier.FShortName, @@ -139,6 +113,17 @@ Company = "1000", Factory = "1000", }; + + var mesSupplier = Db.Queryable<MesSupplier>() + .Where(s => s.SuppNo == entity.SuppNo) + .First(); + + if (mesSupplier != null) + { + entity.Id = mesSupplier.Id; + } + + return entity; } private bool UpdateSupplierStatusBatch(SqlSugarScope db, -- Gitblit v1.9.3