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:
@@ -10,18 +10,17 @@
|
||||
- 事假/调休假/半天休/普通事假等:排班上班天数与填报天数一致 -> 通过,否则驳回
|
||||
- 病假/特别福利假/特殊事假/产假:天数一致 + 已上传附件 -> 人工复核(附件内容需人工核验);
|
||||
天数不一致或缺附件 -> 驳回
|
||||
2. 排班数据获取:调用排班接口,解析 HTML 表格,提取非"休息"日期
|
||||
@Version: 4.0.0
|
||||
2. 排班数据获取:调用考勤逐日接口,统计请假区间内非"休息"天数
|
||||
@Version: 4.1.0
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
import math
|
||||
from typing import Any, Dict, List, Tuple
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
from app.utils.logger import get_logger
|
||||
from app.service.hrbp.oa.leave.parser import VACATION_TYPE_MAP, _resolve_vacation_type, _parse_leave_form
|
||||
from app.service.hrbp.oa.common.oa_api import get_attendance_html, download_attachment
|
||||
from app.service.hrbp.oa.common.parser import parse_attendance_html, get_work_days_in_range
|
||||
from app.service.hrbp.oa.common.oa_api import get_attendance_daily, download_attachment
|
||||
from app.utils.ocr import check_leave_attachment, marriage_within_one_year
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -54,46 +53,33 @@ def _get_date_range(start_time: str, end_time: str) -> Tuple[str, str]:
|
||||
return start_date, end_date
|
||||
|
||||
|
||||
def _get_months_in_range(start_date: str, end_date: str) -> List[Tuple[int, int]]:
|
||||
"""
|
||||
获取日期范围内所有 (year, month) 元组列表。
|
||||
若请假跨月,按月份分段请求,合并结果。
|
||||
"""
|
||||
start = datetime.strptime(start_date, "%Y-%m-%d")
|
||||
end = datetime.strptime(end_date, "%Y-%m-%d")
|
||||
months = []
|
||||
current = start.replace(day=1)
|
||||
while current <= end:
|
||||
months.append((current.year, current.month))
|
||||
# 下个月第一天
|
||||
if current.month == 12:
|
||||
current = current.replace(year=current.year + 1, month=1)
|
||||
else:
|
||||
current = current.replace(month=current.month + 1)
|
||||
return months
|
||||
|
||||
|
||||
def _get_work_days_count(session: Any, staff_id: str, start_date: str, end_date: str) -> int:
|
||||
"""
|
||||
获取请假区间内实际上班天数(非休息日)。
|
||||
|
||||
若请假跨月,按月份分段请求排班数据,合并结果后计算。
|
||||
数据源为考勤逐日接口(rf_s_kq_count_leave_yc_day_all),按日期范围一次查询,
|
||||
返回区间内每天的班次名(bc_name,休息日为"休息"),据此统计非休息的天数。
|
||||
"""
|
||||
months = _get_months_in_range(start_date, end_date)
|
||||
attendance = {}
|
||||
for year, month in months:
|
||||
try:
|
||||
html = get_attendance_html(session, staff_id, year, month)
|
||||
monthly = parse_attendance_html(html)
|
||||
attendance.update(monthly)
|
||||
logger.info("排班数据已获取: %d-%02d, 共 %d 天", year, month, len(monthly))
|
||||
except Exception as e:
|
||||
logger.warning("获取排班失败(%d-%02d): %s", year, month, str(e))
|
||||
try:
|
||||
records = get_attendance_daily(session, staff_id, start_date, end_date)
|
||||
logger.info("排班数据已获取: %s ~ %s, 共 %d 天", start_date, end_date, len(records))
|
||||
except Exception as e:
|
||||
logger.warning("获取排班失败(%s~%s): %s", start_date, end_date, str(e))
|
||||
records = []
|
||||
|
||||
if not attendance:
|
||||
if not records:
|
||||
raise RuntimeError("未能获取到任何排班数据")
|
||||
|
||||
work_days = get_work_days_in_range(attendance, start_date, end_date)
|
||||
attendance = {str(r.get("work_day", "")): r.get("bc_name", "") for r in records}
|
||||
work_days = []
|
||||
current = datetime.strptime(start_date, "%Y-%m-%d")
|
||||
end_dt = datetime.strptime(end_date, "%Y-%m-%d")
|
||||
while current <= end_dt:
|
||||
day = current.strftime("%Y-%m-%d")
|
||||
if attendance.get(day) not in (None, "", "休息"):
|
||||
work_days.append(day)
|
||||
current += timedelta(days=1)
|
||||
|
||||
logger.info("请假区间 %s ~ %s,实际上班天数: %d", start_date, end_date, len(work_days))
|
||||
return len(work_days)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user