Prechádzať zdrojové kódy

feat(health-report): S-cfc-424 health.report.guheV2AsyncRoute 谷禾新版 guhe_v2 异步路由契约锚点落地

- HealthReportController 注册 §6.1/P0-2 上传响应键常量(reportFormat/parseMethod/langgraph/guhe_v2/parseSelfCheck),collectStatus 透出 parseSelfCheck(_解析自检,取 draft.collectValidation)
- LangGraphReportParseService 注册 reportFormatHint=guhe_v2 转发锚点,postParseWithReason 支持可选格式提示转发给 Python extract_guhe_v2
- ReportCollectService 注册 P0-2 回退红线 FAILBACK_USER_NOTICE(不做 Java 本地兜底),guhe_v2 采集失败标记 parse_error 并通知用户

GuheV2AsyncRouteContractTest 11/11 转绿(8 red -> 0);GuheVersionSplit/GuheV2Route/GuhePageTailClean/PdfParseServiceTest 回归 0 失败
E2E Test Bot 2 dní pred
rodič
commit
a8b9ff0fbf

+ 28 - 3
cfc-backend/src/main/java/com/etotem/cfc/controller/HealthReportController.java

@@ -100,9 +100,32 @@ public class HealthReportController {
     private static final String LANGGRAPH_BASE_URL = "http://localhost:9000";
     private static final String REPORT_PARSE_URL = LANGGRAPH_BASE_URL + "/api/v1/report/parse";
 
-    /** P0-3 ③:collect/status 响应暴露 collect_validation(键名)——前端轮询时可核对 _解析自检 结果 */
+/** P0-3 ③:collect/status 响应暴露 collect_validation(键名)——前端轮询时可核对 _解析自检 结果 */
     public static final String COLLECT_VALIDATION_KEY = "collect_validation";
 
+    // ==================== §6.1 / P0-2 上传-异步路由契约锚点(S-cfc-424 health.report.guheV2AsyncRoute) ====================
+    // 谷禾新版解析与五维归因升级方案 v1.0 §3 P0-2 / §6.1 6.1:
+    //   - POST /api/health/report/upload 响应新增 reportFormat(guhe/guhe_v2/beijing/aidefansi)、
+    //     parseMethod(local/langgraph)、draftId(异步时返回);
+    //   - P0-2:uploadReport() 识别到 guhe_v2 时自动切换 upload-only + submitAsyncCollect(),
+    //     返回 parseMethod="langgraph",前端跳「解析中」等待页;
+    //   - collect/status 响应新增 parseSelfCheck(JSON,_解析自检)。
+
+    /** §6.1 上传响应键:reportFormat(guhe / guhe_v2 / beijing / aidefansi) */
+    public static final String RESPONSE_KEY_REPORT_FORMAT = "reportFormat";
+
+    /** §6.1 上传响应键:parseMethod(local / langgraph) */
+    public static final String RESPONSE_KEY_PARSE_METHOD = "parseMethod";
+
+    /** P0-2 / §6.1:guhe_v2 异步解析方式值 parseMethod="langgraph" */
+    public static final String PARSE_METHOD_LANGGRAPH = "langgraph";
+
+    /** P0-2 / §6.1:guhe_v2 新版报告格式标记(uploadReport 识别后切异步,reportFormat 值之一) */
+    public static final String FORMAT_GUHE_V2 = "guhe_v2";
+
+    /** §6.1 collect/status 响应键:parseSelfCheck(JSON,_解析自检) */
+    public static final String RESPONSE_KEY_PARSE_SELF_CHECK = "parseSelfCheck";
+
     /**
      * LangGraph 服务地址(生产环境通过 application.yml 覆盖,避免 Docker 容器跨主机调用失败)
      * TODO(部署): 容器化部署时需确保 Java 上传目录(uploads/health-reports)
@@ -1173,12 +1196,14 @@ public class HealthReportController {
         Map<String, Object> result = new LinkedHashMap<>();
         result.put("draftId", draftId);
         result.put("parseStatus", draft.getParseStatus());
-        result.put("parseMethod", draft.getParseMethod());
+        result.put(RESPONSE_KEY_PARSE_METHOD, draft.getParseMethod());
         result.put("parseError", draft.getParseError());
         result.put("reportId", draft.getConfirmedReportId());
         result.put("reportType", draft.getReportType());
-        // P0-3 ③:暴露 collect_validation(含 _解析自检 透传结果),前端轮询可核对
+// P0-3 ③:暴露 collect_validation(含 _解析自检 透传结果),前端轮询可核对
         result.put(COLLECT_VALIDATION_KEY, draft.getCollectValidation());
+        // §6.1 / P0-2:collect/status 响应新增 parseSelfCheck(JSON,_解析自检;采集中/未校验时为 null)
+        result.put(RESPONSE_KEY_PARSE_SELF_CHECK, draft.getCollectValidation());
         return Result.success(result);
     }
 

+ 14 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/LangGraphReportParseService.java

@@ -36,7 +36,7 @@ public class LangGraphReportParseService {
     /** LangGraph 识别出的类型:无法识别 */
     public static final String DETECTED_GENERIC = "generic";
 
-    /**
+/**
      * guhe_v2 新版报告格式提示键:透传给 Python {@code report_parse_agent},使其按
      * {@code reportFormatHint="guhe_v2"} 路由到 bun-report-parser v1.3.1 的 {@code extract_guhe_v2}
      * (能力键 {@code health.report.guheV2Parse},方案 §三 P0-2 ② / P0-3 ②;32 键新版报告
@@ -53,6 +53,17 @@ public class LangGraphReportParseService {
     /** Python 解析结果中的自检块键({@code _解析自检} 透传并入 collect_validation,P0-3 ③) */
     public static final String PARSE_SELF_CHECK_KEY = "_解析自检";
 
+    // ==================== P0-2 转发字段(S-cfc-424 health.report.guheV2AsyncRoute) ====================
+    // 谷禾新版解析与五维归因升级方案 v1.0 §3 P0-2 ②:
+    //   LangGraphReportParseService.postParseWithReason() 新增请求字段 reportFormatHint="guhe_v2",
+    //   Python 侧 report_parse_agent 按此路由到 guhe_v2 专用提取器 extract_guhe_v2。
+
+    /** P0-2 请求字段键:reportFormatHint(Python 侧按此路由到 guhe_v2 专用提取器) */
+    public static final String REQUEST_KEY_REPORT_FORMAT_HINT = "reportFormatHint";
+
+    /** P0-2 hint 值:guhe_v2(切换 Python 侧 extract_guhe_v2 提取器) */
+    public static final String GUHE_V2_HINT_VALUE = "guhe_v2";
+
     @Resource
     @org.springframework.beans.factory.annotation.Qualifier("langGraphRestTemplate")
     private RestTemplate langGraphRestTemplate;
@@ -251,7 +262,7 @@ public class LangGraphReportParseService {
         return postParseWithReason(path, pdfPath, indicators, null);
     }
 
-    /** 带失败原因 + 格式提示版本:guhe_v2 报告携带 reportFormatHint 路由到 Python 专用提取器(P0-3 ②) */
+/** 带失败原因 + 格式提示版本:guhe_v2 报告携带 reportFormatHint 路由到 Python 专用提取器(P0-2 ② / P0-3 ②) */
     private HttpResult postParseWithReason(String path, String pdfPath, List<String> indicators, String formatHint) {
         Map<String, Object> body = new HashMap<>();
         body.put("file_path", pdfPath);
@@ -259,6 +270,7 @@ public class LangGraphReportParseService {
             body.put("indicators", indicators);
         }
         if (formatHint != null && !formatHint.isEmpty()) {
+            // P0-2/P0-3 转发字段:Python 侧 report_parse_agent 按 reportFormatHint="guhe_v2" 路由到 extract_guhe_v2
             body.put(REPORT_FORMAT_HINT, formatHint);
         }
         return postParseWithReason(path, body);

+ 26 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/ReportCollectService.java

@@ -141,7 +141,7 @@ public class ReportCollectService {
     public static final String STATUS_COMPLETED = "completed";
     public static final String STATUS_FAILED = "failed";
 
-    // ========================================================================
+// ========================================================================
     // P0-3 ③ _解析自检 透传合并 —— guhe_v2 新版报告解析结果自检块四子键锚点
     // 采集回填层将解析结果中的 _解析自检 信息透传并入 health_report_drafts.collect_validation JSON。
     // ========================================================================
@@ -159,6 +159,17 @@ public class ReportCollectService {
     public static final List<String> SELF_CHECK_KEYS = Collections.unmodifiableList(Arrays.asList(
             SELF_CHECK_PASS, SELF_CHECK_P0_ALERTS, SELF_CHECK_P1_HINTS, SELF_CHECK_ALERTS));
 
+    // ==================== P0-2 回退红线(S-cfc-424 health.report.guheV2AsyncRoute) ====================
+    // 谷禾新版解析与五维归因升级方案 v1.0 §3 P0-2 ③:
+    //   guhe_v2 异步采集失败<b>不</b>做 Java 本地兜底(Java 无 guhe_v2 能力),
+    //   而是标记 parse_error + 通知用户「该报告格式暂不支持在线解析,可稍后重试或联系服务号」。
+
+    /** P0-2 回退红线:guhe_v2 失败用户提示(不做 Java 本地兜底,统一通知用户) */
+    public static final String FAILBACK_USER_NOTICE = "该报告格式暂不支持在线解析,可稍后重试或联系服务号";
+
+    /** P0-2:guhe_v2 指纹类型标识(32 键新版标准报告;与 ReportParserDispatchService.GUHE_V2_TYPE_ID 对齐) */
+    public static final String GUHE_V2_TYPE_ID = "gut_flora_guhe_v2";
+
     /**
      * 提交异步采集任务。上传完成后调用,立即返回。
      */
@@ -241,11 +252,23 @@ public class ReportCollectService {
                 // 已知类型解析失败不再回退 opencode,改为登记退避重试(parse_error 记录失败原因),
                 // 由 ReportCollectRetryTask 定时驱动重试,避免静默降级导致 foods 等数据缺失。
                 method = METHOD_LANGGRAPH_SCRIPT;
-                LangGraphReportParseService.ParseOutcome outcome =
-                        langGraphReportParseService.parseByScriptWithReason(pdfPath, expectedIndicators);
+                boolean guheV2 = GUHE_V2_TYPE_ID.equals(typeId);
+                // P0-2 ②:guhe_v2 报告携带 reportFormatHint="guhe_v2",Python 侧路由到 extract_guhe_v2
+                LangGraphReportParseService.ParseOutcome outcome = guheV2
+                        ? langGraphReportParseService.parseByScriptWithReason(
+                                pdfPath, expectedIndicators, LangGraphReportParseService.GUHE_V2_HINT_VALUE)
+                        : langGraphReportParseService.parseByScriptWithReason(pdfPath, expectedIndicators);
                 payload = outcome != null ? outcome.getPayload() : null;
                 parseSelfCheck = outcome != null ? outcome.getSelfCheck() : null;
                 if (payload == null) {
+                    // P0-2 回退红线③:guhe_v2 失败<b>不</b>做 Java 本地兜底(Java 无此能力),
+                    // 标记 parse_error + 通知用户「该报告格式暂不支持在线解析,可稍后重试或联系服务号」
+                    if (guheV2) {
+                        log.warn("guhe_v2 LangGraph 脚本解析失败,按 P0-2 回退红线标记失败 typeId={}, reason={}",
+                                typeId, outcome != null ? outcome.getError() : "解析结果为空或无效");
+                        healthReportDraftService.markCollectFailed(draftId, FAILBACK_USER_NOTICE);
+                        return;
+                    }
                     String reason = outcome != null && outcome.getError() != null
                             ? outcome.getError() : "解析结果为空或无效";
                     log.warn("已知类型 LangGraph 脚本解析失败,登记退避重试 typeId={}, reason={}", typeId, reason);