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
@@ -6,9 +6,9 @@ Hxops 与货代系统之间通过 **目录 + JSON 触发文件** 解耦,RPA
|
||||
|
||||
| 环境变量 | 用途 |
|
||||
|---------|------|
|
||||
| `FREIGHT_RPA_INVENTORY_TRIGGER_DIR` | hxops 写入 `inventory_export_{case_no}.json`,RPA 读取后导库存 |
|
||||
| `FREIGHT_RPA_INVENTORY_TRIGGER_DIR` | hxops 写入 `inventory_export_{task_no}.json`,RPA 读取后导库存 |
|
||||
| `FREIGHT_INVENTORY_DROP_DIR` | RPA 落盘库存 Excel(`.xlsx`),hxops / worker 回调 ingest |
|
||||
| `FREIGHT_RPA_UPLOAD_TRIGGER_DIR` | hxops 写入 `upload_{case_no}.json` |
|
||||
| `FREIGHT_RPA_UPLOAD_TRIGGER_DIR` | hxops 写入 `upload_{task_no}.json` |
|
||||
| `FREIGHT_UPLOAD_QUEUE_DIR` | hxops 复制待上传发货 Excel |
|
||||
|
||||
## 开发环境 Mock
|
||||
|
||||
@@ -45,7 +45,15 @@ def _require_path(name: str) -> Path:
|
||||
value = _env(name)
|
||||
if not value:
|
||||
raise SystemExit(f"Missing env: {name}")
|
||||
backend_dir = Path(__file__).resolve().parents[2] / "backend"
|
||||
path = Path(value)
|
||||
if not path.is_absolute():
|
||||
normalized = value.replace("\\", "/")
|
||||
if normalized.startswith("backend/"):
|
||||
path = backend_dir / normalized[len("backend/") :]
|
||||
else:
|
||||
path = backend_dir / value
|
||||
path = path.resolve()
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path
|
||||
|
||||
@@ -76,7 +84,7 @@ def _post_callback(path: str, payload: dict) -> None:
|
||||
print(f"[callback] {path} HTTP {exc.code}: {err[:300]}", file=sys.stderr)
|
||||
|
||||
|
||||
def _write_sample_inventory(drop_dir: Path, case_no: str) -> Path:
|
||||
def _write_sample_inventory(drop_dir: Path, task_no: str) -> Path:
|
||||
sample = _env("FREIGHT_RPA_SAMPLE_INVENTORY")
|
||||
if sample and Path(sample).is_file():
|
||||
dest = drop_dir / Path(sample).name
|
||||
@@ -86,7 +94,7 @@ def _write_sample_inventory(drop_dir: Path, case_no: str) -> Path:
|
||||
if Workbook is None:
|
||||
raise RuntimeError("openpyxl required to generate mock inventory")
|
||||
|
||||
dest = drop_dir / f"inventory_{case_no}_{datetime.utcnow().strftime('%Y%m%d%H%M%S')}.xlsx"
|
||||
dest = drop_dir / f"inventory_{task_no}_{datetime.utcnow().strftime('%Y%m%d%H%M%S')}.xlsx"
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Inventory"
|
||||
@@ -99,8 +107,8 @@ def _write_sample_inventory(drop_dir: Path, case_no: str) -> Path:
|
||||
|
||||
def _handle_inventory_trigger(trigger_path: Path, drop_dir: Path, processed_dir: Path) -> None:
|
||||
body = json.loads(trigger_path.read_text(encoding="utf-8"))
|
||||
case_no = str(body.get("case_no") or "").strip()
|
||||
if not case_no:
|
||||
task_no = str(body.get("task_no") or "").strip()
|
||||
if not task_no:
|
||||
print(f"[skip] invalid inventory trigger: {trigger_path.name}")
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
return
|
||||
@@ -111,19 +119,19 @@ def _handle_inventory_trigger(trigger_path: Path, drop_dir: Path, processed_dir:
|
||||
return
|
||||
|
||||
try:
|
||||
out_file = _write_sample_inventory(drop_dir, case_no)
|
||||
out_file = _write_sample_inventory(drop_dir, task_no)
|
||||
_post_callback("/api/shipping-notice/rpa/inventory-ready", {
|
||||
"case_no": case_no,
|
||||
"task_no": task_no,
|
||||
"success": True,
|
||||
"file_path": str(out_file),
|
||||
})
|
||||
processed_dir.mkdir(parents=True, exist_ok=True)
|
||||
done = processed_dir / trigger_path.name
|
||||
trigger_path.replace(done)
|
||||
print(f"[inventory] mock export done for {case_no} -> {out_file.name}")
|
||||
print(f"[inventory] mock export done for {task_no} -> {out_file.name}")
|
||||
except Exception as exc:
|
||||
_post_callback("/api/shipping-notice/rpa/inventory-ready", {
|
||||
"case_no": case_no,
|
||||
"task_no": task_no,
|
||||
"success": False,
|
||||
"error_message": str(exc),
|
||||
})
|
||||
@@ -132,9 +140,9 @@ def _handle_inventory_trigger(trigger_path: Path, drop_dir: Path, processed_dir:
|
||||
|
||||
def _handle_upload_trigger(trigger_path: Path, processed_dir: Path) -> None:
|
||||
body = json.loads(trigger_path.read_text(encoding="utf-8"))
|
||||
case_no = str(body.get("case_no") or "").strip()
|
||||
task_no = str(body.get("task_no") or "").strip()
|
||||
file_path = str(body.get("file_path") or "").strip()
|
||||
if not case_no:
|
||||
if not task_no:
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
return
|
||||
|
||||
@@ -145,23 +153,23 @@ def _handle_upload_trigger(trigger_path: Path, processed_dir: Path) -> None:
|
||||
|
||||
if file_path and not Path(file_path).is_file():
|
||||
_post_callback("/api/shipping-notice/rpa/upload-complete", {
|
||||
"case_no": case_no,
|
||||
"task_no": task_no,
|
||||
"success": False,
|
||||
"error_message": f"queue file missing: {file_path}",
|
||||
})
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
return
|
||||
|
||||
ref = f"MOCK-{case_no}-{datetime.utcnow().strftime('%H%M%S')}"
|
||||
ref = f"MOCK-{task_no}-{datetime.utcnow().strftime('%H%M%S')}"
|
||||
_post_callback("/api/shipping-notice/rpa/upload-complete", {
|
||||
"case_no": case_no,
|
||||
"task_no": task_no,
|
||||
"success": True,
|
||||
"freight_ref_no": ref,
|
||||
})
|
||||
processed_dir.mkdir(parents=True, exist_ok=True)
|
||||
done = processed_dir / trigger_path.name
|
||||
trigger_path.replace(done)
|
||||
print(f"[upload] mock upload done for {case_no} ref={ref}")
|
||||
print(f"[upload] mock upload done for {task_no} ref={ref}")
|
||||
|
||||
|
||||
def _scan_triggers(trigger_dir: Path, handler, extra_args: tuple = ()) -> None:
|
||||
|
||||
Reference in new issue
Block a user