Files
37duAutomation/plugins/xq0010/logic/check1.py
T

72 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0010 EHR系统月考勤异常处理 插件 - 检查1「已确认异常 × 请假流程」(由影刀版移植)。
已确认异常(is_adjusted=2)的日期,若同时存在有效请假流程(请假范围覆盖该日)→ 命中,
可能存在「提前确认后请假」仍为异常,需人工复核。
排除「正常」场景(不需要提示):
1. 请假类型为小时特假:允许存在异常,跳过;
2. 半天假(≤0.5 天)且异常时段与请假时段不重叠:如上午异常 + 下午请假,
异常与请假互不覆盖,视为正常,跳过;整日假(≥1 天)覆盖全天,
异常必然落在假期内,不适用该规则;
3. 已撤销(003)/已销假(005)等非生效假单已在索引阶段排除,不构成有效请假。
"""
from ..config import logger, HALF_DAY, EPS, VACATION_TYPE_HOURLY
from .abnormal_utils import (
_get, _to_date_str, _float, _staff_name, _leave_type_name, _leave_type_code,
_time_ranges_overlap,
)
# 输出列(对应需求文档检查1)
OUTPUT_COLUMNS = [
"员工姓名", "工号", "考勤日期", "异常类型", "请假类型", "请假起止", "问题说明",
]
def run_check1(abnormal_confirmed, leave_index):
"""检查1:已确认异常日期命中请假流程 → 返回命中行列表。
Args:
abnormal_confirmed: 已确认异常(is_adjusted=2)记录列表。
leave_index: build_leave_set(need_full_day=False) 产出的
{(base_code, 'YYYY-MM-DD'): leave_rec} 索引。
Returns:
命中行列表(每行为 OUTPUT_COLUMNS 对应字段的 dict)。
"""
rows = []
for ab in 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 = leave_index.get((code, work_day))
if not leave_rec:
continue
# 规则1:小时特假允许存在异常
if _leave_type_code(leave_rec) == VACATION_TYPE_HOURLY:
logger.debug("【检查1跳过】%s %s %s:小时特假允许存在异常",
_staff_name(ab), code, work_day)
continue
# 规则2:半天假(≤0.5 天)且异常时段与请假时段不重叠 → 正常
if _float(leave_rec.get("leave_days"), 1.0) <= HALF_DAY + EPS:
overlap = _time_ranges_overlap(
_get(ab, "begin_time"), _get(ab, "end_time"),
_get(leave_rec, "start_time"), _get(leave_rec, "end_time"),
work_day)
if overlap is False:
logger.debug("【检查1跳过】%s %s %s:异常时段与请假时段不重叠,视为正常",
_staff_name(ab), code, work_day)
continue
rows.append({
"员工姓名": _staff_name(ab),
"工号": code,
"考勤日期": work_day,
"异常类型": _get(ab, "abnormal"),
"请假类型": _leave_type_name(leave_rec),
"请假起止": f"{_to_date_str(_get(leave_rec, 'begin_date', 'start_time'))} ~ "
f"{_to_date_str(_get(leave_rec, 'end_date', 'end_time'))}",
"问题说明": "该日期已确认考勤异常,但同时存在请假流程,可能为「提前确认后请假」仍为异常",
})
return rows