73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
"""
|
|
空运群取消舱位待确认。
|
|
|
|
航线说出和舱位有关的「释放」后先问一句,确认前不打 TMS。
|
|
短协调,不当六态、不当 checkpoint。按群记下工单号,双进程仍能读到。
|
|
两小时没人接话就过期,避免过后回一个「是」误取消。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
|
|
from agent.redis_coord.keys import PENDING_CABIN_CANCEL
|
|
from agent.redis_coord.runtime import get_redis_runtime
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# 问句只在这一阵有效。过期后「是」不再取消舱位。
|
|
_TTL_SECONDS = 2 * 60 * 60
|
|
|
|
|
|
def save_pending_cabin_cancel(chat_id: str, work_order_no: str) -> None:
|
|
"""记下本群正在等航线确认取消哪张单。"""
|
|
room = (chat_id or "").strip()
|
|
no = (work_order_no or "").strip()
|
|
if not room or not no:
|
|
return
|
|
payload = {"work_order_no": no}
|
|
try:
|
|
client = get_redis_runtime().client
|
|
client.raw.set(
|
|
client.key(PENDING_CABIN_CANCEL, room),
|
|
json.dumps(payload, ensure_ascii=False),
|
|
ex=_TTL_SECONDS,
|
|
)
|
|
logger.info("cabin.ask saved chat=%s wo=%s", room, no)
|
|
except Exception:
|
|
logger.exception("写取消舱位待确认失败 chat=%s", room)
|
|
|
|
|
|
def load_pending_cabin_cancel(chat_id: str) -> str:
|
|
"""本群正在等确认的工单号。没有则空串。"""
|
|
room = (chat_id or "").strip()
|
|
if not room:
|
|
return ""
|
|
try:
|
|
client = get_redis_runtime().client
|
|
raw = client.raw.get(client.key(PENDING_CABIN_CANCEL, room))
|
|
if not raw:
|
|
return ""
|
|
if isinstance(raw, bytes):
|
|
raw = raw.decode("utf-8")
|
|
data = json.loads(raw)
|
|
if not isinstance(data, dict):
|
|
return ""
|
|
return str(data.get("work_order_no") or "").strip()
|
|
except Exception:
|
|
logger.exception("读取消舱位待确认失败 chat=%s", room)
|
|
return ""
|
|
|
|
|
|
def clear_pending_cabin_cancel(chat_id: str) -> None:
|
|
"""确认、否认或改口办别的事时清掉。"""
|
|
room = (chat_id or "").strip()
|
|
if not room:
|
|
return
|
|
try:
|
|
client = get_redis_runtime().client
|
|
client.raw.delete(client.key(PENDING_CABIN_CANCEL, room))
|
|
except Exception:
|
|
logger.exception("清取消舱位待确认失败 chat=%s", room)
|