feat(hrbp): 完成HRBP加班审批系统全链路开发
新增: 1. 新增依赖包chinese_calendar,完善.gitignore会话存储配置 2. 新增完整测试套件与项目初始化文件 3. 实现延时/休息日/法定假日加班审批规则(参考aa.md文档) 4. 新增排班、打卡、请假数据获取与解析工具 5. 完善会话管理与持久化存储逻辑 6. 实现格式化审批报告生成功能 修改: 1. 调整请假校验函数签名以传入会话对象 2. 更新审批流程调用逻辑适配新校验函数 3. 重构cookie存储路径与目录创建逻辑 4. 优化日志输出级别与调试信息
This commit is contained in:
@@ -24,9 +24,9 @@ except ImportError:
|
||||
SessionPage = None
|
||||
|
||||
try:
|
||||
from .config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL
|
||||
from .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
|
||||
except ImportError:
|
||||
from config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL
|
||||
from 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
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -209,7 +209,7 @@ def get_wf_activity_by_task_id(
|
||||
f"WfActivity 接口返回非 JSON 数据(状态码 {resp.status_code}): {body}"
|
||||
)
|
||||
|
||||
logger.info("WfActivity 返回: %s", json_data)
|
||||
logger.debug("WfActivity 返回: %s", json_data)
|
||||
return json_data
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ def get_attendance_html(
|
||||
Raises:
|
||||
RuntimeError: 请求失败或响应异常
|
||||
"""
|
||||
url = f"{HR_BASE_URL}/RedseaPlatform/KqCount.mc?method=geRenPaibanByMonth"
|
||||
url = f"{PAIBAN_URL}?method=geRenPaibanByMonth"
|
||||
data = {
|
||||
"type": "2",
|
||||
"staffId": staff_id,
|
||||
@@ -352,3 +352,181 @@ def get_attendance_html(
|
||||
if not html:
|
||||
raise RuntimeError("排班接口未返回 caleHtml 字段")
|
||||
return html
|
||||
|
||||
|
||||
# ---------- 考勤打卡明细接口 ----------
|
||||
def get_attendance_records(
|
||||
session: SessionPage,
|
||||
staff_id: str,
|
||||
start_date: str,
|
||||
end_date: str
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
查询员工某时间段的原始打卡明细。
|
||||
|
||||
Args:
|
||||
session: 已登录的 SessionPage 对象
|
||||
staff_id: 员工 UUID
|
||||
start_date: 查询起始日期 "YYYY-MM-DD"
|
||||
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)
|
||||
|
||||
session.get(KQ_DATA_URL, params=params)
|
||||
resp = session.response
|
||||
if not resp:
|
||||
raise RuntimeError("考勤打卡请求失败,未获取到响应")
|
||||
if resp.status_code != 200:
|
||||
raise RuntimeError(f"考勤打卡接口状态码异常: {resp.status_code}")
|
||||
|
||||
try:
|
||||
json_data = resp.json()
|
||||
except Exception:
|
||||
body = (resp.text or "")[:200]
|
||||
raise RuntimeError(f"考勤打卡接口返回非 JSON 数据: {body}")
|
||||
|
||||
records = json_data.get("jsonList", [])
|
||||
logger.info("打卡明细返回 %d 条", len(records))
|
||||
return records
|
||||
|
||||
|
||||
# ---------- 请假记录接口 ----------
|
||||
def fetch_leave_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"
|
||||
end_date: 查询结束日期 "YYYY-MM-DD"
|
||||
page_no: 页码(从1开始)
|
||||
page_size: 每页条数
|
||||
sub_type: 假期类型编码,默认 "-1" 表示全部
|
||||
|
||||
Returns:
|
||||
接口返回的 data 字段字典,包含 total / pageCount / list
|
||||
|
||||
Raises:
|
||||
RuntimeError: 请求失败或响应异常
|
||||
"""
|
||||
data = {
|
||||
"sub_type": sub_type,
|
||||
"staff_id": staff_id,
|
||||
"begin_date": begin_date,
|
||||
"end_date": end_date,
|
||||
"start": str((page_no - 1) * page_size),
|
||||
"pageSize": str(page_size),
|
||||
"sortType": "",
|
||||
"sortName": "",
|
||||
"pageNo": str(page_no),
|
||||
}
|
||||
logger.info("获取请假记录: staff_id=%s, %s 至 %s, 第%d页", staff_id, begin_date, end_date, page_no)
|
||||
|
||||
session.post(LEAVE_RECORD_URL, data=data)
|
||||
resp = session.response
|
||||
if not resp:
|
||||
raise RuntimeError("请假记录请求失败,未获取到响应")
|
||||
if resp.status_code != 200:
|
||||
raise RuntimeError(f"请假记录接口状态码异常: {resp.status_code}")
|
||||
|
||||
try:
|
||||
json_data = resp.json()
|
||||
except Exception:
|
||||
body = (resp.text or "")[:200]
|
||||
raise RuntimeError(f"请假记录接口返回非 JSON 数据: {body}")
|
||||
|
||||
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_leave_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:
|
||||
请假记录列表,每条包含:
|
||||
- staff_id: 员工ID
|
||||
- staff_name: 员工姓名
|
||||
- leave_businessKey: 审批单号
|
||||
- sub_type: 假期类型编码
|
||||
- vacation_type_name: 假期名称
|
||||
- leave_reason: 请假原因
|
||||
- leave_days: 请假天数
|
||||
- leave_hours: 请假小时
|
||||
- start_time: 开始时间
|
||||
- end_time: 结束时间
|
||||
|
||||
Raises:
|
||||
RuntimeError: 请求失败或响应异常
|
||||
"""
|
||||
all_records: List[Dict[str, Any]] = []
|
||||
|
||||
# 请求第一页,获取总条数与总页数
|
||||
page_info = fetch_leave_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_leave_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
|
||||
|
||||
Reference in New Issue
Block a user