增加了项目侧关于steps的处理。允许保存和提取steps信息。
This commit is contained in:
@@ -81,7 +81,12 @@ class ConstructionTaskApiHandler(BaseApiHandler):
|
||||
results.append(TaskResult.failed(node_id=node.node_id, error=f"{ERROR_VALIDATION_FAILED}: {e}"))
|
||||
continue
|
||||
|
||||
response = await api_create_construction_task(self.api_client, create_model, push_id)
|
||||
response = await api_create_construction_task(
|
||||
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:
|
||||
@@ -134,8 +139,13 @@ class ConstructionTaskApiHandler(BaseApiHandler):
|
||||
|
||||
# 1. 基础信息更新 (ConstructionUpdate)
|
||||
# 业务逻辑:如果 show_name 字段不同,那么仅当 type == 'QT' 时才更新
|
||||
force_steps_update = self._steps_changed(node)
|
||||
steps_payload = self._get_request_steps(node)
|
||||
steps_sent = False
|
||||
base_new_schema_error = self._validate_schema(data, ConstructionUpdate)
|
||||
base_changed_fields = self._schema_changed_fields(ConstructionUpdate, data, origin_data)
|
||||
if force_steps_update and not base_new_schema_error and not base_changed_fields:
|
||||
base_changed_fields = ["__steps__"]
|
||||
base_update_called = False
|
||||
base_update_error: str | None = None
|
||||
if base_new_schema_error:
|
||||
@@ -150,11 +160,29 @@ class ConstructionTaskApiHandler(BaseApiHandler):
|
||||
|
||||
if should_update:
|
||||
try:
|
||||
update_model = ConstructionUpdate.model_validate(data)
|
||||
update_payload = data if (force_steps_update and base_changed_fields == ["__steps__"]) else data
|
||||
update_model = ConstructionUpdate.model_validate(update_payload)
|
||||
push_id = self._generate_push_id()
|
||||
await api_update_construction_task(self.api_client, update_model, push_id, biz_id)
|
||||
request_steps = steps_payload if not steps_sent else []
|
||||
if request_steps:
|
||||
await api_update_construction_task(
|
||||
self.api_client,
|
||||
update_model,
|
||||
push_id,
|
||||
biz_id,
|
||||
steps=request_steps,
|
||||
)
|
||||
else:
|
||||
await api_update_construction_task(
|
||||
self.api_client,
|
||||
update_model,
|
||||
push_id,
|
||||
biz_id,
|
||||
)
|
||||
node_updated = True
|
||||
base_update_called = True
|
||||
steps_sent = steps_sent or bool(steps_payload)
|
||||
self._mark_approval_snapshot_synced(node)
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
base_update_error = str(e)
|
||||
@@ -185,9 +213,26 @@ class ConstructionTaskApiHandler(BaseApiHandler):
|
||||
plan_model = ConstructionPlanUpdate.model_validate(data)
|
||||
plan_dict = plan_model.model_dump(exclude_unset=True)
|
||||
push_id = self._generate_push_id()
|
||||
await api_update_construction_task_plan(self.api_client, plan_dict, push_id, biz_id)
|
||||
request_steps = steps_payload if not steps_sent else []
|
||||
if request_steps:
|
||||
await api_update_construction_task_plan(
|
||||
self.api_client,
|
||||
plan_dict,
|
||||
push_id,
|
||||
biz_id,
|
||||
steps=request_steps,
|
||||
)
|
||||
else:
|
||||
await api_update_construction_task_plan(
|
||||
self.api_client,
|
||||
plan_dict,
|
||||
push_id,
|
||||
biz_id,
|
||||
)
|
||||
node_updated = True
|
||||
plan_update_called = True
|
||||
steps_sent = steps_sent or bool(steps_payload)
|
||||
self._mark_approval_snapshot_synced(node)
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
plan_update_error = str(e)
|
||||
@@ -279,16 +324,23 @@ async def api_get_construction_task_list(client, project_id: str) -> List[Constr
|
||||
return validated_items
|
||||
|
||||
|
||||
async def api_create_construction_task(client, data: ConstructionCreate, push_id: str) -> Dict[str, Any]:
|
||||
request_data = {"push_id": push_id, "data": data.model_dump()}
|
||||
async def api_create_construction_task(client, data: ConstructionCreate, push_id: str, *, steps: List[Dict[str, Any]] | None = None) -> Dict[str, Any]:
|
||||
request_data = {"push_id": push_id, "data": data.model_dump(), "steps": steps or []}
|
||||
response = await client.request(method="POST", endpoint="/construction/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_construction_task(client, data: ConstructionUpdate, push_id: str, biz_id: str) -> None:
|
||||
request_data = {"push_id": push_id, "biz_id": biz_id, "data": data.model_dump(exclude_unset=True)}
|
||||
async def api_update_construction_task(
|
||||
client,
|
||||
data: ConstructionUpdate,
|
||||
push_id: str,
|
||||
biz_id: str,
|
||||
*,
|
||||
steps: List[Dict[str, Any]] | None = None,
|
||||
) -> None:
|
||||
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="/construction/update", data=request_data)
|
||||
if response.get("code") != 200:
|
||||
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
|
||||
@@ -306,9 +358,16 @@ async def api_get_construction_task(client, task_id: str) -> Dict[str, Any]:
|
||||
return response.get("data", {})
|
||||
|
||||
|
||||
async def api_update_construction_task_plan(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
|
||||
async def api_update_construction_task_plan(
|
||||
client,
|
||||
data: Dict[str, Any],
|
||||
push_id: str,
|
||||
biz_id: str,
|
||||
*,
|
||||
steps: List[Dict[str, Any]] | None = None,
|
||||
) -> None:
|
||||
"""PUT /construction/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="/construction/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