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;
+ }
+
/**
* 获取两个bomline的Quantity数量,并返回一个数组
* @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;