AnlaAnla vor 2 Wochen
Ursprung
Commit
df35efd113
3 geänderte Dateien mit 53 neuen und 5 gelöschten Zeilen
  1. 29 0
      Test/minio测试.py
  2. 22 4
      app/api/rating_report.py
  3. 2 1
      app/core/config.py

+ 29 - 0
Test/minio测试.py

@@ -0,0 +1,29 @@
+from minio import Minio
+
+
+client = Minio(
+    "192.168.77.249:9000",
+    access_key="pZEwCGnpNN05KPnmC2Yh",
+    secret_key="KfJRuWiv9pVxhIMcFqbkv8hZT9SnNTZ6LPx592D4",
+    secure=False
+)
+
+bucket_name = "grading"
+
+
+try:
+    # 2. 检查存储桶是否存在
+    found = client.bucket_exists(bucket_name)
+    if not found:
+        client.make_bucket(bucket_name)
+        print(f"存储桶 {bucket_name} 已创建")
+    else:
+        print(f"存储桶 {bucket_name} 已存在")
+
+    # 4. 列出该目录(桶)下的所有文件
+    objects = client.list_objects(bucket_name, recursive=True)
+    for obj in objects:
+        print(f"对象名称: {obj.object_name}, 大小: {obj.size} bytes")
+
+except Exception as e:
+    print(f"发生错误: {e}")

+ 22 - 4
app/api/rating_report.py

@@ -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="生成评级报告数据")
 def generate_rating_report(
-        card_id: int,
         cardNo: str,
         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
     """
     根据 Card ID 生成评级报告 JSON
@@ -178,9 +196,9 @@ def generate_rating_report(
 
         # 设置主图 URL
         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":
-            response_data["backImageUrl"] = img.image_path
+            response_data["backImageUrl"] = f"{settings.DATA_HOST_URL}{img.image_path}"
 
         # 获取有效 JSON
         json_data = _get_active_json(img)
@@ -278,7 +296,7 @@ def generate_rating_report(
             "side": side,
             "location": location_str,
             "type": type_str,
-            "defectImgUrl": defect_img_url
+            "defectImgUrl": f"{settings.DATA_HOST_URL}{defect_img_url}"
         })
 
     response_data["defectDetailList"] = final_defect_list

+ 2 - 1
app/core/config.py

@@ -6,6 +6,7 @@ import json
 
 class Settings:
     BASE_PATH = Path(__file__).parent.parent.parent.absolute()
+    DATA_HOST_URL = "http://192.168.77.249:7755"
 
     CONFIG_PATH = BASE_PATH / 'Config.json'
 
@@ -54,4 +55,4 @@ class Settings:
 
 settings = Settings()
 print(f"项目根目录: {settings.BASE_PATH}")
-print(f"数据存储目录: {settings.DATA_DIR}")
+print(f"数据存储目录: {settings.DATA_DIR}")