소스 검색

前后端数据不一致问题清洗

袁威 2 주 전
부모
커밋
9cfdb1f3b5
2개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 5
      app/api/formate_xy.py
  2. 4 0
      app/utils/xy_process.py

+ 2 - 5
app/api/formate_xy.py

@@ -393,6 +393,8 @@ async def update_gray_image_json(
     
     # 丢弃前端展示用的辅助字段,防止传给算分服务导致报错
     for d in gray_defects:
+        if d.get("label") == "slight_scratch":
+            d["label"] = "scratch"
         d.pop("defectImgUrl", None)
         d.pop("defectImgUrls", None)
 
@@ -459,11 +461,6 @@ async def update_gray_image_json(
             is_fusion = gray_image_type in (ImageType.front_fusion.value, ImageType.back_fusion.value)
             key_to_check = "fusion_id" if is_fusion else "gray_id"
             
-            # 把前端传来的 slight_scratch 强制转换成 scratch
-            # 这是因为算分服务可能不支持 slight_scratch 这种新标签
-            if new_defect.get("label") == "slight_scratch":
-                new_defect["label"] = "scratch"
-                
             identifier = new_defect.get(key_to_check)
 
             # 只有带有对应标识的才进行特殊合并处理

+ 4 - 0
app/utils/xy_process.py

@@ -118,5 +118,9 @@ def convert_xy_to_internal_format(frontend_json: dict) -> dict:
 
         # 这里的 defect["id"] 如果后端不需要存储,可以 del defect["id"]
         # if "id" in defect: del defect["id"]
+        
+        # 处理掉算分服务不支持的新增 label 类型
+        if defect.get("label") == "slight_scratch":
+            defect["label"] = "scratch"
 
     return data