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

This commit is contained in:
2026-11-05 15:20:34 +08:00
parent b976b80d9d
commit 4e8b3e7d43
230 changed files with 19827 additions and 1440 deletions
@@ -48,7 +48,7 @@ class ChongqingSocialChangePlugin(ScenePlugin):
id = "xq0008"
name = "重庆社保增减员办理"
version = "1.0.6"
version = "1.0.8"
description = ("重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + "
"XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、"
"增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号"
@@ -515,10 +515,27 @@ def _to_text(value):
def _clean_value(value):
"""None/NaN 归一为 '',其余原样(用于写入单元格)。"""
"""归一单元格取值:None/NaN/NaT → '',numpy 标量 → Python 原生类型。
xlwt 的 ws.write 只接受 str/int/float/bool/Decimal/datetime/None,
直接写 numpy.int64 会抛 `Unexpected data type <class 'numpy.int64'>`,
因此这里统一做一次类型归零(pandas 读表得到的都是 numpy 标量)。
"""
if value is None:
return ''
import math
try:
import numpy as np
if isinstance(value, np.generic): # numpy.int64 / float64 / bool_ 等
value = value.item()
except ImportError:
pass
try:
import pandas as pd
if pd.isna(value): # NaN / NaT / pd.NA
return ''
except (TypeError, ValueError, ImportError):
pass
if isinstance(value, float) and math.isnan(value):
return ''
return value
@@ -554,14 +571,52 @@ def _id_hit(cid, ref_ids):
return bool(cid) and cid in ref_ids
def _xlsx_valid(path):
"""校验 .xlsx 是否有效(OOXML 是 ZIP 包,文件头应为 PK\\x03\\x04)。
返回 (是否有效, 说明)。常见无效原因:0 KB 空文件、把 .xls 直接改名成 .xlsx、
文件损坏、或正被 Excel/WPS 独占写入。
"""
try:
size = os.path.getsize(path)
except OSError as e:
return False, f"无法读取:{e}"
if size == 0:
return False, "空文件(0 KB)"
try:
with open(path, "rb") as f:
head = f.read(4)
except OSError as e:
return False, f"无法读取:{e}"
if head != b"PK\x03\x04":
return False, f"非有效 xlsx(文件头不是 ZIP,{size / 1024:.0f} KB," \
f"可能是 .xls 改名/损坏/被占用)"
return True, f"{size / 1024:.0f} KB"
def _latest_file(directory, pattern):
"""目录内按模式取最新文件(排除 Excel 临时文件 ~$)。"""
"""目录内按模式取最新文件(排除 Excel 临时文件 ~$)。
.xlsx 额外做有效性校验:最新候选不是有效 xlsx 时直接报错,**不静默回退**
到历史月份名单(否则会按旧数据生成导入名单、回写错办理状态)。
"""
from glob import glob
candidates = [p for p in glob(os.path.join(directory, pattern))
if not os.path.basename(p).startswith("~$")]
if not candidates:
raise FileNotFoundError(f"在 {directory} 下未找到匹配 {pattern} 的文件")
return max(candidates, key=os.path.getmtime)
candidates.sort(key=os.path.getmtime, reverse=True)
if pattern.lower().endswith(".xlsx"):
ok, detail = _xlsx_valid(candidates[0])
if not ok:
others = ";".join(f"{os.path.basename(p)}({_xlsx_valid(p)[1]})"
for p in candidates[1:6]) or "无"
raise ValueError(
f"最新文件不是有效的 xlsx:{os.path.basename(candidates[0])}({detail})"
f";同目录其它候选:{others}。"
f"请确认该文件是否为 0 KB 空文件、是否把 .xls 直接改名成 .xlsx、"
f"是否正被 Excel/WPS 打开(用「另存为 → Excel 工作簿(*.xlsx)」重存后重试)")
return candidates[0]
def _pick_sheet(xl, exact_name, keyword, pattern=None):
@@ -63,17 +63,27 @@ def check_directory():
add("资料根目录", base_ok, base if base_ok else f"目录不存在:{base}")
# ---- 1. 名单制作 / 系统办理:源名单 ----
src_file = None
src_file, src_error = None, ""
candidates = []
if base_ok:
candidates = [p for p in os.listdir(base)
if p.lower().endswith(".xlsx") and not p.startswith("~$")
and config.SOURCE_KEYWORD in p]
add(f"源名单(*{config.SOURCE_KEYWORD}*.xlsx)", bool(candidates),
"、".join(sorted(candidates)[:3]) or "未找到,请放入当月《社保变更及增减名单》")
if candidates:
src_file = os.path.join(base, max(
candidates, key=lambda n: os.path.getmtime(os.path.join(base, n))))
# 逐文件带上有效性/大小,便于一眼看出哪个文件坏了(0 KB / .xls 改名 / 被占用)
detail_items = []
for n in sorted(candidates, key=lambda x: os.path.getmtime(os.path.join(base, x)),
reverse=True)[:5]:
ok_f, info = config._xlsx_valid(os.path.join(base, n))
detail_items.append(f"{n}({info})" if ok_f else f"{n}(无效:{info})")
add(f"源名单(*{config.SOURCE_KEYWORD}*.xlsx)", True, ";".join(detail_items))
try:
src_file = config._latest_file(base, config.SOURCE_GLOB)
except (ValueError, FileNotFoundError) as e:
src_error = str(e)
else:
add(f"源名单(*{config.SOURCE_KEYWORD}*.xlsx)", False,
"未找到,请放入当月《社保变更及增减名单》")
# ---- 2. 告知书数据源:当月文件 ----
if base_ok:
@@ -85,7 +95,11 @@ def check_directory():
# ---- 3. 源名单关键 sheet ----
if src_file:
ok, missing = _check_sheets(src_file, ["参保名单", "停保名单"])
add("源名单关键 sheet(参保名单/停保名单)", ok, "缺失:" + "、".join(missing) if missing else "齐备")
add("源名单关键 sheet(参保名单/停保名单)", ok,
"缺失:" + "、".join(missing) if missing else
f"齐备({os.path.basename(src_file)})")
elif src_error:
add("源名单关键 sheet(参保名单/停保名单)", False, f"无法读取:{src_error}")
else:
add("源名单关键 sheet(参保名单/停保名单)", False, "源名单缺失,跳过校验")
@@ -66,8 +66,8 @@ def _write_template_add(template_file, output_path, unit_no, unit_name, records)
orig_rows = rb.sheet_by_index(0).nrows
wb = xl_copy(rb)
ws = wb.get_sheet(0) # 批量导入
ws.write(0, 1, unit_no) # B1 社保号
ws.write(0, 3, unit_name) # D1 参保单位全称
ws.write(0, 1, config._clean_value(unit_no)) # B1 社保号
ws.write(0, 3, config._clean_value(unit_name)) # D1 参保单位全称
for i, rec in enumerate(records):
r = config.TPL_DATA_START_ROW - 1 + i # 0-based:模板第4行 → index 3
for c, col in enumerate(config.TPL_COLS_ADD):
@@ -183,8 +183,8 @@ def _write_template_stop(template_file, output_path, unit_no, unit_full_name, re
orig_rows = rb.sheet_by_index(0).nrows
wb = xl_copy(rb)
ws = wb.get_sheet(0) # 批量导入
ws.write(0, 1, unit_no) # B1 单位社保号
ws.write(0, 3, unit_full_name) # D1 单位全称
ws.write(0, 1, config._clean_value(unit_no)) # B1 单位社保号
ws.write(0, 3, config._clean_value(unit_full_name)) # D1 单位全称
for i, rec in enumerate(records):
r = config.TPL_DATA_START_ROW - 1 + i
for c, col in enumerate(config.TPL_COLS_STOP):
@@ -2,7 +2,7 @@
"schema_version": 1,
"id": "xq0008",
"name": "重庆社保增减员办理",
"version": "1.0.6",
"version": "1.0.8",
"description": "重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号登录重庆人社政务平台(法人用户+图形验证码识别)完成导入申报、审核结论核查与回盘表核对,回写源名单办理状态/办理停保及备注;生成三类告知书并构造 OA 工作沟通推送,全程 JSON 缓存防崩溃、结束统一落盘。",
"category": "社保",
"icon": "",