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
Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

+10 -2
View File
@@ -15,12 +15,20 @@ WAGE_CARD_URL = "https://hr.37du.co/RedseaPlatform/getPageAjax/HrStaffWageCard.m
# 单页最大抓取条数
PAGE_MAX_SIZE = 500
# ---------- 银行字典接口(aa.md 提供,按 BANK_TYPE 匹配 code -> 开卡银行) ----------
BANK_DICT_URL = "https://hr.37du.co/RedseaPlatform/PtCodeTypeValue.mc?method=getCodeValueByCodes"
BANK_DICT_CODE_TYPE = "WAGE.BANKTYPE"
BANK_DICT_EXPIRE_SEC = 7 * 24 * 60 * 60 # 缓存7天过期,自动重新拉取
# ---------- 员工花名册(自定义导出)页面 ----------
# 花名册自定义导出页面(aa.md 提供),基于 DrissionPage 浏览器自动化操作
ROSTER_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-77128-52242&nworktoday-40175-24311|/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/getCustomCommonList.mc?clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=%E5%91%98%E5%B7%A5%E8%8A%B1%E5%90%8D%E5%86%8C"
# 花名册默认导出的自定义模板名称
ROSTER_TEMPLATE_NAME = "员工基础信息"
# 花名册自定义导出模板(下拉框中全部模板,后续各业务场景可按需选用)
ROSTER_TEMPLATE_NAME = "员工基础信息" # 默认模板
ROSTER_TEMPLATE_CADRE_SELECT = "干部选拔信息" # 干部选拔
ROSTER_TEMPLATE_INDIVIDUAL_TAX = "个税申报基础信息" # 个税申报
ROSTER_TEMPLATE_EMPLOYER_INSURANCE = "雇主险增减员导出模板" # 雇主险增减员
# ---------- 考勤异常查询接口 ----------
# 获取当前用户信息(用于校验 cookies 有效性,并取得查询考勤异常所需的 userId / rootId(treecode))
+114
View File
@@ -8,9 +8,12 @@
@Version: 2.0.0
"""
import json
import os
import time
from typing import Any, Dict, List
from app.common.app_paths import get_sessions_dir
from app.utils.logger import get_logger
from app.service.hrbp.ehr.common.config import (
WAGE_CARD_URL,
@@ -21,7 +24,11 @@ from app.service.hrbp.ehr.common.config import (
SHIFT_URL,
LEAVE_URL,
OVERTIME_URL,
BANK_DICT_URL,
BANK_DICT_CODE_TYPE,
BANK_DICT_EXPIRE_SEC,
)
from app.service.hrbp.ehr.common.session_manager import build_hr_session
logger = get_logger(__name__)
@@ -149,6 +156,113 @@ def fetch_all_wage_card(
return all_rows
# ---------- 银行字典接口(aa.md 提供,按 BANK_TYPE 匹配 code -> 开卡银行) ----------
# 缓存文件统一放在 AppData\Local\37duAutomation\.sessions 目录
_BANK_DICT_CACHE_DIR = get_sessions_dir()
BANK_DICT_LIST_FILE = os.path.join(_BANK_DICT_CACHE_DIR, "bank_dict_list.json")
BANK_DICT_MAP_FILE = os.path.join(_BANK_DICT_CACHE_DIR, "bank_dict_map.json")
def _fetch_bank_dict(session=None):
"""远程调用接口获取银行字典,并写入本地缓存。
Returns:
(list[dict], dict[code->name])
"""
if session is None:
session = build_hr_session()
payload = {
"codeType": BANK_DICT_CODE_TYPE,
"inUse": "0,1,2",
"platformMode": "redseaPlatform",
}
resp = session.post(BANK_DICT_URL, data=payload, timeout=30)
if not resp:
raise RuntimeError("银行字典请求失败,未获取到响应")
if resp.status_code != 200:
raise RuntimeError(f"银行字典接口状态码异常: {resp.status_code}")
if _is_expired(resp.text):
raise HRSessionExpiredError("HR 登录态已过期,银行字典接口返回非 JSON 内容")
resp_json = resp.json()
raw_list = resp_json.get(BANK_DICT_CODE_TYPE) or []
result_list = [{"code": str(item.get("code", "")), "name": item.get("name", "")}
for item in raw_list]
result_map = {item["code"]: item["name"] for item in result_list}
os.makedirs(_BANK_DICT_CACHE_DIR, exist_ok=True)
with open(BANK_DICT_LIST_FILE, "w", encoding="utf-8") as f:
json.dump(result_list, f, ensure_ascii=False, indent=2)
with open(BANK_DICT_MAP_FILE, "w", encoding="utf-8") as f:
json.dump(result_map, f, ensure_ascii=False, indent=2)
logger.info("银行字典远程拉取完成,共 %d 条", len(result_list))
return result_list, result_map
def _load_bank_dict_cache():
"""读取本地银行字典缓存,失败返回 (None, None)。"""
try:
with open(BANK_DICT_LIST_FILE, "r", encoding="utf-8") as f:
lst = json.load(f)
with open(BANK_DICT_MAP_FILE, "r", encoding="utf-8") as f:
mp = json.load(f)
return lst, mp
except Exception as e:
logger.warning("银行字典本地缓存读取失败:%s", e)
return None, None
def get_bank_dict(session=None, force_refresh: bool = False):
"""获取银行字典(优先本地缓存,过期/强制刷新才请求接口)。
Args:
session: 可选的已登录 requests.Session;未提供时自动构建
force_refresh: True 强制重新调用接口
Returns:
(list版本, dict[code->name]版本)
"""
need_refresh = force_refresh
if not (os.path.exists(BANK_DICT_LIST_FILE) and os.path.exists(BANK_DICT_MAP_FILE)):
need_refresh = True
else:
mtime = os.path.getmtime(BANK_DICT_LIST_FILE)
if time.time() - mtime > BANK_DICT_EXPIRE_SEC:
need_refresh = True
if need_refresh:
try:
return _fetch_bank_dict(session)
except Exception as e:
logger.error("银行字典远程拉取失败:%s", e)
lst, mp = _load_bank_dict_cache()
if lst is not None:
logger.warning("降级使用本地银行字典缓存,共 %d 条", len(lst))
return lst, mp
return [], {}
lst, mp = _load_bank_dict_cache()
if lst is None:
# 缓存异常时重新拉取
return _fetch_bank_dict(session)
logger.info("读取本地银行字典缓存,共 %d 条", len(lst))
return lst, mp
def bank_type_to_name(bank_type, bank_map) -> str:
"""按银行编码(BANK_TYPE)匹配字典 code,返回开卡银行;未命中返回空串。"""
if bank_type is None:
return ""
if isinstance(bank_type, float):
if bank_type != bank_type: # NaN
return ""
bank_type = str(int(bank_type))
elif isinstance(bank_type, int):
bank_type = str(bank_type)
else:
bank_type = str(bank_type).strip()
return bank_map.get(bank_type, "")
def adjust_abnormal(
session,
abnormal_ids,
+3 -2
View File
@@ -18,6 +18,7 @@ import cv2
import numpy as np
import io
from dotenv import load_dotenv
from app.common.app_paths import get_sessions_dir
load_dotenv()
# ================== 配置 ==================
@@ -40,8 +41,8 @@ TIMEOUT = 10
HEADLESS = False
DEBUG_DIR = os.path.join(os.path.dirname(__file__), 'captcha_debug')
# 登录 cookies 持久化目录(与 OA 系统一致,服务层统一管理各平台会话文件)
_COOKIE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '.sessions')
# 登录 cookies 持久化目录(统一放在 AppData\Local\37duAutomation,与 OA 系统一致)
_COOKIE_DIR = get_sessions_dir()
COOKIE_FILE = os.path.join(_COOKIE_DIR, 'hr_cookies.json')
def ensure_dir(path):
@@ -11,6 +11,7 @@
import os
import json
from app.common.app_paths import get_sessions_dir
from app.utils.logger import get_logger
try:
@@ -20,8 +21,8 @@ except ImportError:
logger = get_logger(__name__)
# HR 登录 cookies 持久化目录(login.py 登录成功后保存)
_SESSIONS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '.sessions')
# HR 登录 cookies 持久化目录(统一放在 AppData\Local\37duAutomation,login.py 登录成功后保存)
_SESSIONS_DIR = get_sessions_dir()
HR_COOKIE_FILE = os.path.join(_SESSIONS_DIR, 'hr_cookies.json')