feat: 新增考勤异常模块、银行卡校验、OCR附件检测等功能

1. 新增考勤异常查询与导出模块,支持当月异常拉取、Excel导出、钉钉推送提醒
2. 完善请假/加班流程解析与校验,新增附件下载、OCR核验能力
3. 新增银行卡信息校验模块,支持在职/离职员工工资卡数据核对与异常导出
4. 新增通用OCR工具模块,支持病假/婚假/产检假附件关键词检测与日期提取
5. 新增门店请休假异常名单、银行卡检查等需求文档
6. 重构部分现有模块代码,优化配置与接口调用逻辑
7. 新增测试文件与工具类,完善项目基础能力
This commit is contained in:
2026-08-11 17:26:24 +08:00
parent 7e46b5cc06
commit 9927066abb
30 changed files with 2749 additions and 189 deletions
+13 -1
View File
@@ -5,7 +5,7 @@
@Author: 小布丁
@CreateTime: 2026-08-05 17:09
@Description: OA 系统配置,集中管理接口地址、待办类型、分页大小等常量
@Version: 1.2.0
@Version: 1.4.0
"""
# ---------- OA 系统 ----------
@@ -32,6 +32,11 @@ KQ_DATA_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_data_queryBySta
# 请假记录接口(hr 域名,按员工 + 日期范围查询请假明细)
LEAVE_RECORD_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_leave_record_SelectByStaffID/redApiExec.mc"
# 附件下载接口(hr 域名):按 fileId 下载请假单据附件
FILE_DOWNLOAD_URL = f"{HR_BASE_URL}/RedseaPlatform/corePlatformOutUser/fjkFileDownload.mob"
# 附件默认保存目录
ATTACHMENT_SAVE_DIR = r"D:\资料\人资\请假流程审批\附件"
# ---------- 加班审批规则常量(对应 aa.md 审批规则) ----------
# 次日正常上班时间 T(固定 09:00)
WORK_START_TIME = "09:00"
@@ -41,6 +46,13 @@ WORK_END_TIME = "18:00"
FLEX_TRIGGER_TIME = "23:00"
# 延时加班有效时长门槛:不足该小时数直接驳回
OT_MIN_HOURS = 1
# 跨天打卡判定:次日首条打卡时间早于该时刻(6点),视为归属加班当天的跨天有效打卡
CROSS_DAY_BEFORE_HOUR = 6
# 加班审核周期:加班日期距今天不超过该天数才允许审核
OT_REVIEW_DAYS = 8
# 月度截止:每月该日期 12:00 之后,不再审核上一个月的加班流程
MONTH_CUTOFF_DAY = 2
MONTH_CUTOFF_HOUR = 12
# ---------- 分页 ----------
DEFAULT_PAGE_SIZE = 15
+9 -3
View File
@@ -68,7 +68,7 @@ def build_push_summary(results: list, subject: str = "") -> str:
"""
根据校验结果生成钉钉推送的文字消息(多行)。
通过/驳回/人工复核三组均以文字说明推送(不再只发表格):
通过/驳回/人工复核/超期四组均以文字说明推送(不再只发表格):
- 全部通过:用简洁格式
【{subject}审批】本次审批 N 条{subject}申请,
分别是:
@@ -101,9 +101,10 @@ def build_push_summary(results: list, subject: str = "") -> str:
passed = [r for r in results if r.get("decision") == "通过"]
rejected = [r for r in results if r.get("decision") == "驳回"]
review = [r for r in results if r.get("decision") == "人工复核"]
overdue = [r for r in results if r.get("decision") == "超期"]
failed = [r for r in results if r.get("decision") == "失败"]
if not passed and not rejected and not review:
if not passed and not rejected and not review and not overdue:
return ""
def _item(r):
@@ -113,7 +114,7 @@ def build_push_summary(results: list, subject: str = "") -> str:
vtype = info.get("假期类型") or info.get("加班类型") or ""
return f"{title}-{vtype}" if vtype else title
all_pass = (not rejected and not review and not failed)
all_pass = (not rejected and not review and not overdue and not failed)
lines = []
if all_pass:
@@ -141,6 +142,11 @@ def build_push_summary(results: list, subject: str = "") -> str:
for r in review:
lines.append(_item(r))
lines.append(f"详情页:{r.get('detail_url') or '无'}")
if overdue:
lines.append(f"超期待人资处理 {len(overdue)} 条,分别是:")
for r in overdue:
lines.append(_item(r))
lines.append(f"处理原因:{r.get('note') or r.get('error') or '未知'}")
if failed:
lines.append(f"另有处理失败 {len(failed)} 条,请查看日志。")
+71 -4
View File
@@ -5,13 +5,14 @@
@Author: 小布丁
@CreateTime: 2026-08-05 17:10
@Description: OA/HR 系统 API 模块,负责调用系统接口(待办列表、流程引擎、表单、排班等)
@Version: 1.3.1
@Version: 1.4.0
"""
import time
import re
from typing import List, Dict, Any
from urllib.parse import urlencode
import os
from typing import List, Dict, Any, Optional
from urllib.parse import urlencode, unquote
from app.utils.logger import get_logger
try:
@@ -19,11 +20,77 @@ try:
except ImportError:
SessionPage = None
from app.service.hrbp.oa.common.config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL, KQ_DATA_URL, LEAVE_RECORD_URL, PAIBAN_URL
from app.service.hrbp.oa.common.config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL, KQ_DATA_URL, LEAVE_RECORD_URL, PAIBAN_URL, FILE_DOWNLOAD_URL, ATTACHMENT_SAVE_DIR
logger = get_logger(__name__)
def download_attachment(
session: SessionPage,
file_id: str,
save_dir: str = ATTACHMENT_SAVE_DIR,
) -> Optional[str]:
"""
根据附件 fileId 从 OA 下载请假单据附件。
Args:
session: 已登录的 SessionPage 对象(已带登录 Cookie)
file_id: 附件 fileId(表单 result.file 字段值,即下载链接里的 fileId)
save_dir: 保存目录(默认 downloads)
Returns:
保存的完整文件路径;失败返回 None
"""
if not file_id:
logger.warning("附件 fileId 为空,跳过下载")
return None
os.makedirs(save_dir, exist_ok=True)
url = f"{FILE_DOWNLOAD_URL}?fileId={file_id}"
logger.info("下载附件: fileId=%s", file_id)
try:
session.get(url)
resp = session.response
except Exception as e:
logger.warning("附件请求失败(fileId=%s): %s", file_id, e)
return None
if not resp or resp.status_code != 200:
logger.warning("附件下载失败: HTTP %s (fileId=%s)", resp.status_code, file_id)
return None
# 从 Content-Disposition 解析真实文件名(可能带 UTF-8'' 编码)
filename = None
cd = resp.headers.get("Content-Disposition", "")
if "filename=" in cd:
raw = cd.split("filename=")[-1].strip().strip('"')
if raw.startswith("UTF-8''"):
raw = unquote(raw.split("UTF-8''", 1)[1])
if raw:
filename = raw
# 解析不到文件名时,用 fileId 兜底,并按 Content-Type 补扩展名
if not filename:
filename = file_id
ct = (resp.headers.get("Content-Type") or "").split(";")[0].strip().lower()
ext_map = {
"image/png": ".png",
"image/jpeg": ".jpg",
"application/pdf": ".pdf",
"application/octet-stream": ".bin",
}
filename += ext_map.get(ct, ".bin")
# 清理非法字符,防止路径注入
filename = "".join(c for c in filename if c not in '\\/:*?"<>|')
path = os.path.join(save_dir, filename)
with open(path, "wb") as f:
f.write(resp.content)
logger.info("附件已下载: %s", path)
return path
# ---------- 获取待处理单据列表 ----------
def fetch_todo_page(
session: SessionPage,