# -*- coding: utf-8 -*- """登录态自检(共享登录态 + 共享模块验证) - 校验 HR / OA 共享登录态(真实 API 校验,非内存假状态) - 若 HR 在线:实测共享数据模块(desktop/shared/seal_data_export)能否构建 session、 取 userId 并拉取指定月份封存数据 —— 验证 webhost 复用共享模块的完整链路 """ from __future__ import annotations from datetime import datetime from webhost.backend.shared import seal_data_export as _seal from webhost.backend import auth as platform_auth from webhost.backend.plugins.base import PLUGINS, ScenePlugin class PlatformCheck(ScenePlugin): id = "platform_check" name = "登录态自检" version = "1.0.0" description = "校验 HR/OA 共享登录态,并实测共享模块(封存数据拉取)可用性" platform = "" def run(self, fields: dict, ctx) -> dict: report = {} for pid in ("hr", "oa"): online = platform_auth.is_online(pid) label = platform_auth._LABELS[pid] report[pid] = "已登录" if online else "未登录" ctx.log(f"[共享登录态] {label}:{'已登录' if online else '未登录'}") seal_info = None if report.get("hr") == "已登录": ym = str(fields.get("_month") or datetime.now().strftime("%Y-%m")) try: ctx.log("开始实测共享模块 seal_data_export……") ctx.progress(40) session = ctx.get_session("hr") user_id = ctx.get_user_id("hr") ctx.log(f"构建 session 成功,HR userId = {user_id or '(空)'}") page = _seal.fetch_seal_page( session, user_id, ym, page_no=1, page_size=5) rows = page.get("datas") or [] seal_info = f"{ym} 返回 {len(rows)} 条(state={page.get('state')})" ctx.log(f"[共享模块] 封存数据拉取成功:{seal_info}") ctx.progress(100) except Exception as e: # noqa: BLE001 ctx.log(f"[共享模块] 调用失败:{e}", level="ERROR") seal_info = f"error: {e}" else: ctx.log("HR 未登录,跳过共享模块实测(请先点击顶部 HR 登录)") summary = ";".join(f"{platform_auth._LABELS[k]}={v}" for k, v in report.items()) if seal_info: summary += f";封存模块:{seal_info}" return {"summary": summary, "report": report, "seal": seal_info} PLUGINS.append(PlatformCheck())