From 105ee9e867d29a322517888a9c3efb13f3e89961 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期日, 21 九月 2025 22:46:18 +0800
Subject: [PATCH] 1.接口逻辑调整
---
MES.Service/service/BasicData/MesRohInManager.cs | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 269 insertions(+), 0 deletions(-)
diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs
new file mode 100644
index 0000000..758b087
--- /dev/null
+++ b/MES.Service/service/BasicData/MesRohInManager.cs
@@ -0,0 +1,269 @@
+锘縰sing Masuit.Tools;
+using MES.Service.DB;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using SqlSugar;
+using System.Globalization;
+
+namespace MES.Service.service.BasicData;
+
+public class MesRohInManager : Repository<MesRohIn>
+{
+ private readonly MesRohInDataManager rohInDataManager = new();
+
+ // Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜 RohIn 璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔
+ public bool Save(RohIn rohIn)
+ {
+ var rohInErpRohIn = rohIn.ErpRohIn;
+ var mesRohIn = GetMesRohIn(rohInErpRohIn);
+ var mesRohInDatas =
+ GetMesRohInDatas(rohIn.ErpRohinDatas);
+
+ return UseTransaction(db =>
+ {
+ return rohInErpRohIn.Type switch
+ {
+ "2" or "4" or "5" => SaveOrUpdateData(db, mesRohIn,
+ mesRohInDatas, rohInErpRohIn.Type)
+ ? 1
+ : 0,
+ "3" => SaveOrUpdateData(db, mesRohIn,
+ mesRohInDatas, rohInErpRohIn.Type)
+ ? 1
+ : 0, //UpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0,//鍙嶅鏍镐笉鍒犻櫎锛屽仛update銆�
+ _ => throw new NotImplementedException(
+ $"type娌℃湁{rohInErpRohIn.Type}杩欎釜绫诲瀷")
+ };
+ }) > 0;
+ }
+
+
+ // 鏇存柊鏁版嵁鐨勬柟娉�
+ private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn,
+ List<MesRohInData> mesRohInDatas)
+ {
+ var decimals = mesRohInDatas.Select(s => s.Guid).ToArray();
+
+ var update = db.Deleteable<MesRohIn>()
+ .Where(a => a.Guid == mesRohIn.Guid)
+ .ExecuteCommand() > 0;
+
+ var insertOrUpdate = db
+ .Deleteable<MesRohInData>()
+ .Where(s => decimals.Contains(s.Guid))
+ .ExecuteCommand() > 0;
+
+ if (update && insertOrUpdate) return true;
+ throw new NotImplementedException("鏇存柊澶辫触");
+ }
+
+ // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶
+ private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,
+ List<MesRohInData> mesRohInDatas, string type)
+ {
+
+ if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "C"))
+ {
+ mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString();
+ }
+
+ if (mesRohIn.Guid != null)
+ db.Deleteable<MesRohIn>().Where(s => s.Guid == mesRohIn.Guid)
+ .ExecuteCommand();
+
+ if (mesRohInDatas.Count > 0)
+ db.Deleteable<MesRohInData>()
+ .Where(s => s.ErpId == mesRohIn.EbelnK3id).ExecuteCommand();
+
+ var orUpdate = db.Insertable(mesRohIn)
+ .IgnoreColumns(true).ExecuteCommand() > 0;
+
+
+ var baOrUpdate = db.Insertable(mesRohInDatas).PageSize(1)
+ .IgnoreColumnsNull()
+ .ExecuteCommand() > 0;
+
+ if (orUpdate && baOrUpdate) return true;
+ throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�");
+ }
+
+ // 鎵归噺淇濆瓨璁板綍鐨勬柟娉�
+ public bool SaveList(List<RohIn> rohIns)
+ {
+ var result = rohIns.Select(Save).ToList();
+ return result.All(b => b);
+ }
+
+ // 灏� ErpRohIn 瀵硅薄杞崲涓� MesRohIn 瀵硅薄鐨勬柟娉�
+ private MesRohIn GetMesRohIn(ErpRohIn rohIn)
+ {
+ var eid = long.Parse(rohIn.id);
+ var mesRohIn = new MesRohIn();
+
+
+ var single = base.GetSingle(it => it.EbelnK3id == eid);
+ if (single != null) mesRohIn.Guid = single.Guid;
+
+ mesRohIn.EbelnK3id = eid;
+ mesRohIn.BillNo = rohIn.FBillNo;
+ mesRohIn.DocumentStatus = rohIn.FDocumentStatus;
+ mesRohIn.DocumentType = rohIn.FBillTypeID;
+ mesRohIn.BusinessType = rohIn.FBusinessType;
+
+ if (rohIn.FDate != null)
+ mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ mesRohIn.Supplier = rohIn.FSupplierId;
+ mesRohIn.CloseStatus = rohIn.FCloseStatus;
+ mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId;
+ mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId;
+ mesRohIn.PurchaseGroup = rohIn.FPurchaserGroupId;
+ mesRohIn.Purchaser = rohIn.FPurchaserId;
+ mesRohIn.SettlementParty = rohIn.FSettleId;
+ mesRohIn.PaymentParty = rohIn.FChargeId;
+ mesRohIn.Email = rohIn.FProviderEMail;
+ mesRohIn.Remarks = rohIn.Remarks;
+ mesRohIn.CancellationStatus = rohIn.FCancelStatus;
+ mesRohIn.CancellationPerson = rohIn.FCancellerId;
+
+ if (rohIn.FCancelDate != null)
+ if (!mesRohIn.CancellationPerson.IsNullOrEmpty())
+ mesRohIn.CancellationDate =
+ DateTime.ParseExact(rohIn.FCancelDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ mesRohIn.CreateBy = rohIn.FCreatorId;
+
+ if (rohIn.FCreateDate != null)
+ mesRohIn.CreateDate = DateTime.ParseExact(rohIn.FCreateDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ mesRohIn.LastupdateBy = rohIn.FModifierId;
+
+ if (rohIn.FModifyDate != null)
+ mesRohIn.LastupdateDate = DateTime.ParseExact(rohIn.FModifyDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ mesRohIn.ErpCheckBy = rohIn.FApproverId;
+ mesRohIn.ErpCheckDate = rohIn.FApproveDate;
+ mesRohIn.Changereason = rohIn.FChangeReason;
+ mesRohIn.Prearrivaldate = rohIn.Prearrivaldate != null
+ ? DateTime.ParseExact(rohIn.Prearrivaldate,
+ "yyyy-MM-dd HH:mm:ss", null)
+ : null;
+
+ mesRohIn.ReceiveOrgId = rohIn.FReceiveOrgId;
+ mesRohIn.ProviderId = rohIn.FProviderId;
+
+ mesRohIn.Anred = rohIn.FTContact;
+ mesRohIn.Telf1 = rohIn.Fmobilephone;
+ mesRohIn.FixedTelephone = rohIn.FixedTelephone;
+ mesRohIn.Address = rohIn.Address;
+ mesRohIn.Acctype = rohIn.Acctype;
+ mesRohIn.SynchronousDate = DateTime.Now;
+
+ return mesRohIn;
+ }
+
+ // 灏� ErpRohinData 瀵硅薄杞崲涓� MesRohInData 瀵硅薄鐨勬柟娉�
+ private List<MesRohInData> GetMesRohInDatas(
+ List<ErpRohinData> erpRohinDatas)
+ {
+ return erpRohinDatas.Select(s =>
+ {
+ var entity = new MesRohInData
+ {
+ EbelnK3id = Convert.ToDecimal(s.id),
+ ErpId = Convert.ToDecimal(s.Eid),
+ BillNo = s.FBillNo,
+ ItemId = s.FMaterialId,
+ PurchaseUnit = s.FUnitId,
+ PurchaseQty = Convert.ToDecimal(s.FQty),
+ InventoryUnit = s.FStockUnitID,
+ PricingUnit = s.FPriceUnitId,
+ PricingQty = Convert.ToDecimal(s.FPriceUnitQty),
+ DeliveryDate = s.FDeliveryDate != null
+ ? DateTime.ParseExact(s.FDeliveryDate,
+ "yyyy-MM-dd HH:mm:ss", null)
+ : null,
+ EarliestDeliveryDate = s.FDeliveryEarlyDate != null
+ ? DateTime.ParseExact(s.FDeliveryEarlyDate,
+ "yyyy-MM-dd HH:mm:ss", null)
+ : null,
+ LatestDeliveryDate = s.FDeliveryLastDate != null
+ ? DateTime.ParseExact(s.FDeliveryLastDate,
+ "yyyy-MM-dd HH:mm:ss", null)
+ : null,
+ IsGift = s.FGiveAway,
+ Remarks = s.FEntryNote,
+ SupplierItemCode = s.FSupMatId,
+ SupplierItemName = s.FSupMatName,
+ OutsourcingOrderId = s.FSUBREQBILLNO,
+ BatchNumber = s.FLot,
+ BusinessClose = s.FMRPCloseStatus,
+ BusinessFreeze = s.FMRPFreezeStatus,
+ Freezer = s.FFreezerId,
+ //FreezeTime = !string.IsNullOrEmpty(s.FFreezeDate)
+ // && DateTime.TryParseExact(s.FFreezeDate,
+ // new[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }, // 鏀寔澶氱鏍煎紡
+ // CultureInfo.InvariantCulture,
+ // DateTimeStyles.None,
+ // out var parsedDate)
+ // && parsedDate > new DateTime(1900, 1, 1)
+ // ? parsedDate
+ // : (DateTime?)null,
+ BusinessTerminate = s.FMRPTerminateStatus,
+ Terminator = s.FTerminaterId,
+ //TerminateTime = s.FTerminateDate != null
+ // ? DateTime.ParseExact(s.FTerminateDate,
+ // "yyyy-MM-dd HH:mm:ss", null)
+ // : null,
+ TotalReceivedQty = Convert.ToDecimal(s.FReceiveQty), //绱鏀舵枡鏁�
+ RemainingReceivedQty =
+ Convert.ToDecimal(s.FRemainReceiveQty),
+ TotalStoredQty = Convert.ToDecimal(s.FStockInQty), //绱鍏ュ簱鏁�
+ RemainingStoredQty = Convert.ToDecimal(s.FRemainStockINQty),
+ TotalReturnedQty = Convert.ToDecimal(s.FMrbQty),
+ ReturnableReceivedQty =
+ Convert.ToDecimal(s.FCHECKRETQTY), //鏀舵枡鍙��鏁�
+ ReturnableStoredQty = Convert.ToDecimal(s.FSTOCKRETQTY), //搴撳瓨鍙��鏁�
+ SourceDocumentType = s.FSrcBillTypeId,
+ SourceDocumentId = s.FSrcBillNo,
+ DemandTrackingId = s.FReqTraceNo,
+ PlanTrackingId = s.FMtoNo,
+ ChangeFlag = s.FChangeFlag,
+ DemandSource = s.FDEMANDTYPE,
+ DemandDocumentId = s.FDEMANDBILLNO,
+ DemandDocumentLineId = s.FDEMANDBILLENTRYSEQ,
+ DemandOrg = s.FRequireOrgId,
+ ReceivingOrg = s.FReceiveOrgId,
+ SettlementOrg = s.FEntrySettleOrgId,
+ PurchaseOrderLineNumber = s.FSEQ,
+ Demand = s.FRequireOrgId,
+ Receiving = s.FReceiveOrgId,
+ Settlement = s.FSETTLEORGID,
+ DemandDepartment = s.FRequireDeptId,
+ ReceivingDepartment = s.FReceiveDeptId
+ };
+
+ if (s.FFreezeDate != null)
+ if (!s.FFreezerId.IsNullOrEmpty())
+ entity.FreezeTime =
+ DateTime.ParseExact(s.FFreezeDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ if (s.FTerminateDate != null)
+ if (!s.FTerminaterId.IsNullOrEmpty())
+ entity.TerminateTime =
+ DateTime.ParseExact(s.FTerminateDate,
+ "yyyy-MM-dd HH:mm:ss", null);
+
+ var single = rohInDataManager.GetSingle(it =>
+ it.EbelnK3id == entity.EbelnK3id);
+ if (single != null) entity.Guid = single.Guid;
+
+ return entity;
+ }).ToList();
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3