Files
37duAutomation/plugins/platform_check.py
T
puddy 0ab43d0ed8 refactor: 完成项目目录重构与代码迁移
本次提交完成了整体项目的目录梳理与代码迁移:
1.  将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构
2.  移动并整理了插件目录结构,将插件统一放入根级plugins/
3.  调整了前端项目的路径与配置,统一前后端开发构建流程
4.  清理了废弃的旧版app/目录与冗余的构建中间文件
5.  更新了.gitignore与README.md,适配新的项目结构
2026-09-14 17:46:09 +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())