88 lines
2.8 KiB
Python
88 lines
2.8 KiB
Python
"""
|
|
陆运核对卡待确定:等销售回复确定后再建单。
|
|
|
|
短协调,不当六态、不当 checkpoint。进程重启或双进程抢 inbox 后仍能读到刚才那份字段。
|
|
禁止:把运输分类当已建单;写入现网 Redis 前缀。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
from typing import Any
|
|
|
|
from agent.redis_coord.keys import PENDING_LAND_CONFIRM
|
|
from agent.redis_coord.runtime import get_redis_runtime
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def save_pending_land_confirm(
|
|
sender_id: str,
|
|
*,
|
|
facts: dict[str, str],
|
|
immutable_text: str = "",
|
|
wait_version: int = 1,
|
|
phase: str = "wait_confirm",
|
|
work_order_no: str = "",
|
|
) -> None:
|
|
"""出核对卡或查价失败时记下字段,等确定建单/重查。"""
|
|
sid = (sender_id or "").strip()
|
|
if not sid or not isinstance(facts, dict) or not facts:
|
|
return
|
|
payload = {
|
|
"facts": {str(k): str(v) for k, v in facts.items() if str(v).strip()},
|
|
"immutable_text": (immutable_text or "").strip(),
|
|
"wait_version": int(wait_version or 1),
|
|
"business_line": "LAND",
|
|
"phase": (phase or "wait_confirm").strip() or "wait_confirm",
|
|
"work_order_no": (work_order_no or "").strip(),
|
|
}
|
|
try:
|
|
client = get_redis_runtime().client
|
|
# 核对卡不设过期。建单成功后由 clear 清掉。
|
|
client.raw.set(
|
|
client.key(PENDING_LAND_CONFIRM, sid),
|
|
json.dumps(payload, ensure_ascii=False),
|
|
)
|
|
logger.info(
|
|
"land.pending saved sender=%s phase=%s wo=%s keys=%s",
|
|
sid,
|
|
payload["phase"],
|
|
payload["work_order_no"] or "-",
|
|
sorted(payload["facts"]),
|
|
)
|
|
except Exception:
|
|
logger.exception("写陆运待确定失败 sender=%s", sid)
|
|
|
|
|
|
def load_pending_land_confirm(sender_id: str) -> dict[str, Any]:
|
|
"""取出待确定陆运字段。没有则空。"""
|
|
sid = (sender_id or "").strip()
|
|
if not sid:
|
|
return {}
|
|
try:
|
|
client = get_redis_runtime().client
|
|
raw = client.raw.get(client.key(PENDING_LAND_CONFIRM, sid))
|
|
if not raw:
|
|
return {}
|
|
if isinstance(raw, bytes):
|
|
raw = raw.decode("utf-8")
|
|
data = json.loads(raw)
|
|
return dict(data) if isinstance(data, dict) else {}
|
|
except Exception:
|
|
logger.exception("读陆运待确定失败 sender=%s", sid)
|
|
return {}
|
|
|
|
|
|
def clear_pending_land_confirm(sender_id: str) -> None:
|
|
"""建单且查价成功后清掉。查价失败会改记 tms_tech,不要在失败路径调用。"""
|
|
sid = (sender_id or "").strip()
|
|
if not sid:
|
|
return
|
|
try:
|
|
client = get_redis_runtime().client
|
|
client.raw.delete(client.key(PENDING_LAND_CONFIRM, sid))
|
|
except Exception:
|
|
logger.exception("清陆运待确定失败 sender=%s", sid)
|