From f476ec010c22cd4e3c6a119eea035cbf4594bfbb Mon Sep 17 00:00:00 2001 From: kyy <3283105747@qq.com> Date: 星期五, 12 九月 2025 19:32:00 +0800 Subject: [PATCH] 1\修正收料通知单 --- MES.Service/service/BasicData/MesSupplierManager.cs | 116 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 69 insertions(+), 47 deletions(-) diff --git a/MES.Service/service/BasicData/MesSupplierManager.cs b/MES.Service/service/BasicData/MesSupplierManager.cs index 57983a5..ac1cbd1 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,9 +88,8 @@ private MesSupplier GetMesSupplier(ErpSupplier supplier) { - return new MesSupplier + var entity = new MesSupplier { - Id = Convert.ToDecimal(supplier.Id), Type = supplier.Type, SuppNo = supplier.FNumber, SuppSname = supplier.FShortName, @@ -124,17 +97,37 @@ Lxr = supplier.FTContact, Telf1 = supplier.Fmobilephone, Fstaffid = supplier.FStaffId, - FDocumentStatus = supplier.FDocumentStatus, Fforbidstatus = supplier.FForbidStatus, - FSubsidiary = supplier.FUseOrgId, - Fumbrella = supplier.FCreateOrgId, + FSubsidiary = string.IsNullOrEmpty(supplier.FUseOrgId) + ? "1" + : supplier.FUseOrgId, + Fumbrella = string.IsNullOrEmpty(supplier.FCreateOrgId) + ? "1" + : supplier.FCreateOrgId, Remark = supplier.Remark, CreateDate = DateTime.Now, LastupdateDate = DateTime.Now, Company = "1000", Factory = "1000", - }; + + // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚屼緵搴斿晢缂栫爜鐨勮褰� + var existingSupplier = Db.Queryable<MesSupplier>() + .Where(s => s.SuppNo == entity.SuppNo) + .First(); + + if (existingSupplier != null) + { + // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏� + entity.Id = existingSupplier.Id; + } + else + { + // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID + entity.Id = 0; + } + + return entity; } private bool UpdateSupplierStatusBatch(SqlSugarScope db, @@ -173,16 +166,45 @@ throw new NotImplementedException("鍒犻櫎澶辫触"); } + /// <summary> + /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅 + /// </summary> + private decimal GenerateNewId() + { + // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮� + var maxId = Db.Queryable<MesSupplier>().Max(x => (decimal?)x.Id) ?? 0; + var newId = maxId + 1; + + // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦� + while (Db.Queryable<MesSupplier>().Where(x => x.Id == newId).Any()) + { + newId++; + } + + return newId; + } + private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity) { - db.Deleteable<MesSupplier>().Where(s => s.Id == entity.Id) - .ExecuteCommand(); - - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - - return false; + if (entity.Id == 0) + { + // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏� + var newId = GenerateNewId(); + entity.Id = newId; + return db.Insertable(entity).IgnoreColumns(ignoreNullColumn:true).ExecuteCommand() > 0; + } + else + { + // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D + var originalId = entity.Id; + + // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級 + db.Deleteable<MesSupplier>().Where(s => s.Id == originalId).ExecuteCommand(); + + // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D + entity.Id = originalId; + return db.Insertable(entity).IgnoreColumns(ignoreNullColumn:true).ExecuteCommand() > 0; + } } private bool InsertOrUpdateBatch(SqlSugarScope db, -- Gitblit v1.9.3