feat: 新增多插件 UI 支持及运行日志集中回传功能

本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
2026-10-26 15:42:50 +08:00
parent 9fd687ada8
commit 843ff244a6
453 changed files with 243002 additions and 4493 deletions
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
"""XQ0037 步骤5:HR 已发起工号回写钉钉 AI 表格「改签离职电子签跟进-日更新」(新增行)。
链路最后一步,与 step2/3/4 同一作用域闸门:仅处理「待办工号列表.json」内工号
(step2 置位时登记,step4 发起后保留),字段从当天推送表「已发起名单」取。
链路最后一步,字段从当天推送表「已发起名单」取。两类来源:
A. 待办工号列表(step2 置位时登记,step4 发起后保留)—— 与 step3/4 同一作用域闸门;
B. 「调动导出」第34列公式判定 = 已发 的人员(前序已发起、名单中补录,
多为人工在 HR 发起且流程可能已办结,运行中流程反查不到),
直接按已发起回写,发起时间取「操作时间」(非当天)。
发起成功以 HR 系统为准:
1. HR 核查:遍历运行中「改签离职电子签」流程按表单 base_code 匹配工号,
再按流程主键查签署记录,is_initiate_sign 非空非 0 即已发起
1. HR 核查(仅待办路径):遍历运行中「改签离职电子签」流程按表单 base_code
匹配工号,再按流程主键查签署记录,is_initiate_sign 非空非 0 即已发起
(step4 自动发起与人工在 HR 里发起同样命中);未发起/运行中流程未找到
的保留待办,不回写 AI 表、不回填、不移除;
2. HR 已发起者,候选再与名单表取交集(列表内但名单无行的打日志提示,不回写);
@@ -41,7 +44,8 @@ import openpyxl
from .xq35_step2_sign_new_contract import ( # noqa: E402
AITABLE_BASE_ID, AITABLE_OPERATOR_UNIONID, _aitable_request)
from .step2_transfer_initiate import ( # noqa: E402
TARGET_SHEET, _hr_session, load_pending_list, remove_pending)
JUDGE_SENT, KEY_CODE_COL, OP_TIME_COL, SOURCE_HEADER_ROW, SOURCE_SHEET,
TARGET_SHEET, VERDICT_COL, _hr_session, load_pending_list, remove_pending)
from .step3_transfer_todo import ( # noqa: E402
WORKFORM_FORM_ID, _find_push_table, _log, get_business_data,
list_running_workflows)
@@ -95,6 +99,46 @@ def _ms_day(value):
# ---------- 数据源:待办列表 + 名单表字段 ----------
def load_sent_rows():
"""「调动导出」第34列 = 已发 的数据行 -> {工号: 操作时间ms}。
已发 = 前序已发起(HR 侧发起,流程可能早已办结,运行中流程反查不到),
故不走 check_hr_initiated,直接按已发起回写;发起时间取「操作时间」。
第34列公式缓存由第②步刷新落值;取不到缓存(当天未跑②)时本轮跳过该路径。
"""
path, _header = _find_push_table()
try:
wb = openpyxl.load_workbook(path, read_only=True, data_only=True)
except PermissionError as exc:
raise RuntimeError(
f"文件被占用,无法读取:{path}\n请先在 WPS/Excel 中关闭该文件后重试。") from exc
try:
if SOURCE_SHEET not in wb.sheetnames:
raise RuntimeError(f"{os.path.basename(path)} 缺少「{SOURCE_SHEET}」sheet")
ws = wb[SOURCE_SHEET]
sent, uncached = {}, 0
for r in range(SOURCE_HEADER_ROW + 1, ws.max_row + 1):
code = _s(ws.cell(r, KEY_CODE_COL).value)
if not code:
continue
raw = ws.cell(r, VERDICT_COL).value
if raw is None:
uncached += 1
continue
if str(raw).strip() != JUDGE_SENT:
continue
sent[code] = _ms_day(ws.cell(r, OP_TIME_COL).value)
finally:
wb.close()
if uncached:
_log(f"[已发] 「{SOURCE_SHEET}」第{VERDICT_COL}列有 {uncached} 行取不到公式结果,"
f"已发回写本轮跳过(请先执行第②步刷新公式后重试)")
return {}
_log(f"[已发] 「{SOURCE_SHEET}」第{VERDICT_COL}列 = {JUDGE_SENT} 的 {len(sent)} 人"
f"{':' + '、'.join(sorted(sent)) if sent else ''}")
return sent
def fetch_field_choices():
"""「现/原单位名称」字段选项集(两字段选项一致,取并集兜底)。
@@ -244,9 +288,10 @@ def backfill_init_dates(rows, items):
return done
def build_fields(row, today_ms, choices):
def build_fields(row, init_ms, choices):
"""名单行 + 发起时间 + 选项集 -> AI 表新增行 fields(空值字段不写)。
发起时间 init_ms:待办路径=当天;已发路径=「调动导出」操作时间。
singleSelect(是否已发起改签离职/现单位名称/原单位名称)写入传选项名字符串;
单位名称经 pick_unit 匹配选项集,未命中不写该字段(留空告警)。
"""
@@ -254,7 +299,7 @@ def build_fields(row, today_ms, choices):
"姓名": row["姓名"],
"工号": row["工号"],
FIELD_INITIATED: "是",
FIELD_INIT_TIME: today_ms,
FIELD_INIT_TIME: init_ms,
}
t = _ms_day(row["调动时间"])
if t:
@@ -313,28 +358,42 @@ def check_hr_initiated(session, pending):
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("[待办] 待办工号列表为空(本批次无人待办),无事可做")
sent = load_sent_rows()
if not pending and not sent:
_log("[待办] 待办工号列表为空,且「调动导出」无已发人员,无事可做")
return {"added": 0, "skip_exists": 0, "skip_noroster": 0,
"not_initiated": 0, "backfill": 0}
_log("[待办] 本批待办 {} 人:{}".format(
len(pending), "、".join(f"{c}{n}" for c, n in sorted(pending.items()))))
"not_initiated": 0, "backfill": 0, "sent": 0}
if pending:
_log("[待办] 本批待办 {} 人:{}".format(
len(pending), "、".join(f"{c}{n}" for c, n in sorted(pending.items()))))
roster = load_roster_rows()
existing = fetch_follow_records()
# 发起成功以 HR 为准:未发起/无流程的保留待办,不回写不回填不移除
session = _hr_session()
initiated, miss = check_hr_initiated(session, pending)
stats = {"added": 0, "skip_exists": 0, "skip_noroster": 0,
"not_initiated": len(miss), "backfill": 0}
for code, reason in sorted(miss.items()):
_log(f"[跳过] {code} {pending[code]} | {reason},保留待办等下次")
if not initiated:
_log("[完成] HR 侧无人已发起,本轮不回写(试算模式仅核查)"
if dry_run else "[完成] HR 侧无人已发起,本轮不回写")
"not_initiated": 0, "backfill": 0, "sent": len(sent)}
# 待办路径:发起成功以 HR 为准,未发起/无流程的保留待办,不回写不回填不移除
initiated = {}
if pending:
session = _hr_session()
initiated, miss = check_hr_initiated(session, pending)
stats["not_initiated"] = len(miss)
for code, reason in sorted(miss.items()):
_log(f"[跳过] {code} {pending[code]} | {reason},保留待办等下次")
# 已发路径:公式已判定前序已发起(流程可能已办结),直接按已发起回写
sent_only = {c: ms for c, ms in sent.items() if c not in initiated}
now_ms = _ms_day(datetime.now())
# 回写目标:工号 -> 发起时间(已发优先取操作时间,待办取当天)
targets = {code: (sent.get(code) or now_ms) for code in initiated}
targets.update({code: (ms or now_ms) for code, ms in sent_only.items()})
if not targets:
_log("[完成] 本轮无人可回写,不动 AI 表"
+ ("(试算模式仅核查)" if dry_run else ""))
_log(f"[汇总] HR已发起=0 未发起或无流程={stats['not_initiated']} "
f"名单缺行={stats['skip_noroster']} 新增={stats['added']} "
f"已有跳过={stats['skip_exists']} 发起日期回填={stats['backfill']}"
f"已发={len(sent_only)} 名单缺行={stats['skip_noroster']} "
f"新增={stats['added']} 已有跳过={stats['skip_exists']} "
f"发起日期回填={stats['backfill']}"
f"{'(试算模式)' if dry_run else ''}")
return stats
@@ -342,27 +401,28 @@ def main(dry_run=None):
if not choices:
raise RuntimeError("未能获取「现/原单位名称」字段选项集,终止回写以免单位名称写空")
add_items, done_codes, init_items = [], [], []
today_ms = _ms_day(datetime.now())
for code in sorted(initiated):
for code, init_ms in sorted(targets.items()):
tag = "已发" if code in sent_only else "待办"
row = roster.get(code)
if row is None:
_log(f"[跳过] {code} {pending[code]} | 名单表中无该工号,无法取字段")
_log(f"[跳过·{tag}] {code} | 名单表中无该工号,无法取字段")
stats["skip_noroster"] += 1
continue
move_ms = _ms_day(row["调动时间"])
dup = next(((rid, m, im) for rid, m, im in existing.get(code, [])
if m is not None and m == move_ms), None)
if dup:
_log(f"[跳过] {code} {row['姓名']} | 本笔调动({row['调动时间']})"
_log(f"[跳过·{tag}] {code} {row['姓名']} | 本笔调动({row['调动时间']})"
f"AI 表已有记录(record {dup[0]}),视为已回写")
stats["skip_exists"] += 1
done_codes.append(code)
init_items.append((code, dup[2]))
continue
fields = build_fields(row, today_ms, choices)
fields = build_fields(row, init_ms, choices)
warn = "" if ("现单位名称" in fields and "原单位名称" in fields) \
else "(存在无匹配选项的单位名称,已留空待人工核对)"
_log(f"[回写] {code} {row['姓名']} | 现单位 {fields.get('现单位名称') or '空'} | "
_log(f"[回写·{tag}] {code} {row['姓名']} | "
f"现单位 {fields.get('现单位名称') or '空'} | "
f"原单位 {fields.get('原单位名称') or '空'} | 调动 {row['调动时间']}{warn}")
add_items.append(fields)
@@ -371,7 +431,7 @@ def main(dry_run=None):
_log(f"[完成] AI 表新增 {len(add_items)} 行(record id:{ids})")
stats["added"] = len(add_items)
done_codes.extend(f["工号"] for f in add_items)
init_items.extend((f["工号"], today_ms) for f in add_items)
init_items.extend((f["工号"], targets[f["工号"]]) for f in add_items)
elif add_items:
_log(f"[完成] 待新增 {len(add_items)} 行(试算模式,未写入)")
@@ -383,8 +443,9 @@ def main(dry_run=None):
if done_codes and not dry_run:
remove_pending(done_codes)
_log("[待办] 回写完成,已从待办列表移除:{}".format("、".join(done_codes)))
_log(f"[汇总] HR已发起={len(initiated)} 未发起或无流程={stats['not_initiated']} "
f"名单缺行={stats['skip_noroster']} 新增={stats['added']} "
f"已有跳过={stats['skip_exists']} 发起日期回填={stats['backfill']}"
_log(f"[汇总] 待办已发起={len(initiated)} 已发={len(sent_only)} "
f"未发起或无流程={stats['not_initiated']} 名单缺行={stats['skip_noroster']} "
f"新增={stats['added']} 已有跳过={stats['skip_exists']} "
f"发起日期回填={stats['backfill']}"
f"{'(试算模式)' if dry_run else ''}")
return stats