From 6761b0ed84fd7a03400b557244d0835f671dad94 Mon Sep 17 00:00:00 2001 From: sjz <1240968267@qq.com> Date: 星期一, 14 七月 2025 18:02:59 +0800 Subject: [PATCH] 修改多组织 --- MES.Service/service/BasicData/MesDepotsManager.cs | 168 ++++++++++++++++++++++---------------------------------- 1 files changed, 66 insertions(+), 102 deletions(-) diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs index d10b6f7..3087d0b 100644 --- a/MES.Service/service/BasicData/MesDepotsManager.cs +++ b/MES.Service/service/BasicData/MesDepotsManager.cs @@ -16,28 +16,27 @@ switch (depots.Type) { case "0": - if (UpdateDepotStatus(db, entity.DepotId, "A")) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "A")) + return 1; break; case "1": - if (UpdateDepotStatus(db, entity.DepotId, "B")) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "B")) + return 1; break; case "2": - if (InsertDepot(db, entity)) return 1; - + if (InsertDepot(db, entity)) + return 1; break; case "3": - if (DeleteDepot(db, entity.DepotId)) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "B")) + return 1; break; case "4": - if (InsertOrUpdate(db, entity)) return 1; - + if (InsertOrUpdate(db, entity)) + return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{depots.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{depots.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -45,59 +44,56 @@ } // 鏇存柊浠撳簱鐘舵�佺殑鏂规硶 - private bool UpdateDepotStatus(SqlSugarScope db, decimal depotId, - string status) + private bool UpdateDepotStatus(SqlSugarScope db, decimal depotId,string status) { - var result = db.Updateable<MesDepots>() - .SetColumns(s => s.IsNg == status) - .Where(s => s.DepotId == depotId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesDepots>().SetColumns(s => s.IsNg == status).Where(s => s.DepotId == depotId).ExecuteCommand(); + return true; } // 鎻掑叆鏂颁粨搴撶殑鏂规硶 private bool InsertDepot(SqlSugarScope db, MesDepots entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - - throw new NotImplementedException("瀹℃牳澶辫触"); - } - - // 鍒犻櫎浠撳簱鐨勬柟娉� - private bool DeleteDepot(SqlSugarScope db, decimal depotId) - { - var deleteById = db.Deleteable<MesDepots>().In(depotId) - .ExecuteCommand(); - if (deleteById > 0) - return true; - - throw new NotImplementedException("鍙嶅鏍稿け璐�"); - } - - // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 - private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) - { - var exists = db.Queryable<MesDepots>() - .Any(e => e.DepotId == entity.DepotId); + var exists = db.Queryable<MesDepots>().Any(e => e.DepotId == entity.DepotId); if (exists) { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + var result = db.Updateable<MesDepots>().ExecuteCommand(); + return true; } else { var insert = db.Insertable(entity).ExecuteCommand(); if (insert > 0) + { return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } } + } - return false; + // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 + private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) + { + var exists = db.Queryable<MesDepots>().Any(e => e.DepotId == entity.DepotId); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); + return true; + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } // 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉� @@ -105,14 +101,17 @@ { return new MesDepots { + DepotId = Convert.ToDecimal(depots.Id), DepotCode = depots.FNumber, DepotName = depots.FName, - DepotId = Convert.ToDecimal(depots.Id), IsFkc = depots.FAllowMinusQty, CreateBy = depots.FPrincipal, Depottype = depots.FStockProperty, IsNg = depots.FForbidStatus, Zuid = depots.FGroup, + CreateOrg= Convert.ToDecimal(depots.FCreateOrgId), + UseOrg= Convert.ToDecimal(depots.FUseOrgId), + CreateDate = DateTime.Now, Company = "1000", Factory = "1000" }; @@ -121,49 +120,35 @@ // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜浠撳簱璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔 public bool SaveList(List<ErpDepots> erpDepots) { - var list = new List<MesDepots>(); - erpDepots.ForEach(s => - { - var entity = GetMesDepots(s); // 灏� ErpDepots 杞崲涓� MesDepots - entity.Type = s.Type; - list.Add(entity); - }); - - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var list = erpDepots.Select(GetMesDepots).ToList(); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { foreach (var depotsGroup in groupBy) switch (depotsGroup.Key) { case "0": - if (!UpdateDepotStatusBatch(db, depotsGroup.Value, - "A")) // 鎵归噺鍚敤浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value,"A")) // 鎵归噺鍚敤浠撳簱 throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (!UpdateDepotStatusBatch(db, depotsGroup.Value, - "B")) // 鎵归噺绂佺敤浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value,"B")) // 鎵归噺绂佺敤浠撳簱 throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": - if (!InsertDepotBatch(db, - depotsGroup.Value)) // 鎵归噺鎻掑叆浠撳簱 + if (!InsertDepotBatch(db,depotsGroup.Value)) // 鎵归噺鎻掑叆浠撳簱 throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteDepotBatch(db, - depotsGroup.Value)) // 鎵归噺鍒犻櫎浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value, "B")) // 鎵归噺绂佺敤浠撳簱 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": - if (!InsertOrUpdateBatch(db, - depotsGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴� + if (!InsertOrUpdateBatch(db,depotsGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴� throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{depotsGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{depotsGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; @@ -175,48 +160,27 @@ List<MesDepots> depotList, string status) { var ids = depotList.Select(it => it.DepotId).ToArray(); - var result = db.Updateable<MesDepots>() - .SetColumns(s => s.IsNg == status) - .Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesDepots>().SetColumns(s => s.IsNg == status).Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); + return true; } // 鎵归噺鎻掑叆浠撳簱鐨勬柟娉� - private bool InsertDepotBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool InsertDepotBatch(SqlSugarScope db,List<MesDepots> depotList) { var insertRange = db.Insertable(depotList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("瀹℃牳澶辫触"); - } - - // 鎵归噺鍒犻櫎浠撳簱鐨勬柟娉� - private bool DeleteDepotBatch(SqlSugarScope db, - List<MesDepots> depotList) - { - var ids = depotList.Select(it => it.DepotId).ToArray(); - var deleteByIds = - db.Deleteable<MesDepots>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍙嶅鏍稿け璐�"); + return true; } // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesDepots> depotList) { foreach (var entity in depotList) + { if (!InsertOrUpdate(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file -- Gitblit v1.9.3