feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -2,8 +2,8 @@
|
||||
backend/app/services/shipping_notice/intake_service.py
|
||||
|
||||
用途:发货通知接入记录(ShippingNoticeIntake)业务编排(含重复决策投影与权限)。
|
||||
依赖:file_assets.service、intake_parse_workflow、jobs.queue、models、duplicate_detection、
|
||||
attachment_integrity。
|
||||
依赖:file_assets.service、intake_parse_workflow、order_extraction、jobs.queue、models、
|
||||
duplicate_detection、attachment_integrity。
|
||||
逻辑:由 workspace API 与 chat action 调用;解析 Job 由 intake_parse_workflow 执行;
|
||||
创建 Intake:SAVEPOINT 插入 + IntegrityError 回落,mutate/enqueue 前 FOR UPDATE;
|
||||
cancelled/expired 拒绝复活;重投仅复用 queued Job(与 retry 同口径);
|
||||
@@ -54,6 +54,30 @@ def _intake_ttl_hours() -> int:
|
||||
return max(int(current_app.config.get('SHIPPING_NOTICE_INTAKE_TTL_HOURS', 72) or 72), 1)
|
||||
|
||||
|
||||
def _expire_order_extractions_for_read(
|
||||
*,
|
||||
user_id: int,
|
||||
intake_nos: list[str] | None = None,
|
||||
conversation_id: str | None = None,
|
||||
) -> int:
|
||||
"""
|
||||
在 Intake 读取入口惰性回收订单识别超时状态。
|
||||
|
||||
核心逻辑:委托 order_extraction 使用数据库快照和配置超时值完成带锁收口;
|
||||
读取接口无需依赖进程内定时器,服务重启后仍可恢复失败终态。
|
||||
|
||||
Returns:
|
||||
本次由 extracting 收口为 failed 的 Intake 数量。
|
||||
"""
|
||||
from app.services.shipping_notice.order_extraction import expire_stale_order_extractions
|
||||
|
||||
return expire_stale_order_extractions(
|
||||
user_id=user_id,
|
||||
intake_nos=intake_nos,
|
||||
conversation_id=conversation_id,
|
||||
)
|
||||
|
||||
|
||||
def generate_intake_no() -> str:
|
||||
"""生成 SNI-YYYYMMDD-XXXXXXXX 格式接入编号。"""
|
||||
return f"SNI-{datetime.utcnow().strftime('%Y%m%d')}-{uuid.uuid4().hex[:8].upper()}"
|
||||
@@ -230,6 +254,7 @@ def get_intake_for_user(intake_no: str, user_id: int) -> ShippingNoticeIntake:
|
||||
|
||||
def get_intake_detail(*, user_id: int, intake_no: str) -> dict[str, Any]:
|
||||
"""查询单个接入记录详情(含资产摘要与附件全文)。"""
|
||||
_expire_order_extractions_for_read(user_id=user_id, intake_nos=[intake_no])
|
||||
intake = get_intake_for_user(intake_no, user_id)
|
||||
asset = db.session.get(FileAsset, intake.asset_id)
|
||||
if not asset:
|
||||
@@ -387,6 +412,8 @@ def create_shipping_notice_intake(
|
||||
|
||||
def list_active_intakes_for_conversation(*, user_id: int, conversation_id: str | None) -> list[dict[str, Any]]:
|
||||
"""列出会话下未消费的活跃接入记录,供页面恢复。"""
|
||||
conv = str(conversation_id or '').strip()
|
||||
_expire_order_extractions_for_read(user_id=user_id, conversation_id=conv or None)
|
||||
query = db.session.query(ShippingNoticeIntake, FileAsset).join(
|
||||
FileAsset, FileAsset.id == ShippingNoticeIntake.asset_id
|
||||
).filter(
|
||||
@@ -394,7 +421,6 @@ def list_active_intakes_for_conversation(*, user_id: int, conversation_id: str |
|
||||
ShippingNoticeIntake.parse_status.in_(tuple(ACTIVE_INTAKE_STATUSES - {'consumed', 'expired', 'cancelled'})),
|
||||
ShippingNoticeIntake.consumed_at.is_(None),
|
||||
)
|
||||
conv = str(conversation_id or '').strip()
|
||||
if conv:
|
||||
query = query.filter(ShippingNoticeIntake.conversation_id == conv)
|
||||
rows = query.order_by(ShippingNoticeIntake.created_at.desc()).limit(50).all()
|
||||
@@ -406,6 +432,7 @@ def get_intake_statuses(*, user_id: int, intake_nos: list[str]) -> list[dict[str
|
||||
normalized = [str(item or '').strip().upper() for item in intake_nos if str(item or '').strip()]
|
||||
if not normalized:
|
||||
return []
|
||||
_expire_order_extractions_for_read(user_id=user_id, intake_nos=normalized)
|
||||
rows = (
|
||||
db.session.query(ShippingNoticeIntake, FileAsset)
|
||||
.join(FileAsset, FileAsset.id == ShippingNoticeIntake.asset_id)
|
||||
|
||||
Reference in new issue
Block a user