- 新增 logic/snapshot.py:导出后落快照,台账失败可复用上次导出数据重试,不用重新取数 - 台账只走 WPS 表格(不调 Office),字段提示同步改为关闭 WPS - 新增 通联扫码统计 支付数据追加 / 流程 两个测试;前端重建(ui 产物 + usePluginUI/style 拆分)
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""把 SDK `hotel_report` 包成台账维护要的取数接口(带缓存,补多天时不重复查)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
from .ledger import DataProvider
|
|
|
|
|
|
def _norm_ts(value) -> str:
|
|
"""时间文本归一:`2026-11-09T07:00:15+08:00` / `2026-11-09 07:00:15` → 前 19 位比较。"""
|
|
return str(value or "").strip().replace("T", " ")[:19]
|
|
|
|
|
|
class SdkProvider(DataProvider):
|
|
"""`latest_shift` / `detail` / `balance` 三个入口,结果按参数缓存。
|
|
|
|
节流由 SDK 的 `wcf.query` 统一负责(0.3.1 起),这里不用管。
|
|
"""
|
|
|
|
def __init__(self, sdk, cfg):
|
|
self.sdk = sdk
|
|
self.cfg = cfg
|
|
self._latest: dict = {}
|
|
self._detail: dict = {}
|
|
self._balance: dict = {}
|
|
|
|
def latest_shift(self, day: date):
|
|
if day not in self._latest:
|
|
info = self.sdk.latest_shift_time(self.cfg, day)
|
|
self._latest[day] = info.get("latest")
|
|
return self._latest[day]
|
|
|
|
def detail(self, start: str, end: str):
|
|
key = (start, end)
|
|
if key not in self._detail:
|
|
self._detail[key] = self.sdk.collect.collect_member_detail(
|
|
start, end, self.cfg, window=(start, end))
|
|
return self._detail[key]
|
|
|
|
def balance(self, end: str):
|
|
if end not in self._balance:
|
|
self._balance[end] = self.sdk.collect.collect_member_balance(
|
|
end, self.cfg)
|
|
return self._balance[end]
|
|
|
|
|
|
class SnapshotProvider(SdkProvider):
|
|
"""维护台账时用:余额/明细优先命中「导出快照」,没命中才回查 WCF。
|
|
|
|
导出那天的窗口数据一定在快照里(余额 20 万行、明细一整天的流水),所以
|
|
「只维护台账」不用重新取数;台账落后多天、要补历史时,那几天的明细快照里没有,
|
|
自然回退到查库(一次一条 SQL,很快),不会碰导出表。
|
|
"""
|
|
|
|
def __init__(self, sdk, cfg, snapshot: dict | None = None, log=None):
|
|
super().__init__(sdk, cfg)
|
|
self.snapshot = snapshot or {}
|
|
self.log = log or (lambda msg, level="INFO": None)
|
|
self.hits = {"balance": False, "detail": 0}
|
|
|
|
def balance(self, end: str):
|
|
table = self.snapshot.get("balance")
|
|
if table is not None:
|
|
got = getattr(table, "window", ()) or ("", "")
|
|
if _norm_ts(got[-1]) == _norm_ts(end):
|
|
self.hits["balance"] = True
|
|
return table
|
|
self.log("快照余额时间 %s ≠ 需要的 %s,改为重新取数" % (got[-1] or "空", end), "WARN")
|
|
return super().balance(end)
|
|
|
|
def detail(self, start: str, end: str):
|
|
table = self.snapshot.get("detail")
|
|
if table is not None:
|
|
got = getattr(table, "window", ()) or ("", "")
|
|
if _norm_ts(got[0]) == _norm_ts(start) and _norm_ts(got[-1]) == _norm_ts(end):
|
|
self.hits["detail"] += 1
|
|
return table
|
|
return super().detail(start, end)
|