feat(shipping-notice): 添加订单抽取功能,支持异步运行和管理,优化相关数据模型和处理逻辑
This commit is contained in:
1 parent
34d489a2d1
commit
ce26d6d0c4
144 files changed
+12241
-4233
No files matched your search
@@ -54,30 +54,6 @@ 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()}"
|
||||
@@ -253,7 +229,6 @@ 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:
|
||||
@@ -412,7 +387,6 @@ 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(
|
||||
@@ -431,7 +405,6 @@ 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