袁威 2 viikkoa sitten
vanhempi
commit
9199268eaf
1 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 22 0
      app/api/formate_xy.py

+ 22 - 0
app/api/formate_xy.py

@@ -391,7 +391,29 @@ async def update_image_modified_json(
             raise HTTPException(status_code=400, detail=f"未知的 image_type: {image_type}")
 
         # 3. 准备重算 payload:以库内原始 JSON 为底稿,仅覆盖编辑后的 defects
+        # 对 fusion 图,score_type 会映射到 ring;此时底稿也应优先使用 ring 图 JSON,
+        # 否则 fusion 图常见的空框结构会导致算分服务在 ring 逻辑下越界。
         source_json_str = row["modified_json"] if row["modified_json"] else row["detection_json"]
+        if image_type in (ImageType.front_fusion.value, ImageType.back_fusion.value):
+            target_ring_type = (
+                ImageType.front_ring.value
+                if image_type == ImageType.front_fusion.value
+                else ImageType.back_ring.value
+            )
+            cursor.execute(
+                f"SELECT detection_json, modified_json FROM {settings.DB_IMAGE_TABLE_NAME} "
+                f"WHERE card_id = %s AND image_type = %s LIMIT 1",
+                (card_id_to_update, target_ring_type)
+            )
+            ring_row = cursor.fetchone()
+            if ring_row:
+                source_json_str = ring_row["modified_json"] if ring_row["modified_json"] else ring_row["detection_json"]
+            else:
+                logger.warning(
+                    "fusion图重算未找到对应ring底稿,回退到当前图: image_id=%s card_id=%s image_type=%s target_ring_type=%s",
+                    id, card_id_to_update, image_type, target_ring_type
+                )
+
         if isinstance(source_json_str, str):
             source_json_data = json.loads(source_json_str)
         else: