Bläddra i källkod

柱状图去重统计

17491 1 vecka sedan
förälder
incheckning
147f30ebde

+ 38 - 9
src/main/java/com/jeesite/modules/mes/web/MesProductLeakagePointStatController.java

@@ -175,39 +175,49 @@ public class MesProductLeakagePointStatController extends BaseController {
         int noPoint = 0;
         Map<String, Integer> pointCounts = new LinkedHashMap<>();
         List<Map<String, Object>> occurrences = new ArrayList<>();
+        Set<String> countedDefectOccurrences = new LinkedHashSet<>();
         Map<String, Set<String>> leakagePointsByProduct = buildLeakagePointsByProduct(hfRecords);
         for (MesProductQm record : mesProductQmService.findList(query)) {
             if (!matchesDataType(record.getOprno(), dataType)) continue;
             if ("OK".equalsIgnoreCase(record.getTestResult())) qualified++;
             else {
-                defective++;
                 Set<String> points = leakagePointsByProduct.get(leakagePointKey(record.getComponentNum(), record.getOprno()));
-                if (!addLeakagePoints(points, pointCounts)) {
+                if (points == null || points.isEmpty()) {
+                    defective++;
                     noPoint++;
                     addDefectOccurrence(occurrences, "找不到漏点", record.getComponentNum(), record.getTestTime());
-                } else addDefectOccurrences(occurrences, record.getComponentNum(), record.getTestTime(), points);
+                } else {
+                    defective += addUniqueLeakagePoints(record.getComponentNum(), record.getTestTime(), points,
+                            countedDefectOccurrences, pointCounts, occurrences);
+                }
             }
         }
         for (MesProductRecord record : findProductRecords(startDate, endDate)) {
             if (!matchesDataType(record.getOprno(), dataType)) continue;
             if ("OK".equalsIgnoreCase(record.getContent())) qualified++;
             else {
-                defective++;
                 Set<String> points = leakagePointsByProduct.get(leakagePointKey(record.getSn(), record.getOprno()));
-                if (!addLeakagePoints(points, pointCounts)) {
+                if (points == null || points.isEmpty()) {
+                    defective++;
                     noPoint++;
                     addDefectOccurrence(occurrences, "找不到漏点", record.getSn(), record.getUpdateDate());
-                } else addDefectOccurrences(occurrences, record.getSn(), record.getUpdateDate(), points);
+                } else {
+                    defective += addUniqueLeakagePoints(record.getSn(), record.getUpdateDate(), points,
+                            countedDefectOccurrences, pointCounts, occurrences);
+                }
             }
         }
         for (MesProductHf record : hfRecords) {
             if ("OK".equalsIgnoreCase(record.getResult())) { qualified++; continue; }
-            defective++;
             Set<String> points = parseLeakagePoints(record.getHfFlag());
-            if (!addLeakagePoints(points, pointCounts)) {
+            if (points == null || points.isEmpty()) {
+                defective++;
                 noPoint++;
                 addDefectOccurrence(occurrences, "找不到漏点", record.getSn(), record.getCreateDate());
-            } else addDefectOccurrences(occurrences, record.getSn(), record.getCreateDate(), points);
+            } else {
+                defective += addUniqueLeakagePoints(record.getSn(), record.getCreateDate(), points,
+                        countedDefectOccurrences, pointCounts, occurrences);
+            }
         }
         List<Map<String, Object>> quality = new ArrayList<>();
         Map<String, Object> ok = new LinkedHashMap<>(); ok.put("label", "合格数量"); ok.put("count", qualified); ok.put("color", "#2b8c70"); quality.add(ok);
@@ -245,6 +255,21 @@ public class MesProductLeakagePointStatController extends BaseController {
         return true;
     }
 
+    /** Keeps raw point occurrences for chart details, but counts repeat points once for quality rates. */
+    private int addUniqueLeakagePoints(String sn, Date time, Set<String> points, Set<String> countedOccurrences,
+            Map<String, Integer> pointCounts, List<Map<String, Object>> occurrences) {
+        int added = 0;
+        for (String point : points) {
+            // Point composition, point summary, and workpiece details use every original submission.
+            addDefectOccurrence(occurrences, point, sn, time);
+            pointCounts.put(point, pointCounts.getOrDefault(point, 0) + 1);
+            // Only the quality-result numerator/denominator deduplicates a workpiece-point pair.
+            if (!countedOccurrences.add(leakagePointOccurrenceKey(sn, point))) continue;
+            added++;
+        }
+        return added;
+    }
+
     private Set<String> parseLeakagePoints(String value) {
         Set<String> points = new LinkedHashSet<>();
         for (String item : (value == null ? "" : value).split(",")) {
@@ -272,6 +297,10 @@ public class MesProductLeakagePointStatController extends BaseController {
         return StringUtils.defaultString(sn) + "|" + StringUtils.defaultString(oprno);
     }
 
+    private String leakagePointOccurrenceKey(String sn, String point) {
+        return StringUtils.defaultString(sn) + "\u0000" + StringUtils.defaultString(point);
+    }
+
     /** Overall air-tightness results from INSP030A/B are stored in the production-record table. */
     private List<MesProductRecord> findProductRecords(Date startDate, Date endDate) {
         MesProductRecord query = new MesProductRecord();