From c02ff3f682398f022488f98b87a79d4a8e04b5dd Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期三, 30 十月 2024 11:00:11 +0800
Subject: [PATCH] 接口更新
---
MES.Service/service/BasicData/MesDepotsManager.cs | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 209 insertions(+), 0 deletions(-)
diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs
new file mode 100644
index 0000000..b007c92
--- /dev/null
+++ b/MES.Service/service/BasicData/MesDepotsManager.cs
@@ -0,0 +1,209 @@
+锘縰sing MES.Service.DB;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using SqlSugar;
+
+namespace MES.Service.service.BasicData;
+
+public class MesDepotsManager : Repository<MesDepots>
+{
+ // Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜浠撳簱璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔
+ public bool Save(ErpDepots depots)
+ {
+ var entity = GetMesDepots(depots); // 灏� ErpDepots 杞崲涓� MesDepots
+ return UseTransaction(db =>
+ {
+ switch (depots.Type)
+ {
+ case "0":
+ if (UpdateDepotStatus(db, entity.DepotId, "A")) return 1;
+
+ break;
+ case "1":
+ if (UpdateDepotStatus(db, entity.DepotId, "B")) return 1;
+
+ break;
+ case "3":
+ if (DeleteDepot(db, entity.DepotId)) return 1;
+
+ break;
+ case "2":
+ case "4":
+ if (InsertOrUpdate(db, entity)) return 1;
+
+ break;
+ default:
+ throw new ArgumentNullException(
+ $"type娌℃湁{depots.Type}杩欎釜绫诲瀷鐨勫弬鏁�");
+ }
+
+ throw new NotImplementedException("鎿嶄綔澶辫触");
+ }) > 0;
+ }
+
+ // 鏇存柊浠撳簱鐘舵�佺殑鏂规硶
+ 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" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
+ }
+
+ // 鎻掑叆鏂颁粨搴撶殑鏂规硶
+ 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>()
+ .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();
+ var insert = db.Insertable(entity).ExecuteCommand();
+ return insert > 0;
+ }
+
+ // 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉�
+ private MesDepots GetMesDepots(ErpDepots depots)
+ {
+ return new MesDepots
+ {
+ 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,
+ FSubsidiary = depots.FUseOrgId,
+ Fumbrella = depots.FCreateOrgId,
+ CreateDate = DateTime.Now,
+ LastupdateDate = DateTime.Now,
+ Company = "1000",
+ Factory = "1000"
+ };
+ }
+
+ // 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());
+ return UseTransaction(db =>
+ {
+ foreach (var depotsGroup in groupBy)
+ switch (depotsGroup.Key)
+ {
+ case "0":
+ if (!UpdateDepotStatusBatch(db, depotsGroup.Value,
+ "A")) // 鎵归噺鍚敤浠撳簱
+ throw new NotImplementedException("鍚敤澶辫触");
+ break;
+ case "1":
+ if (!UpdateDepotStatusBatch(db, depotsGroup.Value,
+ "B")) // 鎵归噺绂佺敤浠撳簱
+ throw new NotImplementedException("绂佺敤澶辫触");
+ break;
+ case "2":
+ if (!InsertDepotBatch(db,
+ depotsGroup.Value)) // 鎵归噺鎻掑叆浠撳簱
+ throw new NotImplementedException("鎻掑叆澶辫触");
+ break;
+ case "3":
+ if (!DeleteDepotBatch(db,
+ depotsGroup.Value)) // 鎵归噺鍒犻櫎浠撳簱
+ throw new NotImplementedException("鍒犻櫎澶辫触");
+ break;
+ case "4":
+ if (!InsertOrUpdateBatch(db,
+ depotsGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴�
+ throw new NotImplementedException("鍚屾澶辫触");
+ break;
+ default:
+ throw new ArgumentNullException(
+ $"type娌℃湁{depotsGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�");
+ }
+
+ return 1;
+ }) > 0;
+ }
+
+ // 鎵归噺鏇存柊浠撳簱鐘舵�佺殑鏂规硶
+ 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();
+
+ if (result > 0)
+ return true;
+
+ throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
+ }
+
+ // 鎵归噺鎻掑叆浠撳簱鐨勬柟娉�
+ 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>()
+ .Where(s => ids.Contains(s.DepotId)).ExecuteCommand();
+ if (deleteByIds > 0)
+ return true;
+
+ throw new NotImplementedException("鍙嶅鏍稿け璐�");
+ }
+
+ // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
+ private bool InsertOrUpdateBatch(SqlSugarScope db,
+ List<MesDepots> depotList)
+ {
+ return depotList.All(entity => InsertOrUpdate(db, entity));
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3