feat(fulfillment): 接收并展示 order_site 客户主页截图
- 履约任务新增客户角色/平台/系统/主页截图/更新时间字段 - 迁移 0131 - order_site contractVersion=3 快照自动落客户资料 - 增加客户资料 integration 写入接口 - 工作台详情展示客户资料、平台角色比对和截图 - 补充客户资料保存/快照解析测试与对接文档
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from fastapi import HTTPException
|
||||
@@ -21,7 +22,9 @@ from .repository import (
|
||||
_find_customer_task,
|
||||
_integration_actor,
|
||||
_load_task,
|
||||
_load_task_for_update,
|
||||
)
|
||||
from .runtime import _append_event
|
||||
from .views import customer_binding_out
|
||||
|
||||
|
||||
@@ -61,6 +64,57 @@ def ensure_customer_session(
|
||||
return customer_binding_out(db, task.id)
|
||||
|
||||
|
||||
def save_customer_profile(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
customer_role_name: str,
|
||||
platform: str,
|
||||
system: str,
|
||||
home_images: list[dict[str, str]],
|
||||
commit: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
"""保存 order_site 客户资料;至少一张主页截图由 order_site 端强制。"""
|
||||
task = _load_task_for_update(db, task_id)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
raise HTTPException(status_code=409, detail="订单已结束,不能修改客户资料")
|
||||
images = []
|
||||
for item in home_images[:5]:
|
||||
url = str(item.get("url") or "").strip()
|
||||
if not url:
|
||||
continue
|
||||
images.append(
|
||||
{
|
||||
"url": url[:2048],
|
||||
"thumbnailUrl": str(item.get("thumbnail_url") or item.get("thumbnailUrl") or url)[:2048],
|
||||
"objectKey": str(item.get("object_key") or item.get("objectKey") or "")[:512],
|
||||
}
|
||||
)
|
||||
if not images:
|
||||
raise HTTPException(status_code=409, detail="客户主页截图至少需要 1 张")
|
||||
task.customer_role_name = str(customer_role_name or "").strip()[:128]
|
||||
task.customer_platform = str(platform or "").strip()[:16]
|
||||
task.customer_system = str(system or "").strip()[:16]
|
||||
task.customer_home_images = images
|
||||
task.customer_profile_updated_at = datetime.now(UTC)
|
||||
task.updated_at = datetime.now(UTC)
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"customer_profile_saved",
|
||||
actor_type="integration",
|
||||
detail={
|
||||
"customerRoleName": task.customer_role_name,
|
||||
"platform": task.customer_platform,
|
||||
"system": task.customer_system,
|
||||
"homeImageCount": len(images),
|
||||
},
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
return customer_binding_out(db, task.id)
|
||||
|
||||
|
||||
async def customer_start_binding(
|
||||
db: Session,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user