From 54cefea3fe69bf1d42c6114b68c9a2024c411c6f Mon Sep 17 00:00:00 2001
From: zyf <1071160500@qq.com>
Date: 星期二, 20 八月 2024 17:13:31 +0800
Subject: [PATCH] 生产订单新增字段ScrapRate 变动损耗率
---
MES.Service/service/BasicData/MesRohInManager.cs | 373 +++++++++++++++++++++++++----------------------------
1 files changed, 175 insertions(+), 198 deletions(-)
diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs
index a9fb76a..35acb3c 100644
--- a/MES.Service/service/BasicData/MesRohInManager.cs
+++ b/MES.Service/service/BasicData/MesRohInManager.cs
@@ -1,95 +1,144 @@
锘縰sing MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
-using MES.Service.util;
using SqlSugar;
namespace MES.Service.service.BasicData;
public class MesRohInManager : Repository<MesRohIn>
{
- //褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉�
-
private readonly MesRohInDataManager rohInDataManager = new();
- //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 MesRohInManager.cs
-
+ // Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜 RohIn 璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔
public bool Save(RohIn rohIn)
{
var rohInErpRohIn = rohIn.ErpRohIn;
var mesRohIn = GetMesRohIn(rohInErpRohIn);
var mesRohInDatas =
GetMesRohInDatas(rohIn.ErpRohinDatas, rohInErpRohIn.Type);
- switch (rohInErpRohIn.Type)
+
+ return UseTransaction(db =>
{
- case "1":
+ switch (rohInErpRohIn.Type)
+ {
+ // case "2":
+ // return InsertData(db, mesRohIn, mesRohInDatas,
+ // rohInErpRohIn.FBILLTYPE)
+ // ? 1
+ // : 0;
+ case "3":
+ return UpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0;
+ case "2":
+ case "4":
+ return SaveOrUpdateData(db, mesRohIn, mesRohInDatas)
+ ? 1
+ : 0;
+ default:
+ throw new NotImplementedException(
+ $"type娌℃湁{rohInErpRohIn.Type}杩欎釜绫诲瀷");
+ }
+ }) > 0;
+ }
+
+ // 鎻掑叆鏁版嵁鐨勬柟娉�
+ private bool InsertData(SqlSugarScope db, MesRohIn mesRohIn,
+ List<MesRohInData> mesRohInDatas, string FBILLTYPE)
+ {
+ switch (FBILLTYPE)
+ {
+ case "A":
+ {
+ var decimals = mesRohInDatas.Select(s => s.Id).ToArray();
+
+ if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id);
+
+ if (decimals.Length > 0)
+ db.Deleteable<MesRohInData>().In(decimals).ExecuteCommand();
+
var insert = base.Insert(mesRohIn);
- var insertRange = rohInDataManager.InsertRange(mesRohInDatas);
+ var insertRange =
+ rohInDataManager.InsertRange(mesRohInDatas);
if (insert && insertRange) return true;
throw new NotImplementedException("鎻掑叆澶辫触");
- case "2":
- var update = base.Update(mesRohIn);
- var insertOrUpdate =
- rohInDataManager.InsertOrUpdate(mesRohInDatas);
+ }
+ case "B":
+ {
+ var decimals = mesRohInDatas.Select(s => s.Id).ToArray();
+ if (base.DeleteById(mesRohIn.Id) && db
+ .Deleteable<MesRohInData>().In(decimals)
+ .ExecuteCommand() > 0)
+ {
+ var insert = base.Insert(mesRohIn);
+ var insertRange =
+ rohInDataManager.InsertRange(mesRohInDatas);
- if (update && insertOrUpdate) return true;
- throw new NotImplementedException("鏇存柊澶辫触");
- case "4":
- var orUpdate = SaveOrUpdate(mesRohIn);
- var baOrUpdate =
- rohInDataManager.InsertOrUpdate(mesRohInDatas);
- if (orUpdate && baOrUpdate) return true;
- throw new NotImplementedException("鎻掑叆澶辫触");
- default:
- throw new NotImplementedException("type娌℃湁" +
- rohInErpRohIn.Type + "杩欎釜绫诲瀷");
+ if (insert && insertRange) return true;
+ throw new NotImplementedException("鎻掑叆澶辫触");
+ }
+
+ break;
+ }
}
+
+ throw new NotImplementedException("閲囪喘璁㈠崟绫诲瀷閿欒");
}
- private bool SaveOrUpdate(MesRohIn mesRohIn)
+ // 鏇存柊鏁版嵁鐨勬柟娉�
+ private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn,
+ List<MesRohInData> mesRohInDatas)
{
- var mesRohIns = base.GetList(it => it.EbelnK3id == mesRohIn.EbelnK3id);
+ var decimals = mesRohInDatas.Select(s => s.Id).ToArray();
+ var update = base.DeleteById(mesRohIn.Id);
+ var insertOrUpdate = db
+ .Deleteable<MesRohInData>().In(decimals)
+ .ExecuteCommand() > 0;
- if (CollectionUtil.IsNullOrEmpty(mesRohIns))
- {
- return base.Insert(mesRohIn);
- }
-
- return base.Update(mesRohIn);
+ if (update && insertOrUpdate) return true;
+ throw new NotImplementedException("鏇存柊澶辫触");
}
+ // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶
+ private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,
+ List<MesRohInData> mesRohInDatas)
+ {
+ if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id);
+
+ 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 = new List<bool>();
- rohIns.ForEach(s =>
- {
- var save = Save(s);
- result.Add(save);
- });
+ var result = rohIns.Select(Save).ToList();
return result.All(b => b);
}
+ // 灏� ErpRohIn 瀵硅薄杞崲涓� MesRohIn 瀵硅薄鐨勬柟娉�
public MesRohIn GetMesRohIn(ErpRohIn rohIn)
{
var eid = Convert.ToDecimal(rohIn.id);
var mesRohIn = new MesRohIn();
- if (!"1".Equals(rohIn.Type))
- {
- var single = base.GetSingle(it => it.EbelnK3id == eid);
- if (single != null) mesRohIn.Id = single.Id;
- }
+
+ 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.PurchaseDate = DateTime.ParseExact(rohIn.FDate,
+ "yyyy-MM-dd HH:mm:ss", null);
mesRohIn.Supplier = rohIn.FSupplierId;
mesRohIn.CloseStatus = rohIn.FCloseStatus;
@@ -99,11 +148,6 @@
mesRohIn.QtyAcceptance = rohIn.Facctype;
mesRohIn.Purchaser = rohIn.FPurchaserId;
mesRohIn.QualityReq = rohIn.F_UNW_Remarks_zlyq;
- // mesRohIn.SupplierContact = rohIn.F_UNW_GYSLXR;
- // mesRohIn.ContactPhone = rohIn.F_UNW_LXRDH;
- // mesRohIn.Position = rohIn.FProviderJob;
- // mesRohIn.OfficePhone = rohIn.FProviderPhone;
- // mesRohIn.SupplierAddress = rohIn.FProviderAddress;
mesRohIn.SettlementParty = rohIn.FSettleId;
mesRohIn.PaymentParty = rohIn.FChargeId;
mesRohIn.Email = rohIn.FProviderEMail;
@@ -112,174 +156,107 @@
mesRohIn.FixtureMoldProcurement = rohIn.F_UNW_Combo_zjmj;
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.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.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.LastupdateDate = DateTime.ParseExact(rohIn.FModifyDate,
+ "yyyy-MM-dd HH:mm:ss", null);
mesRohIn.ErpCheckBy = rohIn.FApproverId;
mesRohIn.ErpCheckDate = rohIn.FApproveDate;
-
+ mesRohIn.Changereason = rohIn.FCHANGEREASON;
return mesRohIn;
}
- public List<MesRohInData> GetMesRohInDatas(List<ErpRohinData> ErpRohinDatas,
- string type)
+ // 灏� ErpRohinData 瀵硅薄杞崲涓� MesRohInData 瀵硅薄鐨勬柟娉�
+ public List<MesRohInData> GetMesRohInDatas(
+ List<ErpRohinData> erpRohinDatas, string type)
{
- var list = new List<MesRohInData>();
- ErpRohinDatas.ForEach(s =>
+ return erpRohinDatas.Select(s =>
{
- var entity = new MesRohInData();
-
- var eid = Convert.ToDecimal(s.id);
-
- if (!"1".Equals(type))
+ var entity = new MesRohInData
{
- var single =
- rohInDataManager.GetSingle(it => it.EbelnK3id == eid);
- if (single != null) entity.Id = single.Id;
- }
+ EbelnK3id = Convert.ToDecimal(s.id),
+ ErpId = Convert.ToDecimal(s.Eid),
+ BillNo = s.FBillNo,
+ SalesOrderId = s.F_UNW_Text_xsddh,
+ 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,
+ PurchaseOrderLineNumber = s.PurchaseOrderLineNumber,
+ Demand = s.Demand,
+ Receiving = s.Receiving,
+ Settlement = s.Settlement
+ };
- entity.EbelnK3id = Convert.ToDecimal(s.id);
- entity.ErpId = Convert.ToDecimal(s.Eid);
+ var single = rohInDataManager.GetSingle(it =>
+ it.EbelnK3id == entity.EbelnK3id);
+ if (single != null) entity.Id = single.Id;
- entity.BillNo = s.FBillNo;
- entity.SalesOrderId = s.F_UNW_Text_xsddh;
- entity.ItemId = s.FMaterialId;
- entity.PurchaseUnit = s.FUnitId;
- entity.PurchaseQty = Convert.ToDecimal(s.FQty);
- entity.InventoryUnit = s.FStockUnitID;
- entity.PricingUnit = s.FPriceUnitId;
- entity.PricingQty = Convert.ToDecimal(s.FPriceUnitQty);
-
- if (s.FDeliveryDate != null)
- entity.DeliveryDate = DateTime.ParseExact(
- s.FDeliveryDate, "yyyy-MM-dd HH:mm:ss", null);
-
- if (s.FDeliveryEarlyDate != null)
- entity.EarliestDeliveryDate = DateTime.ParseExact(
- s.FDeliveryEarlyDate, "yyyy-MM-dd HH:mm:ss", null);
-
- if (s.FDeliveryLastDate != null)
- entity.LatestDeliveryDate = DateTime.ParseExact(
- s.FDeliveryLastDate, "yyyy-MM-dd HH:mm:ss", null);
-
- entity.IsGift = s.FGiveAway;
- entity.Remarks = s.FEntryNote;
- entity.SupplierItemCode = s.FSupMatId;
- entity.SupplierItemName = s.FSupMatName;
- entity.OutsourcingOrderId = s.FSUBREQBILLNO;
- entity.BatchNumber = s.FLot;
- entity.BusinessClose = s.FMRPCloseStatus;
- entity.BusinessFreeze = s.FMRPFreezeStatus;
- entity.Freezer = s.FFreezerId;
-
- if (s.FFreezeDate != null)
- entity.FreezeTime = DateTime.ParseExact(
- s.FFreezeDate, "yyyy-MM-dd HH:mm:ss", null);
-
- entity.BusinessTerminate = s.FMRPTerminateStatus;
- entity.Terminator = s.FTerminaterId;
-
- if (s.FTerminateDate != null)
- entity.TerminateTime = DateTime.ParseExact(
- s.FTerminateDate, "yyyy-MM-dd HH:mm:ss", null);
-
- entity.TotalReceivedQty = Convert.ToDecimal(s.FReceiveQty);
- entity.RemainingReceivedQty =
- Convert.ToDecimal(s.FRemainReceiveQty);
- entity.TotalStoredQty = Convert.ToDecimal(s.FStockInQty);
- entity.RemainingStoredQty = Convert.ToDecimal(s.FRemainStockINQty);
- entity.TotalReturnedQty = Convert.ToDecimal(s.FMrbQty);
- entity.ReturnableReceivedQty = Convert.ToDecimal(s.FCHECKRETQTY);
- entity.ReturnableStoredQty = Convert.ToDecimal(s.FSTOCKRETQTY);
- entity.SourceDocumentType = s.FSrcBillTypeId;
- entity.SourceDocumentId = s.FSrcBillNo;
- entity.DemandTrackingId = s.FReqTraceNo;
- entity.PlanTrackingId = s.FMtoNo;
- entity.ChangeFlag = s.FChangeFlag;
- entity.DemandSource = s.FDEMANDTYPE;
- entity.DemandDocumentId = s.FDEMANDBILLNO;
- entity.DemandDocumentLineId = s.FDEMANDBILLENTRYSEQ;
- list.Add(entity);
- });
- return list;
+ return entity;
+ }).ToList();
}
-
- #region 鏁欏鏂规硶
-
- /// <summary>
- /// 浠撳偍鏂规硶婊¤冻涓嶄簡澶嶆潅涓氬姟闇�姹傦紝涓氬姟浠g爜璇峰湪杩欓噷闈㈠畾涔夋柟娉�
- /// </summary>
- public void Study()
- {
- /*********鏌ヨ*********/
-
- var data1 = base.GetById(1); //鏍规嵁ID鏌ヨ
- var data2 = base.GetList(); //鏌ヨ鎵�鏈�
- var data3 = base.GetList(it => 1 == 1); //鏍规嵁鏉′欢鏌ヨ
- //var data4 = base.GetSingle(it => 1 == 1);//鏍规嵁鏉′欢鏌ヨ涓�鏉�,濡傛灉瓒呰繃涓�鏉′細鎶ラ敊
-
- var p = new PageModel { PageIndex = 1, PageSize = 2 }; // 鍒嗛〉鏌ヨ
- var data5 = base.GetPageList(it => 1 == 1, p);
- Console.Write(p.TotalCount); //杩斿洖鎬绘暟
-
- var data6 =
- base.GetPageList(it => 1 == 1, p,
- it => SqlFunc.GetRandom()); // 鍒嗛〉鏌ヨ鍔犳帓搴�
- Console.Write(p.TotalCount); //杩斿洖鎬绘暟
-
- var conModels = new List<IConditionalModel>(); //缁勮鏉′欢鏌ヨ浣滀负鏉′欢瀹炵幇 鍒嗛〉鏌ヨ鍔犳帓搴�
- conModels.Add(new ConditionalModel
- {
- FieldName = typeof(MesRohIn).GetProperties()[0].Name,
- ConditionalType = ConditionalType.Equal, FieldValue = "1"
- }); //id=1
- var data7 = base.GetPageList(conModels, p, it => SqlFunc.GetRandom());
-
- AsQueryable().Where(x => 1 == 1)
- .ToList(); //鏀寔浜嗚浆鎹㈡垚queryable,鎴戜滑鍙互鐢╭ueryable瀹炵幇澶嶆潅鍔熻兘
-
-
- /*********鎻掑叆*********/
- var insertData = new MesRohIn(); //娴嬭瘯鍙傛暟
- var insertArray = new[] { insertData };
- base.Insert(insertData); //鎻掑叆
- base.InsertRange(insertArray); //鎵归噺鎻掑叆
- var id = base.InsertReturnIdentity(insertData); //鎻掑叆杩斿洖鑷鍒�
- AsInsertable(insertData).ExecuteCommand(); //鎴戜滑鍙互杞垚 Insertable瀹炵幇澶嶆潅鎻掑叆
-
-
- /*********鏇存柊*********/
- var updateData = new MesRohIn(); //娴嬭瘯鍙傛暟
- var updateArray = new[] { updateData }; //娴嬭瘯鍙傛暟
- base.Update(updateData); //鏍规嵁瀹炰綋鏇存柊
- base.UpdateRange(updateArray); //鎵归噺鏇存柊
- //base.Update(it => new MesRohIn() { ClassName = "a", CreateTime = DateTime.Now }, it => it.id==1);// 鍙洿鏂癈lassName鍒楀拰CreateTime鍒楋紝鍏跺畠鍒椾笉鏇存柊锛屾潯浠秈d=1
- AsUpdateable(updateData).ExecuteCommand(); //杞垚Updateable鍙互瀹炵幇澶嶆潅鐨勬彃鍏�
-
-
- /*********鍒犻櫎*********/
- var deldata = new MesRohIn(); //娴嬭瘯鍙傛暟
- base.Delete(deldata); //鏍规嵁瀹炰綋鍒犻櫎
- base.DeleteById(1); //鏍规嵁涓婚敭鍒犻櫎
- base.DeleteById(new[] { 1, 2 }); //鏍规嵁涓婚敭鏁扮粍鍒犻櫎
- base.Delete(it => 1 == 2); //鏍规嵁鏉′欢鍒犻櫎
- AsDeleteable().Where(it => 1 == 2)
- .ExecuteCommand(); //杞垚Deleteable瀹炵幇澶嶆潅鐨勬搷浣�
- }
-
- #endregion
}
\ No newline at end of file
--
Gitblit v1.9.3