refactor(yingdao): 统一影刀脚本依赖校验逻辑,移除懒加载改为启动即校验
1. 所有影刀脚本改为启动时一次性校验所有依赖,不再懒加载,任一依赖缺失立即报错退出 2. 更新requirements.txt,新增requests、rapidocr-onnxruntime依赖 3. 重构多个影刀脚本的依赖导入和错误提示逻辑,统一提示话术和安装命令 4. 为请假审批脚本内置OCR实现,移除对项目目录OCR模块的依赖,实现单文件自包含 5. 优化考勤异常处理脚本,新增职能序列过滤和合并推送逻辑,减少重复通知
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
@CreateTime: 2026-08-10
|
||||
@Description: 考勤异常查询与导出:通过员工基础信息接口(getCurUserInfo)校验 cookies 有效性,
|
||||
再调用考勤异常接口分页拉取【当月】全部考勤异常数据,导出为 Excel;
|
||||
并按规则(迟到/早退 >=30 分钟,或其他类型异常)向对应员工姓名推送钉钉核实通知。
|
||||
并按规则(迟到/早退 >=30 分钟,或其他类型异常)向对应员工推送钉钉核实通知;
|
||||
仅推送 first_type_name 含「职能」的人员,且按「姓名-工号」合并为一人一条,减少推送次数。
|
||||
底层能力复用:接口调用(hr_api.py)、会话管理(session_manager.py)、接口地址(config.py)。
|
||||
@Version: 2.0.0
|
||||
|
||||
@@ -64,6 +65,7 @@ COL_MAP: Dict[str, str] = {
|
||||
"abnormal_id": "异常ID",
|
||||
"STAFF_NAME": "员工姓名",
|
||||
"base_code": "工号",
|
||||
"first_type_name": "职位序列",
|
||||
"work_day": "考勤日期",
|
||||
"bc_name": "班次",
|
||||
"abnormal": "异常类型",
|
||||
@@ -72,7 +74,7 @@ COL_MAP: Dict[str, str] = {
|
||||
|
||||
# 自定义列展示顺序(核心字段放最前面,其余字段自动排在后面)
|
||||
SHOW_ORDER = [
|
||||
"异常ID", "员工姓名", "工号", "考勤日期", "班次", "异常类型", "异常时长(分钟)",
|
||||
"异常ID", "员工姓名", "工号", "职位序列", "考勤日期", "班次", "异常类型", "异常时长(分钟)",
|
||||
]
|
||||
|
||||
# 考勤异常调整状态过滤(本次只查询「未调整」)
|
||||
@@ -167,48 +169,66 @@ def classify_abnormal(item: dict) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def build_notify_text(item: dict) -> str:
|
||||
"""按需求格式拼接钉钉通知文本。
|
||||
def is_func_staff(item: dict) -> bool:
|
||||
"""判断该员工是否属于职能序列(first_type_name 含「职能」才推送)。"""
|
||||
return "职能" in str(item.get("first_type_name", "") or "")
|
||||
|
||||
确认行按实际异常类型动态生成:查出什么类型就写什么类型;
|
||||
|
||||
def build_notify_text(items: List[dict]) -> str:
|
||||
"""按人员合并拼接钉钉通知文本(一人一条,含该人全部异常)。
|
||||
|
||||
每条异常保留原确认行格式:按实际异常类型动态生成;
|
||||
迟到/早退会在确认项前附上分钟数。
|
||||
"""
|
||||
abnormal = str(item.get("abnormal", "") or "").strip() or "考勤异常"
|
||||
minute = item.get("abnormal_minute")
|
||||
# 迟到/早退 附上分钟数
|
||||
if ("迟到" in abnormal or "早退" in abnormal) and minute not in ("", None):
|
||||
confirm_item = f"{abnormal}{minute}分钟"
|
||||
else:
|
||||
confirm_item = abnormal
|
||||
return (
|
||||
"【考勤异常核实通知】\n"
|
||||
f"姓名:{item.get('STAFF_NAME', '')}\n"
|
||||
f"工号:{item.get('base_code', '')}\n"
|
||||
f"考勤日期:{item.get('work_day', '')}\n"
|
||||
f"班次:{item.get('bc_name', '')}\n"
|
||||
f"异常类型:{abnormal}\n"
|
||||
f"异常时长:{minute}分钟\n"
|
||||
f"请确认本次{confirm_item}真实情况:{abnormal}/漏打卡/外出/其他"
|
||||
)
|
||||
first = items[0]
|
||||
lines = [
|
||||
"【考勤异常核实通知】",
|
||||
f"姓名:{first.get('STAFF_NAME', '')}",
|
||||
f"工号:{first.get('base_code', '')}",
|
||||
f"共 {len(items)} 条考勤异常,请逐条确认:",
|
||||
]
|
||||
for idx, item in enumerate(items, 1):
|
||||
abnormal = str(item.get("abnormal", "") or "").strip() or "考勤异常"
|
||||
minute = item.get("abnormal_minute")
|
||||
# 迟到/早退 附上分钟数
|
||||
if ("迟到" in abnormal or "早退" in abnormal) and minute not in ("", None):
|
||||
confirm_item = f"{abnormal}{minute}分钟"
|
||||
else:
|
||||
confirm_item = abnormal
|
||||
lines.append(
|
||||
f"{idx}. 考勤日期:{item.get('work_day', '')}|班次:{item.get('bc_name', '')}"
|
||||
f"|异常类型:{abnormal}|异常时长:{minute}分钟"
|
||||
)
|
||||
lines.append(f" 请确认本次{confirm_item}真实情况:{abnormal}/漏打卡/外出/其他")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def push_abnormal(items: List[dict]) -> None:
|
||||
"""逐条生成钉钉通知文本(暂不实际发送,先供人工确认)。
|
||||
def push_abnormal(items: List[dict]) -> int:
|
||||
"""按「姓名-工号」分组生成钉钉通知文本(暂不实际发送,先供人工确认)。
|
||||
|
||||
当前仅打印通知文本;确认无误后,取消下方 send_to_person 的注释即可启用推送。
|
||||
同一人员多条异常合并为一条通知,大幅减少推送次数。
|
||||
|
||||
Returns:
|
||||
生成通知的人员数(即推送次数)
|
||||
"""
|
||||
from app.utils.dingtalk_sender import send_to_person # noqa: F401
|
||||
|
||||
groups: Dict[tuple, List[dict]] = {}
|
||||
for it in items:
|
||||
name = it.get("STAFF_NAME", "") or ""
|
||||
if not name:
|
||||
logger.warning("异常记录缺少姓名,跳过:%s", it)
|
||||
continue
|
||||
text = build_notify_text(it)
|
||||
key = (name, it.get("base_code", "") or "")
|
||||
groups.setdefault(key, []).append(it)
|
||||
|
||||
for (_name, _code), group in groups.items():
|
||||
text = build_notify_text(group)
|
||||
# 先注释掉实际推送,仅输出文本供确认
|
||||
logger.info("【待推送通知】\n%s", text)
|
||||
# send_to_person(name, text=text)
|
||||
# logger.info("已向 %s 推送考勤异常通知", name)
|
||||
# send_to_person(_name, text=text)
|
||||
# logger.info("已向 %s 推送考勤异常通知(%d 条合并)", _name, len(group))
|
||||
return len(groups)
|
||||
|
||||
|
||||
# ----------------------------------------------
|
||||
@@ -281,7 +301,8 @@ def download_attendance_abnormal(save_dir: str = None, month: str = None) -> str
|
||||
def handle_attendance_abnormal(save_dir: str = None, month: str = None) -> str:
|
||||
"""查询当月考勤异常,导出 Excel,并按要求向钉钉推送需核实的异常。
|
||||
|
||||
推送规则见 classify_abnormal:迟到/早退 >= 30 分钟,或其他类型异常,按姓名推送。
|
||||
推送规则见 classify_abnormal:迟到/早退 >= 30 分钟,或其他类型异常;
|
||||
且仅推送 first_type_name 含「职能」的人员,并按「姓名-工号」合并为一人一条推送。
|
||||
|
||||
Args:
|
||||
save_dir: 保存目录,默认 SAVE_DIR
|
||||
@@ -302,9 +323,14 @@ def handle_attendance_abnormal(save_dir: str = None, month: str = None) -> str:
|
||||
handled_count = len(data) - len(push_list)
|
||||
logger.info("考勤异常共 %d 条:需推送 %d 条,轻微异常(迟到/早退<30分钟,直接处理) %d 条",
|
||||
len(data), len(push_list), handled_count)
|
||||
if push_list:
|
||||
push_abnormal(push_list)
|
||||
|
||||
# 只推送「职能」序列(first_type_name 含「职能」),并按 姓名-工号 合并推送
|
||||
func_list = [it for it in push_list if is_func_staff(it)]
|
||||
skipped_non_func = len(push_list) - len(func_list)
|
||||
if func_list:
|
||||
push_count = push_abnormal(func_list)
|
||||
else:
|
||||
push_count = 0
|
||||
logger.info("无需推送的异常,跳过钉钉通知")
|
||||
|
||||
# ---- 最终统计汇总 ----
|
||||
@@ -312,7 +338,8 @@ def handle_attendance_abnormal(save_dir: str = None, month: str = None) -> str:
|
||||
logger.info("【考勤异常处理汇总】")
|
||||
logger.info(" 考勤异常总数:%d 条", len(data))
|
||||
logger.info(" 直接处理(轻微,无需通知):%d 条", handled_count)
|
||||
logger.info(" 待通知(需核实推送):%d 条", len(push_list))
|
||||
logger.info(" 非职能人员(first_type_name 不含「职能」,不推送):%d 条", skipped_non_func)
|
||||
logger.info(" 待通知(职能人员):%d 条,合并为 %d 条推送", len(func_list), push_count)
|
||||
logger.info(" 导出文件:%s", path)
|
||||
logger.info("=" * 60)
|
||||
return path
|
||||
|
||||
+3
-1
@@ -10,4 +10,6 @@ openpyxl
|
||||
Pillow
|
||||
opencv-python
|
||||
numpy
|
||||
pandas
|
||||
pandas
|
||||
requests
|
||||
rapidocr-onnxruntime
|
||||
@@ -12,7 +12,7 @@
|
||||
- 单文件自包含,可放任意目录直接运行(含 App 项目目录或影刀环境)。
|
||||
- 内含 HR 登录(滑块验证码识别),保证工资卡查询所需的 hr.37du.co 登录态。
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install DrissionPage python-dotenv requests pandas openpyxl opencv-python numpy Pillow
|
||||
|
||||
环境变量(.env 文件或系统变量):
|
||||
@@ -30,34 +30,23 @@ import sys
|
||||
import time
|
||||
from datetime import date, timedelta
|
||||
|
||||
# ==================== 第三方库导入 ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
except ImportError:
|
||||
ChromiumPage = None
|
||||
ChromiumOptions = None
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
requests = None
|
||||
|
||||
try:
|
||||
import pandas as pd
|
||||
except ImportError:
|
||||
pd = None
|
||||
|
||||
try:
|
||||
import cv2
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
cv2 = None
|
||||
np = None
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install DrissionPage python-dotenv requests pandas openpyxl opencv-python "
|
||||
"numpy Pillow\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
|
||||
# ==================== 日志(print 替代 logging) ====================
|
||||
@@ -243,10 +232,7 @@ def load_cookies(path):
|
||||
|
||||
# ==================== HR 登录(滑块验证码) ====================
|
||||
def match_slider_dual(bg_bytes, slider_bytes):
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。缺 opencv 时抛清晰错误。"""
|
||||
if cv2 is None or np is None:
|
||||
raise RuntimeError("缺少滑块识别依赖,请安装: pip install opencv-python numpy Pillow")
|
||||
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。"""
|
||||
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
||||
slider_color = cv2.imdecode(np.frombuffer(slider_bytes, np.uint8), cv2.IMREAD_UNCHANGED)
|
||||
if bg_img is None or slider_color is None:
|
||||
@@ -427,9 +413,6 @@ def hr_login(username=None, password=None):
|
||||
if not final_username or not final_password:
|
||||
raise RuntimeError("HR 用户名或密码未提供,请设置环境变量 hr_login_username / hr_login_password")
|
||||
|
||||
if ChromiumPage is None:
|
||||
raise RuntimeError("缺少 DrissionPage 依赖,请先安装: pip install DrissionPage")
|
||||
|
||||
co = ChromiumOptions()
|
||||
if HR_HEADLESS:
|
||||
co.headless()
|
||||
@@ -499,8 +482,6 @@ def get_hr_session():
|
||||
|
||||
|
||||
def _build_hr_session():
|
||||
if requests is None:
|
||||
raise RuntimeError("缺少 requests 依赖,请先安装")
|
||||
cookies = load_cookies(COOKIE_FILE_HR)
|
||||
if not cookies:
|
||||
raise RuntimeError("无 hr cookies,请先完成 HR 登录")
|
||||
@@ -703,8 +684,6 @@ def get_leave_range(today=None):
|
||||
|
||||
# ==================== 工资卡导出 Excel ====================
|
||||
def export_excel(data_on_job, data_leave, save_dir):
|
||||
if pd is None:
|
||||
raise RuntimeError("缺少 pandas 依赖,无法导出 Excel")
|
||||
if not (data_on_job or data_leave):
|
||||
raise ValueError("未查询到任何数据,无法导出")
|
||||
|
||||
@@ -851,9 +830,6 @@ def check_wage_card(input_path, output_path=None):
|
||||
- 无银行卡表.xlsx:未提供银行卡号(银行卡空白)的人员
|
||||
- 工资卡异常名单.xlsx:除无银行卡外的其他异常人员(含身份证不一致)
|
||||
"""
|
||||
if pd is None:
|
||||
raise RuntimeError("缺少 pandas 依赖,无法处理 Excel")
|
||||
|
||||
df = pd.read_excel(input_path)
|
||||
logger.info("读取工资卡汇总表:%s(%d 行)", input_path, len(df))
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
- 单文件自包含,可放任意目录直接运行(含 App 项目目录或影刀环境)。
|
||||
- 复刻 app 版 employer_insurance.py 全部业务逻辑(校验/初始化/业务处理/分配/输出)。
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install pandas openpyxl
|
||||
|
||||
环境变量(.env 文件或系统变量,可选):
|
||||
@@ -47,16 +47,18 @@ from collections import defaultdict
|
||||
from copy import copy
|
||||
from datetime import datetime
|
||||
|
||||
# ==================== 第三方库导入(懒加载) ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
import pandas as pd
|
||||
except ImportError:
|
||||
pd = None
|
||||
|
||||
try:
|
||||
from openpyxl import load_workbook
|
||||
except ImportError:
|
||||
load_workbook = None
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install pandas openpyxl\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
|
||||
# ==================== 日志(print 替代 logging) ====================
|
||||
@@ -714,9 +716,6 @@ def main():
|
||||
前置:先运行 roster_filter_yingdao.py(筛选复制),并手动打开目标文件
|
||||
刷新公式计算结果(Ctrl+S 保存)后,再运行本步骤。
|
||||
"""
|
||||
if pd is None or load_workbook is None:
|
||||
raise RuntimeError("缺少 pandas/openpyxl 依赖,请先安装: pip install pandas openpyxl")
|
||||
|
||||
logger.info("目标文件:%s", TARGET_FILE)
|
||||
|
||||
# 检查文件是否存在
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
- 输出统一规范:单 sheet、只保留第2行表头(丢弃第1行标题)、「类型」列统一在最后一列
|
||||
(与 app 版 roster_export._merge_roster_files 输出一致,供后续筛选复制直接读取)。
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install DrissionPage python-dotenv requests pandas openpyxl opencv-python numpy Pillow
|
||||
|
||||
环境变量(.env 文件或系统变量):
|
||||
@@ -41,29 +41,22 @@ import random
|
||||
import re
|
||||
import time
|
||||
|
||||
# ==================== 第三方库导入 ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
except ImportError:
|
||||
ChromiumPage = None
|
||||
ChromiumOptions = None
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
try:
|
||||
import pandas as pd
|
||||
except ImportError:
|
||||
pd = None
|
||||
|
||||
try:
|
||||
import cv2
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
cv2 = None
|
||||
np = None
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install DrissionPage python-dotenv requests pandas openpyxl opencv-python "
|
||||
"numpy Pillow\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
|
||||
# ==================== 日志(print 替代 logging) ====================
|
||||
@@ -194,10 +187,7 @@ def load_cookies(path):
|
||||
|
||||
# ==================== HR 登录(滑块验证码) ====================
|
||||
def match_slider_dual(bg_bytes, slider_bytes):
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。缺 opencv 时抛清晰错误。"""
|
||||
if cv2 is None or np is None:
|
||||
raise RuntimeError("缺少滑块识别依赖,请安装: pip install opencv-python numpy Pillow")
|
||||
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。"""
|
||||
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
||||
slider_color = cv2.imdecode(np.frombuffer(slider_bytes, np.uint8), cv2.IMREAD_UNCHANGED)
|
||||
if bg_img is None or slider_color is None:
|
||||
@@ -377,8 +367,6 @@ class LoginRequiredError(Exception):
|
||||
|
||||
def _create_page():
|
||||
"""创建新的 ChromiumPage(统一配置)。"""
|
||||
if ChromiumPage is None:
|
||||
raise RuntimeError("缺少 DrissionPage 依赖,请先安装: pip install DrissionPage")
|
||||
co = ChromiumOptions()
|
||||
if HR_HEADLESS:
|
||||
co.headless()
|
||||
@@ -717,8 +705,6 @@ def _normalize_and_save(files_with_status, output_path):
|
||||
Returns:
|
||||
合并后文件路径
|
||||
"""
|
||||
if pd is None:
|
||||
raise RuntimeError("缺少 pandas 依赖,无法合并 Excel")
|
||||
dfs = []
|
||||
for status, path in files_with_status:
|
||||
df = pd.read_excel(path, header=1) # 取第2行作表头,丢弃第1行标题
|
||||
@@ -774,9 +760,6 @@ def export_roster(download_dir=None, template_name=None, output_path=None, statu
|
||||
Raises:
|
||||
RuntimeError: 任何流程步骤失败或下载未检测到时抛出。
|
||||
"""
|
||||
if ChromiumPage is None:
|
||||
raise RuntimeError("缺少 DrissionPage 依赖,请先安装: pip install DrissionPage")
|
||||
|
||||
download_dir = os.path.abspath(download_dir or DEFAULT_DOWNLOAD_DIR)
|
||||
template_name = template_name or DEFAULT_TEMPLATE
|
||||
statuses = list(statuses) if statuses else list(DEFAULT_STATUSES)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
B~O 覆盖写入、清空超出新数据的旧行(与 app 版逻辑一致)。
|
||||
- 依赖同目录 roster_export_yingdao.py(仅源表缺失且需自动导出时懒加载引用)。
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install pandas openpyxl
|
||||
|
||||
环境变量(.env 文件或系统变量,可选):
|
||||
@@ -35,16 +35,18 @@ import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
# ==================== 第三方库导入(懒加载) ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
import pandas as pd
|
||||
except ImportError:
|
||||
pd = None
|
||||
|
||||
try:
|
||||
from openpyxl import load_workbook
|
||||
except ImportError:
|
||||
load_workbook = None
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install pandas openpyxl\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
|
||||
# ==================== 日志(print 替代 logging) ====================
|
||||
@@ -129,11 +131,6 @@ def filter_and_copy_roster(employee_file: str = None, target_file: str = None) -
|
||||
FileNotFoundError: 源表或目标表不存在
|
||||
ValueError: 源表列数不足 或 目标表缺少指定 Sheet
|
||||
"""
|
||||
if pd is None:
|
||||
raise RuntimeError("缺少 pandas 依赖,无法读取源表,请先安装: pip install pandas")
|
||||
if load_workbook is None:
|
||||
raise RuntimeError("缺少 openpyxl 依赖,无法写入目标表,请先安装: pip install openpyxl")
|
||||
|
||||
employee_file, target_file = check_files(employee_file, target_file)
|
||||
|
||||
# ---------- 1. 读取源表(统一规范:单 sheet,自动定位表头行,业务列 B~O) ----------
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
@Description: 请假审批流程(影刀单文件版)- 合并自原项目 13 个模块,业务逻辑完全一致
|
||||
@Version: 2.0.0
|
||||
|
||||
依赖安装:
|
||||
pip install DrissionPage python-dotenv pyautogui pywin32 pyperclip
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install DrissionPage python-dotenv pyautogui pywin32 pyperclip Pillow numpy rapidocr-onnxruntime
|
||||
|
||||
环境变量(.env 文件或系统变量):
|
||||
oa_login_url=登录页URL
|
||||
@@ -31,51 +31,31 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Callable, Dict, List, Tuple
|
||||
from urllib.parse import urlencode, urlparse, parse_qs
|
||||
|
||||
# ==================== 第三方库导入 ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
from DrissionPage import ChromiumPage, SessionPage
|
||||
except ImportError:
|
||||
ChromiumPage = None
|
||||
SessionPage = None
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
# 钉钉推送依赖(懒加载,缺失时给出清晰提示)
|
||||
try:
|
||||
import pyautogui
|
||||
except ImportError:
|
||||
pyautogui = None
|
||||
|
||||
try:
|
||||
import win32gui
|
||||
import win32con
|
||||
import win32clipboard
|
||||
except ImportError:
|
||||
win32gui = None
|
||||
win32con = None
|
||||
win32clipboard = None
|
||||
|
||||
try:
|
||||
import pyperclip
|
||||
except ImportError:
|
||||
pyperclip = None
|
||||
from PIL import Image, ImageEnhance
|
||||
import numpy as np
|
||||
from rapidocr_onnxruntime import RapidOCR
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install DrissionPage python-dotenv pyautogui pywin32 pyperclip "
|
||||
"Pillow numpy rapidocr-onnxruntime\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
# ==================== OCR 依赖(附件内容检测,复用 app/utils/ocr.py) ====================
|
||||
# 保证无论从哪个目录运行都能导入 app 包(项目根目录 = 本文件上级目录的上级)
|
||||
try:
|
||||
import sys as _sys
|
||||
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if _PROJECT_ROOT not in _sys.path:
|
||||
_sys.path.insert(0, _PROJECT_ROOT)
|
||||
from app.utils.ocr import check_leave_attachment, marriage_within_one_year
|
||||
except Exception as _ocr_import_err: # noqa: BLE001
|
||||
check_leave_attachment = None
|
||||
marriage_within_one_year = None
|
||||
logger_ocr = None
|
||||
# 缺失时由调用方回退到人工复核
|
||||
# ==================== OCR 附件内容检测(单文件自包含) ====================
|
||||
# 影刀版不依赖项目目录,直接使用下方内置 OCR 实现(行为与原项目 app/utils/ocr.py 完全一致)。
|
||||
# Pillow/numpy/rapidocr 已在上方启动校验中强制安装,不做懒加载。
|
||||
|
||||
|
||||
# ==================== 路径 & 常量配置 ====================
|
||||
@@ -118,6 +98,151 @@ class _PrintLogger:
|
||||
logger = _PrintLogger()
|
||||
|
||||
|
||||
# ==================== 内置 OCR 兜底实现 ====================
|
||||
# 内置 OCR 实现(单文件自包含),行为与原项目 app/utils/ocr.py 完全一致:
|
||||
# 病假/婚假/产检假按关键词命中检测,结婚证按最大日期识别登记日期并判断 1 年内。
|
||||
_OCR_LEAVE_KEYWORDS = {
|
||||
# 病假/医疗类:对应医院诊断证明、病历、检验单等
|
||||
"sick": {
|
||||
"医院", "门诊", "就诊", "诊断", "病历", "医嘱", "病假", "病情",
|
||||
"检查", "检验", "处方", "诊断证明", "疾病", "治疗", "医技报告单",
|
||||
},
|
||||
# 婚假类:对应结婚证、婚姻登记证明
|
||||
"marriage": {
|
||||
"结婚证", "婚姻登记", "结婚登记", "持证人", "婚姻登记机关",
|
||||
"婚姻证", "中华人民共和国结婚证",
|
||||
},
|
||||
# 产检假类:对应产检报告、B超单、妊娠诊断证明
|
||||
"maternity": {
|
||||
"产检", "产前检查", "孕检", "妊娠", "怀孕", "孕周", "预产期",
|
||||
"超声检查", "B超", "胎儿", "产科", "孕期", "产前筛查", "胎心",
|
||||
},
|
||||
}
|
||||
_OCR_CONFIDENCE_THRESHOLD = 0.5
|
||||
_OCR_VALID_TYPES = set(_OCR_LEAVE_KEYWORDS.keys()) | {"all"}
|
||||
|
||||
_ocr_engine = None # 前向声明,稍后在模块加载时统一初始化(不做懒加载)
|
||||
|
||||
|
||||
def _ocr_read_text(file_path, debug=False):
|
||||
"""OCR 识别图片,返回 (清洗后拼接文本, 原始拼接文本)。"""
|
||||
if _ocr_engine is None:
|
||||
raise RuntimeError("OCR 引擎未初始化(rapidocr-onnxruntime 缺失或初始化失败)")
|
||||
|
||||
with Image.open(file_path) as img:
|
||||
gray_img = img.convert("L")
|
||||
enhancer = ImageEnhance.Contrast(gray_img)
|
||||
enhanced_img = enhancer.enhance(2.0)
|
||||
img_array = np.array(enhanced_img)
|
||||
|
||||
ocr_result, _ = _ocr_engine(img_array)
|
||||
|
||||
if debug:
|
||||
print("=" * 60)
|
||||
print("【OCR原始识别片段(含置信度)】")
|
||||
for idx, (box, txt, score) in enumerate(ocr_result or []):
|
||||
print(f" [{idx:02d}] 置信度:{score:.3f} | 文本: {txt}")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
raw_text = ""
|
||||
full_text = ""
|
||||
for box, text, score in ocr_result or []:
|
||||
if score < _OCR_CONFIDENCE_THRESHOLD:
|
||||
continue
|
||||
raw_text += text
|
||||
clean_text = text.replace(" ", "").replace("\u3000", "")
|
||||
full_text += clean_text
|
||||
|
||||
# 过滤乱码特殊符号,保留常用字符
|
||||
clean_pattern = re.compile(r'[^\u4e00-\u9fa5a-zA-Z0-9,。!?;:、《》“”‘’()【】.,;:!?年月日]')
|
||||
full_text = clean_pattern.sub('', full_text)
|
||||
|
||||
return full_text, raw_text
|
||||
|
||||
|
||||
def _ocr_check_leave_attachment(file_path, leave_type="sick", debug=False):
|
||||
"""检测附件图片是否包含对应假期关键词;文件异常/识别失败/未命中均返回 False。"""
|
||||
if leave_type not in _OCR_VALID_TYPES:
|
||||
return False
|
||||
if not os.path.isfile(file_path):
|
||||
return False
|
||||
|
||||
try:
|
||||
full_text, _ = _ocr_read_text(file_path, debug=debug)
|
||||
except Exception as e:
|
||||
if debug:
|
||||
print(f"[识别异常] {e}")
|
||||
return False
|
||||
|
||||
if debug:
|
||||
print("【清洗后匹配文本】")
|
||||
print(full_text)
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
if leave_type == "all":
|
||||
target_keywords = set()
|
||||
for kw_set in _OCR_LEAVE_KEYWORDS.values():
|
||||
target_keywords.update(kw_set)
|
||||
else:
|
||||
target_keywords = _OCR_LEAVE_KEYWORDS[leave_type]
|
||||
|
||||
hit_words = [kw for kw in target_keywords if kw in full_text]
|
||||
if debug:
|
||||
print(f"【命中关键词】: {hit_words}")
|
||||
|
||||
return len(hit_words) > 0
|
||||
|
||||
|
||||
def _ocr_extract_dates(text):
|
||||
"""从文本中提取所有日期,支持 "20XX年X月X日"、"XXXX-XX-XX"、"XXXX/XX/XX" 等格式。"""
|
||||
dates = []
|
||||
patterns = [
|
||||
r'(\d{4})\s*年\s*(\d{1,2})\s*月\s*(\d{1,2})\s*日?',
|
||||
r'(\d{4})\s*[-/.年]\s*(\d{1,2})\s*[-/.月]\s*(\d{1,2})\s*日?',
|
||||
]
|
||||
for pat in patterns:
|
||||
for m in re.finditer(pat, text):
|
||||
try:
|
||||
dates.append(datetime(int(m.group(1)), int(m.group(2)), int(m.group(3))).date())
|
||||
except ValueError:
|
||||
continue
|
||||
return dates
|
||||
|
||||
|
||||
def _ocr_marriage_within_one_year(file_path, today=None, debug=False):
|
||||
"""识别结婚证登记日期(取最大日期)并判断是否在当前日期 1 年内。"""
|
||||
if today is None:
|
||||
today = datetime.now().date()
|
||||
if not os.path.isfile(file_path):
|
||||
return False, None
|
||||
|
||||
try:
|
||||
full_text, _ = _ocr_read_text(file_path, debug=debug)
|
||||
except Exception as e:
|
||||
if debug:
|
||||
print(f"[识别异常] {e}")
|
||||
return False, None
|
||||
|
||||
dates = _ocr_extract_dates(full_text)
|
||||
if not dates:
|
||||
if debug:
|
||||
print("【未识别到任何日期】")
|
||||
return False, None
|
||||
|
||||
reg_date = max(dates)
|
||||
ok = reg_date <= today and (today - reg_date).days <= 365
|
||||
if debug:
|
||||
print(f"【识别日期】: {dates}")
|
||||
print(f"【登记日期】: {reg_date},1年内: {ok}")
|
||||
return ok, reg_date
|
||||
|
||||
|
||||
# 单文件自包含:直接使用内置 OCR 实现(启动即初始化引擎,不做懒加载)
|
||||
check_leave_attachment = _ocr_check_leave_attachment
|
||||
marriage_within_one_year = _ocr_marriage_within_one_year
|
||||
_ocr_engine = RapidOCR() # 首次运行自动下载模型,缺库/失败立即暴露
|
||||
|
||||
|
||||
# ==================== 重试装饰器 ====================
|
||||
class RetryExhaustedError(Exception):
|
||||
pass
|
||||
@@ -774,14 +899,7 @@ def resolve_sso_params(browser, sso_url, wait_timeout=20):
|
||||
|
||||
|
||||
# ==================== 审批引擎 ====================
|
||||
def _check_browser_deps():
|
||||
"""检查浏览器自动化依赖是否就绪,缺失时给出清晰提示。"""
|
||||
if ChromiumPage is None or SessionPage is None:
|
||||
raise RuntimeError("DrissionPage 未安装,请运行: pip install DrissionPage")
|
||||
|
||||
|
||||
def _get_browser_and_session(subject):
|
||||
_check_browser_deps()
|
||||
saved_session = load_saved_session()
|
||||
if saved_session is not None and is_session_valid(saved_session, subject):
|
||||
logger.info("复用已保存的登录会话,跳过登录")
|
||||
@@ -896,19 +1014,6 @@ def show_rpa_result_popup(page: ChromiumPage,
|
||||
DINGTALK_WINDOW_KEYWORD = "钉钉"
|
||||
|
||||
|
||||
def _check_dingtalk_deps():
|
||||
"""检查钉钉推送必需的第三方依赖,缺失时抛出带安装提示的 RuntimeError。"""
|
||||
missing = []
|
||||
if pyautogui is None:
|
||||
missing.append("pyautogui")
|
||||
if win32gui is None:
|
||||
missing.append("pywin32")
|
||||
if pyperclip is None:
|
||||
missing.append("pyperclip")
|
||||
if missing:
|
||||
raise RuntimeError(f"缺少依赖: {', '.join(missing)},请运行: pip install {' '.join(missing)}")
|
||||
|
||||
|
||||
def _find_dingtalk_hwnd():
|
||||
"""用 win32gui.EnumWindows 按标题查找钉钉主窗口句柄。"""
|
||||
matches = []
|
||||
@@ -977,7 +1082,6 @@ def _activate_dingtalk():
|
||||
|
||||
def _send_dingtalk_text(target, text):
|
||||
"""搜索联系人并发送文本:激活 -> 搜索 -> 进会话 -> 点击输入框聚焦 -> 粘贴 -> 发送。"""
|
||||
_check_dingtalk_deps()
|
||||
_activate_dingtalk()
|
||||
# 搜索联系人
|
||||
pyautogui.hotkey("ctrl", "shift", "f")
|
||||
@@ -1295,9 +1399,6 @@ def _verify_attachment(session, vacation_type, reason, file_id):
|
||||
if not path:
|
||||
return "人工复核", "附件下载失败,需人工核验", None
|
||||
|
||||
if check_leave_attachment is None:
|
||||
return "人工复核", "OCR 模块不可用,需人工核验", path
|
||||
|
||||
if vacation_type == "病假":
|
||||
if check_leave_attachment(path, "sick"):
|
||||
return "通过", "附件OCR检测通过(病假)", path
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
@Description: 加班审批流程(影刀单文件版)- 合并自原项目 13 个模块
|
||||
@Version: 1.0.0
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install DrissionPage python-dotenv chinese_calendar pyautogui pywin32 pyperclip
|
||||
|
||||
环境变量(.env 文件或系统变量):
|
||||
@@ -31,40 +31,27 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
from urllib.parse import urlencode, urlparse, parse_qs
|
||||
|
||||
# ==================== 第三方库导入 ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
from DrissionPage import ChromiumPage, SessionPage
|
||||
except ImportError:
|
||||
ChromiumPage = None
|
||||
SessionPage = None
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
# 模块加载时即读取 .env,避免复用已保存会话(跳过 oa_login)时环境变量未加载
|
||||
load_dotenv()
|
||||
|
||||
# 钉钉推送依赖(懒加载,缺失时给出清晰提示)
|
||||
try:
|
||||
import pyautogui
|
||||
except ImportError:
|
||||
pyautogui = None
|
||||
|
||||
try:
|
||||
import win32gui
|
||||
import win32con
|
||||
import win32clipboard
|
||||
except ImportError:
|
||||
win32gui = None
|
||||
win32con = None
|
||||
win32clipboard = None
|
||||
|
||||
try:
|
||||
import pyperclip
|
||||
except ImportError:
|
||||
pyperclip = None
|
||||
import chinese_calendar as cc
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install DrissionPage python-dotenv chinese_calendar pyautogui pywin32 pyperclip\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
# 模块加载时即读取 .env,避免复用已保存会话(跳过 oa_login)时环境变量未加载
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# ==================== 路径 & 常量配置 ====================
|
||||
@@ -722,14 +709,7 @@ def resolve_sso_params(browser, sso_url, wait_timeout=20):
|
||||
|
||||
|
||||
# ==================== 审批引擎 ====================
|
||||
def _check_browser_deps():
|
||||
"""检查浏览器自动化依赖是否就绪,缺失时给出清晰提示。"""
|
||||
if ChromiumPage is None or SessionPage is None:
|
||||
raise RuntimeError("DrissionPage 未安装,请运行: pip install DrissionPage")
|
||||
|
||||
|
||||
def _get_browser_and_session(subject):
|
||||
_check_browser_deps()
|
||||
saved_session = load_saved_session()
|
||||
if saved_session is not None and is_session_valid(saved_session, subject):
|
||||
logger.info("复用已保存的登录会话,跳过登录")
|
||||
@@ -844,19 +824,6 @@ def show_rpa_result_popup(page: ChromiumPage,
|
||||
DINGTALK_WINDOW_KEYWORD = "钉钉"
|
||||
|
||||
|
||||
def _check_dingtalk_deps():
|
||||
"""检查钉钉推送必需的第三方依赖,缺失时抛出带安装提示的 RuntimeError。"""
|
||||
missing = []
|
||||
if pyautogui is None:
|
||||
missing.append("pyautogui")
|
||||
if win32gui is None:
|
||||
missing.append("pywin32")
|
||||
if pyperclip is None:
|
||||
missing.append("pyperclip")
|
||||
if missing:
|
||||
raise RuntimeError(f"缺少依赖: {', '.join(missing)},请运行: pip install {' '.join(missing)}")
|
||||
|
||||
|
||||
def _find_dingtalk_hwnd():
|
||||
"""用 win32gui.EnumWindows 按标题查找钉钉主窗口句柄。"""
|
||||
matches = []
|
||||
@@ -925,7 +892,6 @@ def _activate_dingtalk():
|
||||
|
||||
def _send_dingtalk_text(target, text):
|
||||
"""搜索联系人并发送文本:激活 -> 搜索 -> 进会话 -> 点击输入框聚焦 -> 粘贴 -> 发送。"""
|
||||
_check_dingtalk_deps()
|
||||
_activate_dingtalk()
|
||||
# 搜索联系人
|
||||
pyautogui.hotkey("ctrl", "shift", "f")
|
||||
@@ -1216,7 +1182,6 @@ def _is_within_arrival_window(punch_str, start_dt,
|
||||
|
||||
def _is_spring_festival(date_str):
|
||||
try:
|
||||
import chinese_calendar as cc
|
||||
date = datetime.strptime(date_str, "%Y-%m-%d").date()
|
||||
is_holiday, holiday_name = cc.get_holiday_detail(date)
|
||||
return (is_holiday and holiday_name == 'Spring Festival'
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
- 参保申请表:某工号在 HR 参保记录中「有返回数据」→ 已参保,属异常;
|
||||
- 停保申请表:某工号在 HR 参保记录中「无返回数据」→ 已停保,属异常。
|
||||
|
||||
依赖安装:
|
||||
依赖安装(影刀版启动校验:所有库必须预先装齐,任一缺失启动即报错退出,不懒加载):
|
||||
pip install DrissionPage python-dotenv requests xlrd openpyxl opencv-python numpy Pillow pyautogui pywin32 pyperclip
|
||||
|
||||
环境变量(.env 文件或系统变量):
|
||||
@@ -36,65 +36,31 @@ import time
|
||||
from datetime import datetime
|
||||
from urllib.parse import urljoin, urlparse, parse_qs
|
||||
|
||||
# ==================== 第三方库导入 ====================
|
||||
# ==================== 第三方库导入(影刀版启动校验:全部必须预先安装,不懒加载) ====================
|
||||
# 任一依赖缺失会立即报错退出,避免运行到中途才发现缺库
|
||||
try:
|
||||
from DrissionPage import ChromiumPage, SessionPage, ChromiumOptions
|
||||
except ImportError:
|
||||
ChromiumPage = None
|
||||
SessionPage = None
|
||||
ChromiumOptions = None
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
requests = None
|
||||
|
||||
try:
|
||||
import xlrd
|
||||
except ImportError:
|
||||
xlrd = None
|
||||
|
||||
try:
|
||||
from openpyxl import load_workbook as _load_workbook
|
||||
from openpyxl import Workbook as _XlsxWorkbook
|
||||
from openpyxl.styles import PatternFill, Font, Alignment
|
||||
from openpyxl.utils import get_column_letter
|
||||
except ImportError:
|
||||
_load_workbook = None
|
||||
_XlsxWorkbook = None
|
||||
PatternFill = None
|
||||
Font = None
|
||||
Alignment = None
|
||||
get_column_letter = None
|
||||
|
||||
# 滑块验证码识别依赖(懒加载)
|
||||
try:
|
||||
import cv2
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
cv2 = None
|
||||
np = None
|
||||
|
||||
# 钉钉推送依赖(懒加载)
|
||||
try:
|
||||
import pyautogui
|
||||
except ImportError:
|
||||
pyautogui = None
|
||||
try:
|
||||
import win32gui
|
||||
import win32con
|
||||
except ImportError:
|
||||
win32gui = None
|
||||
win32con = None
|
||||
try:
|
||||
import pyperclip
|
||||
except ImportError:
|
||||
pyperclip = None
|
||||
except ImportError as _import_err:
|
||||
raise RuntimeError(
|
||||
"缺少必需依赖,无法启动(影刀版要求所有库在启动前装齐,不懒加载)。\n"
|
||||
"请先执行安装:\n"
|
||||
" pip install DrissionPage python-dotenv requests xlrd openpyxl opencv-python "
|
||||
"numpy Pillow pyautogui pywin32 pyperclip\n"
|
||||
f"缺失依赖详情: {_import_err}"
|
||||
)
|
||||
|
||||
|
||||
# ==================== 路径 & 常量配置 ====================
|
||||
@@ -370,10 +336,7 @@ HR_HEADLESS = False
|
||||
|
||||
|
||||
def match_slider_dual(bg_bytes, slider_bytes):
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。缺 opencv 时抛清晰错误。"""
|
||||
if cv2 is None or np is None:
|
||||
raise RuntimeError("缺少滑块识别依赖,请安装: pip install opencv-python numpy Pillow")
|
||||
|
||||
"""模板匹配滑块缺口,返回物理距离(px)。"""
|
||||
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
||||
slider_color = cv2.imdecode(np.frombuffer(slider_bytes, np.uint8), cv2.IMREAD_UNCHANGED)
|
||||
if bg_img is None or slider_color is None:
|
||||
@@ -624,8 +587,6 @@ def get_hr_session():
|
||||
|
||||
|
||||
def _build_hr_session():
|
||||
if requests is None:
|
||||
raise RuntimeError("缺少 requests 依赖,请先安装")
|
||||
cookies = load_cookies(COOKIE_FILE_HR)
|
||||
if not cookies:
|
||||
raise RuntimeError("无 hr cookies,请先完成 HR 登录")
|
||||
@@ -786,8 +747,6 @@ def _date_display(value, wb):
|
||||
|
||||
|
||||
def _read_and_clean(xls_path):
|
||||
if xlrd is None:
|
||||
raise RuntimeError("缺少 xlrd 依赖,无法读取 .xls")
|
||||
wb = xlrd.open_workbook(xls_path)
|
||||
sh = wb.sheet_by_index(0)
|
||||
headers = [str(sh.cell_value(0, c)).strip() for c in range(sh.ncols)]
|
||||
@@ -886,9 +845,6 @@ def _si_preflight(session):
|
||||
|
||||
|
||||
def _write_annotated(headers, rows, emp_col, mode, base_name, output_dir="."):
|
||||
if _XlsxWorkbook is None:
|
||||
raise RuntimeError("缺少 openpyxl 依赖,无法导出 .xlsx")
|
||||
|
||||
unique_codes, seen = [], set()
|
||||
for row in rows:
|
||||
code = str(row[emp_col]).strip()
|
||||
@@ -1013,18 +969,6 @@ def export_suspension(output_dir=".", query_date=None):
|
||||
|
||||
|
||||
# ==================== 钉钉推送 ====================
|
||||
def _check_dingtalk_deps():
|
||||
missing = []
|
||||
if pyautogui is None:
|
||||
missing.append("pyautogui")
|
||||
if win32gui is None:
|
||||
missing.append("pywin32")
|
||||
if pyperclip is None:
|
||||
missing.append("pyperclip")
|
||||
if missing:
|
||||
raise RuntimeError(f"缺少依赖: {', '.join(missing)},请运行: pip install {' '.join(missing)}")
|
||||
|
||||
|
||||
def _find_dingtalk_hwnd():
|
||||
matches = []
|
||||
|
||||
@@ -1070,7 +1014,6 @@ def _activate_dingtalk():
|
||||
|
||||
|
||||
def _send_dingtalk_text(target, text):
|
||||
_check_dingtalk_deps()
|
||||
_activate_dingtalk()
|
||||
pyautogui.hotkey("ctrl", "shift", "f")
|
||||
time.sleep(0.5)
|
||||
@@ -1099,7 +1042,7 @@ def _send_dingtalk_text(target, text):
|
||||
|
||||
def _read_abnormal(xlsx_path, label):
|
||||
"""读取标注表,返回 (总条数, 异常行列表)。异常行形如 [工号, 申请人/姓名, 结果] 说明文本。"""
|
||||
if _load_workbook is None or not os.path.exists(xlsx_path):
|
||||
if not os.path.exists(xlsx_path):
|
||||
return 0, []
|
||||
ws = _load_workbook(xlsx_path).active
|
||||
rows = list(ws.iter_rows(values_only=True))
|
||||
|
||||
Reference in New Issue
Block a user