From 65ca7f2ccc8f1ba83188597f5b879794cd277005 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 25 Jun 2026 15:27:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(v0.11+):=20log=20exception/request=20?= =?UTF-8?q?=E6=94=B9=E8=B5=B0=20webapi=20=E9=95=9C=E5=83=8F=20(loadLog)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 响应用户: '之前 NEW-CMD 都走平台 api, 应该走 webapi' - log/exception.ts: c.get → loadLog.getLogList(category=4) - log/request.ts: c.get → loadLog.getLogList(category=5) webapi/log.ts 已镜像 web/api/system/log.ts 5 函数 (getLogList/delLog/batchDelLog/getInfo/batchDelLoginLog) Co-Authored-By: Claude --- src/commands/log/exception.ts | 34 +++++++++++++++------------------- src/commands/log/request.ts | 23 +++++++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/commands/log/exception.ts b/src/commands/log/exception.ts index 88bbf62..dc4af30 100644 --- a/src/commands/log/exception.ts +++ b/src/commands/log/exception.ts @@ -1,13 +1,14 @@ /** * commands/log/exception.ts — 异常日志 (P0 AI 调试核心入口) * - * v0.11+ Phase 2 (2026-06-25) 新增: 异常日志 (category='4') 查后端 Java 异常堆栈 - * 解决: form create 失败 → 想查异常原因 → log exception 命令不存在 盲点 + * v0.11+ Phase 2: webapi 化 (loadLog.getLogList + category=4) + * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadLog } from '../../webapi/log.ts' interface ListOpts { keyword?: string @@ -17,38 +18,37 @@ interface ListOpts { export function buildLogExceptionCommand(): Command { const cmd = new Command('exception') - .description('异常日志 (Java 异常堆栈, AI 调试核心入口)') + .description('异常日志 (Java 异常堆栈, AI 调试核心入口, v0.11+ webapi)') .option('--keyword ', '按账号/异常名/URL 模糊搜索') .option('--limit ', '最多取 N 条 (默认 20)', '20') .option('--json', '原始 JSON 输出', false) .action(async (opts: ListOpts) => { const c = await JnpfClient.fromToken() - // JNPF 异常日志 = Log + category='4' (web/src/views/sysLog/errorLog/index.vue) - const r = await c.get<{ list: Record[] }>('/system/Log', { + await initWebapi(c) + // v0.11+ Phase 2: 走 webapi 镜像 + const r = (await loadLog.getLogList({ category: '4', keyword: opts.keyword, currentPage: 1, pageSize: opts.limit || '20', - }) - if (r.code !== 200) { - log.error(`log exception 失败: ${r.msg}`) + })) as { list?: Record[] } + if (!r || (r as { code?: number }).code !== 200 && (r as { code?: number }).code !== undefined) { + log.error(`log exception 失败: ${(r as { msg?: string }).msg}`) process.exit(1) } - const list = r.data?.list || [] + const list = r.list || [] if (opts.json) { - printJson(r.data) + printJson(r) return } log.info(`异常日志 ${list.length} 条 (category=4, 找后端 Java 异常堆栈)`) for (const d of list) { - // 异常日志核心字段: userName / ipAddress / moduleName / requestMethod / requestUrl / json / createTime const time = String(d.createTime || d.F_CreatorTime || '').slice(0, 19) const user = String(d.userName || d.F_UserId || '-') const url = String(d.requestUrl || d.F_RequestUrl || '-') const module = String(d.moduleName || d.F_ModuleName || '-') const method = String(d.requestMethod || d.F_RequestMethod || '-') console.log(`[${time}] ${user} ${method} ${url} (${module})`) - // 输出 json 字段 (含异常堆栈, 不截断) const json = String(d.json || d.F_Json || '') if (json) { console.log(' ↳ 异常详情:') @@ -58,7 +58,7 @@ export function buildLogExceptionCommand(): Command { } }) installAiHelpHook(cmd, { - purpose: '异常日志 (Java 异常堆栈, AI 调试后端错误核心入口). 解决 form create 失败 / 业务异常无路径排查盲点.', + purpose: '异常日志 (Java 异常堆栈, AI 调试后端错误核心入口).', optional: { '--keyword': '按账号/异常名/URL 模糊搜索', '--limit': '最多取 N 条', '--json': '原始 JSON 输出' }, example: [ 'dacli log exception', @@ -68,13 +68,9 @@ export function buildLogExceptionCommand(): Command { source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/errorLog/index.vue', api: 'GET /api/system/Log?category=4', - ref: 'dacli/docs/cmd-review/log.md §NEW-CMD P0', + ref: 'web/.../api/system/log.ts getLogList()', }, - notes: [ - 'v0.11+ P0 新增, 之前 AI 排查后端异常无路可走', - 'category=4 是 JNPF 固定枚举 (1 登录 / 3 操作 / 4 异常 / 5 请求)', - 'json 字段含完整 Java 堆栈, --json 拿全', - ], + notes: ['v0.11+ 改用 webapi 镜像 (loadLog.getLogList + category=4)'], }) return cmd } diff --git a/src/commands/log/request.ts b/src/commands/log/request.ts index 4e56cb3..89f5600 100644 --- a/src/commands/log/request.ts +++ b/src/commands/log/request.ts @@ -1,12 +1,14 @@ /** * commands/log/request.ts — 请求日志 (P0 审计 API 调用) * - * v0.11+ Phase 2 (2026-06-25) 新增: 请求日志 (category='5') 审计 API 调用 + * v0.11+ Phase 2: webapi 化 (loadLog.getLogList + category=5) + * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadLog } from '../../webapi/log.ts' interface ListOpts { keyword?: string @@ -16,25 +18,26 @@ interface ListOpts { export function buildLogRequestCommand(): Command { const cmd = new Command('request') - .description('请求日志 (API 调用审计, category=5)') + .description('请求日志 (API 调用审计, category=5, v0.11+ webapi)') .option('--keyword ', '按账号/URL 模糊搜索') .option('--limit ', '最多取 N 条 (默认 20)', '20') .option('--json', '原始 JSON 输出', false) .action(async (opts: ListOpts) => { const c = await JnpfClient.fromToken() - const r = await c.get<{ list: Record[] }>('/system/Log', { + await initWebapi(c) + const r = (await loadLog.getLogList({ category: '5', keyword: opts.keyword, currentPage: 1, pageSize: opts.limit || '20', - }) - if (r.code !== 200) { - log.error(`log request 失败: ${r.msg}`) + })) as { list?: Record[] } + if (!r || (r as { code?: number }).code !== 200 && (r as { code?: number }).code !== undefined) { + log.error(`log request 失败: ${(r as { msg?: string }).msg}`) process.exit(1) } - const list = r.data?.list || [] + const list = r.list || [] if (opts.json) { - printJson(r.data) + printJson(r) return } log.info(`请求日志 ${list.length} 条 (category=5, 审计 API 调用)`) @@ -56,8 +59,8 @@ export function buildLogRequestCommand(): Command { 'dacli log request --keyword=/api/visualdev', 'dacli log request --keyword=500 --limit=10', ], - source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/requestLog/index.vue', api: 'GET /api/system/Log?category=5' }, - notes: ['v0.11+ P0 新增, web 端已实现, 之前 dacli 缺'], + source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/requestLog/index.vue', api: 'GET /api/system/Log?category=5', ref: 'web/.../api/system/log.ts getLogList()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadLog.getLogList + category=5)'], }) return cmd }