81 lines
3.4 KiB
Python
81 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""XQ0010 EHR系统月考勤异常处理 插件 - 检查3「整日请假 × 残留考勤异常」(由影刀版移植)。
|
||
|
||
员工整日请假(leave_days>=1)当日,仍存在其他考勤异常(未调整/已确认)→ 提示。
|
||
「班段」列取排班接口的真实班段时间({date}_bc_time,如 "09:00 ~ 18:00"),
|
||
而非异常记录的发生时段(begin_time ~ end_time);排班取不到时回退异常时段。
|
||
|
||
数据来源:
|
||
- 请假:report 层传入的请假记录(build_leave_set 只保留整日请假);
|
||
- 排班:data.hr_api.fetch_all_shift(按工号缓存,取请假日班段)。
|
||
"""
|
||
from ..config import logger
|
||
from ..data.hr_api import fetch_all_shift
|
||
from .abnormal_utils import (
|
||
_get, _to_date_str, _staff_name, _leave_type_name, build_leave_set,
|
||
_extract_day_shift, _shift_segment,
|
||
)
|
||
|
||
# 输出列(对应需求文档检查3)
|
||
OUTPUT_COLUMNS = [
|
||
"员工姓名", "工号", "请假日期", "请假类型", "请假天数", "异常类型", "班段",
|
||
"异常状态", "提示",
|
||
]
|
||
|
||
|
||
def run_check3(abnormal_confirmed, abnormal_open, leaves,
|
||
session, user_id, treecode, begin, end):
|
||
"""检查3:整日请假当日仍残留考勤异常 → 返回命中行列表。
|
||
|
||
Args:
|
||
abnormal_confirmed: 已确认异常(is_adjusted=2)记录列表。
|
||
abnormal_open: 未调整异常(is_adjusted=0)记录列表。
|
||
leaves: 全部请假记录(仅已备案的整日假参与索引)。
|
||
session / user_id / treecode: 底座注入的 HR 会话与用户信息。
|
||
begin / end: 排班查询月份范围 "YYYY-MM-DD"。
|
||
|
||
Returns:
|
||
命中行列表(每行为 OUTPUT_COLUMNS 对应字段的 dict)。
|
||
"""
|
||
rows = []
|
||
|
||
# 整日请假日期索引 {(code, date): leave_rec}
|
||
full_day_leave = build_leave_set(leaves, need_full_day=True)
|
||
if not full_day_leave:
|
||
logger.info("无整日请假记录,检查3跳过")
|
||
return rows
|
||
|
||
# 按工号缓存排班记录,避免重复请求
|
||
shift_cache = {}
|
||
|
||
# 异常并集(同一员工同一日期可能同时有未调整/已确认,各自输出一条便于核查)
|
||
for ab in list(abnormal_open) + list(abnormal_confirmed):
|
||
code = str(_get(ab, "base_code")).strip()
|
||
work_day = _to_date_str(_get(ab, "work_day"))
|
||
if not code or not work_day:
|
||
continue
|
||
leave_rec = full_day_leave.get((code, work_day))
|
||
if not leave_rec:
|
||
continue
|
||
|
||
# 拉取该员工排班(缓存),取请假日的真实排班班段时间
|
||
if code not in shift_cache:
|
||
shift_cache[code] = fetch_all_shift(session, user_id, code, begin, end, treecode)
|
||
shift_time = _extract_day_shift(shift_cache.get(code, []), work_day)["bc_time"]
|
||
|
||
is_adjusted = str(ab.get("is_adjusted", ""))
|
||
status = "确认异常" if is_adjusted == "2" else ("未调整" if is_adjusted == "0" else "异常")
|
||
hint = f"该员工{work_day}考勤状态存在异常"
|
||
rows.append({
|
||
"员工姓名": _staff_name(ab),
|
||
"工号": code,
|
||
"请假日期": work_day,
|
||
"请假类型": _leave_type_name(leave_rec),
|
||
"请假天数": _get(leave_rec, "leave_days"),
|
||
"异常类型": _get(ab, "abnormal"),
|
||
"班段": shift_time or _shift_segment(ab),
|
||
"异常状态": status,
|
||
"提示": hint,
|
||
})
|
||
return rows
|