docs: 更新 AGENTS/README 平台架构说明与月度总结,运行日志视图支持已取消状态
This commit is contained in:
@@ -1,79 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""CRM数据导出 - webhost 场景插件(XQ0048)
|
||||
|
||||
流程:
|
||||
1) 登录态预检(API 校验 %LOCALAPPDATA%\\37duAutomation\\.sessions\\crm_cookie_header.txt);
|
||||
有效则全程免扫码,失效则打开可见浏览器等钉钉扫码一次(同次运行最多弹一次);
|
||||
2) 打开「报表统计/储值卡余额」整页截图 → 储值卡余额-YYYYMMDD.png;
|
||||
3) requests 复用同一登录态,按日期规则导出 22 张报表 xlsx
|
||||
(礼品卡订单因接口限制跨度 ≤31 天,近 3 个自然月按月拆分)。
|
||||
"""
|
||||
import os
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from . import config
|
||||
from .data import crm_export
|
||||
|
||||
|
||||
class CrmDataExportPlugin(ScenePlugin):
|
||||
id = "xq0048"
|
||||
name = "CRM数据导出"
|
||||
version = "1.1.11"
|
||||
description = ("37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选),"
|
||||
"登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),"
|
||||
"按各报表日期规则自动计算区间,礼品卡订单按月拆分")
|
||||
platform = "" # CRM 为钉钉扫码登录,插件内自带登录流程,不使用底座共享登录态
|
||||
uses_month = False
|
||||
capabilities = ["xq0048"]
|
||||
permissions = {"platforms": []}
|
||||
# 与 plugin.json.fields 一致
|
||||
fields = {
|
||||
"reports": {"type": "array", "title": "导出内容", "default": [],
|
||||
"description": "勾选键列表(截图=__screenshot__,报表=接口#规则);空/缺省=全部导出"},
|
||||
"save_dir": {"type": "string", "title": "保存目录", "default": "",
|
||||
"description": "留空=D:\\资料\\财务\\CRM数据导出"},
|
||||
"debug_mode": {"type": "boolean", "title": "调试日志", "default": False},
|
||||
}
|
||||
|
||||
def run(self, fields, ctx) -> dict:
|
||||
fields = fields or {}
|
||||
config.set_log(ctx.log)
|
||||
config.set_progress(ctx.progress)
|
||||
config.set_debug(bool(fields.get("debug_mode")))
|
||||
|
||||
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
ctx.log(f"保存目录:{save_dir}")
|
||||
|
||||
report_keys = fields.get("reports")
|
||||
reports, include_shot = config.filter_reports(report_keys)
|
||||
if not reports and not include_shot:
|
||||
raise RuntimeError("未勾选任何导出内容,请至少勾选一项")
|
||||
if report_keys is None:
|
||||
ctx.log("导出内容:全部(截图 + %d 张报表)" % len(reports))
|
||||
else:
|
||||
ctx.log(f"导出内容:{'截图、' if include_shot else ''}{len(reports)} 张报表(按勾选)")
|
||||
|
||||
result = crm_export.run_export(save_dir, report_keys=report_keys)
|
||||
config.progress(100)
|
||||
|
||||
files = result.get("exports") or []
|
||||
shot_part = f"截图 {1 if result.get('screenshot') else 0}/1," if include_shot else ""
|
||||
summary = (f"{shot_part}"
|
||||
f"报表 {result.get('done')}/{result.get('total')},"
|
||||
f"共 {len(files) + (1 if result.get('screenshot') else 0)} 个文件")
|
||||
return {
|
||||
"summary": summary,
|
||||
"detail": {
|
||||
"screenshot": result.get("screenshot") or "",
|
||||
"reports_done": result.get("done", 0),
|
||||
"reports_total": result.get("total", 0),
|
||||
"files": files,
|
||||
"save_dir": save_dir,
|
||||
},
|
||||
"path": save_dir,
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(CrmDataExportPlugin())
|
||||
# -*- coding: utf-8 -*-
|
||||
"""CRM数据导出 - webhost 场景插件(XQ0048)
|
||||
|
||||
流程:
|
||||
1) 登录态预检(API 校验 %LOCALAPPDATA%\\37duAutomation\\.sessions\\crm_cookie_header.txt);
|
||||
有效则全程免扫码,失效则打开可见浏览器等钉钉扫码一次(同次运行最多弹一次);
|
||||
2) 打开「报表统计/储值卡余额」整页截图 → 储值卡余额-YYYYMMDD.png;
|
||||
3) requests 复用同一登录态,按日期规则导出 22 张报表 xlsx
|
||||
(礼品卡订单因接口限制跨度 ≤31 天,近 3 个自然月按月拆分)。
|
||||
"""
|
||||
import os
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from . import config
|
||||
from .data import crm_export
|
||||
|
||||
|
||||
class CrmDataExportPlugin(ScenePlugin):
|
||||
id = "xq0048"
|
||||
name = "CRM数据导出"
|
||||
version = "1.1.12"
|
||||
description = ("37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选),"
|
||||
"登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),"
|
||||
"按各报表日期规则自动计算区间,礼品卡订单按月拆分")
|
||||
platform = "" # CRM 为钉钉扫码登录,插件内自带登录流程,不使用底座共享登录态
|
||||
uses_month = False
|
||||
capabilities = ["xq0048"]
|
||||
permissions = {"platforms": []}
|
||||
# 与 plugin.json.fields 一致
|
||||
fields = {
|
||||
"reports": {"type": "array", "title": "导出内容", "default": [],
|
||||
"description": "勾选键列表(截图=__screenshot__,报表=接口#规则);空/缺省=全部导出"},
|
||||
"save_dir": {"type": "string", "title": "保存目录", "default": "",
|
||||
"description": "留空=D:\\资料\\财务\\CRM数据导出"},
|
||||
"debug_mode": {"type": "boolean", "title": "调试日志", "default": False},
|
||||
}
|
||||
|
||||
def run(self, fields, ctx) -> dict:
|
||||
fields = fields or {}
|
||||
config.set_log(ctx.log)
|
||||
config.set_progress(ctx.progress)
|
||||
config.set_debug(bool(fields.get("debug_mode")))
|
||||
|
||||
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
ctx.log(f"保存目录:{save_dir}")
|
||||
|
||||
report_keys = fields.get("reports")
|
||||
reports, include_shot = config.filter_reports(report_keys)
|
||||
if not reports and not include_shot:
|
||||
raise RuntimeError("未勾选任何导出内容,请至少勾选一项")
|
||||
if report_keys is None:
|
||||
ctx.log("导出内容:全部(截图 + %d 张报表)" % len(reports))
|
||||
else:
|
||||
ctx.log(f"导出内容:{'截图、' if include_shot else ''}{len(reports)} 张报表(按勾选)")
|
||||
|
||||
result = crm_export.run_export(save_dir, report_keys=report_keys)
|
||||
config.progress(100)
|
||||
|
||||
files = result.get("exports") or []
|
||||
shot_part = f"截图 {1 if result.get('screenshot') else 0}/1," if include_shot else ""
|
||||
summary = (f"{shot_part}"
|
||||
f"报表 {result.get('done')}/{result.get('total')},"
|
||||
f"共 {len(files) + (1 if result.get('screenshot') else 0)} 个文件")
|
||||
return {
|
||||
"summary": summary,
|
||||
"detail": {
|
||||
"screenshot": result.get("screenshot") or "",
|
||||
"reports_done": result.get("done", 0),
|
||||
"reports_total": result.get("total", 0),
|
||||
"files": files,
|
||||
"save_dir": save_dir,
|
||||
},
|
||||
"path": save_dir,
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(CrmDataExportPlugin())
|
||||
|
||||
@@ -7,7 +7,7 @@ zip 根含 plugin.json,可被 agent_cli publish 直接发布。详见 docs/插
|
||||
用法(任意 cwd 均可):
|
||||
d:\\work\\code\\37duAutomation\\.venv\\Scripts\\python.exe "plugins\\XQ0001-0100\\XQ0048 CRM数据导出\\_pack.py"
|
||||
随后发布:
|
||||
.venv\\Scripts\\python.exe -m controlplane.tools.agent_cli publish \
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py publish \
|
||||
dist-plugin\\xq0048_v<版本>.zip --id xq0048 --version <版本>
|
||||
"""
|
||||
import json
|
||||
|
||||
@@ -1,43 +1,45 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "xq0048",
|
||||
"name": "CRM数据导出",
|
||||
"version": "1.1.11",
|
||||
"description": "37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选)。登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),按各报表日期规则自动计算区间,礼品卡订单因接口限制跨度 ≤31 天按月拆分。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"ui": true,
|
||||
"capabilities": ["xq0048"],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reports": {
|
||||
"type": "array",
|
||||
"title": "导出内容",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": [],
|
||||
"description": "勾选键列表(截图=__screenshot__,报表=接口#规则);空/缺省=全部导出"
|
||||
},
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "保存目录",
|
||||
"default": "D:\\资料\\财务\\CRM数据导出",
|
||||
"description": "截图与全部 xlsx 统一输出目录"
|
||||
},
|
||||
"debug_mode": {
|
||||
"type": "boolean",
|
||||
"title": "调试日志",
|
||||
"default": false,
|
||||
"description": "开启后输出完整调试日志(默认关闭)"
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "xq0048",
|
||||
"name": "CRM数据导出",
|
||||
"version": "1.1.12",
|
||||
"description": "37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选)。登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),按各报表日期规则自动计算区间,礼品卡订单因接口限制跨度 ≤31 天按月拆分。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"ui": true,
|
||||
"capabilities": [
|
||||
"xq0048"
|
||||
],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reports": {
|
||||
"type": "array",
|
||||
"title": "导出内容",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": [],
|
||||
"description": "勾选键列表(截图=__screenshot__,报表=接口#规则);空/缺省=全部导出"
|
||||
},
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "保存目录",
|
||||
"default": "D:\\资料\\财务\\CRM数据导出",
|
||||
"description": "截图与全部 xlsx 统一输出目录"
|
||||
},
|
||||
"debug_mode": {
|
||||
"type": "boolean",
|
||||
"title": "调试日志",
|
||||
"default": false,
|
||||
"description": "开启后输出完整调试日志(默认关闭)"
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ export function usePluginUI(opts = {}) {
|
||||
let pollTimer = null
|
||||
let saveTimer = null
|
||||
|
||||
// 传空 type 视为清除横幅(不能留 {type:null},否则会渲染成只有"!"的空横幅)
|
||||
// 传空 type 视为清除横幅(不能留 {type:null},否则会渲染成只有"!"的空横幅)
|
||||
const notify = (type, text) => { notice.value = type ? { type, text } : null }
|
||||
|
||||
// ---------- 当前配置:加载 / 防抖自动保存 ----------
|
||||
@@ -303,7 +303,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 }
|
||||
}
|
||||
@@ -315,6 +316,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)
|
||||
@@ -332,6 +334,13 @@ export function usePluginUI(opts = {}) {
|
||||
if (summary) notify('ok', summary)
|
||||
}
|
||||
|
||||
// 用户主动停止 / 排队取消 / 排队超时:不算失败,给中性的「已取消」提示
|
||||
function cancelled(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
notify('warn', '任务已取消:' + (err || '用户已停止'))
|
||||
}
|
||||
|
||||
function failed(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
|
||||
+17
-17
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>CRM数据导出</title>
|
||||
<script type="module" crossorigin src="/pui/xq0048/assets/index-C4AfJdEx.js"></script>
|
||||
<script type="module" crossorigin src="/pui/xq0048/assets/index-CGwC8bM4.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0048/assets/index-DTPKi6j7.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user