feat(oa): 新增审批异常状态的统计与通知

1. 为请假、加班审批流程新增异常状态分类统计和专属报告清单
2. 完善审批提交弹窗选择兼容逻辑,适配多类型确认弹窗
3. 提交失败时自动将单据标记为异常状态并记录原始结论
4. 推送摘要中新增异常审批条目展示
This commit is contained in:
2026-08-20 21:45:44 +08:00
parent 250cfc5eb7
commit cfb4c935da
5 changed files with 63 additions and 374 deletions
+26 -5
View File
@@ -103,10 +103,23 @@ def submit_approval(browser, decision: str) -> Dict[str, str]:
return {"action": label, "ok": "false", "message": msg}
logger.info("点击审批按钮: %s(%s)", selector, label)
btn.click()
# 点击弹出的确认框"确定"按钮(同意/驳回共用同一确认框,仅标题不同)
confirm = _find_button(browser, "#custom-confirm-modal-ok", timeout=3)
# 点击同意/退回后,弹出的弹窗结构不固定,需兼容两类"确定"按钮:
# 1) #custom-confirm-modal-ok(普通确认框);
# 2) tag:button@@class:btn-primary@@onclick:confirmSelect(选择人员弹窗,如加班
# "选择中心负责人",人员由系统自动选中,确定按钮 onclick=confirmSelect()
# 为弹窗独有,用多属性与匹配(@@)+包含匹配(:)精确咬住,避免误点页面其它
# modal-footer 里的同类确定按钮)
# 确认框由点击审批按钮后动态生成(modal 渐入动画),轮询等待其出现。
confirm = None
for _ in range(10):
confirm = _find_button(browser, "#custom-confirm-modal-ok", timeout=1)
if confirm is None:
confirm = _find_button(browser, "tag:button@@class:btn-primary@@onclick:confirmSelect", timeout=1)
if confirm:
break
time.sleep(0.5)
if confirm is None:
msg = "未找到确认框确定按钮 #custom-confirm-modal-ok,审批未提交"
msg = "未找到确认框确定按钮(#custom-confirm-modal-ok 或 .modal-footer .btn.btn-primary),审批未提交"
logger.error(msg)
return {"action": label, "ok": "false", "message": msg}
confirm.click()
@@ -224,9 +237,17 @@ def run_flow(
result = validate_doc(doc_detail, session)
# 真实审批提交:仅当 overtime_approve_enabled=true 时执行(默认关闭)
if _approve_enabled():
submit = submit_approval(browser, result.get("decision"))
orig_decision = result.get("decision")
submit = submit_approval(browser, orig_decision)
result["审批动作"] = submit["action"]
result["审批结果"] = f"{'成功' if submit['ok'] == 'true' else '失败'},{submit['message']}"
# 提交失败兜底:单据在 OA 中状态未变,不能仍标为通过/驳回,
# 归为「异常」并附机器结论,交由人工跟进
if submit["ok"] == "false":
result["decision"] = "异常"
result["note"] = (
f"机器结论[{orig_decision}]但审批提交失败:{submit['message']}"
)
result["审批结果"] = f"{submit['message']}"
logger.info("审批提交: %s %s", submit["action"], result["审批结果"])
results.append(result)
logger.info(
+8 -2
View File
@@ -102,9 +102,10 @@ def build_push_summary(results: list, subject: str = "") -> str:
rejected = [r for r in results if r.get("decision") == "驳回"]
review = [r for r in results if r.get("decision") == "人工复核"]
overdue = [r for r in results if r.get("decision") == "超期"]
abnormal = [r for r in results if r.get("decision") == "异常"]
failed = [r for r in results if r.get("decision") == "失败"]
if not passed and not rejected and not review and not overdue:
if not passed and not rejected and not review and not overdue and not abnormal:
return ""
def _item(r):
@@ -114,7 +115,7 @@ def build_push_summary(results: list, subject: str = "") -> str:
vtype = info.get("假期类型") or info.get("加班类型") or ""
return f"{title}-{vtype}" if vtype else title
all_pass = (not rejected and not review and not overdue and not failed)
all_pass = (not rejected and not review and not overdue and not abnormal and not failed)
lines = []
if all_pass:
@@ -147,6 +148,11 @@ def build_push_summary(results: list, subject: str = "") -> str:
for r in overdue:
lines.append(_item(r))
lines.append(f"处理原因:{r.get('note') or r.get('error') or '未知'}")
if abnormal:
lines.append(f"审批异常 {len(abnormal)} 条,分别是:")
for r in abnormal:
lines.append(_item(r))
lines.append(f"详情页:{r.get('detail_url') or '无'}")
if failed:
lines.append(f"另有处理失败 {len(failed)} 条,请查看日志。")