Files
inquiry_robot/inquiry-agent/agent/redis_coord/pending_quote_confirm.py
T
linmianxun 04e00f0cfc checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口
- Python 同义词加载/归一化与 1板/2箱 机读
- 同步当前分支既有协作、报价识别、陆运等改动
2026-11-24 16:26:49 +08:00

80 lines
2.4 KiB
Python

"""
待确认的报价/调价:机器人先回识别回执,等成员@机器人回「确认/确定」后再出价格方案/改价。
短协调,不当六态、不当 checkpoint。Redis 正式;进程内兜底给单测和 Redis 不可用。
"""
from __future__ import annotations
import json
import logging
import time
from typing import Any
from agent.redis_coord.keys import PENDING_QUOTE_CONFIRM
from agent.redis_coord.runtime import get_redis_runtime
logger = logging.getLogger(__name__)
# 两天:跨夜也能确认;过期就当没有待确认。
_TTL_SEC = 2 * 24 * 3600
_local: dict[str, dict[str, Any]] = {}
def _no(work_order_no: str) -> str:
return (work_order_no or "").strip()
def save_pending_confirm(work_order_no: str, payload: dict[str, Any]) -> None:
"""记下刚抽出的报价/调价,等成员确认。"""
no = _no(work_order_no)
if not no or not isinstance(payload, dict) or not payload:
return
data = dict(payload)
data["_ts"] = time.time()
_local[no] = data
try:
client = get_redis_runtime().client
client.raw.set(
client.key(PENDING_QUOTE_CONFIRM, no),
json.dumps(data, ensure_ascii=False),
ex=_TTL_SEC,
)
except Exception:
logger.exception("写待确认报价失败 wo=%s", no)
def load_pending_confirm(work_order_no: str) -> dict[str, Any]:
"""取出待确认报价/调价。没有或过期返回空。"""
no = _no(work_order_no)
if not no:
return {}
local = _local.get(no)
if local:
return dict(local)
try:
client = get_redis_runtime().client
raw = client.raw.get(client.key(PENDING_QUOTE_CONFIRM, no))
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("读待确认报价失败 wo=%s", no)
return {}
def clear_pending_confirm(work_order_no: str) -> None:
"""确认/覆盖/作废后清掉,避免下一句误用旧价。"""
no = _no(work_order_no)
if not no:
return
_local.pop(no, None)
try:
client = get_redis_runtime().client
client.raw.delete(client.key(PENDING_QUOTE_CONFIRM, no))
except Exception:
logger.exception("清待确认报价失败 wo=%s", no)