refactor: 重构HRBP公共层与业务模块,整理废弃资源
1. 迁移并统一HR会话、配置、API等公共能力至hrbp/common层,实现ehr/oa模块复用 2. 删除captcha_debug调试用图片资源与旧session_manager文件 3. 重构考勤异常处理模块,补充分级逻辑与导出优化 4. 新增OA/HR多套API封装模块与配套文档 5. 移除旧通用接口规划文档,补充完整需求与开发文档
This commit is contained in:
@@ -1083,6 +1083,81 @@ def push_report(report, subject=""):
|
||||
return False
|
||||
|
||||
|
||||
# ==================== 真实审批提交 ====================
|
||||
# 影刀环境无 .env 文件,开关直接写死在代码中;如需临时关闭自动审批改为 False
|
||||
APPROVE_ENABLED = True
|
||||
# 审批按钮:通过->同意(#chooseSubmit),驳回->退回申请人(#backApplySubmit)
|
||||
_APPROVE_BUTTONS = {
|
||||
"通过": ("#chooseSubmit", "同意"),
|
||||
"驳回": ("#backApplySubmit", "退回申请人"),
|
||||
}
|
||||
|
||||
|
||||
def _find_button(page, selector, timeout=3.0):
|
||||
"""在详情页查找审批按钮:优先主文档,找不到则遍历 iframe(部分详情页按钮在 iframe 内)。"""
|
||||
try:
|
||||
btn = page.ele(selector, timeout=timeout)
|
||||
if btn:
|
||||
return btn
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
frames = page.get_frames()
|
||||
except Exception:
|
||||
frames = []
|
||||
for frame in frames:
|
||||
try:
|
||||
btn = frame.ele(selector, timeout=1)
|
||||
if btn:
|
||||
return btn
|
||||
except Exception:
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
def submit_approval(page, decision):
|
||||
"""
|
||||
按校验结论在流程详情页执行真实审批提交。
|
||||
|
||||
Args:
|
||||
page: 停留在详情页的 ChromiumPage
|
||||
decision: 校验决策(通过/驳回;其余决策不提交)
|
||||
|
||||
Returns:
|
||||
{"action": "同意"/"退回申请人"/"-", "ok": "true"/"false", "message": ...}
|
||||
"""
|
||||
if decision not in _APPROVE_BUTTONS:
|
||||
return {"action": "-", "ok": "true", "message": "无需提交"}
|
||||
selector, label = _APPROVE_BUTTONS[decision]
|
||||
try:
|
||||
btn = _find_button(page, selector)
|
||||
if btn is None:
|
||||
msg = f"未找到审批按钮 {selector}({label}),可能页面未加载完成或按钮在未识别的 iframe 中"
|
||||
logger.error(msg)
|
||||
return {"action": label, "ok": "false", "message": msg}
|
||||
logger.info("点击审批按钮: %s(%s)", selector, label)
|
||||
btn.click()
|
||||
# 点击弹出的确认框"确定"按钮(同意/驳回共用同一确认框,仅标题不同)。
|
||||
# 确认框由 rsMessageBox.confirm 点击后动态生成(modal 渐入动画),轮询等待其出现
|
||||
confirm = None
|
||||
for _ in range(10):
|
||||
confirm = _find_button(page, "#custom-confirm-modal-ok", timeout=1)
|
||||
if confirm:
|
||||
break
|
||||
time.sleep(0.5)
|
||||
if confirm is None:
|
||||
msg = "未找到确认框确定按钮 #custom-confirm-modal-ok,审批未提交"
|
||||
logger.error(msg)
|
||||
return {"action": label, "ok": "false", "message": msg}
|
||||
confirm.click()
|
||||
logger.info("已点击确认框确定按钮")
|
||||
time.sleep(1.0)
|
||||
return {"action": label, "ok": "true", "message": f"已执行审批提交[{label}]"}
|
||||
except Exception as e:
|
||||
logger.error("审批提交失败[%s]: %s", label, str(e))
|
||||
return {"action": label, "ok": "false", "message": f"审批提交[{label}]失败: {e}"}
|
||||
|
||||
|
||||
def run_flow(subject, validate_doc, generate_report):
|
||||
logger.info("%s审批流程开始", subject)
|
||||
|
||||
@@ -1096,9 +1171,20 @@ def run_flow(subject, validate_doc, generate_report):
|
||||
try:
|
||||
doc_detail = _fetch_doc_detail(browser, session, doc)
|
||||
result = validate_doc(doc_detail, session)
|
||||
# 真实审批提交:仅当 APPROVE_ENABLED=True 时执行(默认关闭)
|
||||
# 与加班共用同一开关(公共审批引擎亦如此),驳回暂不自动处理(保留待人工复核),仅对"通过"提交真实审批
|
||||
if APPROVE_ENABLED:
|
||||
if result.get("decision") == "通过":
|
||||
submit = submit_approval(browser, result.get("decision"))
|
||||
result["审批动作"] = submit["action"]
|
||||
result["审批结果"] = f"{'成功' if submit['ok'] == 'true' else '失败'},{submit['message']}"
|
||||
logger.info("审批提交: %s %s", submit["action"], result["审批结果"])
|
||||
else:
|
||||
logger.info("决策为%s,暂不自动提交审批(待人工处理)", result.get("decision"))
|
||||
results.append(result)
|
||||
logger.info("已校验: %s - %s -> %s", result["creator"], result["title"], result["decision"])
|
||||
# 弹出结果提示:通过=绿勾,其余(驳回/人工复核/失败)=红叉,停留便于演示
|
||||
# 必须放在审批提交之后:全屏弹窗会遮挡审批按钮,导致真实点击被拦截
|
||||
try:
|
||||
show_rpa_result_popup(
|
||||
browser,
|
||||
@@ -1414,6 +1500,8 @@ def generate_report(results):
|
||||
lines.append(f" {detail}")
|
||||
if note:
|
||||
lines.append(f" 备注: {note}")
|
||||
if r.get("审批动作"):
|
||||
lines.append(f" 审批动作: {r['审批动作']}({r.get('审批结果', '')})")
|
||||
lines.append("")
|
||||
|
||||
# ----- 驳回清单 -----
|
||||
|
||||
@@ -43,6 +43,9 @@ try:
|
||||
except ImportError:
|
||||
load_dotenv = lambda *args, **kwargs: None
|
||||
|
||||
# 模块加载时即读取 .env,避免复用已保存会话(跳过 oa_login)时环境变量未加载
|
||||
load_dotenv()
|
||||
|
||||
# 钉钉推送依赖(懒加载,缺失时给出清晰提示)
|
||||
try:
|
||||
import pyautogui
|
||||
@@ -1034,7 +1037,9 @@ def push_report(report, subject=""):
|
||||
return False
|
||||
|
||||
|
||||
# ==================== 真实审批提交(默认关闭) ====================
|
||||
# ==================== 真实审批提交 ====================
|
||||
# 影刀环境无 .env 文件,开关直接写死在代码中;如需临时关闭自动审批改为 False
|
||||
APPROVE_ENABLED = True
|
||||
# 审批按钮:通过->同意(#chooseSubmit),驳回->退回申请人(#backApplySubmit)
|
||||
_APPROVE_BUTTONS = {
|
||||
"通过": ("#chooseSubmit", "同意"),
|
||||
@@ -1086,8 +1091,14 @@ def submit_approval(page, decision):
|
||||
return {"action": label, "ok": "false", "message": msg}
|
||||
logger.info("点击审批按钮: %s(%s)", selector, label)
|
||||
btn.click()
|
||||
# 点击弹出的确认框"确定"按钮(同意/驳回共用同一确认框,仅标题不同)
|
||||
confirm = _find_button(page, "#custom-confirm-modal-ok", timeout=3)
|
||||
# 点击弹出的确认框"确定"按钮(同意/驳回共用同一确认框,仅标题不同)。
|
||||
# 确认框由 rsMessageBox.confirm 点击后动态生成(modal 渐入动画),轮询等待其出现
|
||||
confirm = None
|
||||
for _ in range(10):
|
||||
confirm = _find_button(page, "#custom-confirm-modal-ok", timeout=1)
|
||||
if confirm:
|
||||
break
|
||||
time.sleep(0.5)
|
||||
if confirm is None:
|
||||
msg = "未找到确认框确定按钮 #custom-confirm-modal-ok,审批未提交"
|
||||
logger.error(msg)
|
||||
@@ -1114,7 +1125,18 @@ def run_flow(subject, validate_doc, generate_report):
|
||||
try:
|
||||
doc_detail = _fetch_doc_detail(browser, session, doc)
|
||||
result = validate_doc(doc_detail, session)
|
||||
# 真实审批提交:仅当 APPROVE_ENABLED=True 时执行(默认关闭)
|
||||
if APPROVE_ENABLED:
|
||||
# 驳回暂不自动处理(保留待人工复核),仅对"通过"提交真实审批
|
||||
if result.get("decision") == "通过":
|
||||
submit = submit_approval(browser, result.get("decision"))
|
||||
result["审批动作"] = submit["action"]
|
||||
result["审批结果"] = f"{'成功' if submit['ok'] == 'true' else '失败'},{submit['message']}"
|
||||
logger.info("审批提交: %s %s", submit["action"], result["审批结果"])
|
||||
else:
|
||||
logger.info("决策为%s,暂不自动提交审批(待人工处理)", result.get("decision"))
|
||||
# 弹出结果提示:通过=绿勾,其余(驳回/人工复核/失败)=红叉,停留便于演示
|
||||
# 必须放在审批提交之后:全屏弹窗会遮挡审批按钮,导致真实点击被拦截
|
||||
try:
|
||||
show_rpa_result_popup(
|
||||
browser,
|
||||
@@ -1123,12 +1145,6 @@ def run_flow(subject, validate_doc, generate_report):
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 真实审批提交:仅当 overtime_approve_enabled=true 时执行(默认关闭)
|
||||
if os.getenv("overtime_approve_enabled", "false").lower() == "true":
|
||||
submit = submit_approval(browser, result.get("decision"))
|
||||
result["审批动作"] = submit["action"]
|
||||
result["审批结果"] = f"{'成功' if submit['ok'] == 'true' else '失败'},{submit['message']}"
|
||||
logger.info("审批提交: %s %s", submit["action"], result["审批结果"])
|
||||
results.append(result)
|
||||
logger.info("已校验: %s - %s -> %s", result["creator"], result["title"], result["decision"])
|
||||
except Exception as e:
|
||||
@@ -1304,6 +1320,8 @@ def _validate_delayed(info, punch, session, staff_id):
|
||||
end = _parse_dt(info.get("加班结束时间"))
|
||||
actual_checkout = _parse_dt(punch.get("当日最晚打卡"))
|
||||
reasons = []
|
||||
# 申请结束时间晚于实际下班打卡、但实际在岗时长(按系统取整)仍满足申请时长时,用于附加到通过备注
|
||||
end_checkout_note = ""
|
||||
|
||||
# 1. 日期校验:加班开始日期与申请加班日期不一致时直接驳回,
|
||||
# 无需再校验后续的时长、区间合规等内容
|
||||
@@ -1353,8 +1371,23 @@ def _validate_delayed(info, punch, session, staff_id):
|
||||
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})")
|
||||
elif start is not None and hours is not None:
|
||||
# 核心原则:申请的加班时长必须与打卡可支撑的实际在岗时长相符。
|
||||
# 按系统取整规则(_calc_delayed_hours),用实际打卡区间(申请开始->实际下班打卡)
|
||||
# 计算实际在岗时长,>= 申请时长即通过(申请结束时间比打卡晚几分钟也属正常)。
|
||||
# 例:申请 18:00-23:05(取整5h),实际打卡23:00:45,实际在岗取整后也是5h,应通过
|
||||
actual_hours = _calc_delayed_hours(start, actual_checkout)
|
||||
if actual_hours >= hours:
|
||||
if end > actual_checkout:
|
||||
end_checkout_note = (
|
||||
f"申请结束时间({end:%H:%M})晚于实际下班打卡({actual_checkout:%H:%M:%S}),"
|
||||
f"实际在岗时长按系统取整为{actual_hours:g}小时,满足申请时长"
|
||||
)
|
||||
else:
|
||||
reasons.append(
|
||||
f"申请结束时间({end:%H:%M})晚于实际下班打卡时间({actual_checkout:%H:%M:%S}),"
|
||||
f"实际在岗时长按取整仅{actual_hours:g}小时,不足申请{hours:g}小时"
|
||||
)
|
||||
|
||||
info["计算加班时长(小时)"] = hours
|
||||
if reasons:
|
||||
@@ -1426,8 +1459,10 @@ def _validate_delayed(info, punch, session, staff_id):
|
||||
info["有效加班时长(小时)"] = effective
|
||||
info["弹性额度D(小时)"] = d_hours
|
||||
note = f"审批通过,有效加班时长{effective:g}小时"
|
||||
if flex_note:
|
||||
note += f"({flex_note})"
|
||||
extra_parts = [end_checkout_note, flex_note]
|
||||
extra = ";".join(p for p in extra_parts if p)
|
||||
if extra:
|
||||
note += f"({extra})"
|
||||
return "通过", note
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user