88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
"""Mock runners for Mac-side state-machine verification."""
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from typing import Any
|
|
|
|
from ..runtime.errors import NodeError
|
|
|
|
|
|
def run(node_code: str, job: dict[str, Any], client: Any) -> dict[str, Any]:
|
|
if node_code == "ORDER_FETCH":
|
|
return run_order_fetch(job, client)
|
|
if node_code == "OCR_EXTRACT":
|
|
return {"summary": {"ocr": "mock"}}
|
|
if node_code == "CONTRACT_CREATE":
|
|
contract_no = f"HT{str(job.get('order_date') or '').replace('-', '')}{uuid.uuid4().hex[:5].upper()}"
|
|
return {"businessRefs": {"contractSystemNo": contract_no}, "summary": {"sourceType": job.get("source_type")}}
|
|
if node_code == "REBATE_HEADER":
|
|
return {"businessRefs": {"rebateOrderNo": f"FL-{uuid.uuid4().hex[:8].upper()}"}}
|
|
if node_code == "REBATE_IMPORT":
|
|
return {"summary": {"imported": 1, "failed": 0}}
|
|
if node_code == "REBATE_SUBMIT":
|
|
return {"summary": {"submitted": True}}
|
|
if node_code == "M5_CREATE_ORDER":
|
|
return {"businessRefs": {"m5OrderNo": f"M5-{uuid.uuid4().hex[:8].upper()}"}, "summary": {"autoSave": False}}
|
|
if node_code == "ARCHIVE_JOB":
|
|
return {"summary": {"archived": True}}
|
|
raise NodeError(f"no mock runner for {node_code}")
|
|
|
|
|
|
def run_order_fetch(job: dict[str, Any], client: Any) -> dict[str, Any]:
|
|
from pathlib import Path
|
|
import json
|
|
|
|
fixture = (
|
|
Path(__file__).resolve().parents[2]
|
|
/ "state_center"
|
|
/ "fixtures"
|
|
/ "orders"
|
|
/ "yyc-fujian-20260804.json"
|
|
)
|
|
order_date = str(job.get("order_date") or "2026-08-12")
|
|
if fixture.is_file():
|
|
data = json.loads(fixture.read_text(encoding="utf-8"))
|
|
row = data["row"]
|
|
order_no = row.get("orderNo") or f"DD-{order_date.replace('-', '')}-001"
|
|
rows = [
|
|
{
|
|
"orderNo": order_no,
|
|
"rawProductName": row["rawProductName"],
|
|
"platformProductCode": row.get("platformProductCode"),
|
|
"spec": row.get("spec"),
|
|
"manufacturer": row.get("manufacturer"),
|
|
"approvalNo": row.get("approvalNo"),
|
|
"qty": row.get("qty") or 1,
|
|
"sourceRowNo": row.get("sourceRowNo"),
|
|
}
|
|
]
|
|
else:
|
|
order_no = f"DD-{order_date.replace('-', '')}-001"
|
|
rows = [
|
|
{
|
|
"orderNo": order_no,
|
|
"rawProductName": "阿卡波糖片",
|
|
"platformProductCode": "YP-001",
|
|
"spec": "50mg*30片",
|
|
"manufacturer": "示例制药",
|
|
"approvalNo": "国药准字H00000001",
|
|
"qty": 100,
|
|
"unitPrice": 25.5,
|
|
"sourceRowNo": 1,
|
|
}
|
|
]
|
|
if hasattr(client, "ingest_items"):
|
|
client.ingest_items(job["job_id"], rows, replace=True)
|
|
return {
|
|
"summary": {
|
|
"orderCount": 1,
|
|
"supplierList": [job.get("supplier_name")],
|
|
"orderNoList": [order_no],
|
|
},
|
|
"artifacts": [{
|
|
"artifactType": "SOURCE_EXCEL",
|
|
"storagePath": f"/tmp/mock_rpa_data/orders_{job.get('supplier_name')}_{order_date}.xlsx",
|
|
"fileHash": "sha256:mock-order-excel",
|
|
}],
|
|
}
|