From 62d96156bc293576a1cb81ac1ea1df2f2fe80433 Mon Sep 17 00:00:00 2001 From: xiongcz Date: Mon, 26 May 2025 14:37:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ysr):=20=E4=BC=98=E5=8C=96=20ECN1=20?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E6=95=B0=E9=87=8F=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 getAllChange 方法,合并前后 BOMLine 的 key 集合,去重处理 - 重构主逻辑,使用 changeSet 遍历所有变化的 BOMLine - 优化数量对比逻辑,处理 null值和新增/删除的 BOMLine - 删除冗余代码,提高代码可读性和维护性 --- .idea/vcs.xml | 6 + .../ysr/form/YSR8_ECN1RevisionMasterForm.java | 124 +++++++++++++----- 2 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/cn/com/ebewin/ysr/form/YSR8_ECN1RevisionMasterForm.java b/src/cn/com/ebewin/ysr/form/YSR8_ECN1RevisionMasterForm.java index db2b299..87a624f 100644 --- a/src/cn/com/ebewin/ysr/form/YSR8_ECN1RevisionMasterForm.java +++ b/src/cn/com/ebewin/ysr/form/YSR8_ECN1RevisionMasterForm.java @@ -20,6 +20,7 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -1229,40 +1230,62 @@ public class YSR8_ECN1RevisionMasterForm extends AbstractRendering { System.out.println("ǰ㲿BOMLineChild="+beforeMap.size()); System.out.println("ĺ㲿BOMLineChild="+afterMap.size()); - - - for (Map.Entry beforeEntry : beforeMap.entrySet()) { - String key = beforeEntry.getKey(); - System.out.println("1_beforeMap ["+key+"] : ["+beforeMap.get(key)+"]"); - System.out.println("1_afterMap ["+key+"] : ["+afterMap.get(key)+"]"); - if (afterMap.containsKey(key)) { - System.out.println("1"); -// Object compResult = TCUtil.compareBOMLineQuantity(beforeMap.get(key), afterMap.get(key));//ԭݡװλ޶ǰ㲿 -// if (compResult instanceof double[]) { -// System.out.println("2"); -// double[] ds = (double[]) compResult; -// resultMap.put(afterMap.get(key), ds[1] - ds[0]); -// } +// Set changeSet = new LinkedHashSet(); + Set changeSet = getAllChange(beforeMap,afterMap); + for (String key : changeSet) { + TCComponentBOMLine beforeBomLine1 = beforeMap.get(key); + TCComponentBOMLine afterBomLine1 = afterMap.get(key); + if (beforeBomLine1 == null && afterBomLine1 == null) { + continue; + }else { //߼ - double[] ds = getBOMLineQuantity(beforeMap.get(key),afterMap.get(key)); + double[] ds = getBOMLineQuantity(beforeBomLine1,afterBomLine1); System.out.println("["+beforeMap.get(key)+"]ǰ=["+ds[0]+"]=["+ds[1]+"]"); double changeNum = ds[1] - ds[0]; if (changeNum == 0) { continue; } - resultMap.put(afterMap.get(key), ds[1] - ds[0]); - } - } - for (Map.Entry afterEntry : afterMap.entrySet()) { - String key = afterEntry.getKey(); - System.out.println("afterMap "+key+":"+afterMap.get(key)); - if (beforeMap.containsKey(key)) { - System.out.println("3"); - } else { - System.out.println("4"); - resultMap.put(afterMap.get(key), TCUtil.totalBOMLineQuantity(afterMap.get(key))); + TCComponentBOMLine putBomLine = afterMap.get(key) == null ? beforeMap.get(key) : afterMap.get(key); + resultMap.put(putBomLine, ds[1] - ds[0]); } + } + + +// for (Map.Entry beforeEntry : beforeMap.entrySet()) { +// String key = beforeEntry.getKey(); +// System.out.println("1_beforeMap ["+key+"] : ["+beforeMap.get(key)+"]"); +// System.out.println("1_afterMap ["+key+"] : ["+afterMap.get(key)+"]"); +// if (afterMap.containsKey(key)) { +// System.out.println("1"); +//// Object compResult = TCUtil.compareBOMLineQuantity(beforeMap.get(key), afterMap.get(key));//ԭݡװλ޶ǰ㲿 +//// if (compResult instanceof double[]) { +//// System.out.println("2"); +//// double[] ds = (double[]) compResult; +//// resultMap.put(afterMap.get(key), ds[1] - ds[0]); +//// } +// //߼ +// double[] ds = getBOMLineQuantity(beforeMap.get(key),afterMap.get(key)); +// System.out.println("["+beforeMap.get(key)+"]ǰ=["+ds[0]+"]=["+ds[1]+"]"); +// double changeNum = ds[1] - ds[0]; +// if (changeNum == 0) { +// continue; +// } +// resultMap.put(afterMap.get(key), ds[1] - ds[0]); +// } +// } + + +// for (Map.Entry afterEntry : afterMap.entrySet()) { +// String key = afterEntry.getKey(); +// System.out.println("afterMap "+key+":"+afterMap.get(key)); +// if (beforeMap.containsKey(key)) { +// System.out.println("3"); +// } else { +// System.out.println("4"); +// resultMap.put(afterMap.get(key), TCUtil.totalBOMLineQuantity(afterMap.get(key))); +// } +// } String ysr8_ReasonAnalysisVal = ""; TCComponentItem ecn1Item = ecn1Revision.getItem(); @@ -1381,24 +1404,57 @@ public class YSR8_ECN1RevisionMasterForm extends AbstractRendering { } } + /** + * еkeyӵsetУﵽȥصĿ + * @param beforeMap + * @param afterMap + * @return + */ + private Set getAllChange(Map beforeMap, + Map afterMap) { + Set changeSet = new LinkedHashSet(); + + // beforeMap key ӽ set + if (beforeMap != null) { + changeSet.addAll(beforeMap.keySet()); + } + + // afterMap key ӽ set + if (afterMap != null) { + changeSet.addAll(afterMap.keySet()); + } + + return changeSet; + } + /** * ȡbomlineQuantityһ * @param beforeBOMLine ǰ - * @param afterBOMLine2 + * @param afterBOMLine * @return * @throws TCException */ - private double[] getBOMLineQuantity(TCComponentBOMLine beforeBOMLine, TCComponentBOMLine afterBOMLine2) throws TCException { + private double[] getBOMLineQuantity(TCComponentBOMLine beforeBOMLine, TCComponentBOMLine afterBOMLine) throws TCException { System.out.println("getBOMLineQuantityʼִС"); - if (beforeBOMLine == null || afterBOMLine2 == null) { + double bl1 = 0; + double bl2 = 0; + String bl_quantity1 = null; + String bl_quantity2 = null; + String targetName = null; + if (beforeBOMLine == null && afterBOMLine == null) { System.out.println("getBOMLineQuantity쳣Ϊnull"); return null; } - String targetName = beforeBOMLine.getItem().getStringProperty("object_string"); - String bl_quantity1 = beforeBOMLine.getStringProperty("bl_quantity"); - String bl_quantity2 = afterBOMLine2afterBOMLine2.getStringProperty("bl_quantity"); - double bl1 = Double.parseDouble(bl_quantity1); - double bl2 = Double.parseDouble(bl_quantity2); + if (beforeBOMLine != null) { + bl_quantity1 = beforeBOMLine.getStringProperty("bl_quantity"); + bl1 = Double.parseDouble(bl_quantity1 == null ? "0" : bl_quantity1); + targetName = beforeBOMLine.getItem().getStringProperty("object_string"); + } + if (afterBOMLine != null) { + bl_quantity2 = afterBOMLine.getStringProperty("bl_quantity"); + bl2 = Double.parseDouble(bl_quantity2 == null ? "0" : bl_quantity2); + targetName = afterBOMLine.getItem().getStringProperty("object_string"); + } System.out.println(targetName+"ӦbomlineǰԱ="+bl_quantity1+":"+bl_quantity2+""); double[] re = {bl1, bl2}; return re;