Files
37duAutomation/plugins/xq0002/report/notify.py
T
puddy 843ff244a6 feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
2026-10-26 15:42:50 +08:00

121 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0002 插件 - 钉钉群通知(业务消息构建 + 推送,口径与影刀版 add_sub_import 一致)。
推送内容:
1. 汇总一条:调度/筛选结果统计 + HR 导入结果(或人工导入提示)+ 注意事项;
2. 增员/减员导入异常名单各一条(接口返回的业务异常明细 + 流程失败单元),
名单过长由 dingtalk_robot 按批自动分批(每批 10 条)。
消息状态色:全部正常 success(绿);有异常/待确认/注意事项 warning(橙);调度全军覆没 error(红)。
推送失败只记 WARN 日志,不影响插件主流程。
"""
from ..config import DINGTALK_ENV, log
from . import dingtalk_robot
TITLE_SUMMARY = "雇主险增减操作完成"
def _import_issues(import_results):
"""从 HR 导入结果中提取异常/流程失败明细,按菜单(增员导入/减员导入)分组。
Returns:
dict: {menu: [{"category", "staff_code", "staff_name",
"insurance_name", "message"}, ...]}
"""
grouped = {}
for r in import_results or []:
menu = r.get("menu") or "导入"
if r.get("error"):
# 流程失败(登录/元素/文件缺失等):无业务结果,合并为一条异常上报
grouped.setdefault(menu, []).append({
"category": r.get("category", ""),
"staff_code": "", "staff_name": "", "insurance_name": "",
"message": f"流程失败({r.get('error_type', 'Exception')}):{r['error']}",
})
continue
for exc in r.get("exceptions") or []:
grouped.setdefault(menu, []).append({
"category": r.get("category", ""),
"staff_code": exc.get("staff_code", ""),
"staff_name": exc.get("staff_name", ""),
"insurance_name": exc.get("insurance_name", ""),
"message": exc.get("message", ""),
})
return grouped
def _build_messages(total, filtered, scheduled, import_on, import_lines,
import_results, notes):
"""构建待推送消息列表(汇总 + 异常名单),块格式交由 dingtalk_robot 分批发送。"""
issues = _import_issues(import_results)
issue_total = sum(len(v) for v in issues.values())
# ---- 1. 汇总消息 ----
summary_lines = [
"**处理类别 {} 个:筛选复制成功 {} 个、调度成功 {} 个**".format(
total, filtered, scheduled),
]
if import_on:
summary_lines.extend(import_lines or ["HR 导入未执行(登录态缺失或整体失败,详见注意事项与日志)"])
else:
summary_lines.append("HR 自动导入未开启:请取各类别文件夹内导入文件,先【减员】后【增员】人工导入")
blocks = ["\n\n".join(summary_lines)]
if notes:
blocks.append("**⚠️ 注意事项({})**\n\n{}".format(
len(notes), "\n\n".join("> - {}".format(n) for n in notes)))
if scheduled == 0:
status = "error"
elif notes or issue_total:
status = "warning"
else:
status = "success"
messages = [{"title": TITLE_SUMMARY, "blocks": blocks, "status": status}]
# ---- 2. 增员/减员导入异常名单(各一条独立消息) ----
for menu, excs in issues.items():
if not excs:
continue
exc_blocks = []
for exc in excs:
exc_blocks.append(
"**🔹 {} / {}**\n\n"
"> 工号:{}\n\n"
"> 姓名:{}\n\n"
"> 方案:{}\n\n"
"> 异常:{}".format(
exc.get("category", "") or "-",
exc.get("staff_name", "") or "-",
exc.get("staff_code", "") or "-",
exc.get("staff_name", "") or "-",
exc.get("insurance_name", "") or "-",
exc.get("message", ""),
))
messages.append({
"title": "【{}】异常名单({} 条)".format(menu, len(excs)),
"blocks": exc_blocks,
"status": "error",
})
return messages
def push_run_result(total, filtered, scheduled, import_on, import_lines,
import_results, notes):
"""把本次运行结果推送到钉钉群(环境取 config.DINGTALK_ENV),失败不影响主流程。
Args:
total/filtered/scheduled: 处理/筛选复制/调度成功的类别数
import_on: 是否执行了 HR 自动导入
import_lines: hr_import.summarize_results 的可读文本行(未执行时传 [])
import_results: hr_import.import_all 的逐单元结果(未执行时传 [])
notes: 本次运行的注意事项列表
"""
try:
messages = _build_messages(total, filtered, scheduled, import_on,
import_lines, import_results, notes)
result = dingtalk_robot.main(messages, env=DINGTALK_ENV)
if result.get("success"):
log(f"钉钉群通知已推送:{result.get('message', '')}", "INFO")
else:
log(f"钉钉群通知推送失败:{result.get('message', '')}", "WARN")
except Exception as e:
log(f"钉钉群通知推送失败(不影响主流程):{e}", "WARN")