From c6d9fc76d16c944e64d6490eb2a6d866fd7a38f0 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期三, 12 十一月 2025 09:06:01 +0800
Subject: [PATCH] 11
---
MES.Service/service/BasicData/MesDepotsManager.cs | 180 ++++++++++++++++++++++-------------------------------------
1 files changed, 68 insertions(+), 112 deletions(-)
diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs
index 34b8bc0..ae137ed 100644
--- a/MES.Service/service/BasicData/MesDepotsManager.cs
+++ b/MES.Service/service/BasicData/MesDepotsManager.cs
@@ -1,5 +1,4 @@
-锘縰sing Castle.Core.Resource;
-using MES.Service.DB;
+锘縰sing MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
@@ -17,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("鎿嶄綔澶辫触");
@@ -46,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 && e.DepotCode == entity.DepotCode);
if (exists)
{
- var update = db.Updateable(entity).ExecuteCommand();
- if (update > 0)
- return true;
+ var result = db.Updateable(entity).Where(e => e.DepotId == entity.DepotId && e.DepotCode == entity.DepotCode).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 && e.DepotCode == entity.DepotCode);
+ if (exists)
+ {
+ var update = db.Updateable(entity).Where(e => e.DepotId == entity.DepotId && e.DepotCode == entity.DepotCode).ExecuteCommand();
+ return true;
+ }
+ else
+ {
+ var insert = db.Insertable(entity).ExecuteCommand();
+ if (insert > 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
// 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉�
@@ -106,20 +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,
- FSubsidiary = depots.FSubsidiary,
- Fumbrella = depots.Fumbrella,
- FSUPPLIERID = depots.FSUPPLIERID,
- Fdeptid = depots.Fdeptid,
- CreateDate=DateTime.Now,
- LastupdateDate=DateTime.Now,
+ CreateOrg = Convert.ToDecimal(depots.FCreateOrgId),
+ UseOrg = Convert.ToDecimal(depots.FUseOrgId),
+ CreateDate = DateTime.Now,
Company = "1000",
Factory = "1000"
};
@@ -128,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;
@@ -178,52 +156,30 @@
}
// 鎵归噺鏇存柊浠撳簱鐘舵�佺殑鏂规硶
- 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();
-
- 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