refactor: 替换排班/打卡接口为考勤逐日接口,清理旧依赖

1. 重构考勤相关接口:将get_attendance_html、get_attendance_records替换为get_attendance_daily,使用新的ATTENDANCE_DAILY_URL接口替代旧接口
2. 更新请假校验逻辑:使用考勤逐日接口统计上班天数,替换原跨月排班HTML请求逻辑
3. 升级测试用例:同步更新test_03_attendance.py和test_06_leave_online.py适配新接口
4. 新增/完善文档:新增多份流程与需求文档,删除旧版冗余文档,整理docs目录结构
5. 清理废弃文件:删除原周考勤异常、门店请休假异常相关旧需求文档
6. 配置更新:更新config.py中的考勤相关URL常量,补充注释说明
7. 待办优化:更新aa.md内容,同步加班审批规则说明
This commit is contained in:
2026-08-18 12:00:53 +08:00
parent ce388951fc
commit 5422dc8e3f
53 changed files with 6119 additions and 1064 deletions
@@ -25,8 +25,7 @@ from app.service.hrbp.oa.common.oa_api.flow import (
download_attachment,
)
from app.service.hrbp.oa.common.oa_api.attendance import (
get_attendance_html,
get_attendance_records,
get_attendance_daily,
)
from app.service.hrbp.oa.common.oa_api.leave import (
fetch_leave_record_page,
@@ -44,8 +43,7 @@ __all__ = [
"extract_form_id",
"get_business_data",
"download_attachment",
"get_attendance_html",
"get_attendance_records",
"get_attendance_daily",
"fetch_leave_record_page",
"get_leave_records",
]
+29 -65
View File
@@ -2,8 +2,8 @@
"""
@Module: hrbp.oa.common.oa_api
@FileName: attendance.py
@Description: 排班 HTML 与考勤打卡明细接口。
@Version: 1.0.0
@Description: 考勤逐日接口(按员工 + 日期范围查询每日班次与上下班打卡)。
@Version: 1.3.0
"""
from typing import List, Dict, Any
@@ -14,60 +14,26 @@ try:
except ImportError:
SessionPage = None
from app.service.hrbp.oa.common.config import PAIBAN_URL, KQ_DATA_URL
from app.service.hrbp.oa.common.config import ATTENDANCE_DAILY_URL
from app.service.hrbp.oa.common.oa_api.base import oa_request_json
logger = get_logger(__name__)
def get_attendance_html(
session: SessionPage,
staff_id: str,
year: int,
month: int
) -> str:
"""
获取指定员工某月的排班 HTML。
Args:
session: 已登录的 SessionPage 对象
staff_id: 员工 UUID
year: 年份(如 2026)
month: 月份(1-12)
Returns:
排班表格的 HTML 字符串(从返回 JSON 的 caleHtml 字段提取)
Raises:
RuntimeError: 请求失败或响应异常
"""
url = f"{PAIBAN_URL}?method=geRenPaibanByMonth"
data = {
"type": "2",
"staffId": staff_id,
"year": str(year),
"month": str(month)
}
logger.info("获取排班: %s %d-%02d", staff_id, year, month)
json_data = oa_request_json(session, "POST", url, data, "排班")
if json_data.get("success") != "true":
raise RuntimeError(f"排班接口返回失败: {json_data}")
html = json_data.get("caleHtml")
if not html:
raise RuntimeError("排班接口未返回 caleHtml 字段")
return html
def get_attendance_records(
def get_attendance_daily(
session: SessionPage,
staff_id: str,
start_date: str,
end_date: str
) -> List[Dict[str, Any]]:
"""
查询员工某时间段的原始打卡明细。
按员工 + 日期范围查询每日考勤(含班次起止时间与上下班打卡)。
接口: rf_s_kq_count_leave_yc_day_all/redApiExec.mc
kq_status_total 按考勤状态分类返回记录(来源为前端 JS 扒取的请求构造):
- 0=休息日、1=正常班、9=未打卡、11=异常(如上班漏打卡)
因此需按这四种状态各查一次,再按 work_day 合并去重,才能同时拿到
班次名/班次时段与休息日、异常班当天的上下班打卡。
Args:
session: 已登录的 SessionPage 对象
@@ -76,25 +42,23 @@ def get_attendance_records(
end_date: 查询结束日期 "YYYY-MM-DD"
Returns:
打卡记录列表(接口返回的 jsonList,每条含 kq_time / status / time_order 等)
- status: "1"=上班打卡, "5"=下班打卡, "6"=重复打卡
- time_order: "1"=上班时段, "2"=下班时段
Raises:
RuntimeError: 请求失败或响应异常
每日考勤记录列表(四种状态合并去重后,按日期升序)
"""
params = {
"staff_id": staff_id,
"rootId": "",
"countId": "",
"bc_date": start_date,
"bc_date_end": end_date,
"begin": start_date,
"end": end_date,
}
logger.info("获取打卡明细: staff_id=%s, %s 至 %s", staff_id, start_date, end_date)
json_data = oa_request_json(session, "GET", KQ_DATA_URL, params, "考勤打卡")
records = json_data.get("jsonList", [])
logger.info("打卡明细返回 %d 条", len(records))
by_day: Dict[str, Dict[str, Any]] = {}
for status in ("0", "1", "9", "11"):
params = {
"staff_id": staff_id,
"begin_date": start_date,
"end_date": end_date,
"kq_status_total": status,
}
logger.info(
"获取考勤逐日(kq_status_total=%s): staff_id=%s, %s 至 %s",
status, staff_id, start_date, end_date,
)
json_data = oa_request_json(session, "POST", ATTENDANCE_DAILY_URL, params, "考勤逐日")
for r in json_data.get("data", []) or []:
by_day.setdefault(str(r.get("work_day", "")), r)
records = [by_day[k] for k in sorted(by_day)]
logger.info("考勤逐日合并返回 %d 天", len(records))
return records
@@ -100,6 +100,13 @@ def parse_todo_list(data: Dict[str, Any]) -> List[Dict[str, Any]]:
if detail_url and not detail_url.startswith(("http://", "https://")):
detail_url = BASE_URL + detail_url
# 跳过"工作沟通/协作"类待办(如"请回复…与您的工作沟通:加班申请"):
# 链接指向协作模块 kmCollaborateMain.do,非审批工作流,SSO 后仅到
# unifyWorkFlow.jsp?fkId=… 拿不到 businessKey,永远无法解析,直接跳过避免无谓重试
if "kmCollaborateMain.do" in detail_url:
logger.warning("跳过非审批待办(工作沟通/协作): %s", title)
continue
docs.append({
"title": title,
"creator": creator,