feat: 新增打卡明细接口支持,优化加班校验逻辑

1. 新增打卡明细接口封装,支持单页查询与自动分页获取员工真实打卡记录
2. 重构加班校验逻辑,使用打卡明细接口替代原考勤逐日接口的打卡字段,解决跨天打卡归属错误问题
3. 移除过时的打卡时间解析与单条打卡修正逻辑,简化代码维护
4. 优化OA登录脚本,新增requests依赖并完善会话校验逻辑
5. 新增钉钉群机器人推送通用模块,支持多场景通知推送
This commit is contained in:
2026-08-18 13:35:11 +08:00
parent c95720514b
commit 60112ad367
8 changed files with 1163 additions and 290 deletions
+6
View File
@@ -35,6 +35,12 @@ ATTENDANCE_DAILY_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_count_
# 请假记录接口(hr 域名,按员工 + 日期范围查询请假明细)
LEAVE_RECORD_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_leave_record_SelectByStaffID/redApiExec.mc"
# 打卡明细接口(hr 域名,按员工 + 日期范围查询真实打卡明细)
# kq_time=真实打卡时间、bc_date=考勤归属日(跨天打卡次日0点~6点归入前一天)、
# time_order=上下班类型(1=上班、2=下班)。加班校验用其替代考勤逐日接口的打卡字段,
# 避免人工拼接日期导致跨天打卡归属错误。
PUNCH_RECORD_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_data_queryByStaffId/redApiExec.mc"
# 附件下载接口(hr 域名):按 fileId 下载请假单据附件
FILE_DOWNLOAD_URL = f"{HR_BASE_URL}/RedseaPlatform/corePlatformOutUser/fjkFileDownload.mob"
# 附件默认保存目录
@@ -31,6 +31,10 @@ from app.service.hrbp.oa.common.oa_api.leave import (
fetch_leave_record_page,
get_leave_records,
)
from app.service.hrbp.oa.common.oa_api.punch import (
fetch_punch_record_page,
get_punch_records,
)
__all__ = [
"oa_request_json",
@@ -46,4 +50,6 @@ __all__ = [
"get_attendance_daily",
"fetch_leave_record_page",
"get_leave_records",
"fetch_punch_record_page",
"get_punch_records",
]
+132
View File
@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
"""
@Module: hrbp.oa.common.oa_api
@FileName: punch.py
@Description: 员工打卡明细接口:单页查询与自动分页。
kq_time 为真实打卡时间,bc_date 为考勤归属日(跨天打卡次日0点~6点归入前一天)。
@Version: 1.0.0
"""
from typing import List, Dict, Any
from app.utils.logger import get_logger
try:
from DrissionPage import SessionPage
except ImportError:
SessionPage = None
from app.service.hrbp.oa.common.config import PUNCH_RECORD_URL, DEFAULT_PAGE_SIZE
from app.service.hrbp.oa.common.oa_api.base import oa_request_json
logger = get_logger(__name__)
def fetch_punch_record_page(
session: SessionPage,
staff_id: str,
begin_date: str,
end_date: str,
page_no: int = 1,
page_size: int = DEFAULT_PAGE_SIZE,
sub_type: str = "-1"
) -> Dict[str, Any]:
"""
请求单页员工打卡明细。
Args:
session: 已登录的 SessionPage 对象
staff_id: 员工 UUID
begin_date: 查询起始日期 "YYYY-MM-DD"(同时作为 bc_date/bc_date_end/begin/end)
end_date: 查询结束日期 "YYYY-MM-DD"
page_no: 页码(从1开始)
page_size: 每页条数
sub_type: 类型编码,默认 "-1" 表示全部
Returns:
接口返回的 data 字段字典,包含 total / pageCount / list
Raises:
RuntimeError: 请求失败或响应异常
"""
data = {
"start": str((page_no - 1) * page_size),
"sortType": "",
"sortName": "",
"pageNo": str(page_no),
"pageSize": str(page_size),
"staff_id": staff_id,
"rootId": "",
"countId": "",
"bc_date": begin_date,
"bc_date_end": end_date,
"begin": begin_date,
"end": end_date,
"sub_type": sub_type,
}
logger.info("获取打卡明细: staff_id=%s, %s 至 %s, 第%d页", staff_id, begin_date, end_date, page_no)
json_data = oa_request_json(session, "POST", PUNCH_RECORD_URL, data, "打卡明细")
if json_data.get("success") is not True or json_data.get("code") != 200:
raise RuntimeError(f"打卡明细接口返回失败: {json_data}")
page_info = json_data.get("data")
if not isinstance(page_info, dict):
raise RuntimeError(f"打卡明细接口未返回 data 字段: {json_data}")
return page_info
def get_punch_records(
session: SessionPage,
staff_id: str,
begin_date: str,
end_date: str,
page_size: int = DEFAULT_PAGE_SIZE,
sub_type: str = "-1"
) -> List[Dict[str, Any]]:
"""
查询员工某时间段内的全部打卡明细(自动分页)。
Args:
session: 已登录的 SessionPage 对象
staff_id: 员工 UUID
begin_date: 查询起始日期 "YYYY-MM-DD"
end_date: 查询结束日期 "YYYY-MM-DD"
page_size: 每页条数
sub_type: 类型编码,默认 "-1" 表示全部
Returns:
打卡明细列表,每条包含:
- kq_time: 真实打卡时间 "YYYY-MM-DD HH:MM:SS"
- bc_date: 考勤归属日 "YYYY-MM-DD"(跨天打卡次日0点~6点归入前一天)
- time_order: 上下班类型 "1"=上班 "2"=下班
- status: 打卡状态
- address: 打卡地点
Raises:
RuntimeError: 请求失败或响应异常
"""
all_records: List[Dict[str, Any]] = []
# 请求第一页,获取总条数与总页数
page_info = fetch_punch_record_page(
session, staff_id, begin_date, end_date,
page_no=1, page_size=page_size, sub_type=sub_type
)
total = int(page_info.get("total", 0))
page_total = int(page_info.get("pageCount", 1))
records = page_info.get("list", []) or []
all_records.extend(records)
logger.info("打卡明细总数: %d, 第1页获取 %d 条", total, len(records))
# 若存在多页,继续翻页
if page_total > 1:
for p in range(2, page_total + 1):
page_info = fetch_punch_record_page(
session, staff_id, begin_date, end_date,
page_no=p, page_size=page_size, sub_type=sub_type
)
records = page_info.get("list", []) or []
all_records.extend(records)
logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(records), len(all_records))
return all_records