feat: 新增考勤异常模块、银行卡校验、OCR附件检测等功能
1. 新增考勤异常查询与导出模块,支持当月异常拉取、Excel导出、钉钉推送提醒 2. 完善请假/加班流程解析与校验,新增附件下载、OCR核验能力 3. 新增银行卡信息校验模块,支持在职/离职员工工资卡数据核对与异常导出 4. 新增通用OCR工具模块,支持病假/婚假/产检假附件关键词检测与日期提取 5. 新增门店请休假异常名单、银行卡检查等需求文档 6. 重构部分现有模块代码,优化配置与接口调用逻辑 7. 新增测试文件与工具类,完善项目基础能力
This commit is contained in:
@@ -158,8 +158,31 @@ COL_CHECK_RESULT = "核对结果"
|
||||
COL_CHECK_BASIS = "校验依据"
|
||||
|
||||
# ---------- 银行卡校验规则 ----------
|
||||
BIN_16 = {"621483", "622622", "621691", "622619", "622620"}
|
||||
BIN_18 = {"622908"}
|
||||
# 16 位银联卡 BIN(按银行归类,经实际工资卡数据比对核验)
|
||||
BIN_16 = {
|
||||
# 招商银行
|
||||
"621483", "621485", "621486", "622588", "622609",
|
||||
# 民生银行
|
||||
"621691", "622615", "622617", "622619", "622620", "622622",
|
||||
# 民生银行信用卡(16 位贷记卡)
|
||||
"622601",
|
||||
# 重庆农村商业银行
|
||||
"621258", "621465", "621528", "622867",
|
||||
# 浦东发展银行
|
||||
"621792", "621793", "622521",
|
||||
# 其他银行
|
||||
"621499", # 建设银行理财金卡
|
||||
"621755", # 重庆三峡银行
|
||||
"623020", # 华夏银行
|
||||
}
|
||||
# 18 位银联储蓄卡 BIN
|
||||
BIN_18 = {"622908"} # 兴业银行
|
||||
# 非 62 开头但合法的老版储蓄卡 BIN(历史卡仍在使用,标准均为 19 位)
|
||||
NON62_BIN = {
|
||||
"436742", # 建设银行龙卡储蓄卡
|
||||
"601382", # 中国银行长城电子借记卡
|
||||
"955882", # 工商银行牡丹灵通卡
|
||||
}
|
||||
NUM_REG = re.compile(r"^\d+$")
|
||||
|
||||
|
||||
@@ -618,17 +641,18 @@ def check_bank_card(card_raw):
|
||||
return {"card": card, "status": "无效", "reason": "空白,无卡号"}
|
||||
if not NUM_REG.match(card):
|
||||
return {"card": card, "status": "无效", "reason": "非纯数字,属于文字备注/脏数据"}
|
||||
if not card.startswith("62"):
|
||||
|
||||
bin6 = card[:6]
|
||||
if not (card.startswith("62") or bin6 in NON62_BIN):
|
||||
return {"card": card, "status": "无效", "reason": "非62开头,非标准银联储蓄卡"}
|
||||
|
||||
card_len = len(card)
|
||||
if card_len not in (16, 18, 19):
|
||||
return {"card": card, "status": "错误", "reason": f"位数异常{card_len}位,仅支持16/18/19位银行卡"}
|
||||
|
||||
bin6 = card[:6]
|
||||
if bin6 in BIN_16:
|
||||
if card_len == 16:
|
||||
return {"card": card, "status": "正常", "reason": "合规16位储蓄卡"}
|
||||
return {"card": card, "status": "正常", "reason": "合规16位银联卡"}
|
||||
else:
|
||||
return {"card": card, "status": "错误", "reason": f"BIN{bin6}标准16位,录入位数错误"}
|
||||
if bin6 in BIN_18:
|
||||
@@ -642,6 +666,55 @@ def check_bank_card(card_raw):
|
||||
return {"card": card, "status": "错误", "reason": f"BIN{bin6}标准19位,录入位数错误,需人工核对"}
|
||||
|
||||
|
||||
# ==================== 核对分类 ====================
|
||||
def classify_card_issue(idcard, card_idcard, staff_name, card_name, bank_account):
|
||||
"""按 4 类异常对单条工资卡记录分类。
|
||||
|
||||
返回 (issues, basis, id_inconsistent, bank_info)
|
||||
issues: 4 类异常标签(写入核对结果)
|
||||
basis : 详细校验依据(写入校验依据)
|
||||
1. 开户人信息或银行卡空白
|
||||
2. 员工身份证与开户人身份证不一致
|
||||
3. 员工姓名与开户人姓名不一致(仅身份证一致时比对)
|
||||
4. 银行卡信息异常(银行卡非空但格式/位数错误)
|
||||
"""
|
||||
issues = []
|
||||
basis = []
|
||||
bank_info = None
|
||||
|
||||
# ---- 1. 开户人信息或银行卡空白 ----
|
||||
if _is_empty(card_idcard):
|
||||
issues.append("开户人身份证空白")
|
||||
basis.append("开户人身份证空白")
|
||||
if _is_empty(card_name):
|
||||
issues.append("开户人姓名空白")
|
||||
basis.append("开户人姓名空白")
|
||||
if _is_empty(bank_account):
|
||||
issues.append("银行卡空白")
|
||||
basis.append("银行卡空白")
|
||||
|
||||
# ---- 2. 身份证不一致(开户人身份证非空且与员工不一致) ----
|
||||
id_inconsistent = (not _is_empty(card_idcard)) and idcard != card_idcard
|
||||
if id_inconsistent:
|
||||
issues.append("员工身份证与开户人身份证不一致")
|
||||
basis.append(f"身份证不一致(员工:{idcard} vs 开户人:{card_idcard})")
|
||||
|
||||
# ---- 3. 姓名不一致(仅身份证一致时比对) ----
|
||||
if (not id_inconsistent and not _is_empty(card_idcard)
|
||||
and not _is_empty(card_name) and staff_name != card_name):
|
||||
issues.append("员工姓名与开户人姓名不一致")
|
||||
basis.append(f"姓名不一致(员工:{staff_name} vs 开户人:{card_name})")
|
||||
|
||||
# ---- 4. 银行卡信息异常(银行卡非空但格式/位数错误) ----
|
||||
if not _is_empty(bank_account):
|
||||
bank_info = check_bank_card(bank_account)
|
||||
if bank_info["status"] != "正常":
|
||||
issues.append("银行卡信息异常")
|
||||
basis.append(f"银行卡信息异常({bank_info['reason']})")
|
||||
|
||||
return issues, basis, id_inconsistent, bank_info
|
||||
|
||||
|
||||
# ==================== 核对辅助 ====================
|
||||
def _is_empty(val):
|
||||
if val is None:
|
||||
@@ -673,6 +746,8 @@ def check_wage_card(input_path, output_path=None):
|
||||
df = pd.read_excel(input_path)
|
||||
logger.info("读取工资卡汇总表:%s(%d 行)", input_path, len(df))
|
||||
|
||||
id_mismatch_rows = []
|
||||
|
||||
for idx, row in df.iterrows():
|
||||
idcard = _normalize_id(row.get(COL_IDCARD, ""))
|
||||
card_idcard = _normalize_id(row.get(COL_CARD_IDCARD, ""))
|
||||
@@ -680,30 +755,16 @@ def check_wage_card(input_path, output_path=None):
|
||||
card_name = str(row.get(COL_CARD_NAME, "")).strip()
|
||||
bank_account = row.get(COL_BANK_ACCOUNT, "")
|
||||
|
||||
issues = []
|
||||
basis = []
|
||||
|
||||
# ---- 身份证核对 ----
|
||||
if _is_empty(card_idcard):
|
||||
issues.append("开户人身份证为空")
|
||||
elif idcard != card_idcard:
|
||||
issues.append("身份证不一致")
|
||||
basis.append(f"身份证不一致(员工:{idcard} vs 开户人:{card_idcard})")
|
||||
else:
|
||||
# ---- 姓名核对(仅身份证一致时) ----
|
||||
if _is_empty(card_name):
|
||||
issues.append("开户人姓名为空")
|
||||
elif staff_name != card_name:
|
||||
issues.append("姓名不一致")
|
||||
basis.append(f"姓名不一致(员工:{staff_name} vs 开户人:{card_name})")
|
||||
|
||||
# ---- 银行卡校验 ----
|
||||
bk = check_bank_card(bank_account)
|
||||
issues, basis, id_inconsistent, bk = classify_card_issue(
|
||||
idcard, card_idcard, staff_name, card_name, bank_account,
|
||||
)
|
||||
if id_inconsistent:
|
||||
id_mismatch_rows.append(idx)
|
||||
|
||||
df.at[idx, COL_CHECK_RESULT] = "、".join(issues) if issues else "通过"
|
||||
df.at[idx, COL_CHECK_BASIS] = ";".join(basis) if basis else ""
|
||||
df.at[idx, COL_BANK_STATUS] = bk["status"]
|
||||
df.at[idx, COL_BANK_REASON] = bk["reason"]
|
||||
df.at[idx, COL_BANK_STATUS] = bk["status"] if bk else ""
|
||||
df.at[idx, COL_BANK_REASON] = bk["reason"] if bk else ""
|
||||
|
||||
# 统计
|
||||
result_counts = df[df[COL_CHECK_RESULT] != "通过"][COL_CHECK_RESULT].value_counts().to_dict()
|
||||
@@ -724,11 +785,23 @@ def check_wage_card(input_path, output_path=None):
|
||||
check_cols = [COL_CHECK_RESULT, COL_CHECK_BASIS, COL_BANK_STATUS, COL_BANK_REASON]
|
||||
other_cols = [c for c in df.columns if c not in check_cols]
|
||||
df = df[check_cols + other_cols]
|
||||
|
||||
# 保存核对结果
|
||||
df.to_excel(output_path, index=False)
|
||||
logger.info("核对结果已保存:%s", output_path)
|
||||
|
||||
# 生成异常名单
|
||||
abnormal = df[df[COL_CHECK_RESULT] != "通过"]
|
||||
# 身份证不一致单独存表(独立文件,供人工校验)
|
||||
if id_mismatch_rows:
|
||||
base, ext = os.path.splitext(output_path)
|
||||
id_path = os.path.join(os.path.dirname(base), f"身份证不一致表{ext}")
|
||||
df.loc[id_mismatch_rows].to_excel(id_path, index=False)
|
||||
logger.info("身份证不一致表已保存:%s(%d 条)", id_path, len(id_mismatch_rows))
|
||||
else:
|
||||
logger.info("无身份证不一致记录")
|
||||
|
||||
# 生成异常名单(排除已单独成表的身份证不一致记录)
|
||||
mask = (df[COL_CHECK_RESULT] != "通过") & (~df.index.isin(id_mismatch_rows))
|
||||
abnormal = df[mask]
|
||||
if len(abnormal) > 0:
|
||||
base, ext = os.path.splitext(output_path)
|
||||
abnormal_path = os.path.join(os.path.dirname(base), f"工资卡异常名单{ext}")
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1105,7 +1105,8 @@ def _read_abnormal(xlsx_path, label):
|
||||
headers = [str(h) if h is not None else "" for h in rows[0]]
|
||||
emp_col = next((i for i, h in enumerate(headers) if "工号" in h), None)
|
||||
res_col = headers.index(SI_RESULT_COL)
|
||||
name_col = next((i for i, h in enumerate(headers) if h in ("申请人", "停保人姓名")), None)
|
||||
name_candidates = ("参保人",) if label == "参保" else ("停保人姓名",)
|
||||
name_col = next((i for i, h in enumerate(headers) if h in name_candidates), None)
|
||||
abnormal = []
|
||||
for r in rows[1:]:
|
||||
val = r[res_col] if res_col < len(r) else ""
|
||||
|
||||
Reference in New Issue
Block a user