Files
37duAutomation/tests/xq0052_湖畔储值卡/wcf_probe.py
T
puddy 9873eb1963 restore: 恢复 11-06~11-09 本地未提交改动
- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto
- controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图
- electron-shell: 插件同步、注册表、runner 调整
- plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新
- tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
2026-11-09 17:27:10 +08:00

145 lines
6.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0052 探针:验证 WCF 只读通道能否承载「会员卡统计(余额 + 明细)」。
结论决定 SDK hotel_report 的实现路径:
· 四段式能读会员库视图 / 能调会员库标量函数 F_GetMemberMoney → 余额可改写成单条 CTE,纯 WCF 实现;
· 否则余额只能退回 pyodbc 直连(执行机需 ODBC 驱动 + 库账号)。
用法(项目根,.venv):
.venv\\Scripts\\python.exe tests\\xq0052_湖畔储值卡\\wcf_probe.py
"""
from __future__ import annotations
import os
import sys
import time
import traceback
from datetime import datetime, timedelta
BASE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(BASE, "..", "..", "libs", "hotel_report"))
from hotel_report import HotelConfig, latest_shift_time, wcf # noqa: E402
def step(no: str, title: str, sql: str, params=()) -> bool:
print(f"\n--- [{no}] {title}")
print(" SQL: " + " ".join(sql.split())[:220])
t0 = time.time()
try:
rows = wcf.query(sql, cfg, params)
except Exception as e: # noqa: BLE001
print(f" FAIL ({time.time() - t0:.1f}s): {type(e).__name__}: {e}")
return False
cost = time.time() - t0
print(f" OK {len(rows)} 行 / {cost:.1f}s")
if rows:
keys = list(rows[0].keys())
print(" 列: " + ", ".join(keys[:12]) + (" ..." if len(keys) > 12 else ""))
for r in rows[:3]:
print(" 行: " + " | ".join(f"{k}={r[k]}" for k in keys[:8]))
return True
def main() -> int:
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
global cfg
cfg = HotelConfig.resolve()
print(f"WCF: {cfg.wcf_url}")
# 0 连通性
step("0", "连通性 getdate()", "select getdate() as now")
# 1 最晚交班(昨日/今日)→ 得到余额/明细的时间窗口
start = end = None
try:
today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
prev = latest_shift_time(cfg, today - timedelta(days=1))
cur = latest_shift_time(cfg, today)
print(f"\n--- [1] 最晚交班")
print(f" 昨日 {prev['day']} → {prev['latest']}")
print(f" 今日 {cur['day']} → {cur['latest']}")
start = prev["latest"] or (today - timedelta(days=1)).strftime("%Y-%m-%d 00:00:00")
end = cur["latest"]
except Exception as e: # noqa: BLE001
print(f" FAIL: {type(e).__name__}: {e}")
if not end:
print("\n今日无交班记录,退化为最近两天做通道探测")
end = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if not start:
start = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d 00:00:00")
print(f" 探测窗口: {start} ~ {end}")
# 2 会员库视图(两段式走链接服务器默认库)
ok_view = step(
"2", "四段式读会员库视图 jgmember.dbo.V_GetMemberOperateHistory",
"select top 5 memberid, membername, feeindate, status, money "
"from jgmember.dbo.V_GetMemberOperateHistory with (nolock) order by feeindate desc")
# 2b 链接服务器 + 库名两段(抓包里的写法)
if not ok_view:
step(
"2b", "链接服务器全名 jgmember.jgmember.dbo.V_GetMemberOperateHistory",
"select top 5 memberid, feeindate from jgmember.jgmember.dbo.V_GetMemberOperateHistory "
"with (nolock) order by feeindate desc")
# 3 关键:跨库调用会员库标量函数 F_GetMemberMoney
step(
"3", "会员库标量函数 jgmember.dbo.F_GetMemberMoney('余额',...)",
"select jgmember.dbo.F_GetMemberMoney('余额','',100,null,null,null) as v")
# 4 会员系统参数(决定本金/赠金列是否显示)
step(
"4", "会员系统参数 cmbIsCalcMemberPercent",
"select ParaValue from jgmember.dbo.Dt_MemberSysPara with (nolock) "
"where ParaName='cmbIsCalcMemberPercent'")
# 5 明细主查询(单语句,golden 上执行)
detail_sql = (
"select top 5 a.feeindate, a.memberid, a.membername, a.billid, a.mobilephone, "
"a.leavecardmoney, a.money, a.truemoney, a.feetype, a.basemoney, a.giftmoney, "
"a.cardtypename, "
"dbo.F_GetMemberMoney('全部', sp.ParaValue, b.OldMoney, a.VRealPercentNum, "
"a.PRealPercentNum, NULL) as oldmoney, "
"dbo.F_GetMemberMoney('全部', sp.ParaValue, b.Shishou, a.VRealPercentNum, "
"a.PRealPercentNum, NULL) as shishou, "
"b.favourmoney, a.vpnname, a.opersite, a.persumename, a.employname as hj, "
"a.waternum, -(a.griftmoney * a.money) as factconsume, a.totalconsume, "
"a.memberremark, a.coach, a.enterdate, a.operatorname, b.jifen "
"from jgmember.dbo.V_GetMemberOperateHistory a "
"left join sn_bill b on a.billid = b.billid "
"left join dbo.Dt_SysPara sp on sp.ParaName = 'cmbIsStartAdjustBill' "
"where a.feeindate <= ? and a.feeindate >= ? "
"and a.status <> '删除' and a.Status <> '作废' and a.remark <> '非卡结' "
"order by a.memberid, a.feeindate")
step("5", "明细主查询(窗口内 top5)", detail_sql, (end, start))
# 6 明细末尾动态支付方式列
step(
"6", "充值单收款方式(按 BillId 关联 v_snchangeclass)",
"select top 5 a.Billid, b.MethodName, sum(b.PayAmount) as amt "
"from jgmember.dbo.dt_membercardcomein a "
"left join v_snchangeclass b on b.BillId = a.Billid "
"where a.feeindate >= ? and a.feeindate <= ? and a.feetype = '充值' "
"group by a.Billid, b.MethodName", (start, end))
# 7 余额改写方向验证:会员库函数在 golden 侧可用性 + 视图带 nolock 的大表扫描耗时
step(
"7", "余额所需基础数据:按 memberguid 聚合最新一笔",
"select count(*) as n from jgmember.dbo.V_GetMemberOperateHistory a with (nolock) "
"where a.FeeInDate <= ? and (a.Remark <> '非卡结' or a.Remark is null) "
"and a.status <> '删除'", (end,))
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except Exception: # noqa: BLE001
traceback.print_exc()
sys.exit(1)