build(desktop): 升级 electron-shell 版本至 1.6.3 并调整插件执行超时配置

- 插件执行超时默认延长至 6 小时,支持插件单独配置超时时间
- 新增插件根目录迁移逻辑,解决旧版权限问题
- 新增多个服务端实体、DTO、配置模块等基础代码
- 新增插件 UI 模板及相关静态资源
This commit is contained in:
2026-10-15 11:38:45 +08:00
parent 3dcedf95fd
commit f27639777f
717 changed files with 88647 additions and 17543 deletions
@@ -41,7 +41,7 @@ import re
import sys
import time
import traceback
from datetime import date
from datetime import date, datetime, timedelta
# ==================== 第三方库导入(启动校验:全部必须预先安装,不懒加载) ====================
try:
@@ -77,8 +77,10 @@ MONTHLY_HEADER_ROW = 1 # 「本月发起名单」表头行(单行表
JUDGE_COL = 39 # 「调动导出」是否需要发起改签(公式列,读缓存值)
JUDGE_VALUE = "需要" # 命中值
COPY_COL_START, COPY_COL_END = 2, 32 # B~AF 列(姓名~备注),两边 sheet 布局一致
KEY_CODE_COL, KEY_NAME_COL = 3, 2 # 去重键:工号 + 姓名(操作时间被 COM 写入存在
# ±8h 时区漂移、双链路不稳定,不作键)
KEY_CODE_COL, KEY_NAME_COL = 3, 2 # 去重键列:工号 + 姓名(去重键=工号+调动时间(按天),
# 缺调动时间时回退工号+姓名,见 append_to_monthly)
TRANSFER_TIME_COL = "调动时间" # 去重键组成部分(按天归一:吸收 COM 写入 ±8h 时区漂移,
# 同人工号在不同调动日调动多次时各自保留,不再漏掉第二笔)
# ==================== 环节二(HR 变更电子签状态)常量 ====================
SHARE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "share")
@@ -170,10 +172,36 @@ def _norm_code(v):
return s
def _norm_transfer_day(v):
"""调动时间按天归一(yyyy-MM-dd):datetime/Timestamp/字符串/Excel 序列号均可;
失败返回 None(调用方回退「工号+姓名」去重键)。
按天粒度可吸收 COM 写入 ±8h 时区漂移(跨午夜边界除外);同人同日仅可能有一笔
调动,不会误合并不同调动(与 step5 AI表格防重「工号+调动日期」口径一致)。
"""
if v is None:
return None
if isinstance(v, pd.Timestamp):
v = v.to_pydatetime()
if isinstance(v, datetime):
return v.date().isoformat()
if isinstance(v, (int, float)):
try:
return (datetime(1899, 12, 30) + timedelta(days=float(v))).date().isoformat()
except (ValueError, OverflowError):
return None
s = str(v).strip()
m = re.match(r"^(\d{4})-(\d{1,2})-(\d{1,2})", s)
if m:
return f"{int(m.group(1)):04d}-{int(m.group(2)):02d}-{int(m.group(3)):02d}"
return None
def append_to_monthly(target_path: str, df: pd.DataFrame) -> int:
"""把名单按 B~AF 追加到「本月发起名单」(openpyxl 直写,不经 WPS COM)。
- 去重键 = 工号 + 姓名(类型归一后比对),已在名单中的跳过;
- 去重键 = 工号 + 调动时间(按天归一后比对;缺调动时间列回退工号+姓名),
已在名单中的跳过——同人工号在不同调动日调动多次时各自保留(如陆昌立);
- 只写 B~AF 列,序号/公式列/其他列一概不动;
- 新行单元格拷贝上一行同列样式,保证显示格式一致。
@@ -212,23 +240,54 @@ def append_to_monthly(target_path: str, df: pd.DataFrame) -> int:
raise RuntimeError(
f"「{TARGET_SHEET}」B~AF 表头与来源不匹配。\n sheet:{hdr}\n 来源:{expected}")
# 2. 数据末行(按工号列向上)与去重(工号+姓名,类型归一)
# 2. 数据末行(按工号列向上)与去重(工号+调动时间按天;缺调动时间回退工号+姓名,类型归一)
# 同人工号在不同调动日调动多次时各自保留(去重键含调动时间,不再漏掉第二笔调动);
# 调动时间按天归一可吸收 COM 写入 ±8h 时区漂移(与 step5「工号+调动日期」防重口径一致)。
last = MONTHLY_HEADER_ROW
for r in range(MONTHLY_HEADER_ROW + 1, ws.max_row + 1):
if ws.cell(row=r, column=KEY_CODE_COL).value not in (None, ""):
last = r
day_col = None # 「调动时间」在 df 中的列序号(0 基);sheet 绝对列 = COPY_COL_START + day_col
for _i, _h in enumerate(expected):
if str(_h) == TRANSFER_TIME_COL:
day_col = _i
break
def _sheet_day(r):
"""sheet 行 r 的调动日期(按天归一);无调动时间列返回 None。"""
if day_col is None:
return None
return _norm_transfer_day(ws.cell(row=r, column=COPY_COL_START + day_col).value)
def _row_key(code, name, day):
"""去重键:有调动日期 -> (工号, D, 日期);无调动日期 -> (工号, N, 姓名) 回退旧口径。"""
if day:
return (_norm_code(code), "D", day)
return (_norm_code(code), "N", str(name).strip())
existing = set()
for r in range(MONTHLY_HEADER_ROW + 1, last + 1):
code = ws.cell(row=r, column=KEY_CODE_COL).value
name = ws.cell(row=r, column=KEY_NAME_COL).value
if code is not None and name is not None:
existing.add((_norm_code(code), str(name).strip()))
keys = [(_norm_code(r[KEY_CODE_COL - COPY_COL_START]),
str(r[KEY_NAME_COL - COPY_COL_START]).strip())
for r in df.itertuples(index=False, name=None)]
keep = [i for i, k in enumerate(keys) if k not in existing]
if code is None:
continue
existing.add(_row_key(code, ws.cell(row=r, column=KEY_NAME_COL).value,
_sheet_day(r)))
seen = set(existing) # 同时对 df 内部重复行去重(同人同日只追加一次)
keys = []
for r in df.itertuples(index=False, name=None):
day = None if day_col is None else _norm_transfer_day(r[day_col])
keys.append(_row_key(r[KEY_CODE_COL - COPY_COL_START],
r[KEY_NAME_COL - COPY_COL_START], day))
keep = []
for i, k in enumerate(keys):
if k in seen:
continue
seen.add(k)
keep.append(i)
if len(keep) < len(df):
logger.info("去重:%d 条中 %d 条已在名单,追加 %d 条",
logger.info("去重:%d 条中 %d 条已在名单/重复,追加 %d 条",
len(df), len(df) - len(keep), len(keep))
if not keep:
logger.info("全部记录已在名单,无需追加")
@@ -130,19 +130,30 @@ def load_launch_rows():
# ---------- HR 流程侧 ----------
def list_running_workflows(session, page_size=100):
"""运行中「改签离职电子签」流程(datas 行)。"""
params = {
"version": "", "PACKAGE_ID": "cq37du", "process_type": "", "defProcessType": "",
"struId": "", "rootId": "cq37du", "taskIds": "", "title": FLOW_TITLE,
"state": "", "startTime": "", "endTime": "",
"sortType": "desc", "sortName": "CREATE_TIME",
"commonQuery": "[]", "start": "0", "pageNo": "1", "pageSize": str(page_size),
}
resp = _request_retry(
"POST", f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData",
session, data=params)
return resp.json().get("datas") or []
def list_running_workflows(session, page_size=100, max_pages=50):
"""运行中「改签离职电子签」流程(分页遍历全部页,datas 行)。
分页遍历避免运行中流程超过单页条数时漏查(首页截断会让 step3/4/5
漏处理排在后续页的流程,误判「无待办/未发起」)。
"""
rows_all = []
for page in range(max_pages):
params = {
"version": "", "PACKAGE_ID": "cq37du", "process_type": "", "defProcessType": "",
"struId": "", "rootId": "cq37du", "taskIds": "", "title": FLOW_TITLE,
"state": "", "startTime": "", "endTime": "",
"sortType": "desc", "sortName": "CREATE_TIME",
"commonQuery": "[]", "start": str(page * page_size),
"pageNo": str(page + 1), "pageSize": str(page_size),
}
resp = _request_retry(
"POST", f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData",
session, data=params)
rows = resp.json().get("datas") or []
rows_all.extend(rows)
if len(rows) < page_size:
break
return rows_all
def find_worker_tasks(session):
@@ -3,7 +3,7 @@
链路最后一步,与 step2/3/4 同一作用域闸门:仅处理「待办工号列表.json」内工号
(step2 置位时登记,step4 发起后保留),字段从当天推送表「本月发起名单」取。
发起成功以 HR 系统为准(用户澄清:AI 表只是回写结果,不是判定依据):
发起成功以 HR 系统为准:
1. HR 核查:遍历运行中「改签离职电子签」流程按表单 base_code 匹配工号,
再按流程主键查签署记录,is_initiate_sign 非空非 0 即已发起
(step4 自动发起与人工在 HR 里发起同样命中);未发起/运行中流程未找到
@@ -70,6 +70,7 @@ FIELD_INIT_TIME = "发起时间"
# 试算开关:True=试算(只打印,不写 AI 表);False=实跑写入
DRY_RUN = False
FIELD_INIT_DATE = "发起日期" # 「本月发起名单」值列(第38列),已发起时回填
DATE_FMT = "yyyy/mm/dd" # 回填显示格式
def _s(v):
@@ -173,7 +174,7 @@ def append_follow_rows(items):
def backfill_init_dates(rows, items):
"""已发起回填:发起日期写入「本月发起名单」对应行「发起日期」列。
"""已发起回填:发起日期写入「本月发起名单」对应行「发起日期」列(显示 yyyy/mm/dd)。
Args:
rows: load_roster_rows() 返回(借 _row 定位行)
@@ -197,9 +198,12 @@ def backfill_init_dates(rows, items):
continue
d = datetime.fromtimestamp((ms or _ms_day(datetime.now())) / 1000)
cell = ws.cell(row["_row"], col)
if isinstance(cell.value, datetime) and cell.value.date() == d.date():
same_day = isinstance(cell.value, datetime) and cell.value.date() == d.date()
if same_day and cell.number_format == DATE_FMT:
continue
cell.value = d
if not same_day:
cell.value = d
cell.number_format = DATE_FMT
done += 1
try:
wb.save(path)
@@ -239,7 +243,7 @@ def build_fields(row, today_ms):
return fields
# ---------- HR 发起状态核查(发起成功以 HR 为准,用户澄清) ----------
# ---------- HR 发起状态核查 ----------
def check_hr_initiated(session, pending):
"""核查各待办工号电子签发起状态 -> (initiated, miss)。
@@ -42,7 +42,8 @@ from step2_sign_new_contract import ( # noqa: E402
_aitable_request, _build_query_params, _encode_common_query,
_build_like_condition, _request_retry)
from step2_transfer_initiate import _hr_session # noqa: E402
from step3_transfer_todo import _log # noqa: E402
from step3_transfer_todo import ( # noqa: E402
WORKFORM_FORM_ID, _log, get_business_data)
from step4_transfer_esign import query_sign_status # noqa: E402
from step5_transfer_aitable import _ms_day, RECORDS_LIST_URL # noqa: E402
@@ -58,6 +59,10 @@ FIELD_LEAVE_DONE = "是否完成离职签署"
FIELD_NEW_DONE = "是否完成新合同签署"
SIGN_DONE = "2" # 电子签状态编码:1=签署中 2=已完成
# WeProcess 分页遍历(流程反查不再受单页条数截断)
WF_PAGE_SIZE = 100
MAX_WF_PAGES = 50
# 试算开关:True=试算(只打印,不回填);False=实跑回填
DRY_RUN = False
@@ -121,22 +126,40 @@ def _triple_done(triple):
return all(t == SIGN_DONE for t in triple)
def find_running_flow(session, name, code):
"""运行中「改签离职电子签」流程按姓名(标题含)+ 工号兜底匹配 -> businessKey。"""
params = {
"version": "", "PACKAGE_ID": "cq37du", "process_type": "",
"defProcessType": "", "struId": "", "rootId": "cq37du", "taskIds": "",
"title": "改签离职电子签", "state": "", "startTime": "", "endTime": "",
"sortType": "desc", "sortName": "CREATE_TIME",
"commonQuery": "[]", "start": "0", "pageNo": "1", "pageSize": "100",
}
resp = _request_retry(
"POST", f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData",
session, data=params)
for r in resp.json().get("datas") or []:
title = str(r.get("title") or "")
if name in title:
def find_running_flow(session, code, name):
"""运行中「改签离职电子签」流程按表单工号精确匹配 -> businessKey。
分页遍历运行中流程(每页 WF_PAGE_SIZE=100,上限 MAX_WF_PAGES 页),先用标题
「{姓名}-改签离职电子签」粗筛(低开销),再读流程表单业务数据按 base_code
精确确认(防重名误伤:重名同事的流程不会误判成本人的流程)。
表单读取失败无法排除时按本人流程处理(返回该 businessKey),避免误入
「流程已办结」分支造成提前回填。
"""
key = f"{(name or '').strip()}-改签离职电子签"
for page in range(MAX_WF_PAGES):
params = {
"version": "", "PACKAGE_ID": "cq37du", "process_type": "",
"defProcessType": "", "struId": "", "rootId": "cq37du", "taskIds": "",
"title": "改签离职电子签", "state": "", "startTime": "", "endTime": "",
"sortType": "desc", "sortName": "CREATE_TIME",
"commonQuery": "[]",
"start": str(page * WF_PAGE_SIZE), "pageNo": str(page + 1),
"pageSize": str(WF_PAGE_SIZE),
}
resp = _request_retry(
"POST", f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData",
session, data=params)
rows = resp.json().get("datas") or []
for r in rows:
if key not in str(r.get("title") or ""):
continue
biz = get_business_data(session, str(r.get("businessKey") or ""), WORKFORM_FORM_ID)
biz_code = str(biz.get("base_code") or "").strip()
if biz and biz_code and biz_code != str(code).strip():
continue # 标题含重名但工号不符:重名同事的流程,跳过
return str(r.get("businessKey") or "")
if len(rows) < WF_PAGE_SIZE:
break
return ""
@@ -170,7 +193,7 @@ def check_one(session, row):
# 旧合同仍在生效中(改签未生效)-> 流程反查签署三状态
notes.append("生效中Tab为旧合同(起始{})".format(
old_rows[0].get("hr_staff_contract.contract_start_date")))
biz = find_running_flow(session, name, code)
biz = find_running_flow(session, code, name)
if biz:
st = query_sign_status(session, biz)
triple = (str(st.get("is_initiate_sign") or ""),
@@ -185,7 +208,7 @@ def check_one(session, row):
else:
# 生效中既无旧也无新:查待生效 tab(新合同签署中/签完未生效)
notes.append("生效中Tab无合同行")
biz = find_running_flow(session, name, code)
biz = find_running_flow(session, code, name)
if biz:
st = query_sign_status(session, biz)
triple = (str(st.get("is_initiate_sign") or ""),