Browse Source

fix(health): 菌群分类层级表归一化 category/level 与前端对齐

- 后端 normalizeFloraCategory:'菌X构成' → 'taxonomy'
- 后端 normalizeFloraLevel:'门/纲/目/科/属/种' → PHYLUM/CLASS/ORDER/FAMILY/GENUS/SPECIES
- 新增 HealthGutFlora.LEVEL_PHYLUM 常量(北京报告特有门级)
- 前端 gut-flora-species-detail.vue 新增 '菌门' tab 及 PHYLUM 映射
- 修复募极/北京格式分类层级在前端 taxonomy 标签页显示为空的问题
E2E Test Bot 1 month ago
parent
commit
b7e9f146cd

+ 32 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/HealthReportController.java

@@ -1996,11 +1996,41 @@ public class HealthReportController {
         gf.setPopulationLevel(pf.getPopulationLevel());
         gf.setDetectionRate(pf.getDetectionRate());
         gf.setDescription(pf.getDescription());
-        gf.setCategory(pf.getCategory());
-        gf.setLevel(pf.getLevel());
+        // 分类层级表归一化:募极/北京的"菌纲构成/菌目构成..."→ taxonomy + 英文LEVEL,
+        // 否则前端 taxonomy 标签页按 category='taxonomy' + level='CLASS' 过滤匹配不到
+        gf.setCategory(normalizeFloraCategory(pf.getCategory()));
+        gf.setLevel(normalizeFloraLevel(pf.getCategory(), pf.getLevel()));
         return gf;
     }
 
+    /**
+     * 菌群分类归一化:以"构成"结尾的层级分类(菌门构成/菌纲构成/菌目构成/菌科构成/菌属构成/菌种构成)
+     * 统一映射为 taxonomy,与前端标签页过滤条件对齐。
+     */
+    private String normalizeFloraCategory(String category) {
+        if (category == null) return null;
+        if (category.endsWith("构成")) {
+            return HealthGutFlora.CATEGORY_TAXONOMY; // "taxonomy"
+        }
+        return category;
+    }
+
+    /**
+     * 菌群层级归一化:中文层级(门/纲/目/科/属/种)→ 英文 LEVEL 常量,
+     * 与前端 levelMap 对齐。非层级数据(如 category=核心菌属 且 level=GENUS)原样保留。
+     */
+    private String normalizeFloraLevel(String category, String level) {
+        if (level == null) return null;
+        String normalized = level;
+        if ("门".equals(level)) normalized = HealthGutFlora.LEVEL_PHYLUM;
+        else if ("纲".equals(level)) normalized = HealthGutFlora.LEVEL_CLASS;
+        else if ("目".equals(level)) normalized = HealthGutFlora.LEVEL_ORDER;
+        else if ("科".equals(level)) normalized = HealthGutFlora.LEVEL_FAMILY;
+        else if ("属".equals(level)) normalized = HealthGutFlora.LEVEL_GENUS;
+        else if ("种".equals(level)) normalized = HealthGutFlora.LEVEL_SPECIES;
+        return normalized;
+    }
+
     private List<HealthDiseaseRisk> buildDiseaseRisksFromPayload(ParsedReportPayload.Payload payload) {
         List<ParsedReportPayload.DiseaseRisk> list = payload.getDiseaseRisks();
         if (list == null || list.isEmpty()) return new ArrayList<>();

+ 1 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/HealthGutFlora.java

@@ -17,6 +17,7 @@ import java.util.Date;
 public class HealthGutFlora implements Serializable {
 
     // ===== Level 常量 =====
+    public static final String LEVEL_PHYLUM = "PHYLUM";    // 门
     public static final String LEVEL_CLASS = "CLASS";      // 纲
     public static final String LEVEL_ORDER = "ORDER";      // 目
     public static final String LEVEL_FAMILY = "FAMILY";    // 科

+ 20 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/HealthReportService.java

@@ -1435,11 +1435,29 @@ public class HealthReportService {
         gf.setPopulationLevel(pf.getPopulationLevel());
         gf.setDetectionRate(pf.getDetectionRate());
         gf.setDescription(pf.getDescription());
-        gf.setCategory(pf.getCategory());
-        gf.setLevel(pf.getLevel());
+        gf.setCategory(normalizeFloraCategory(pf.getCategory()));
+        gf.setLevel(normalizeFloraLevel(pf.getCategory(), pf.getLevel()));
         return gf;
     }
 
+    private String normalizeFloraCategory(String category) {
+        if (category == null) return null;
+        if (category.endsWith("构成")) return HealthGutFlora.CATEGORY_TAXONOMY;
+        return category;
+    }
+
+    private String normalizeFloraLevel(String category, String level) {
+        if (level == null) return null;
+        String normalized = level;
+        if ("门".equals(level)) normalized = HealthGutFlora.LEVEL_PHYLUM;
+        else if ("纲".equals(level)) normalized = HealthGutFlora.LEVEL_CLASS;
+        else if ("目".equals(level)) normalized = HealthGutFlora.LEVEL_ORDER;
+        else if ("科".equals(level)) normalized = HealthGutFlora.LEVEL_FAMILY;
+        else if ("属".equals(level)) normalized = HealthGutFlora.LEVEL_GENUS;
+        else if ("种".equals(level)) normalized = HealthGutFlora.LEVEL_SPECIES;
+        return normalized;
+    }
+
     List<HealthDiseaseRisk> buildDiseaseRisksFromPayload(ParsedReportPayload.Payload payload) {
         List<ParsedReportPayload.DiseaseRisk> list = payload.getDiseaseRisks();
         if (list == null || list.isEmpty()) return new ArrayList<>();

+ 2 - 0
cfc-frontend/pages/health/gut-flora-species-detail.vue

@@ -72,6 +72,7 @@ export default {
         { key: 'other', label: '其它菌属' },
         { key: 'pathogen_genus', label: '病原菌属' },
         { key: 'pathogen_detection', label: '病原菌检出' },
+        { key: 'taxonomy_phylum', label: '菌门' },
         { key: 'taxonomy_class', label: '菌纲' },
         { key: 'taxonomy_order', label: '菌目' },
         { key: 'taxonomy_family', label: '菌科' },
@@ -93,6 +94,7 @@ export default {
       // Taxonomy tabs: filter by category='taxonomy' + level
       if (this.selectedTab.indexOf('taxonomy_') === 0) {
         var levelMap = {
+          'taxonomy_phylum': 'PHYLUM',
           'taxonomy_class': 'CLASS',
           'taxonomy_order': 'ORDER',
           'taxonomy_family': 'FAMILY',