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

165 lines
7.6 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 -*-
"""XQ0037 调动改签离职电子签 · 执行机场景插件。
由影刀版(workflows/XQ0001-0100/XQ0037 ...)移植:钉钉 AI表格字段接力驱动,
六个生产步骤按单步模式执行(错峰定时由壳子「定时任务」按方案控制):
① 调动台账导出 —— 近一月台账导出 + 操作时间近2天筛选 + 贴入每日推送工作簿
② HR调动信息置位 —— "需要"名单贴入本月发起名单 + HR 两电子签标志置 1 + 登记待办工号
③ 待办完善信息提交 —— 完善信息环节自动保存+送审办结(合同期限/模板/签署单位计算)
④ 发起离职电子签 —— 离职电子签办理环节发起(复用 XQ0035 initiate_resign_esign 内嵌副本)
⑤ 回写AI表格跟进 —— HR 已发起者回写「改签离职电子签跟进-日更新」+ 回填发起日期
⑥ 签署完成核查回写 —— 离职/新合同签署完成核查 + checkbox 回写
会话: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 (step1_transfer_export, step2_transfer_initiate,
step3_transfer_todo, step4_transfer_esign,
step5_transfer_aitable, step6_transfer_followup)
STEP_EXPORT = "① 调动台账导出"
STEP_INITIATE = "② HR调动信息置位"
STEP_TODO = "③ 待办完善信息提交"
STEP_ESIGN = "④ 发起离职电子签"
STEP_AITABLE = "⑤ 回写AI表格跟进"
STEP_FOLLOWUP = "⑥ 签署完成核查回写"
ALL_STEPS = (STEP_EXPORT, STEP_INITIATE, STEP_TODO, STEP_ESIGN,
STEP_AITABLE, STEP_FOLLOWUP)
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 Xq0037Plugin(ScenePlugin):
id = "xq0037"
name = "调动改签离职电子签"
version = "1.0.0"
description = ("XQ0037 调动改签离职电子签:①调动台账导出 ②HR调动信息置位 ③待办完善信息提交 "
"④发起离职电子签 ⑤回写AI表格跟进 ⑥签署完成核查回写,"
"AI表格字段接力驱动、单步执行错峰定时")
platform = "hr"
uses_month = False
capabilities = ["xq0037"]
permissions = {"platforms": ["hr"]}
# 与 plugin.json.fields 一致(ui=true 前端自渲染,此处分层作为参数契约文档)
fields = {
"step": {"type": "string", "title": "执行步骤", "default": STEP_EXPORT,
"enum": list(ALL_STEPS)},
"dry_run": {"type": "boolean", "title": "试算模式", "default": False},
"push_dir": {"type": "string", "title": "推送目录", "default": config.DEFAULT_PUSH_DIR},
}
def run(self, fields, ctx) -> dict:
fields = fields or {}
step = str(fields.get("step") or STEP_EXPORT).strip()
dry_run = bool(fields.get("dry_run"))
push_dir = str(fields.get("push_dir") or "").strip().strip('"')
if step not in ALL_STEPS:
raise RuntimeError(f"未知执行步骤:{step}")
# ---------- 注入钩子(日志/会话/路径)+ print 改道 ----------
config.set_log(ctx.log)
config.set_session_factory(lambda: ctx.get_session("hr"))
config.set_push_dir(push_dir)
if not isinstance(sys.stdout, _LogWriter):
sys.stdout = _LogWriter(ctx.log)
ctx.log(f"=== XQ0037 {name_of(step)} 开始"
f"(试算模式:{'开' if dry_run else '关'},推送目录:{config.get_push_dir()}) ===")
ctx.progress(5)
# ---------- 按步骤分发(各步骤内部自带防重/断点续跑/重试) ----------
detail = []
if step == STEP_EXPORT:
ret = step1_transfer_export.main()
if not ret.get("success"):
raise RuntimeError(str(ret.get("error") or "第一步执行失败"))
ctx.progress(95)
summary = f"名单 {ret.get('count', 0)} 条已写入推送工作簿"
detail = [{k: ret.get(k) for k in
("raw_path", "filtered_path", "target_path", "count")}]
elif step == STEP_INITIATE:
# 试算模式 -> 仅贴名单(do_hr_change=False:不置位 HR、不写待办列表)
ret = step2_transfer_initiate.main(do_hr_change=not dry_run)
if not ret.get("success"):
raise RuntimeError(str(ret.get("error") or "第二步执行失败"))
ctx.progress(95)
hr_results = ret.get("hr_results") or []
summary = (f"命中 {ret.get('needed', 0)} 条,追加发起名单 {ret.get('appended', 0)} 条,"
f"HR 置位处理 {len(hr_results)} 条")
detail = hr_results if isinstance(hr_results, list) else []
else:
# ③④⑤⑥:main(dry_run=...) 返回统计 dict,失败直接抛异常由运行器标记失败
if step == STEP_TODO:
stats = step3_transfer_todo.main(dry_run=dry_run)
elif step == STEP_ESIGN:
stats = step4_transfer_esign.main(dry_run=dry_run)
elif step == STEP_AITABLE:
stats = step5_transfer_aitable.main(dry_run=dry_run)
else:
stats = step6_transfer_followup.main(dry_run=dry_run)
ctx.progress(95)
summary = summarize(step, stats or {})
detail = [stats] if isinstance(stats, dict) else []
ctx.log(f"=== XQ0037 {name_of(step)} 结束:{summary} ===")
ctx.progress(100)
return {"summary": f"{name_of(step)}:{summary}",
"detail": detail,
"path": "",
"notes": []}
def name_of(step):
return {"①": "调动台账导出", "②": "HR调动信息置位", "③": "待办完善信息提交",
"④": "发起离职电子签", "⑤": "回写AI表格跟进", "⑥": "签署完成核查回写"}.get(step[:1], step)
def summarize(step, stats):
"""③④⑤⑥ 统计 dict -> 摘要文本。"""
if step == STEP_TODO:
return (f"完成 {stats.get('done', 0)},已送审 {stats.get('submitted', 0)},"
f"异常 {stats.get('abnormal', 0)},失败 {stats.get('error', 0)},"
f"列表外跳过 {stats.get('skip', 0)}")
if step == STEP_ESIGN:
return (f"发起 {stats.get('initiated', 0)},此前已完成 {stats.get('already', 0)},"
f"失败 {stats.get('error', 0)}")
if step == STEP_AITABLE:
return (f"AI表新增 {stats.get('added', 0)},已有跳过 {stats.get('skip_exists', 0)},"
f"未发起/无流程 {stats.get('not_initiated', 0)},发起日期回填 {stats.get('backfill', 0)}")
return (f"离职完成 {stats.get('leave_done', 0)},新合同完成 {stats.get('new_done', 0)},"
f"回填 {stats.get('updates', 0)}")
PLUGINS.append(Xq0037Plugin())