Files
37duAutomation/plugins/XQ0001-0100/XQ0034 续签电子签/__init__.py
T
puddy f0a94bf523 build(desktop): 升级 electron-shell 版本至 1.6.3 并调整插件执行超时配置
- 插件执行超时默认延长至 6 小时,支持插件单独配置超时时间
- 新增插件根目录迁移逻辑,解决旧版权限问题
- 新增多个服务端实体、DTO、配置模块等基础代码
- 新增插件 UI 模板及相关静态资源
2026-10-15 11:38:45 +08:00

100 lines
3.8 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 -*-
"""XQ0034 续签电子签 · 执行机场景插件。
由影刀版(workflows/XQ0001-0100/XQ0034 ...)移植:钉钉 AI表格【续签名单到期跟进-月更新】
驱动,单流程执行:
① 「是否续签=否」-> 回填人资是否推送=否;
② 「是否续签=是」-> 手机号校验(电子签接收电话 vs 花名册联系方式,异常反馈暂不处理)
+ HR【合同台账-生效中合同】属性页「续签合同」提交推送电子签
+ 回填人资是否推送=是/推送时间。
会话:ctx.get_session("hr") 注入共享 HR 登录态(壳子运行前自动补登);
日志:业务模块 print/logger 统一改道 ctx.log 推送前端;试算模式只检查不回写。
"""
import sys
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
from . import config
from .data import renewal_esign
class _LogWriter:
"""print 改道器:把移植模块的 print 输出逐行转发 ctx.log(原 stdout 已被运行器改到 stderr)。"""
def __init__(self, log_fn):
self._log = log_fn
self._buf = ""
def write(self, s):
try:
self._buf += s
while "\n" in self._buf:
line, self._buf = self._buf.split("\n", 1)
if line.strip():
self._log(line.rstrip())
except Exception:
pass
return len(s)
def flush(self):
pass
def isatty(self):
return False
class Xq0034Plugin(ScenePlugin):
id = "xq0034"
name = "续签电子签"
version = "1.0.0"
description = ("XQ0034 续签电子签:AI表格【续签名单到期跟进-月更新】驱动——否续签回填、"
"是续签手机号校验后 HR 生效中合同属性页「续签合同」提交推送电子签并回填,"
"HR 会话由壳子注入")
platform = "hr"
uses_month = False
capabilities = ["xq0034"]
permissions = {"platforms": ["hr"]}
# 与 plugin.json.fields 一致(ui=true 前端自渲染,此处分层作为参数契约文档)
fields = {
"dry_run": {"type": "boolean", "title": "试算模式", "default": False},
}
def run(self, fields, ctx) -> dict:
fields = fields or {}
dry_run = bool(fields.get("dry_run"))
# ---------- 注入钩子(日志/会话)+ print 改道 ----------
config.set_log(ctx.log)
config.set_session_factory(lambda: ctx.get_session("hr"))
if not isinstance(sys.stdout, _LogWriter):
sys.stdout = _LogWriter(ctx.log)
ctx.log(f"=== XQ0034 续签电子签 开始(试算模式:{'开' if dry_run else '关'}) ===")
ctx.progress(5)
# ---------- 执行(内部自带手机号校验/防重/复查/重试) ----------
ret = renewal_esign.main(dry_run=dry_run)
ctx.progress(95)
# ---------- 汇总 ----------
message = str(ret.get("message") or "完成")
results = ret.get("results") or []
if not ret.get("success"):
# 业务层捕获后的失败(含登录态失效):置为运行失败,便于前端横幅与排查
raise RuntimeError(message)
ctx.log(f"=== XQ0034 续签电子签 结束:{message} ===")
ctx.progress(100)
notes = []
if isinstance(results, list) and results:
ok = sum(1 for r in results if isinstance(r, dict) and r.get("status") == "已推送")
notes.append(f"候选 {len(results)} 条:推送成功 {ok} 条,其余为试算/防重/跳过/"
f"手机号异常/失败(详见运行日志)")
return {"summary": f"续签电子签:{message}",
"detail": results if isinstance(results, list) else [],
"path": "",
"notes": notes}
PLUGINS.append(Xq0034Plugin())