增加了项目侧关于steps的处理。允许保存和提取steps信息。

This commit is contained in:
strepsiades
2026-03-11 10:34:49 +08:00
parent 291aa0b4b7
commit 1f68bd5ca8
22 changed files with 759 additions and 142 deletions
@@ -241,22 +241,41 @@ class ProjectApiHandler(BaseApiHandler):
node_updated = False
error = None
force_steps_update = self._steps_changed(node)
steps_payload = self._get_request_steps(node)
steps_sent = False
allow_force_steps = True
# 遍历所有更新 schema,检查差异并更新
for schema, api_func in update_configs:
update_data = self._get_schema_diff(schema, data, original_data, node.node_id)
update_data = self._get_schema_diff(
schema,
data,
original_data,
node.node_id,
force_full_schema=force_steps_update and allow_force_steps,
)
if not update_data:
continue
# 执行更新(差异已由 _get_schema_diff 打印)
try:
full_update_data = self._filter_update_data(data, original_data, schema)
full_update_data = self._filter_update_data(
data,
original_data,
schema,
force_full_schema=force_steps_update and allow_force_steps,
)
await self._submit_update_and_wait(
api_func=api_func,
data=full_update_data,
biz_id=biz_id,
steps=steps_payload if not steps_sent else [],
)
node_updated = True
steps_sent = steps_sent or bool(steps_payload)
allow_force_steps = False
self._mark_approval_snapshot_synced(node)
except Exception as e:
error = str(e)
break
@@ -285,9 +304,9 @@ class ProjectApiHandler(BaseApiHandler):
"""轮询异步任务状态"""
return await super().poll_tasks(task_ids)
async def _submit_update_and_wait(self, *, api_func, data: Dict[str, Any], biz_id: str) -> None:
async def _submit_update_and_wait(self, *, api_func, data: Dict[str, Any], biz_id: str, steps: List[Dict[str, Any]] | None = None) -> None:
push_id = self._generate_push_id()
await api_func(self.api_client, data, push_id, biz_id)
await api_func(self.api_client, data, push_id, biz_id, steps=steps or [])
max_attempts = 20
poll_interval = 0.2
@@ -400,46 +419,46 @@ async def api_get_project_all_info(client, project_id: str) -> Dict[str, Any]:
return validated.model_dump()
async def api_update_project_base_info(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_base_info(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project - 更新项目基本信息"""
ProjectBaseInfoUpdate.model_validate(data)
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="/project", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
async def api_update_project_key_constraints(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_key_constraints(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project/key_constraints - 更新关键节点"""
ProjectKeyConstraints.model_validate(data)
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="/project/key_constraints", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
async def api_update_project_complete_investment(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_complete_investment(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project/complete_investment - 更新完成投资"""
ProjectCompleteInvestment.model_validate(data)
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="/project/complete_investment", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
async def api_update_project_investment_decision(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_investment_decision(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project/investment_decision - 更新投资决策"""
ProjectInvestmentDecision.model_validate(data)
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="/project/investment_decision", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
async def api_update_project_dynamic_investment(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_dynamic_investment(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project/dynamic_investment - 更新动态投资"""
ProjectDynamicInvestment.model_validate(data)
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="/project/dynamic_investment", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")
@@ -447,10 +466,10 @@ async def api_update_project_dynamic_investment(client, data: Dict[str, Any], pu
async def api_update_project_settlement_investment(client, data: Dict[str, Any], push_id: str, biz_id: str) -> None:
async def api_update_project_settlement_investment(client, data: Dict[str, Any], push_id: str, biz_id: str, *, steps: List[Dict[str, Any]] | None = None) -> None:
"""PUT /project/settlement_investment - 更新结算投资"""
ProjectSettlementInvestment.model_validate(data)
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="/project/settlement_investment", data=request_data)
if response.get("code") != 200:
raise Exception(f"API error: {response.get('message', 'Unknown error')}")