From c89f7dcf9344a35efde2a00edb10491b401ba000 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 16 九月 2026 09:19:00 +0800
Subject: [PATCH] feat(trace): 添加种子流向信息展示功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/trace/MesProTracePublicServiceImpl.java |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/trace/MesProTracePublicServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/trace/MesProTracePublicServiceImpl.java
index 110c7b1..d4ef2c7 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/trace/MesProTracePublicServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/trace/MesProTracePublicServiceImpl.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchFlowRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchProcessTraceRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPurchaseSourceRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchSalesTargetRespVO;
@@ -38,6 +39,9 @@
 
 import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -212,6 +216,7 @@
         fillAntiFake(resp, traceCode);
         // 鍙�夋墿灞曞尯鍧楋紙鏈夋暟鎹墠杩斿洖锛�
         fillOptionalModules(resp, batch);
+        fillTimelineAndDecision(resp);
         return resp;
     }
 
@@ -329,15 +334,59 @@
             resp.setPurchaseSources(CollUtil.isNotEmpty(purchaseSources) ? purchaseSources : List.of());
             resp.setSalesTargets(CollUtil.isNotEmpty(salesTargets) ? salesTargets : List.of());
             resp.setProcessTraces(CollUtil.isNotEmpty(processTraces) ? processTraces : List.of());
+            List<MesWmBatchFlowRespVO> seedFlows = mesWmBatchService.getBatchFlowList(batch.getCode());
+            resp.setSeedFlows(CollUtil.isNotEmpty(seedFlows) ? seedFlows : List.of());
         } catch (Exception ex) {
             // 浠撳簱鎵规浣撶郴锛堥噰璐�/閿�鍞�/娴佽浆锛夋湭鍚敤鏃跺閿欙紝涓嶅奖鍝嶆牳蹇冭拷婧�
             log.warn("[fillOptionalModules][鎵规 {} 鎵╁睍妯″潡鏌ヨ澶辫触: {}]", batch.getCode(), ex.getMessage());
             resp.setPurchaseSources(List.of());
             resp.setSalesTargets(List.of());
             resp.setProcessTraces(List.of());
+            resp.setSeedFlows(List.of());
         }
     }
 
+    private void fillTimelineAndDecision(MesProTracePublicRespVO resp) {
+        List<MesProTracePublicRespVO.TimelineVO> timeline = new ArrayList<>();
+        if (resp.getProduceDate() != null) {
+            timeline.add(timeline("鐢熶骇", "BATCH_CREATED", "鐢熶骇鎵规寤虹珛", resp.getProduceDate(), null,
+                    resp.getBatchStatusName()));
+        }
+        if (resp.getProcessTraces() != null) {
+            resp.getProcessTraces().forEach(item -> timeline.add(timeline("鍔犲伐", item.getEventType(),
+                    item.getEventType() == null ? "宸ュ簭娴佽浆" : ("IN".equals(item.getEventType()) ? "宸ュ簭鎶曞叆" : "宸ュ簭浜у嚭"),
+                    item.getEventTime(), item.getQuantity(), item.getQualityStatus() == null ? null : String.valueOf(item.getQualityStatus()))));
+        }
+        if (resp.getInbound() != null) {
+            timeline.add(timeline("浠撳偍", "INBOUND", "浠撳偍鍏ュ簱", resp.getInbound().getEventTime(),
+                    resp.getInbound().getQuantity(), resp.getInbound().getStatus()));
+        }
+        if (resp.getSalesTargets() != null) {
+            resp.getSalesTargets().forEach(item -> timeline.add(timeline("閿�鍞�", "OUTBOUND", "閿�鍞嚭搴�",
+                    item.getSalesDate(), item.getQuantity(), item.getQualityStatus() == null ? null : String.valueOf(item.getQualityStatus()))));
+        }
+        timeline.sort(Comparator.comparing(MesProTracePublicRespVO.TimelineVO::getEventTime,
+                Comparator.nullsLast(Comparator.naturalOrder())));
+        resp.setTimeline(timeline);
+
+        MesProTracePublicRespVO.DecisionVO decision = new MesProTracePublicRespVO.DecisionVO();
+        decision.setQualityRisk(resp.getQuality() != null && Integer.valueOf(2).equals(resp.getQuality().getResult()));
+        decision.setInboundQuantity(resp.getInbound() == null ? null : resp.getInbound().getQuantity());
+        decision.setSalesTargetCount(resp.getSalesTargets() == null ? 0 : resp.getSalesTargets().size());
+        decision.setConsumerScanCount(resp.getAntiFake() == null ? 0L : resp.getAntiFake().getScanCount());
+        decision.setRiskLevel(Boolean.TRUE.equals(decision.getQualityRisk()) ? "HIGH" : "NORMAL");
+        resp.setDecision(decision);
+    }
+
+    private MesProTracePublicRespVO.TimelineVO timeline(String stage, String eventType, String eventName,
+                                                         java.time.LocalDateTime eventTime, BigDecimal quantity,
+                                                         String status) {
+        MesProTracePublicRespVO.TimelineVO vo = new MesProTracePublicRespVO.TimelineVO();
+        vo.setStage(stage).setEventType(eventType).setEventName(eventName).setEventTime(eventTime)
+                .setQuantity(quantity).setStatus(status);
+        return vo;
+    }
+
     // ==================== 鍚嶇О鏄犲皠 ====================
 
     private String userName(Long userId) {

--
Gitblit v1.9.3