refactor: 统一所有缓存/会话文件的存储路径

1.  重构会话管理模块,新增app.common.app_paths统一管理缓存路径,所有登录态与缓存统一迁移至%LOCALAPPDATA%\37duAutomation\.sessions
2.  更新所有涉及文件存储路径的代码,包括考勤、工资卡、社保、审批等模块
3.  新增银行字典缓存功能,统一管理银行编码映射
4.  添加雇主险业务模块,实现花名册筛选复制功能
5.  更新.gitignore,将所有.sessions目录纳入忽略列表
6.  删除影刀脚本旧的本地缓存文件
7.  优化加班审批校验逻辑,新增提前到岗型加班校验规则
8.  完善工资卡核对功能,补充开卡银行信息展示
This commit is contained in:
2026-08-13 21:20:55 +08:00
parent c749d951a0
commit 186636a8e4
45 changed files with 4507 additions and 393 deletions
@@ -48,6 +48,8 @@ def _format_detail(info: Dict[str, Any]) -> str:
("当日最早打卡", "最早打卡"),
("当日最晚打卡", "最晚打卡"),
("次日最早打卡", "次日最早打卡"),
("前一天最晚打卡", "前一天最晚打卡"),
("到岗打卡", "到岗打卡"),
("计算加班时长(小时)", "计算时长"),
("弹性扣减(小时)", "弹性扣减"),
("有效加班时长(小时)", "有效时长"),
@@ -105,6 +107,8 @@ def generate_report(results: List[Dict[str, Any]]) -> str:
lines.append(f" {detail}")
if note:
lines.append(f" 备注: {note}")
if r.get("审批动作"):
lines.append(f" 审批动作: {r['审批动作']}({r.get('审批结果', '')})")
lines.append("")
# ----- 驳回清单 -----
+55 -15
View File
@@ -35,6 +35,8 @@ from app.service.hrbp.oa.common.config import (
ZHINENG_HALF_MORNING_HOURS,
ZHINENG_HALF_AFTERNOON_HOURS,
ZHINENG_HALF_CUTOFF_HOUR,
OT_PRE_SHIFT_ARRIVE_BEFORE_HOURS,
OT_PRE_SHIFT_ARRIVE_AFTER_MINUTES,
)
@@ -86,6 +88,19 @@ def _next_day(date_str: str) -> str:
return (d + timedelta(days=1)).strftime("%Y-%m-%d")
def _is_within_arrival_window(
punch_str: Any,
start_dt: datetime,
before_hours: float = OT_PRE_SHIFT_ARRIVE_BEFORE_HOURS,
after_minutes: int = OT_PRE_SHIFT_ARRIVE_AFTER_MINUTES,
) -> bool:
"""提前到岗型加班:判断打卡时间是否落在加班开始时间附近的到岗证据窗口内。"""
p = _parse_dt(punch_str)
if p is None:
return False
return (start_dt - timedelta(hours=before_hours)) <= p <= (start_dt + timedelta(minutes=after_minutes))
def _is_spring_festival(date_str: str) -> bool:
"""
判断日期是否为春节法定节假日(初一至初三)。
@@ -155,32 +170,36 @@ def _check_punch_records(session: Any, staff_id: str, ot_date: str) -> Dict[str,
加班常跨天(如 18:00 至次日 00:00),下班打卡可能落在次日,因此查询
范围扩展到 ot_date 次日;次日最早打卡用于延时加班的弹性到岗兑换判定。
另扩展到前一天:提前到岗型延时加班(开始<=6点)的到岗打卡可能被系统归到前一天。
"""
if not ot_date or not staff_id:
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
"打卡备注": "缺少加班日期或员工ID"}
"前一天最晚打卡": None, "打卡备注": "缺少加班日期或员工ID"}
start = datetime.strptime(ot_date, "%Y-%m-%d")
prev_day = (start - timedelta(days=1)).strftime("%Y-%m-%d")
next_day = (start + timedelta(days=1)).strftime("%Y-%m-%d")
try:
records = get_attendance_records(session, staff_id, ot_date, next_day)
records = get_attendance_records(session, staff_id, prev_day, next_day)
summary = summarize_attendance_records(records)
prev_summary = next((r for r in summary if r["attend_date"] == prev_day), None)
day_summary = next((r for r in summary if r["attend_date"] == ot_date), None)
next_summary = next((r for r in summary if r["attend_date"] == next_day), None)
if not day_summary and not next_summary:
if not day_summary and not next_summary and not prev_summary:
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
"打卡备注": "当天及次日无打卡记录"}
"前一天最晚打卡": None, "打卡备注": "当天及次日无打卡记录"}
return {
"当日最早打卡": day_summary["first_check_in"] if day_summary else None,
"当日最晚打卡": day_summary["last_check_out"] if day_summary else None,
"次日最早打卡": next_summary["first_check_in"] if next_summary else None,
"前一天最晚打卡": prev_summary["last_check_out"] if prev_summary else None,
"打卡备注": "",
}
except Exception as e:
logger.warning("获取打卡明细失败: %s", str(e))
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
"打卡备注": f"获取失败: {e}"}
"前一天最晚打卡": None, "打卡备注": f"获取失败: {e}"}
def _check_leave_covers_morning(session: Any, staff_id: str, date_str: str) -> bool:
@@ -250,17 +269,38 @@ def _validate_delayed(
if hours < OT_MIN_HOURS:
reasons.append(f"加班时长为{hours:g}小时,不足{OT_MIN_HOURS}小时")
# 3. 区间合规校验:开始 >= 规定下班时间,结束 <= 实际下班打卡时间
# 3. 区间合规校验
work_start = datetime.strptime(f"{ot_date} {WORK_START_TIME}", "%Y-%m-%d %H:%M")
work_end = datetime.strptime(f"{ot_date} {WORK_END_TIME}", "%Y-%m-%d %H:%M")
if start is not None and start < work_end:
reasons.append(f"申请开始时间({start:%H:%M})早于规定下班时间({WORK_END_TIME})")
if end is not None:
if actual_checkout is None:
reasons.append("当日无下班打卡记录,无法校验区间合规")
elif end > actual_checkout:
reasons.append(
f"申请结束时间({end:%H:%M})晚于实际下班打卡时间({actual_checkout:%H:%M:%S})"
)
# 提前到岗型延时加班:加班开始时间早于当天正常上班时间(09:00)。
# 常规"晚于18:00""当日有下班打卡"校验不适用,改以加班开始时间附近的到岗打卡作为证据:
# - 开始<=6点时,到岗打卡可能被系统归到前一天(跨天打卡),需回看前一天记录;
# - 6点~9点开始的,到岗打卡归属当天,只看当天记录。
# 提前到岗型只会早到、不会晚到,打卡须不晚于加班开始时间。
is_pre_shift = start is not None and start < work_start
if is_pre_shift:
candidates = [punch.get("当日最早打卡")]
cross_cutoff = start.replace(hour=CROSS_DAY_BEFORE_HOUR, minute=0, second=0, microsecond=0)
if start <= cross_cutoff:
candidates.append(punch.get("前一天最晚打卡"))
arrival_punch = next(
(c for c in candidates if _is_within_arrival_window(c, start)),
None,
)
if arrival_punch is None:
reasons.append(f"提前到岗型加班,未找到加班开始时间({start:%H:%M})附近的到岗打卡")
else:
info["到岗打卡"] = arrival_punch
else:
if start is not None and start < work_end:
reasons.append(f"申请开始时间({start:%H:%M})早于规定下班时间({WORK_END_TIME})")
if end is not None:
if actual_checkout is None:
reasons.append("当日无下班打卡记录,无法校验区间合规")
elif end > actual_checkout:
reasons.append(
f"申请结束时间({end:%H:%M})晚于实际下班打卡时间({actual_checkout:%H:%M:%S})"
)
info["计算加班时长(小时)"] = hours
if reasons: