feat(XQ0037): 新增调动改签离职电子签全流程步骤文件及相关逻辑

- 修复 cashier_login.py 登录成功判定逻辑,调整 URL 条件为同时包含 SUCCESS_KEYWORD 且不在 /login 路径,避免误判
- 调整 roster_export_api.py 默认参数,新增离职状态及时间范围,更新输出路径
- 扩展 absence_analysis.py 日期范围支持 YYYYMM 格式
- 新增 transfer_roster_export_api.py 调动改签电子签导出模板字段配置
- 新增 XQ0037 调动改签离职电子签全流程步骤文件 step1~step6,涵盖台账导出筛选、待办处理、电子签发起及跟进回写等功能
This commit is contained in:
2026-10-12 17:15:58 +08:00
parent 489748dfc1
commit e7c874537e
10 changed files with 2172 additions and 8 deletions
@@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-
"""XQ0037 步骤4:改签流程「离职电子签办理」环节发起离职电子签。
处理 HR「改签离职电子签」流程已推进到「离职电子签办理」环节、
办理人含「人资专用号」且任务状态 WAITING/ACCEPTED 的记录:
1. 仅处理 step2 置位时登记的「待办工号列表.json」内工号(本批次作用域闸门;
人工发起的单子/其他批次人员不在列表,永不触碰)
2. 复用 XQ0035 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 sign_new_contract import ( # noqa: E402
HR_BASE_URL, _request_retry, query_process_tasks)
from 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 = "离职电子签办理"
# 电子签真实发起状态查询(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 = (os.environ.get("XQ0037_DRY_RUN", "1") == "1"
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()