feat: 启用考勤异常直接推送,重构钉钉推送适配逻辑
1. 启用app版考勤异常推送:移除push_abnormal中的注释,直接调用钉钉推送接口,不再仅打印日志
2. 更新钉钉推送文档与适配逻辑:
- 重构dingtalk_sender参数为search_keyword/verify_keyword替代target/display_name
- 更新考勤异常推送分组与参数格式,适配新的OCR推送逻辑
3. 移除影刀审批脚本的单聊推送支持,统一使用群机器人推送
4. 优化缺勤分析缓存逻辑,移除历史月缓存限制,改用懒加载缓存
5. 为影刀考勤异常脚本新增联调测试模式,避免联调期间打扰真实员工
This commit is contained in:
@@ -19,9 +19,7 @@
|
||||
- 本脚本不内联任何消息推送逻辑;仅生成待推送的文本消息,经 main() 写入影刀全局变量
|
||||
messages(列表,每项一条消息,按结果类型分组:通过/校验不通过/人工复核/失败 各一条),
|
||||
由「37du钉钉群机器人推送」指令读取后逐条发送;本地独立运行时静默跳过写全局变量;
|
||||
- main(push_type, target):
|
||||
push_type="group"(默认)群消息:全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送;
|
||||
push_type="person" 单聊:main 返回值仍为 {target, text} 列表,可交给「37du钉钉推送」指令走 OCR 单聊。
|
||||
- main():全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送。
|
||||
"""
|
||||
|
||||
# ==================== 标准库导入 ====================
|
||||
@@ -1098,18 +1096,17 @@ def show_rpa_result_popup(page: ChromiumPage,
|
||||
|
||||
|
||||
# ==================== 推送消息生成(不发送,交由消息推送模块) ====================
|
||||
# 本脚本不发送任何消息:仅把审批结果拼成文本消息(默认群消息,只含 text;
|
||||
# 传 push_type="person" 时生成含 target 的单聊消息),经 main() 把纯文本写入影刀全局变量 messages。
|
||||
# 本脚本不发送任何消息:仅把审批结果拼成文本消息(群消息,只含 text),
|
||||
# 经 main() 把纯文本写入影刀全局变量 messages。
|
||||
|
||||
|
||||
def _build_push_messages(texts, push_type="group", target=None):
|
||||
def _build_push_messages(texts):
|
||||
"""把推送内容列表转成推送消息列表(字典列表)。
|
||||
|
||||
texts 项可为:
|
||||
- 纯文本:包成 {"text": ...}(单条消息)
|
||||
- 块格式分组 dict(含 blocks):原样保留,交由钉钉机器人模块内部分批推送
|
||||
push_type 推送类型:"group" 群消息(钉钉群机器人 webhook 推送);
|
||||
"person" 单聊(含 target,钉钉联系人 OCR 推送)。
|
||||
仅生成群消息({"text": ...},钉钉群机器人 webhook 推送)。
|
||||
"""
|
||||
messages = []
|
||||
for text in texts:
|
||||
@@ -1117,8 +1114,6 @@ def _build_push_messages(texts, push_type="group", target=None):
|
||||
msg = dict(text)
|
||||
else:
|
||||
msg = {"text": text}
|
||||
if push_type == "person":
|
||||
msg["target"] = target
|
||||
messages.append(msg)
|
||||
return messages
|
||||
|
||||
@@ -1199,6 +1194,16 @@ def build_push_summary(results, subject=""):
|
||||
_push_group(f"【{subject}审批】审批异常", abnormal)
|
||||
_push_group(f"【{subject}审批】处理失败", failed)
|
||||
|
||||
# 汇总消息:本次审批各类别数量(一条,含 0 的类别)
|
||||
summary_lines = [f"本次共审批 **{len(results)}** 条:"]
|
||||
for label, cnt in [("通过", len(passed)),
|
||||
("校验不通过未处理", len(rejected)),
|
||||
("需人工复核", len(review)),
|
||||
("审批异常", len(abnormal)),
|
||||
("处理失败", len(failed))]:
|
||||
summary_lines.append(f"- {label}:{cnt} 条")
|
||||
messages.append({"title": f"【{subject}审批】汇总", "blocks": ["\n".join(summary_lines)]})
|
||||
|
||||
return messages
|
||||
|
||||
|
||||
@@ -1284,11 +1289,8 @@ def submit_approval(page, decision):
|
||||
return {"action": label, "ok": "false", "message": f"审批提交[{label}]失败: {e}"}
|
||||
|
||||
|
||||
def run_flow(subject, validate_doc, generate_report, push_type="group", target=None):
|
||||
"""请假审批主流程;返回生成的推送消息列表(字典列表,本脚本不发送)。
|
||||
|
||||
push_type 推送类型:"group" 群消息(钉钉群机器人 webhook);"person" 单聊(钉钉联系人 OCR 推送)。
|
||||
target 单聊推送目标(联系人),仅 push_type="person" 时使用。
|
||||
def run_flow(subject, validate_doc, generate_report):
|
||||
"""请假审批主流程;返回生成的推送消息列表(字典列表,群消息,本脚本不发送)。
|
||||
"""
|
||||
logger.info("%s审批流程开始", subject)
|
||||
|
||||
@@ -1305,7 +1307,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无待办单据:不开浏览器,直接生成提示消息返回
|
||||
if not docs:
|
||||
logger.info("%s无待审批单据,跳过浏览器操作", subject)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"], push_type, target)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"])
|
||||
logger.info("%s审批流程结束,共处理 0 条(无单据)", subject)
|
||||
return push_messages
|
||||
|
||||
@@ -1370,7 +1372,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无任何待办/结果时也生成一条提示消息,避免静默不推送
|
||||
if not texts:
|
||||
texts.append(f"暂无待审批的{subject}单据")
|
||||
push_messages = _build_push_messages(texts, push_type, target)
|
||||
push_messages = _build_push_messages(texts)
|
||||
|
||||
logger.info("%s审批流程结束,共处理 %d 条", subject, len(results))
|
||||
return push_messages
|
||||
@@ -1745,25 +1747,16 @@ def generate_report(results):
|
||||
|
||||
|
||||
# ==================== 主入口 ====================
|
||||
def main(push_type="group", target=None):
|
||||
def main():
|
||||
"""请假审批:登录 -> 查待办 -> 解析SSO -> 获取表单 -> 校验 -> 报告 -> 生成推送消息。
|
||||
|
||||
push_type 推送类型:"group" 群消息(缺省,写入全局变量 messages 为纯文本,
|
||||
直接交给钉钉群机器人 webhook 推送);
|
||||
"person" 单聊(钉钉联系人 OCR 推送,需配合 target)
|
||||
target 单聊推送目标(联系人),仅 push_type="person" 时使用
|
||||
仅生成群消息:写入全局变量 messages 为纯文本,直接交给钉钉群机器人 webhook 推送。
|
||||
返回:推送消息列表(字典列表,本脚本不发送);同时把纯文本写入全局变量 messages。
|
||||
"""
|
||||
push_type = str(push_type or "group").lower()
|
||||
if push_type == "person" and not target:
|
||||
logger.warning("push_type=person 但未提供 target,已按群消息(group)处理")
|
||||
push_type = "group"
|
||||
push_messages = run_flow(
|
||||
subject="请假",
|
||||
validate_doc=validate_doc,
|
||||
generate_report=generate_report,
|
||||
push_type=push_type,
|
||||
target=target,
|
||||
)
|
||||
# 写入影刀全局变量 messages(块格式分组列表:{title, blocks}),
|
||||
# 供「37du钉钉群机器人推送」指令读取后整体传入 main(),由模块内部分批逐条发送;
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
- 本脚本不内联任何消息推送逻辑;仅生成待推送的文本消息,经 main() 写入影刀全局变量
|
||||
messages(列表,每项一条消息,按结果类型分组:通过/校验不通过/人工复核/超期/失败 各一条),
|
||||
由「37du钉钉群机器人推送」指令读取后逐条发送;本地独立运行时静默跳过写全局变量;
|
||||
- main(push_type, target):
|
||||
push_type="group"(默认)群消息:全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送;
|
||||
push_type="person" 单聊:main 返回值仍为 {target, text} 列表,可交给「37du钉钉推送」指令走 OCR 单聊。
|
||||
- main():全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送。
|
||||
"""
|
||||
|
||||
# ==================== 标准库导入 ====================
|
||||
@@ -777,18 +775,17 @@ def show_rpa_result_popup(page: ChromiumPage,
|
||||
|
||||
|
||||
# ==================== 推送消息生成(不发送,交由推送指令) ====================
|
||||
# 本脚本不发送任何消息:仅把审批结果按类型拼成多条文本消息(默认群消息,只含 text;
|
||||
# 传 push_type="person" 时生成含 target 的单聊消息),经 main() 把列表写入影刀全局变量 messages。
|
||||
# 本脚本不发送任何消息:仅把审批结果按类型拼成多条文本消息(群消息,只含 text),
|
||||
# 经 main() 把列表写入影刀全局变量 messages。
|
||||
|
||||
|
||||
def _build_push_messages(texts, push_type="group", target=None):
|
||||
def _build_push_messages(texts):
|
||||
"""把推送内容列表转成推送消息列表(字典列表)。
|
||||
|
||||
texts 项可为:
|
||||
- 纯文本:包成 {"text": ...}(单条消息)
|
||||
- 块格式分组 dict(含 blocks):原样保留,交由钉钉机器人模块内部分批推送
|
||||
push_type 推送类型:"group" 群消息(钉钉群机器人 webhook 推送);
|
||||
"person" 单聊(含 target,钉钉联系人 OCR 推送)。
|
||||
仅生成群消息({"text": ...},钉钉群机器人 webhook 推送)。
|
||||
"""
|
||||
messages = []
|
||||
for text in texts:
|
||||
@@ -796,8 +793,6 @@ def _build_push_messages(texts, push_type="group", target=None):
|
||||
msg = dict(text)
|
||||
else:
|
||||
msg = {"text": text}
|
||||
if push_type == "person":
|
||||
msg["target"] = target
|
||||
messages.append(msg)
|
||||
return messages
|
||||
|
||||
@@ -872,6 +867,17 @@ def build_push_summary(results, subject=""):
|
||||
_push_group(f"【{subject}审批】审批异常", abnormal)
|
||||
_push_group(f"【{subject}审批】处理失败", failed)
|
||||
|
||||
# 汇总消息:本次审批各类别数量(一条,含 0 的类别)
|
||||
summary_lines = [f"本次共审批 **{len(results)}** 条:"]
|
||||
for label, cnt in [("通过", len(passed)),
|
||||
("校验不通过未处理", len(rejected)),
|
||||
("需人工复核", len(review)),
|
||||
("超期待人资处理", len(overdue)),
|
||||
("审批异常", len(abnormal)),
|
||||
("处理失败", len(failed))]:
|
||||
summary_lines.append(f"- {label}:{cnt} 条")
|
||||
messages.append({"title": f"【{subject}审批】汇总", "blocks": ["\n".join(summary_lines)]})
|
||||
|
||||
return messages
|
||||
|
||||
def _find_button(page, selector, timeout=3.0):
|
||||
@@ -956,11 +962,8 @@ def submit_approval(page, decision):
|
||||
return {"action": label, "ok": "false", "message": f"审批提交[{label}]失败: {e}"}
|
||||
|
||||
|
||||
def run_flow(subject, validate_doc, generate_report, push_type="group", target=None):
|
||||
"""加班审批主流程;返回生成的推送消息列表(字典列表,本脚本不发送)。
|
||||
|
||||
push_type 推送类型:"group" 群消息(钉钉群机器人 webhook);"person" 单聊(钉钉联系人 OCR 推送)。
|
||||
target 单聊推送目标(联系人),仅 push_type="person" 时使用。
|
||||
def run_flow(subject, validate_doc, generate_report):
|
||||
"""加班审批主流程;返回生成的推送消息列表(字典列表,群消息,本脚本不发送)。
|
||||
"""
|
||||
logger.info("%s审批流程开始", subject)
|
||||
|
||||
@@ -977,7 +980,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无待办单据:不开浏览器,直接生成提示消息返回
|
||||
if not docs:
|
||||
logger.info("%s无待审批单据,跳过浏览器操作", subject)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"], push_type, target)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"])
|
||||
logger.info("%s审批流程结束,共处理 0 条(无单据)", subject)
|
||||
return push_messages
|
||||
|
||||
@@ -1038,7 +1041,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无任何待办/结果时也生成一条提示消息,避免静默不推送
|
||||
if not texts:
|
||||
texts.append(f"暂无待审批的{subject}单据")
|
||||
push_messages = _build_push_messages(texts, push_type, target)
|
||||
push_messages = _build_push_messages(texts)
|
||||
|
||||
logger.info("%s审批流程结束,共处理 %d 条", subject, len(results))
|
||||
return push_messages
|
||||
@@ -1729,27 +1732,16 @@ def generate_report(results):
|
||||
|
||||
|
||||
# ==================== 主入口 ====================
|
||||
def main(push_type="group", target=None):
|
||||
"""加班审批:查待办 -> 解析SSO -> 获取表单 -> 校验 -> 报告 -> 生成推送消息。...
|
||||
def main():
|
||||
"""加班审批:查待办 -> 解析SSO -> 获取表单 -> 校验 -> 报告 -> 生成推送消息。
|
||||
|
||||
本脚本不发送任何消息:仅生成待推送消息(返回列表并写入影刀全局变量 messages),
|
||||
由「37du钉钉群机器人推送」/「37du钉钉推送」指令消费。
|
||||
|
||||
Args:
|
||||
push_type: 推送类型 "group"(默认,群消息,全局变量 messages 为纯文本直接发送)
|
||||
/ "person"(单聊,返回列表含 target,交由 OCR 单聊推送指令)
|
||||
target: 单聊推送目标(联系人),仅 push_type="person" 时使用
|
||||
由「37du钉钉群机器人推送」指令消费;仅生成群消息。
|
||||
"""
|
||||
push_type = str(push_type or "group").lower()
|
||||
if push_type == "person" and not target:
|
||||
logger.warning("push_type=person 但未提供 target,已按群消息(group)处理")
|
||||
push_type = "group"
|
||||
push_messages = run_flow(
|
||||
subject="加班",
|
||||
validate_doc=validate_doc,
|
||||
generate_report=generate_report,
|
||||
push_type=push_type,
|
||||
target=target,
|
||||
)
|
||||
# 写入影刀全局变量 messages(块格式分组列表:{title, blocks}),
|
||||
# 供「37du钉钉群机器人推送」指令读取后整体传入 main(),由模块内部分批逐条发送;
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
- 本脚本不内联任何消息推送逻辑;仅生成待推送的文本消息,经 main() 写入影刀全局变量
|
||||
messages(列表,仅一条汇总消息:本次审批通过/未通过各多少个,不含单笔明细),
|
||||
由「37du钉钉群机器人推送」指令读取后发送;本地独立运行时静默跳过写全局变量;
|
||||
- main(push_type, target):
|
||||
push_type="group"(默认)群消息:全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送;
|
||||
push_type="person" 单聊:main 返回值仍为 {target, text} 列表,可交给「37du钉钉推送」指令走 OCR 单聊。
|
||||
- main():全局变量 messages 为文本列表,逐条交钉钉群机器人 webhook 推送。
|
||||
"""
|
||||
|
||||
# ==================== 标准库导入 ====================
|
||||
@@ -671,26 +669,18 @@ def show_rpa_result_popup(page: ChromiumPage,
|
||||
|
||||
|
||||
# ==================== 推送消息生成(不发送,交由推送指令) ====================
|
||||
# 本脚本不发送任何消息:仅把审批结果拼成一条汇总文本消息(默认群消息,只含 text;
|
||||
# 传 push_type="person" 时生成含 target 的单聊消息),经 main() 把列表写入影刀全局变量 messages。
|
||||
# 本脚本不发送任何消息:仅把审批结果拼成一条汇总文本消息(群消息,只含 text),
|
||||
# 经 main() 把列表写入影刀全局变量 messages。
|
||||
|
||||
|
||||
# ==================== 推送消息生成(不发送,交由推送指令) ====================
|
||||
# 本脚本不发送任何消息:仅把审批结果拼成一条汇总文本消息(默认群消息,只含 text;
|
||||
# 传 push_type="person" 时生成含 target 的单聊消息),经 main() 把列表写入影刀全局变量 messages。
|
||||
|
||||
|
||||
def _build_push_messages(texts, push_type="group", target=None):
|
||||
def _build_push_messages(texts):
|
||||
"""把文本列表转成推送消息列表(字典列表)。
|
||||
|
||||
push_type 推送类型:"group" 群消息(仅 text,钉钉群机器人 webhook 推送);
|
||||
"person" 单聊(含 target,钉钉联系人 OCR 推送)。
|
||||
仅生成群消息({"text": ...},钉钉群机器人 webhook 推送)。
|
||||
"""
|
||||
messages = []
|
||||
for text in texts:
|
||||
msg = {"text": text}
|
||||
if push_type == "person":
|
||||
msg["target"] = target
|
||||
messages.append(msg)
|
||||
return messages
|
||||
|
||||
@@ -799,11 +789,8 @@ def submit_approval(page, decision):
|
||||
return {"action": label, "ok": "false", "message": f"审批提交[{label}]失败: {e}"}
|
||||
|
||||
|
||||
def run_flow(subject, validate_doc, generate_report, push_type="group", target=None):
|
||||
"""离职电子签审批主流程;返回生成的推送消息列表(字典列表,本脚本不发送)。
|
||||
|
||||
push_type 推送类型:"group" 群消息(钉钉群机器人 webhook);"person" 单聊(钉钉联系人 OCR 推送)。
|
||||
target 单聊推送目标(联系人),仅 push_type="person" 时使用。
|
||||
def run_flow(subject, validate_doc, generate_report):
|
||||
"""离职电子签审批主流程;返回生成的推送消息列表(字典列表,群消息,本脚本不发送)。
|
||||
"""
|
||||
logger.info("%s审批流程开始", subject)
|
||||
|
||||
@@ -820,7 +807,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无待办单据:不开浏览器,直接生成提示消息返回
|
||||
if not docs:
|
||||
logger.info("%s无待审批单据,跳过浏览器操作", subject)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"], push_type, target)
|
||||
push_messages = _build_push_messages([f"暂无待审批的{subject}单据"])
|
||||
logger.info("%s审批流程结束,共处理 0 条(无单据)", subject)
|
||||
return push_messages
|
||||
|
||||
@@ -881,7 +868,7 @@ def run_flow(subject, validate_doc, generate_report, push_type="group", target=N
|
||||
# 无任何待办/结果时也生成一条提示消息,避免静默不推送
|
||||
if not texts:
|
||||
texts.append(f"暂无待审批的{subject}单据")
|
||||
push_messages = _build_push_messages(texts, push_type, target)
|
||||
push_messages = _build_push_messages(texts)
|
||||
|
||||
logger.info("%s审批流程结束,共处理 %d 条", subject, len(results))
|
||||
return push_messages
|
||||
@@ -1057,27 +1044,16 @@ def generate_report(results):
|
||||
|
||||
|
||||
# ==================== 主入口 ====================
|
||||
def main(push_type="group", target=None):
|
||||
def main():
|
||||
"""改签离职电子签流程审核:查待办 -> 解析SSO -> 获取表单 -> 校验 -> 报告 -> 生成推送消息。
|
||||
|
||||
本脚本不发送任何消息:仅生成待推送消息(返回列表并写入影刀全局变量 messages),
|
||||
由「37du钉钉群机器人推送」/「37du钉钉推送」指令消费。
|
||||
|
||||
Args:
|
||||
push_type: 推送类型 "group"(默认,群消息,全局变量 messages 为纯文本直接发送)
|
||||
/ "person"(单聊,返回列表含 target,交由 OCR 单聊推送指令)
|
||||
target: 单聊推送目标(联系人),仅 push_type="person" 时使用
|
||||
由「37du钉钉群机器人推送」指令消费;仅生成群消息。
|
||||
"""
|
||||
push_type = str(push_type or "group").lower()
|
||||
if push_type == "person" and not target:
|
||||
logger.warning("push_type=person 但未提供 target,已按群消息(group)处理")
|
||||
push_type = "group"
|
||||
push_messages = run_flow(
|
||||
subject="改签离职电子签流程",
|
||||
validate_doc=validate_doc,
|
||||
generate_report=generate_report,
|
||||
push_type=push_type,
|
||||
target=target,
|
||||
)
|
||||
# 写入影刀全局变量 messages(列表,每项一条消息,按结果类型分组),
|
||||
# 供「37du钉钉群机器人推送」指令读取后逐条发送;本地独立运行时静默跳过
|
||||
|
||||
Reference in New Issue
Block a user