From 0c1a03e880bbf795b771a9c8ee4b7b271c262b58 Mon Sep 17 00:00:00 2001 From: sjz <1240968267@qq.com> Date: 星期五, 12 九月 2025 14:23:56 +0800 Subject: [PATCH] 切换验收数据库 --- MES.Service/service/BasicData/MesDepotsManager.cs | 80 ++++++++++++++++------------------------ 1 files changed, 32 insertions(+), 48 deletions(-) diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs index 0045341..ffd63f3 100644 --- a/MES.Service/service/BasicData/MesDepotsManager.cs +++ b/MES.Service/service/BasicData/MesDepotsManager.cs @@ -16,25 +16,24 @@ 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 "3": - if (DeleteDepot(db, entity.DepotId)) return 1; - + if (DeleteDepot(db, entity.DepotId)) + return 1; break; case "2": 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("鎿嶄綔澶辫触"); @@ -42,16 +41,14 @@ } // 鏇存柊浠撳簱鐘舵�佺殑鏂规硶 - 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(); + 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" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); } @@ -68,20 +65,18 @@ // 鍒犻櫎浠撳簱鐨勬柟娉� private bool DeleteDepot(SqlSugarScope db, decimal depotId) { - var deleteById = db.Deleteable<MesDepots>() - .Where(s => s.DepotId == depotId).ExecuteCommand(); + var deleteById = db.Deleteable<MesDepots>().Where(s => s.DepotId == depotId).ExecuteCommand(); if (deleteById > 0) + { return true; - + } throw new NotImplementedException("鍙嶅鏍稿け璐�"); } // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) { - db.Deleteable<MesDepots>() - .Where(s => s.DepotId == entity.DepotId) - .ExecuteCommand(); + db.Deleteable<MesDepots>().Where(s => s.DepotId == entity.DepotId).ExecuteCommand(); var insert = db.Insertable(entity).ExecuteCommand(); return insert > 0; } @@ -129,37 +124,31 @@ list.Add(entity); }); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.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 "3": - if (!DeleteDepotBatch(db, - depotsGroup.Value)) // 鎵归噺鍒犻櫎浠撳簱 + if (!DeleteDepotBatch(db,depotsGroup.Value)) // 鎵归噺鍒犻櫎浠撳簱 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "2": 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; @@ -167,17 +156,15 @@ } // 鎵归噺鏇存柊浠撳簱鐘舵�佺殑鏂规硶 - private bool UpdateDepotStatusBatch(SqlSugarScope db, - List<MesDepots> depotList, string status) + private bool UpdateDepotStatusBatch(SqlSugarScope db,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(); + 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" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); } @@ -193,22 +180,19 @@ } // 鎵归噺鍒犻櫎浠撳簱鐨勬柟娉� - private bool DeleteDepotBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool DeleteDepotBatch(SqlSugarScope db,List<MesDepots> depotList) { var ids = depotList.Select(it => it.DepotId).ToArray(); - var deleteByIds = - db.Deleteable<MesDepots>() - .Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); + var deleteByIds =db.Deleteable<MesDepots>().Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); if (deleteByIds > 0) + { return true; - + } throw new NotImplementedException("鍙嶅鏍稿け璐�"); } // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesDepots> depotList) { return depotList.All(entity => InsertOrUpdate(db, entity)); } -- Gitblit v1.9.3