docs: 更新 AGENTS/README 平台架构说明与月度总结,运行日志视图支持已取消状态
This commit is contained in:
@@ -1,77 +1,77 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""微盟数据导出 - webhost 场景插件(XQ0047)
|
||||
|
||||
流程:
|
||||
1) 复用有效登录态(API 校验 weimob_cookies.json),失效则打开可见浏览器登录;
|
||||
微盟登录可能弹腾讯验证码,脚本无法绕过,会提示「请在浏览器窗口完成验证」并等待;
|
||||
2) 探测「上月1日 00:00 ~ 此刻」订单总数,按单段 45000 单等分并逐段校验细分;
|
||||
3) 批量创建 exportOrder 导出任务 → 统一轮询 download/list → 并发下载 zip 解压;
|
||||
4) 各段 Excel 合并为单个 xlsx(桌面/微盟订单导出/微盟订单_YYYYMMDD_HHMMSS.xlsx)。
|
||||
"""
|
||||
import os
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from . import config
|
||||
from .data import weimob_export, weimob_login
|
||||
|
||||
|
||||
class WeimobExportPlugin(ScenePlugin):
|
||||
id = "xq0047"
|
||||
name = "微盟数据导出"
|
||||
version = "1.0.2"
|
||||
description = ("微盟商家后台订单数据自动导出:登录微盟(腾讯验证码需人工完成,登录态缓存复用),"
|
||||
"按订单量自动等分时间区间批量创建导出任务,统一轮询下载并合并为一个 Excel")
|
||||
platform = "" # 微盟自带登录页(腾讯验证码),插件内现场真登录,不使用底座共享登录态
|
||||
uses_month = False
|
||||
capabilities = ["xq0047"]
|
||||
permissions = {"platforms": []}
|
||||
# 与 plugin.json.fields 一致(ui=true 前端自渲染,此处分层作为参数契约文档)
|
||||
fields = {
|
||||
"wm_username": {"type": "string", "title": "微盟登录手机号", "default": ""},
|
||||
"wm_password": {"type": "string", "title": "微盟登录密码", "default": "",
|
||||
"format": "password"},
|
||||
"save_dir": {"type": "string", "title": "保存目录", "default": ""},
|
||||
}
|
||||
|
||||
def run(self, fields, ctx) -> dict:
|
||||
fields = fields or {}
|
||||
config.set_log(ctx.log)
|
||||
|
||||
# ---------- 解析与校验 ----------
|
||||
username = str(fields.get("wm_username") or "").strip()
|
||||
password = str(fields.get("wm_password") or "").strip()
|
||||
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
|
||||
|
||||
if not username or not password:
|
||||
raise RuntimeError("微盟登录账号/密码缺失:请在插件界面填写并保存配置后重试")
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
ctx.log(f"保存目录:{save_dir}")
|
||||
|
||||
# ---------- 登录(缓存复用,失效时浏览器现场登录) ----------
|
||||
ctx.progress(2)
|
||||
login = weimob_login.ensure_login(username, password)
|
||||
if not login.get("success"):
|
||||
raise RuntimeError(f"微盟登录失败:{login.get('message')}")
|
||||
ctx.log(login.get("message") or "登录态就绪")
|
||||
ctx.progress(10)
|
||||
|
||||
# ---------- 导出 ----------
|
||||
result = weimob_export.run_export(save_dir, ctx.progress)
|
||||
if not result.get("success"):
|
||||
raise RuntimeError(result.get("message") or "微盟订单导出失败")
|
||||
|
||||
ctx.progress(100)
|
||||
return {
|
||||
"summary": result["message"],
|
||||
"detail": {
|
||||
"excel_path": result.get("excel_path"),
|
||||
"segments": result.get("segments", 0),
|
||||
"rows": result.get("rows", 0),
|
||||
"save_dir": save_dir,
|
||||
},
|
||||
"path": result.get("excel_path"),
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(WeimobExportPlugin())
|
||||
# -*- coding: utf-8 -*-
|
||||
"""微盟数据导出 - webhost 场景插件(XQ0047)
|
||||
|
||||
流程:
|
||||
1) 复用有效登录态(API 校验 weimob_cookies.json),失效则打开可见浏览器登录;
|
||||
微盟登录可能弹腾讯验证码,脚本无法绕过,会提示「请在浏览器窗口完成验证」并等待;
|
||||
2) 探测「上月1日 00:00 ~ 此刻」订单总数,按单段 45000 单等分并逐段校验细分;
|
||||
3) 批量创建 exportOrder 导出任务 → 统一轮询 download/list → 并发下载 zip 解压;
|
||||
4) 各段 Excel 合并为单个 xlsx(桌面/微盟订单导出/微盟订单_YYYYMMDD_HHMMSS.xlsx)。
|
||||
"""
|
||||
import os
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from . import config
|
||||
from .data import weimob_export, weimob_login
|
||||
|
||||
|
||||
class WeimobExportPlugin(ScenePlugin):
|
||||
id = "xq0047"
|
||||
name = "微盟数据导出"
|
||||
version = "1.0.3"
|
||||
description = ("微盟商家后台订单数据自动导出:登录微盟(腾讯验证码需人工完成,登录态缓存复用),"
|
||||
"按订单量自动等分时间区间批量创建导出任务,统一轮询下载并合并为一个 Excel")
|
||||
platform = "" # 微盟自带登录页(腾讯验证码),插件内现场真登录,不使用底座共享登录态
|
||||
uses_month = False
|
||||
capabilities = ["xq0047"]
|
||||
permissions = {"platforms": []}
|
||||
# 与 plugin.json.fields 一致(ui=true 前端自渲染,此处分层作为参数契约文档)
|
||||
fields = {
|
||||
"wm_username": {"type": "string", "title": "微盟登录手机号", "default": ""},
|
||||
"wm_password": {"type": "string", "title": "微盟登录密码", "default": "",
|
||||
"format": "password"},
|
||||
"save_dir": {"type": "string", "title": "保存目录", "default": ""},
|
||||
}
|
||||
|
||||
def run(self, fields, ctx) -> dict:
|
||||
fields = fields or {}
|
||||
config.set_log(ctx.log)
|
||||
|
||||
# ---------- 解析与校验 ----------
|
||||
username = str(fields.get("wm_username") or "").strip()
|
||||
password = str(fields.get("wm_password") or "").strip()
|
||||
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
|
||||
|
||||
if not username or not password:
|
||||
raise RuntimeError("微盟登录账号/密码缺失:请在插件界面填写并保存配置后重试")
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
ctx.log(f"保存目录:{save_dir}")
|
||||
|
||||
# ---------- 登录(缓存复用,失效时浏览器现场登录) ----------
|
||||
ctx.progress(2)
|
||||
login = weimob_login.ensure_login(username, password)
|
||||
if not login.get("success"):
|
||||
raise RuntimeError(f"微盟登录失败:{login.get('message')}")
|
||||
ctx.log(login.get("message") or "登录态就绪")
|
||||
ctx.progress(10)
|
||||
|
||||
# ---------- 导出 ----------
|
||||
result = weimob_export.run_export(save_dir, ctx.progress)
|
||||
if not result.get("success"):
|
||||
raise RuntimeError(result.get("message") or "微盟订单导出失败")
|
||||
|
||||
ctx.progress(100)
|
||||
return {
|
||||
"summary": result["message"],
|
||||
"detail": {
|
||||
"excel_path": result.get("excel_path"),
|
||||
"segments": result.get("segments", 0),
|
||||
"rows": result.get("rows", 0),
|
||||
"save_dir": save_dir,
|
||||
},
|
||||
"path": result.get("excel_path"),
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(WeimobExportPlugin())
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
用法(仓库根下执行):
|
||||
.venv\\Scripts\\python.exe "plugins\\XQ0001-0100\\XQ0047 微盟数据导出\\_pack.py"
|
||||
随后发布(desktop/ 下执行,见 docs/插件/发版规范.md):
|
||||
.venv\\Scripts\\python.exe -m controlplane.tools.agent_cli publish \\
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py publish \\
|
||||
dist-plugin/xq0047_v1.0.2.zip --id xq0047 --version 1.0.2
|
||||
"""
|
||||
import json
|
||||
|
||||
@@ -1,41 +1,46 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "xq0047",
|
||||
"name": "微盟数据导出",
|
||||
"version": "1.0.2",
|
||||
"description": "微盟商家后台(master.weimob.com)订单数据自动导出:登录微盟(腾讯验证码需人工完成,登录态缓存复用),按订单量自动等分时间区间批量创建导出任务,统一轮询下载 zip 并合并为一个 Excel",
|
||||
"category": "报表",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"ui": true,
|
||||
"capabilities": ["xq0047"],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"wm_username": {
|
||||
"type": "string",
|
||||
"title": "微盟登录手机号",
|
||||
"default": "",
|
||||
"description": "微盟商家后台登录手机号(保存在本机,下次免填)"
|
||||
},
|
||||
"wm_password": {
|
||||
"type": "string",
|
||||
"title": "微盟登录密码",
|
||||
"default": "",
|
||||
"format": "password",
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填"
|
||||
},
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "保存目录",
|
||||
"default": "",
|
||||
"description": "留空=桌面/微盟订单导出;输出单个 xlsx(微盟订单_YYYYMMDD_HHMMSS.xlsx),各段源文件同目录保留"
|
||||
}
|
||||
},
|
||||
"required": ["wm_username", "wm_password"]
|
||||
}
|
||||
}
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "xq0047",
|
||||
"name": "微盟数据导出",
|
||||
"version": "1.0.3",
|
||||
"description": "微盟商家后台(master.weimob.com)订单数据自动导出:登录微盟(腾讯验证码需人工完成,登录态缓存复用),按订单量自动等分时间区间批量创建导出任务,统一轮询下载 zip 并合并为一个 Excel",
|
||||
"category": "报表",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"ui": true,
|
||||
"capabilities": [
|
||||
"xq0047"
|
||||
],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"wm_username": {
|
||||
"type": "string",
|
||||
"title": "微盟登录手机号",
|
||||
"default": "",
|
||||
"description": "微盟商家后台登录手机号(保存在本机,下次免填)"
|
||||
},
|
||||
"wm_password": {
|
||||
"type": "string",
|
||||
"title": "微盟登录密码",
|
||||
"default": "",
|
||||
"format": "password",
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填"
|
||||
},
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "保存目录",
|
||||
"default": "",
|
||||
"description": "留空=桌面/微盟订单导出;输出单个 xlsx(微盟订单_YYYYMMDD_HHMMSS.xlsx),各段源文件同目录保留"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"wm_username",
|
||||
"wm_password"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,8 @@ export function usePluginUI(opts = {}) {
|
||||
ws = connectWS((ev) => {
|
||||
if (ev.run_id && ev.run_id !== runId) return // 只看本次运行
|
||||
if (ev.t === 'progress') progress.value = Math.max(progress.value, ev.pct || 0)
|
||||
else if (ev.t === 'run_done') ev.ok ? finished() : failed(ev.error || '执行失败')
|
||||
// 用户强制停止 / 排队取消 / 排队超时 → 「已取消」,不显示成「执行失败」
|
||||
else if (ev.t === 'run_done') ev.ok ? finished() : (ev.status === 'cancelled' ? cancelled(ev.error) : failed(ev.error || '执行失败'))
|
||||
})
|
||||
ws.onclose = () => { ws = null }
|
||||
}
|
||||
@@ -305,6 +306,7 @@ export function usePluginUI(opts = {}) {
|
||||
try {
|
||||
const r = await getRun(runId)
|
||||
if (r.status === 'done') finished(r.result?.summary || '执行完成')
|
||||
else if (r.status === 'cancelled') cancelled(r.error)
|
||||
else if (r.status === 'error') failed(r.error || '执行失败')
|
||||
} catch (_) { /* 下轮再试 */ }
|
||||
}, 5000)
|
||||
@@ -321,6 +323,13 @@ export function usePluginUI(opts = {}) {
|
||||
banner.value = { type: 'success', text: summary || '执行完成' }
|
||||
}
|
||||
|
||||
// 用户主动停止 / 排队取消 / 排队超时:不算失败,给中性的「已取消」提示
|
||||
function cancelled(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
banner.value = { type: 'warning', text: '任务已取消:' + (err || '用户已停止') }
|
||||
}
|
||||
|
||||
function failed(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
|
||||
+14
-14
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>微盟数据导出</title>
|
||||
<script type="module" crossorigin src="/pui/xq0047/assets/index-CXWi8_0M.js"></script>
|
||||
<script type="module" crossorigin src="/pui/xq0047/assets/index-DZHj0Evd.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0047/assets/index-BS4ABaKl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user