Ver código fonte

修复隐患识别无法正确建立历史记录次二级场景映射的问题

KCY 1 mês atrás
pai
commit
02f3702828
1 arquivos alterados com 8 adições e 2 exclusões
  1. 8 2
      shudao-chat-py/routers/scene.py

+ 8 - 2
shudao-chat-py/routers/scene.py

@@ -93,13 +93,18 @@ def _build_record_view(record: RecognitionRecord, db: Session = None):
     if db and display_labels:
         try:
             from models.scene import SecondScene, ThirdScene
+            from utils.label_translator import translate_scenes_for_query
             
             for label in display_labels:
-                # Find matching secondary scene
+                # Translate sub-secondary scene to secondary scene for database query
+                # e.g., "加油机" -> "加油设施_附属场地"
+                query_label = translate_scenes_for_query([label])[0] if label else label
+                
+                # Find matching secondary scene using translated name
                 second_scene = (
                     db.query(SecondScene)
                     .filter(
-                        SecondScene.second_scene_name == label,
+                        SecondScene.second_scene_name == query_label,
                         SecondScene.is_deleted == 0,
                     )
                     .first()
@@ -117,6 +122,7 @@ def _build_record_view(record: RecognitionRecord, db: Session = None):
                     )
                     
                     if third_scene_records:
+                        # Use original label as key for frontend matching
                         element_hazards[label] = [
                             ts.third_scene_name for ts in third_scene_records
                         ]