feat: 新增交通银行数据导出插件及测试通道机制

This commit is contained in:
2026-11-05 15:20:34 +08:00
parent 85051f979b
commit 4bac1248ad
230 changed files with 19827 additions and 1440 deletions
+80
View File
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
"""临时校验脚本(用后即删):影刀版 attendance_points_update.py 新增快照逻辑。"""
import importlib.util
import os
import shutil
from datetime import date
import openpyxl
ROOT = os.path.dirname(os.path.abspath(__file__))
WF = os.path.join(ROOT, "workflows", "XQ0001-0100", "XQ0033 门店管理及服务岗出勤积分更新",
"attendance_points_update.py")
spec = importlib.util.spec_from_file_location("wf_xq0033", WF)
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
SRC = r"D:\资料\人资\门店管理及服务岗出勤积分更新"
TMP = os.path.join(ROOT, ".tmp_wf0033")
os.makedirs(TMP, exist_ok=True)
shutil.copy2(os.path.join(SRC, "员工出勤及遵章积分导入1026.xlsx"),
os.path.join(TMP, "员工出勤及遵章积分导入1026.xlsx"))
shutil.copy2(os.path.join(SRC, "员工出勤及遵章积分导入1018.xlsx"),
os.path.join(TMP, "员工出勤及遵章积分导入1018.xlsx"))
m.TARGET_DIR = TMP
m.STATE_FILE = os.path.join(TMP, "_xq0033_state.json")
try:
# 1) 按积分日期找上轮文件
got = m.pick_prev_file(date(2026, 10, 18))
print("pick_prev_file(10-18) ->", os.path.basename(got or ""))
assert got and os.path.basename(got).endswith("1018.xlsx")
assert m.pick_prev_file(date(2026, 10, 25)) is None
# 2) 新建批次:源文件按积分日期最大
path, is_new, covered = m.pick_target_file(date(2026, 10, 25))
print("pick_target_file(10-25) ->", os.path.basename(path), is_new, covered)
assert os.path.basename(path).endswith("1023.xlsx") and is_new and covered == date(2026, 10, 26)
# 3) 上轮文件今日导出 → 本批前一日导出
wb = openpyxl.load_workbook(os.path.join(TMP, "员工出勤及遵章积分导入1026.xlsx"))
try:
assert m.read_report_month(wb) == (2026, 10)
t2 = date(2026, 11, 3)
assert m._is_new_month((2026, 10), date(2026, 10, 26), t2) is True
assert m._is_new_month((2026, 11), date(2026, 10, 26), t2) is False
assert m._is_new_month(None, date(2026, 10, 26), t2) is True
assert m._is_new_month(None, date(2026, 10, 28), date(2026, 10, 30)) is False
assert m._is_new_month(None, None, t2) is False
src = openpyxl.load_workbook(os.path.join(TMP, "员工出勤及遵章积分导入1018.xlsx"),
data_only=True, read_only=True)
try:
expect = [list(r) for r in src[m.SHEET_TODAY].iter_rows(
min_row=m.EXP_DATA_START, min_col=1, max_col=41, values_only=True)]
finally:
src.close()
while expect and all(v in (None, "") for v in expect[-1]):
expect.pop()
n = m.copy_file_today_to_prev(wb, os.path.join(TMP, "员工出勤及遵章积分导入1018.xlsx"))
assert n == len(expect), (n, len(expect))
ws = wb[m.SHEET_PREV]
for i in range(0, min(len(expect), 50)):
row = [ws.cell(row=m.EXP_DATA_START + i, column=c).value for c in (1, 9, 10)]
assert row == [expect[i][0], expect[i][8], expect[i][9]], (i, row, expect[i][:10])
print(f"copy_file_today_to_prev OK:{n} 行,前 50 行一致")
m.reset_snapshots(wb)
for name in (m.SHEET_TODAY, m.SHEET_PREV):
last = m._scan_last_data_row(wb[name], 1, m.EXP_DATA_START)
assert last == m.EXP_DATA_START - 1, (name, last)
assert wb[m.SHEET_PREV].cell(row=4, column=1).value == "工号"
print("reset_snapshots OK")
finally:
wb.close()
finally:
shutil.rmtree(TMP, ignore_errors=True)
print("ALL OK")