Files
37duAutomation/workflows/XQ0001-0100/XQ0037 调动改签离职电子签/step4_transfer_esign.py
T
puddy 3dcedf95fd feat: 新增通知推送功能及离线登录,优化重连逻辑
- 新增通知推送模块:支持 WebSocket 实时推送与轮询兜底,新增通知管理界面
- 新增离线登录功能:断网时凭本地 7 天授权票据自动登录或手动登录
- 优化 Electron 客户端 WebSocket 重连逻辑,避免死循环
- 调整工作流脚本,拆分重构合同相关分支逻辑
- 新增设备上报客户端版本字段,用于升级追踪与关旧依据
2026-10-13 17:46:49 +08:00

134 lines
6.2 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 步骤4:改签流程「离职电子签办理」环节发起离职电子签。
处理 HR「改签离职电子签」流程已推进到「离职电子签办理」环节、
办理人含「人资专用号」且任务状态 WAITING/ACCEPTED 的记录:
1. 仅处理 step2 置位时登记的「待办工号列表.json」内工号(本批次作用域闸门;
人工发起的单子/其他批次人员不在列表,永不触碰)
2. 复用 XQ0035 step1_trial_period_change.initiate_resign_esign:
msca getLastContract 取签署单位 → mscaCreateSign 发起
(个人 autoSign=0 + 企业 autoSign=1 双签,第三方 CA 承载,向员工发短信)
3. 幂等双保险:先查签署记录 is_initiate_sign(1=签署中/2=已完成,
非空即已发起,人工/此前发起均跳过);msca 报「已发起或已完成」也按已完成
跳过;其余发起失败写入「改签异常名单.xlsx」
4. 发起成功后保留在待办工号列表(移除职责在链路最后一步 step5 回写 AI 表完成时)
职责边界(与 XQ0035 一致,2026-10-09 用户澄清):发起即终点;
「离职电子签办理」任务的提交办结由 XQ0020 在员工 CA 签完后自动审核。
依赖环境变量:根目录 .env(hr 账号配置,沿用共享指令)。
"""
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
_XQ35 = r"d:\work\code\37duAutomation\workflows\XQ0001-0100\XQ0035 服务岗转正不通过电子签(离职+入职)"
for _p in (_XQ35, HERE):
if _p not in sys.path:
sys.path.insert(0, _p)
from step2_sign_new_contract import ( # noqa: E402
HR_BASE_URL, _request_retry, query_process_tasks)
from step1_trial_period_change import initiate_resign_esign # noqa: E402
from step2_transfer_initiate import _hr_session, load_pending_list # noqa: E402
from step3_transfer_todo import ( # noqa: E402
WORKER_NAME, WORKFORM_FORM_ID, _log, get_business_data,
list_running_workflows, write_abnormal)
ACTIVITY_ESIGN = "离职电子签办理"
# 试算开关:True=试算(只打印,不发起电子签);False=实跑发起
DRY_RUN = False
# 电子签真实发起状态查询(XQ0020 同款接口;按流程 businessKey/main_id 查签署记录)
SIGN_STATUS_URL = (f"{HR_BASE_URL}/RedseaPlatform/getContentLinkage/redApi/"
"rf_hr_staff_contract_signature_select_sp_cq37du/WorkformEngine.mc")
def query_sign_status(session, contract_id):
"""签署记录查询 -> {is_initiate_sign, sign_status_yg, sign_status_qy, file}。
该合同无电子签记录时服务端业务报错 -> 返回空 dict(按未发起处理)。
"""
resp = _request_retry("POST", SIGN_STATUS_URL, session,
data={"contract_id": contract_id,
"inParamFormId": "", "colCode": "main_id"})
d = resp.json()
result = d.get("result")
if str(d.get("state")) != "1" or not isinstance(result, dict):
return {}
return result
def find_esign_candidates(session, pending):
"""yield (flow, base_code, name):离职电子签办理环节、人资专用号待办、本批待办内。
待办列表外(人工单/其他批次)静默跳过;本环节无自己任务(未走到/已走过)跳过。
"""
for flow in list_running_workflows(session):
tasks = query_process_tasks(session, flow.get("processId"))
mine = [t for t in tasks
if str(t.get("activityName") or "") == ACTIVITY_ESIGN
and str(t.get("participantName") or "") == WORKER_NAME]
if not any(str(t.get("currentState") or "") in ("WAITING", "ACCEPTED")
for t in mine):
continue
biz = get_business_data(session, flow.get("businessKey"), WORKFORM_FORM_ID)
code = str(biz.get("base_code") or "").strip()
name = str(biz.get("staff_name") or "").strip()
if code not in pending:
continue
yield flow, code, name
def process_one(session, flow, code, name, dry_run):
title = str(flow.get("title") or "")
status = query_sign_status(session, flow.get("businessKey"))
if str(status.get("is_initiate_sign") or "") not in ("", "0"):
_log(f"[跳过] {code} {name} | 电子签此前已发起(is_initiate_sign="
f"{status.get('is_initiate_sign')}),不重复发起")
return "already"
if dry_run:
_log(f"[试算·不发起] {code} {name} | {title}")
return "dry"
ok, msg = initiate_resign_esign(
session, {"base_code": code},
{"business_key": flow.get("businessKey"),
"process_id": flow.get("processId")})
if ok and "此前已完成" in msg:
_log(f"[跳过] {code} {name} | {msg}")
return "already"
if ok:
_log(f"[发起] {code} {name} | {msg}")
return "initiated"
if "已发起或已完成" in msg:
# msca 侧重复发起保护(签署记录可能滞后):按已完成处理,不算异常
_log(f"[跳过] {code} {name} | {msg}(按此前已发起处理)")
return "already"
_log(f"[失败] {code} {name} | {msg}")
write_abnormal(code, name, title, "电子签发起失败", msg, dry_run)
return "error"
def main(dry_run=None):
dry_run = DRY_RUN if dry_run is None else dry_run
pending = load_pending_list()
if not pending:
_log("[待办] 待办工号列表为空(本批次无人待办),无事可做")
return {"initiated": 0, "already": 0, "error": 0, "dry": 0}
_log("[待办] 本批待办 {} 人:{}".format(
len(pending), "、".join(f"{c}{n}" for c, n in sorted(pending.items()))))
session = _hr_session()
stats = {"initiated": 0, "already": 0, "error": 0, "dry": 0}
for flow, code, name in find_esign_candidates(session, pending):
stats[process_one(session, flow, code, name, dry_run)] += 1
_log(f"[汇总] 发起={stats['initiated']} 此前已完成={stats['already']} "
f"失败={stats['error']} 试算={stats['dry']}"
f"{'(试算模式,未发起)' if dry_run else ''}"
f"(待办列表由 step5 回写 AI 表后移除)")
return stats
if __name__ == "__main__":
main()