From 88cd740124f9e821fd11e4af9d5bb10d7bde98a6 Mon Sep 17 00:00:00 2001 From: liangjunyu <13726812+shifang-tianhua_0@user.noreply.gitee.com> Date: Fri, 14 Nov 2025 17:27:07 +0800 Subject: [PATCH] 1 --- Context/SQL/TB_BS_MTRL.sql | 4 +- Controllers/EnpowerApiController.cs | 63 ++++++++++++++++++---------- Models/Cloud/bill/PRD_PPBOMChange.cs | 2 + 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Context/SQL/TB_BS_MTRL.sql b/Context/SQL/TB_BS_MTRL.sql index cb70083..08e9783 100644 --- a/Context/SQL/TB_BS_MTRL.sql +++ b/Context/SQL/TB_BS_MTRL.sql @@ -29,7 +29,7 @@ from T_BD_MATERIAL m1 LEFT JOIN T_BD_MATERIALAUXPTY f on f.FMATERIALID=m1.FMATERIALID and f.FAuxPropertyId=100001 LEFT JOIN T_BD_MATERIALINVPTY g on g.FMATERIALID=m1.FMATERIALID and g.FINVPTYID=10004 WHERE m1.FDocumentStatus=''C'' -AND (CONVERT(VARCHAR(10),m1.FAPPROVEDATE,23)=CONVERT(VARCHAR(10),GETDATE(),23) or CONVERT(VARCHAR(10),m1.FMODIFYDATE,23)=CONVERT(VARCHAR(10),GETDATE(),23)) -AND m1.FUSEORGID=@defaultorgid + AND (CONVERT(VARCHAR(10),m1.FAPPROVEDATE,23)=CONVERT(VARCHAR(10),GETDATE(),23) or CONVERT(VARCHAR(10),m1.FMODIFYDATE,23)=CONVERT(VARCHAR(10),GETDATE(),23)) + AND m1.FUSEORGID=@defaultorgid ' WHERE FID = 3 \ No newline at end of file diff --git a/Controllers/EnpowerApiController.cs b/Controllers/EnpowerApiController.cs index f308ee8..5645cb6 100644 --- a/Controllers/EnpowerApiController.cs +++ b/Controllers/EnpowerApiController.cs @@ -57,8 +57,7 @@ namespace RB_MES_API.Controllers /// /// /// - public EnpowerApiController(RBContext context, IShareController shareController, IKDCloudHttpClient kdhttpClient, - IChiledSelect chiledSelect, IKDSqlHelper kdsqlhelper ) + public EnpowerApiController(RBContext context, IShareController shareController, IKDCloudHttpClient kdhttpClient, IChiledSelect chiledSelect, IKDSqlHelper kdsqlhelper) { _context = context; _shareController = shareController; @@ -9878,7 +9877,7 @@ namespace RB_MES_API.Controllers //FNumerator = b.IS_BACK == "Y" ? GetNumerator(b.TN_QTY, a.FQty, true) : a.FNumerator, //FDenominator = b.IS_BACK == "Y" ? GetNumerator(b.TN_QTY, a.FQty, false) : a.FDenominator, FNumerator = (b.IS_BACK == "Y" ? b.TN_QTY : (b.TN_QTY == 0 ? 0 : GetNumerator(b.TN_QTY, a.FQty, true))),//20250108 - FDenominator = (b.IS_BACK == "Y" ? a.FQty : (b.TN_QTY == 0 ? 1 : GetNumerator(b.TN_QTY, a.FQty, true))),//20250108 + FDenominator = (b.IS_BACK == "Y" ? a.FQty : (b.TN_QTY == 0 ? 1 : GetNumerator(b.TN_QTY, a.FQty, false))),//20250108 //FUseRate= b.TN_QTY==0 ? 0 : 100, FPositionNO = b.POINT_STR, FNeedQty2 = b.IS_BACK == "Y" ? 0 : b.TN_QTY, @@ -10079,19 +10078,26 @@ namespace RB_MES_API.Controllers select new { FReplaceGroup = b.Key.FReplaceGroup, - TotalQty = b.Sum(s => s.FMustQty) + TotalQty = b.Sum(s => s.FMustQty), + TotalCount = b.Count() }).ToList().Distinct(); foreach (var item in groupid) { int id = item.FReplaceGroup; + decimal itemqty = item.TotalQty; + int itemCount = item.TotalCount; + List itemgroup = entities.Where(s => s.FReplaceGroup == id && s.FChangeType != "2").ToList(); var count = itemgroup.Count(); var index = 0; foreach (PRD_PPBOMChange.Entity entity in itemgroup) { + if (itemCount > 1) + entity.FReplaceGroupNumerator = itemqty; + index++; if (itemqty != 0) { @@ -10168,6 +10174,10 @@ namespace RB_MES_API.Controllers } } + /// + /// 合并用料清单的重算使用比例 + /// + /// private void UpdateUseRate(List entities) { var groupid = (from a in entities.Where(s => s.FChangeType != "2") @@ -10178,19 +10188,25 @@ namespace RB_MES_API.Controllers select new { FReplaceGroup = b.Key.FReplaceGroup, - TotalQty = b.Sum(s => s.FMustQty) + TotalQty = b.Sum(s => s.FMustQty), + TotalCount = b.Count() }).ToList().Distinct(); foreach (var item in groupid) { int id = item.FReplaceGroup; decimal itemqty = item.TotalQty; + int itemCount = item.TotalCount; + List itemgroup = entities.Where(s => s.FReplaceGroup == id && s.FChangeType != "2").ToList(); var count = itemgroup.Count(); var index = 0; foreach (var entity in itemgroup) { + if (itemCount > 1) + entity.FReplaceGroupNumerator = itemqty; + index++; if (itemqty != 0) { @@ -10342,6 +10358,7 @@ namespace RB_MES_API.Controllers FIssueType = a.IS_BACK == "Y" ? 0 : 1, FPPBOMEntrySeq = int.Parse(a.SEQ.ToString()) //对应MES提供的JSON中的唯一项 }).ToList(); + return entities; } private List GetSUBEntitiesForNew(List ppbomlist, List newpbom @@ -10445,7 +10462,7 @@ namespace RB_MES_API.Controllers List bills = (from b in ppbom select new PRD_PPBOMChange { - //FBillNo=b.FPPBOMNo, + //FBillNo = b.FPPBOMNo, FMaterialID = new Dictionary { { "FNumber", b.FParentMaterial } }, FWorkshopID = new Dictionary { { "FNumber", b.FWorkshopID } }, FBOMID = new Dictionary { { "FNumber", b.FBOMID } }, @@ -10485,6 +10502,7 @@ namespace RB_MES_API.Controllers if (newentities.Count != 0) { //var changees = newentities.Where(s => int.Parse(s.FChangeType) != 3); + int idx = 0; foreach (PRD_PPBOMChange.Entity entity in newentities) { //从源单信息中把主料找出来 @@ -10496,25 +10514,16 @@ namespace RB_MES_API.Controllers var mainrow = ppbom.Where(s => s.FMainMaterial == mainitem && s.FMaterial == mainitem && s.FMaterialType == 1); if (mainrow.Any()) { - entity.FReplacePriority = ppbomchanges.Count(w => - w.FReplaceGroup == mainrow.FirstOrDefault().FReplaceGroup - && (w.FChangeType == "3" || w.FChangeType == "1") - ); + entity.FReplacePriority = ppbomchanges.Count(w => w.FReplaceGroup == mainrow.FirstOrDefault().FReplaceGroup && (w.FChangeType == "3" || w.FChangeType == "1")); entity.FParentRowId = mainrow.FirstOrDefault().FRowId; entity.FReplaceGroup = mainrow.FirstOrDefault().FReplaceGroup; //实际上是多余的,提交给ERP之后,会被覆盖... } - ////entity.FSeq = maxseq; //对于新的子项,这里的赋值没起作用... - //WPLAN_MN_CHANGE _CHANGE = newpbom.Find(s=>s.MTRL_ID==entity.FMaterialID2.FirstOrDefault().Value && s.SEQ==entity.FPPBOMEntrySeq); - //string parrowid = string.Empty; - //int groupno = GetChangeReplaceGroup(entity, entity.FMaterialID2.FirstOrDefault().Value, _CHANGE, ref reason, ref parrowid); - //if (!string.IsNullOrWhiteSpace(reason)) { break; } - ////if (groupno == 0 && entity.FMaterialType == "3") - ////{ - //// reason = "替代子项的同时主料也得变更"; - //// return null; - ////} - //entity.FReplaceGroup = groupno; - //entity.FParentRowId = parrowid; + else + { + entity.FReplaceGroup = 9999 - idx; + entity.FSeq = idx++; + } + //entity.FSeq = maxseq; //对于新的子项,这里的赋值没起作用... //注意:FPPBOMEntrySeq在此之前属于主料的SEQ,用完既应该恢复为0 entity.FPPBOMEntrySeq = 0; } @@ -10526,6 +10535,16 @@ namespace RB_MES_API.Controllers if (string.IsNullOrEmpty(reason)) { UpdateUseRate(ppbomchanges); + + ppbomchanges.ForEach(data => + { + if (data.FSeq + data.FReplaceGroup == 9999) + { + data.FSeq = 0; + data.FReplaceGroup = 0; + } + }); //提交前把SEQ清0,让系统自动生成 + var hp = ppbomchanges.OrderBy(s => s.FReplaceGroup).ThenBy(s => s.FReplaceType).ToList(); change.FEntity.AddRange(hp); } diff --git a/Models/Cloud/bill/PRD_PPBOMChange.cs b/Models/Cloud/bill/PRD_PPBOMChange.cs index 8ae1c8f..c1c9e24 100644 --- a/Models/Cloud/bill/PRD_PPBOMChange.cs +++ b/Models/Cloud/bill/PRD_PPBOMChange.cs @@ -250,6 +250,8 @@ namespace RB_MES_API.Models.Cloud /// public int FReplaceGroup { get; set; } + public decimal FReplaceGroupNumerator { get; set; } + public List FEntity_Link { get; set; } public class Entity_Link {