|
@@ -116,10 +116,28 @@ def _crop_defect_image(original_image_path_str: str, min_rect: List, output_file
|
|
|
|
|
|
|
|
@router.get("/generate", status_code=200, summary="生成评级报告数据")
|
|
@router.get("/generate", status_code=200, summary="生成评级报告数据")
|
|
|
def generate_rating_report(
|
|
def generate_rating_report(
|
|
|
- card_id: int,
|
|
|
|
|
cardNo: str,
|
|
cardNo: str,
|
|
|
db_conn: PooledMySQLConnection = Depends(get_db_connection)
|
|
db_conn: PooledMySQLConnection = Depends(get_db_connection)
|
|
|
):
|
|
):
|
|
|
|
|
+ if not cardNo or not cardNo.strip():
|
|
|
|
|
+ raise HTTPException(status_code=400, detail="cardNo 不能为空")
|
|
|
|
|
+
|
|
|
|
|
+ # 根据cardNo 查询id
|
|
|
|
|
+ try:
|
|
|
|
|
+ with db_conn.cursor() as cursor:
|
|
|
|
|
+ query_sql = f"SELECT id, cardNo FROM {settings.DB_CARD_TABLE_NAME} WHERE cardNo = %s"
|
|
|
|
|
+ cursor.execute(query_sql, (cardNo,))
|
|
|
|
|
+ card_id = cursor.fetchone()[0]
|
|
|
|
|
+
|
|
|
|
|
+ if not card_id:
|
|
|
|
|
+ raise HTTPException(
|
|
|
|
|
+ status_code=404,
|
|
|
|
|
+ detail=f"未找到卡号为 {cardNo} 的相关记录"
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"创建卡牌失败: {e}")
|
|
|
|
|
+ raise HTTPException(status_code=500, detail="数据库查询失败。")
|
|
|
|
|
+
|
|
|
top_n_defects = 3
|
|
top_n_defects = 3
|
|
|
"""
|
|
"""
|
|
|
根据 Card ID 生成评级报告 JSON
|
|
根据 Card ID 生成评级报告 JSON
|
|
@@ -178,9 +196,9 @@ def generate_rating_report(
|
|
|
|
|
|
|
|
# 设置主图 URL
|
|
# 设置主图 URL
|
|
|
if img_type == "front_ring":
|
|
if img_type == "front_ring":
|
|
|
- response_data["frontImageUrl"] = img.image_path
|
|
|
|
|
|
|
+ response_data["frontImageUrl"] = f"{settings.DATA_HOST_URL}{img.image_path}"
|
|
|
elif img_type == "back_ring":
|
|
elif img_type == "back_ring":
|
|
|
- response_data["backImageUrl"] = img.image_path
|
|
|
|
|
|
|
+ response_data["backImageUrl"] = f"{settings.DATA_HOST_URL}{img.image_path}"
|
|
|
|
|
|
|
|
# 获取有效 JSON
|
|
# 获取有效 JSON
|
|
|
json_data = _get_active_json(img)
|
|
json_data = _get_active_json(img)
|
|
@@ -278,7 +296,7 @@ def generate_rating_report(
|
|
|
"side": side,
|
|
"side": side,
|
|
|
"location": location_str,
|
|
"location": location_str,
|
|
|
"type": type_str,
|
|
"type": type_str,
|
|
|
- "defectImgUrl": defect_img_url
|
|
|
|
|
|
|
+ "defectImgUrl": f"{settings.DATA_HOST_URL}{defect_img_url}"
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
response_data["defectDetailList"] = final_defect_list
|
|
response_data["defectDetailList"] = final_defect_list
|