From b957cfb89c9968f47cc5ce9795e6ffb05bc57fd8 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 30 十月 2024 16:05:48 +0800 Subject: [PATCH] 11 --- MES.Service/service/BasicData/MesRohInManager.cs | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 232 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..6509483 --- /dev/null +++ b/MES.Service/service/BasicData/MesRohInManager.cs @@ -0,0 +1,232 @@ +锘縰sing MES.Service.DB; +using MES.Service.Dto.webApi; +using MES.Service.Modes; +using SqlSugar; + +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) + ? 1 + : 0, + "3" => UpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0, + _ => throw new NotImplementedException( + $"type娌℃湁{rohInErpRohIn.Type}杩欎釜绫诲瀷") + }; + }) > 0; + } + + + // 鏇存柊鏁版嵁鐨勬柟娉� + private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn, + List<MesRohInData> mesRohInDatas) + { + var decimals = mesRohInDatas.Select(s => s.Id).ToArray(); + + var update = db.Deleteable<MesRohIn>() + .Where(a => a.Id == mesRohIn.Id) + .ExecuteCommand() > 0; + + var insertOrUpdate = db + .Deleteable<MesRohInData>() + .Where(s => decimals.Contains(s.Id)) + .ExecuteCommand() > 0; + + if (update && insertOrUpdate) return true; + throw new NotImplementedException("鏇存柊澶辫触"); + } + + // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶 + private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn, + List<MesRohInData> mesRohInDatas) + { + if (mesRohIn.Id != null) + db.Deleteable<MesRohIn>().Where(s => s.Id == mesRohIn.Id) + .ExecuteCommand(); + + if (mesRohInDatas.Count > 0) + db.Deleteable<MesRohInData>() + .Where(s => s.ErpId == mesRohIn.EbelnK3id).ExecuteCommand(); + + var orUpdate = base.Insert(mesRohIn); + var baOrUpdate = rohInDataManager.InsertRange(mesRohInDatas); + 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.Id = single.Id; + + 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) + 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; + + + 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 = s.FFreezeDate != null + ? DateTime.ParseExact(s.FFreezeDate, + "yyyy-MM-dd HH:mm:ss", null) + : 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 + }; + + var single = rohInDataManager.GetSingle(it => + it.EbelnK3id == entity.EbelnK3id); + if (single != null) entity.Id = single.Id; + + return entity; + }).ToList(); + } +} \ No newline at end of file -- Gitblit v1.9.3