diff --git a/app/service/hrbp/oa/common/config.py b/app/service/hrbp/oa/common/config.py index d11178c..60af579 100644 --- a/app/service/hrbp/oa/common/config.py +++ b/app/service/hrbp/oa/common/config.py @@ -53,6 +53,12 @@ OT_REVIEW_DAYS = 8 # 月度截止:每月该日期 12:00 之后,不再审核上一个月的加班流程 MONTH_CUTOFF_DAY = 2 MONTH_CUTOFF_HOUR = 12 +# 职能排班半天加班时长:上午3.5小时、下午4.5小时 +# (休息日/节假日加班,不再统一按4小时半天处理,整天仍为9小时) +ZHINENG_HALF_MORNING_HOURS = 3.5 +ZHINENG_HALF_AFTERNOON_HOURS = 4.5 +# 职能排班上午/下午分界:申请加班开始时间早于该时刻(12点)视为上午半天 +ZHINENG_HALF_CUTOFF_HOUR = 12 # ---------- 分页 ---------- DEFAULT_PAGE_SIZE = 15 diff --git a/app/service/hrbp/oa/work_overtime/validator.py b/app/service/hrbp/oa/work_overtime/validator.py index 01588f6..9f49fd2 100644 --- a/app/service/hrbp/oa/work_overtime/validator.py +++ b/app/service/hrbp/oa/work_overtime/validator.py @@ -32,6 +32,9 @@ from app.service.hrbp.oa.common.config import ( OT_REVIEW_DAYS, MONTH_CUTOFF_DAY, MONTH_CUTOFF_HOUR, + ZHINENG_HALF_MORNING_HOURS, + ZHINENG_HALF_AFTERNOON_HOURS, + ZHINENG_HALF_CUTOFF_HOUR, ) @@ -120,6 +123,27 @@ def _get_shift(session: Any, staff_id: str, date_str: str) -> str: return "获取失败" +def _is_zhineng_schedule(session: Any, staff_id: str, date_str: str) -> bool: + """ + 判断员工是否为职能排班(休息日/节假日加班半天规则专用)。 + + 不看加班当天(当天排班通常显示'休息'),而是查看当月排班日历中的其他天: + 只要任一班次包含'职能'(如 职能正班A),即按职能排班处理。 + 排班获取失败时优雅降级返回 False,沿用默认半天4小时规则。 + """ + if not date_str or not staff_id: + return False + try: + year = int(date_str[:4]) + month = int(date_str[5:7]) + html = get_attendance_html(session, staff_id, year, month) + attendance = parse_attendance_html(html) + return any("职能" in (shift or "") for shift in attendance.values()) + except Exception as e: + logger.warning("获取排班判断职能失败(%s): %s", date_str, str(e)) + return False + + def _check_attendance(session: Any, staff_id: str, ot_date: str) -> Dict[str, Any]: """查询员工在加班日期的排班班次""" return {"加班当天班次": _get_shift(session, staff_id, ot_date)} @@ -326,7 +350,8 @@ def _validate_day_ot( - 加班时长 > 0; - 当天有上下班打卡(跨天打卡处理:当天无打卡时,若次日首条打卡早于6点, 视为归属加班当天的跨天有效打卡,不再因缺打卡驳回); - - 打卡时间间隔满足申报天数(0.5天>=4h, 1天>=9h, 1.5天>=13h, 2天>=18h...)。 + - 打卡时间间隔满足申报天数(0.5天>=4h, 1天>=9h, 1.5天>=13h, 2天>=18h...); + 职能排班半天(0.5天)例外:上午(开始时间<12:00)>=3.5h、下午>=4.5h,整天仍为9h。 """ ot_date = info.get("加班日期") reasons = [] @@ -384,6 +409,14 @@ def _validate_day_ot( reasons.append("申报天数缺失或为0") elif interval is not None: threshold = _calc_day_ot_threshold(apply_days) + # 职能排班半天(0.5天)加班:上午3.5小时、下午4.5小时,不再统一按4小时半天处理; + # 上/下午按申请加班开始时间判定(早于12:00视为上午半天) + if abs(apply_days - 0.5) < 1e-9 and _is_zhineng_schedule(session, staff_id, ot_date): + start = _parse_dt(info.get("加班开始时间")) + if start is not None and start.hour < ZHINENG_HALF_CUTOFF_HOUR: + threshold = ZHINENG_HALF_MORNING_HOURS + else: + threshold = ZHINENG_HALF_AFTERNOON_HOURS if interval < threshold: reasons.append( f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时" diff --git a/yingdao/overtime_approval_yingdao.py b/yingdao/overtime_approval_yingdao.py index 529a825..8dbb6bf 100644 --- a/yingdao/overtime_approval_yingdao.py +++ b/yingdao/overtime_approval_yingdao.py @@ -93,6 +93,12 @@ OT_REVIEW_DAYS = 8 # 月度截止:每月该日期 12:00 之后,不再审核上一个月的加班流程 MONTH_CUTOFF_DAY = 2 MONTH_CUTOFF_HOUR = 12 +# 职能排班半天加班时长:上午3.5小时、下午4.5小时 +# (休息日/节假日加班,不再统一按4小时半天处理,整天仍为9小时) +ZHINENG_HALF_MORNING_HOURS = 3.5 +ZHINENG_HALF_AFTERNOON_HOURS = 4.5 +# 职能排班上午/下午分界:申请加班开始时间早于该时刻(12点)视为上午半天 +ZHINENG_HALF_CUTOFF_HOUR = 12 # ---------- 分页 ---------- DEFAULT_PAGE_SIZE = 15 @@ -1115,6 +1121,27 @@ def _get_shift(session, staff_id, date_str): return "获取失败" +def _is_zhineng_schedule(session, staff_id, date_str): + """ + 判断员工是否为职能排班(休息日/节假日加班半天规则专用)。 + + 不看加班当天(当天排班通常显示'休息'),而是查看当月排班日历中的其他天: + 只要任一班次包含'职能'(如 职能正班A),即按职能排班处理。 + 排班获取失败时优雅降级返回 False,沿用默认半天4小时规则。 + """ + if not date_str or not staff_id: + return False + try: + year = int(date_str[:4]) + month = int(date_str[5:7]) + html = get_attendance_html(session, staff_id, year, month) + attendance = parse_attendance_html(html) + return any("职能" in (shift or "") for shift in attendance.values()) + except Exception as e: + logger.warning("获取排班判断职能失败(%s): %s", date_str, str(e)) + return False + + def _check_attendance(session, staff_id, ot_date): return {"加班当天班次": _get_shift(session, staff_id, ot_date)} @@ -1325,8 +1352,18 @@ def _validate_day_ot(info, punch, session, staff_id, require_holiday): reasons.append("申报天数缺失或为0") elif interval is not None: threshold = _calc_day_ot_threshold(apply_days) + # 职能排班半天(0.5天)加班:上午3.5小时、下午4.5小时,不再统一按4小时半天处理; + # 上/下午按申请加班开始时间判定(早于12:00视为上午半天) + if abs(apply_days - 0.5) < 1e-9 and _is_zhineng_schedule(session, staff_id, ot_date): + start = _parse_dt(info.get("加班开始时间")) + if start is not None and start.hour < ZHINENG_HALF_CUTOFF_HOUR: + threshold = ZHINENG_HALF_MORNING_HOURS + else: + threshold = ZHINENG_HALF_AFTERNOON_HOURS if interval < threshold: - reasons.append(f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时") + reasons.append( + f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时" + ) info["打卡时间间隔(小时)"] = interval info["申报天数(天)"] = apply_days