feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑 - 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示 - 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败 - 新增路径工具类统一管理相对路径,优化配置文件处理逻辑 - 归档旧文档,将部署、Dify配置合并到`shipping_notice.md` - 新增完整单元测试与集成测试覆盖核心流程 - 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
1 parent
b62082758b
commit
8deae3146b
65 files changed
+6477
-1937
No files matched your search
@@ -4,69 +4,70 @@ from typing import Any
|
||||
|
||||
from sqlalchemy import desc
|
||||
|
||||
from app.models import ShippingCase, ShippingCaseEvent
|
||||
from app.models import ShippingTask, ShippingTaskEvent
|
||||
|
||||
|
||||
def serialize_case_summary(case: ShippingCase) -> dict[str, Any]:
|
||||
def serialize_task_summary(task: ShippingTask) -> dict[str, Any]:
|
||||
return {
|
||||
"id": case.id,
|
||||
"case_no": case.case_no,
|
||||
"source_type": case.source_type,
|
||||
"customer_name": case.customer_name,
|
||||
"process_status": case.process_status,
|
||||
"review_status": case.review_status,
|
||||
"match_status": case.match_status,
|
||||
"pending_human_reason": case.pending_human_reason,
|
||||
"conversation_id": case.conversation_id,
|
||||
"export_file_name": case.export_file_name,
|
||||
"freight_ref_no": case.freight_ref_no,
|
||||
"created_at": case.created_at.isoformat() if case.created_at else None,
|
||||
"updated_at": case.updated_at.isoformat() if case.updated_at else None,
|
||||
"id": task.id,
|
||||
"task_no": task.task_no,
|
||||
"source_type": task.source_type,
|
||||
"customer_name": task.customer_name,
|
||||
"process_status": task.process_status,
|
||||
"review_status": task.review_status,
|
||||
"match_status": task.match_status,
|
||||
"pending_human_reason": task.pending_human_reason,
|
||||
"conversation_id": task.conversation_id,
|
||||
"export_file_name": task.export_file_name,
|
||||
"freight_ref_no": task.freight_ref_no,
|
||||
"created_at": task.created_at.isoformat() if task.created_at else None,
|
||||
"updated_at": task.updated_at.isoformat() if task.updated_at else None,
|
||||
}
|
||||
|
||||
|
||||
def serialize_case_detail(case: ShippingCase) -> dict[str, Any]:
|
||||
data = serialize_case_summary(case)
|
||||
def serialize_task_detail(task: ShippingTask) -> dict[str, Any]:
|
||||
data = serialize_task_summary(task)
|
||||
data.update({
|
||||
"customer_code": case.customer_code,
|
||||
"ship_to": case.ship_to,
|
||||
"required_date": case.required_date,
|
||||
"lines": case.lines_json or [],
|
||||
"shortage": case.shortage_json,
|
||||
"line_results": case.line_results_json or [],
|
||||
"parse_confidence": case.parse_confidence,
|
||||
"error_message": case.error_message,
|
||||
"customer_code": task.customer_code,
|
||||
"ship_to": task.ship_to,
|
||||
"po_number": task.po_number,
|
||||
"required_date": task.required_date,
|
||||
"lines": task.lines_json or [],
|
||||
"shortage": task.shortage_json,
|
||||
"line_results": task.line_results_json or [],
|
||||
"parse_confidence": task.parse_confidence,
|
||||
"error_message": task.error_message,
|
||||
"events": [
|
||||
{
|
||||
"event_type": e.event_type,
|
||||
"detail_json": e.detail_json,
|
||||
"created_at": e.created_at.isoformat() if e.created_at else None,
|
||||
}
|
||||
for e in sorted(case.events or [], key=lambda x: x.created_at or "")
|
||||
for e in sorted(task.events or [], key=lambda x: x.created_at or "")
|
||||
],
|
||||
})
|
||||
return data
|
||||
|
||||
|
||||
def list_cases_for_user(
|
||||
def list_tasks_for_user(
|
||||
user_id: int,
|
||||
*,
|
||||
process_status: str | None = None,
|
||||
limit: int = 100,
|
||||
) -> list[dict[str, Any]]:
|
||||
q = ShippingCase.query.filter(
|
||||
(ShippingCase.user_id == user_id) | (ShippingCase.user_id.is_(None))
|
||||
q = ShippingTask.query.filter(
|
||||
(ShippingTask.user_id == user_id) | (ShippingTask.user_id.is_(None))
|
||||
)
|
||||
if process_status:
|
||||
q = q.filter(ShippingCase.process_status == process_status)
|
||||
rows = q.order_by(desc(ShippingCase.created_at)).limit(max(1, min(limit, 500))).all()
|
||||
return [serialize_case_summary(c) for c in rows]
|
||||
q = q.filter(ShippingTask.process_status == process_status)
|
||||
rows = q.order_by(desc(ShippingTask.created_at)).limit(max(1, min(limit, 500))).all()
|
||||
return [serialize_task_summary(c) for c in rows]
|
||||
|
||||
|
||||
def get_case_for_user(case_no: str, user_id: int) -> ShippingCase | None:
|
||||
case = ShippingCase.query.filter_by(case_no=case_no).first()
|
||||
if not case:
|
||||
def get_task_for_user(task_no: str, user_id: int) -> ShippingTask | None:
|
||||
task = ShippingTask.query.filter_by(task_no=task_no).first()
|
||||
if not task:
|
||||
return None
|
||||
if case.user_id is not None and case.user_id != user_id:
|
||||
if task.user_id is not None and task.user_id != user_id:
|
||||
return None
|
||||
return case
|
||||
return task
|
||||
Reference in new issue
Block a user