Files
37duAutomation/webhost/backend/plugins/platform_check.py
T
puddy 53913f0c7d refactor(workflows): 统一替换 yingdao 目录引用为 workflows
1.  将所有文档、代码中对 `yingdao/` 目录的引用替换为 `workflows/`,统一影刀版代码的命名空间
2.  调整 workflows/share 模块内的路径引用与文档注释,确保一致性
3.  同步更新测试代码与配置文件中的旧目录引用
2026-09-08 16:16:35 +08:00

60 lines
2.5 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 -*-
"""登录态自检(共享登录态 + 共享模块验证)
- 校验 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())