Ver código fonte

卡牌找不到修改

袁威 2 semanas atrás
pai
commit
dfd2467153
1 arquivos alterados com 9 adições e 9 exclusões
  1. 9 9
      app/api/formate_xy.py

+ 9 - 9
app/api/formate_xy.py

@@ -130,22 +130,19 @@ def _process_images_to_xy_format(card_data: dict):
     all_images = card_data.get("images", [])
     if all_images:
         for img in all_images:
-            # 处理 detection_json
-            if img.detection_json:
-                d_json = img.detection_json
+            # Pydantic模型属性访问
+            d_json = img.detection_json
+            if d_json:
                 if isinstance(d_json, str):
                     d_json = json.loads(d_json)
                 _process_defects_for_json(card_id, img.id, img.image_path, d_json, img.image_type, all_images)
-                # *** 转换逻辑 ***
                 img.detection_json = convert_internal_to_xy_format(d_json)
 
-            # 处理 modified_json
-            if img.modified_json:
-                m_json = img.modified_json
+            m_json = img.modified_json
+            if m_json:
                 if isinstance(m_json, str):
                     m_json = json.loads(m_json)
                 _process_defects_for_json(card_id, img.id, img.image_path, m_json, img.image_type, all_images)
-                # *** 转换逻辑 ***
                 img.modified_json = convert_internal_to_xy_format(m_json)
     return card_data
 
@@ -486,11 +483,14 @@ async def update_gray_image_json(
             with db_conn.cursor() as cursor:
                 review_state = 2
                 # 更新指定 card_id 的 review_state 字段
+                # 注意:MySQL 在 “值未变化” 的情况下 rowcount 可能为 0,但这不代表记录不存在。
                 query_update = f"UPDATE {settings.DB_CARD_TABLE_NAME} SET review_state = %s WHERE id = %s"
                 cursor.execute(query_update, (review_state, card_id))
 
                 if cursor.rowcount == 0:
-                    raise HTTPException(status_code=404, detail=f"ID为 {card_id} 的卡牌未找到。")
+                    cursor.execute(f"SELECT 1 FROM {settings.DB_CARD_TABLE_NAME} WHERE id = %s LIMIT 1", (card_id,))
+                    if not cursor.fetchone():
+                        raise HTTPException(status_code=404, detail=f"ID为 {card_id} 的卡牌未找到。")
 
                 db_conn.commit()
                 logger.info(f"卡牌 ID {card_id} 的审核状态已成功修改为 {review_state}。")