|
@@ -48,6 +48,33 @@ def _is_center_box_shapes_empty(center_result: dict) -> bool:
|
|
|
return not inner_shapes and not outer_shapes
|
|
return not inner_shapes and not outer_shapes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _normalize_center_result(center_result: dict) -> dict:
|
|
|
|
|
+ """
|
|
|
|
|
+ 兜底补齐算分服务依赖的 center_result 结构,避免 KeyError: 'box_result'。
|
|
|
|
|
+ """
|
|
|
|
|
+ normalized = center_result if isinstance(center_result, dict) else {}
|
|
|
|
|
+ box_result = normalized.get("box_result")
|
|
|
|
|
+ if not isinstance(box_result, dict):
|
|
|
|
|
+ box_result = {}
|
|
|
|
|
+ normalized["box_result"] = box_result
|
|
|
|
|
+
|
|
|
|
|
+ inner_box = box_result.get("inner_box")
|
|
|
|
|
+ if not isinstance(inner_box, dict):
|
|
|
|
|
+ inner_box = {}
|
|
|
|
|
+ box_result["inner_box"] = inner_box
|
|
|
|
|
+ if not isinstance(inner_box.get("shapes"), list):
|
|
|
|
|
+ inner_box["shapes"] = []
|
|
|
|
|
+
|
|
|
|
|
+ outer_box = box_result.get("outer_box")
|
|
|
|
|
+ if not isinstance(outer_box, dict):
|
|
|
|
|
+ outer_box = {}
|
|
|
|
|
+ box_result["outer_box"] = outer_box
|
|
|
|
|
+ if not isinstance(outer_box.get("shapes"), list):
|
|
|
|
|
+ outer_box["shapes"] = []
|
|
|
|
|
+
|
|
|
|
|
+ return normalized
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _prepare_recalculate_payload(edited_json: dict, source_json: dict) -> dict:
|
|
def _prepare_recalculate_payload(edited_json: dict, source_json: dict) -> dict:
|
|
|
"""
|
|
"""
|
|
|
以数据库里的原始 JSON 为底稿,合并前端编辑结果,得到更稳定的重算入参。
|
|
以数据库里的原始 JSON 为底稿,合并前端编辑结果,得到更稳定的重算入参。
|
|
@@ -83,6 +110,7 @@ def _prepare_recalculate_payload(edited_json: dict, source_json: dict) -> dict:
|
|
|
base["result"]["center_result"] = incoming_center
|
|
base["result"]["center_result"] = incoming_center
|
|
|
elif "center_result" not in base["result"]:
|
|
elif "center_result" not in base["result"]:
|
|
|
base["result"]["center_result"] = incoming_center if isinstance(incoming_center, dict) else {}
|
|
base["result"]["center_result"] = incoming_center if isinstance(incoming_center, dict) else {}
|
|
|
|
|
+ base["result"]["center_result"] = _normalize_center_result(base["result"].get("center_result"))
|
|
|
|
|
|
|
|
return base
|
|
return base
|
|
|
|
|
|