增加了项目侧关于steps的处理。允许保存和提取steps信息。
This commit is contained in:
@@ -101,14 +101,31 @@ class MaterialApiHandler(BaseApiHandler):
|
||||
|
||||
node_updated = False
|
||||
error = None
|
||||
steps_payload = self._get_request_steps(node)
|
||||
steps_sent = False
|
||||
|
||||
# 1. 基础信息更新 (MaterialUpdate)
|
||||
base_diff = self._get_schema_diff(MaterialUpdate, data, origin_data, node.node_id)
|
||||
force_steps_update = self._steps_changed(node)
|
||||
base_diff = self._get_schema_diff(
|
||||
MaterialUpdate,
|
||||
data,
|
||||
origin_data,
|
||||
node.node_id,
|
||||
force_full_schema=force_steps_update,
|
||||
)
|
||||
if base_diff:
|
||||
try:
|
||||
update_model = MaterialUpdate.model_validate(data)
|
||||
push_id = self._generate_push_id()
|
||||
await api_update_material(self.api_client, update_model, push_id, biz_id)
|
||||
await api_update_material(
|
||||
self.api_client,
|
||||
update_model,
|
||||
push_id,
|
||||
biz_id,
|
||||
steps=steps_payload if not steps_sent else [],
|
||||
)
|
||||
self._mark_approval_snapshot_synced(node)
|
||||
steps_sent = steps_sent or bool(steps_payload)
|
||||
node_updated = True
|
||||
except ValidationError as e:
|
||||
error = f"{ERROR_VALIDATION_FAILED}: {e}"
|
||||
@@ -124,8 +141,11 @@ class MaterialApiHandler(BaseApiHandler):
|
||||
self.api_client,
|
||||
plan_model.model_dump(exclude_unset=True),
|
||||
push_id,
|
||||
biz_id
|
||||
biz_id,
|
||||
steps=steps_payload if not steps_sent else [],
|
||||
)
|
||||
self._mark_approval_snapshot_synced(node)
|
||||
steps_sent = steps_sent or bool(steps_payload)
|
||||
node_updated = True
|
||||
except ValidationError as e:
|
||||
error = f"{ERROR_VALIDATION_FAILED}: {e}"
|
||||
@@ -182,7 +202,12 @@ class MaterialApiHandler(BaseApiHandler):
|
||||
error=f"{ERROR_VALIDATION_FAILED}: {e}"
|
||||
)
|
||||
|
||||
response = await api_create_material(self.api_client, create_model, push_id)
|
||||
response = await api_create_material(
|
||||
self.api_client,
|
||||
create_model,
|
||||
push_id,
|
||||
steps=self._get_request_steps(node),
|
||||
)
|
||||
if self.poll_mode == "sync":
|
||||
created_id = self._extract_created_id_from_response(response)
|
||||
if not created_id:
|
||||
@@ -330,26 +355,40 @@ async def api_get_material_list(client, project_id: str) -> List[MaterialRespons
|
||||
return validated_items
|
||||
|
||||
|
||||
async def api_create_material(client, data: MaterialCreate, push_id: str) -> Dict[str, Any]:
|
||||
async def api_create_material(client, data: MaterialCreate, push_id: str, *, steps: List[Dict[str, Any]] | None = None) -> Dict[str, Any]:
|
||||
"""创建物资 POST /material/create"""
|
||||
request_data = {"push_id": push_id, "data": data.model_dump()}
|
||||
request_data = {"push_id": push_id, "data": data.model_dump(), "steps": steps or []}
|
||||
response = await client.request(method="POST", endpoint="/material/create", data=request_data)
|
||||
if response.get("code") != 200:
|
||||
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
|
||||
return response
|
||||
|
||||
|
||||
async def api_update_material(client, data: MaterialUpdate, push_id: str, biz_id: str) -> None:
|
||||
async def api_update_material(
|
||||
client,
|
||||
data: MaterialUpdate,
|
||||
push_id: str,
|
||||
biz_id: str,
|
||||
*,
|
||||
steps: List[Dict[str, Any]] | None = None,
|
||||
) -> None:
|
||||
"""更新物资 PUT /material/update"""
|
||||
request_data = {"push_id": push_id, "biz_id": biz_id, "data": data.model_dump(exclude_unset=True)}
|
||||
request_data = {"push_id": push_id, "biz_id": biz_id, "data": data.model_dump(exclude_unset=True), "steps": steps or []}
|
||||
response = await client.request(method="PUT", endpoint="/material/update", data=request_data)
|
||||
if response.get("code") != 200:
|
||||
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
|
||||
|
||||
|
||||
async def api_update_material_plan(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
|
||||
async def api_update_material_plan(
|
||||
client,
|
||||
data: Dict[str, Any],
|
||||
push_id: str,
|
||||
biz_id: str,
|
||||
*,
|
||||
steps: List[Dict[str, Any]] | None = None,
|
||||
) -> None:
|
||||
"""更新物资计划 PUT /material/plan"""
|
||||
request_data = {"push_id": push_id, "biz_id": biz_id, "data": data}
|
||||
request_data = {"push_id": push_id, "biz_id": biz_id, "data": data, "steps": steps or []}
|
||||
response = await client.request(method="PUT", endpoint="/material/plan", data=request_data)
|
||||
if response.get("code") != 200:
|
||||
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
|
||||
|
||||
Reference in New Issue
Block a user