diff --git a/src/commands/schedule/create.ts b/src/commands/schedule/create.ts index 05553ae..1d9861c 100644 --- a/src/commands/schedule/create.ts +++ b/src/commands/schedule/create.ts @@ -1,13 +1,14 @@ /** * commands/schedule/create.ts — 新建定时任务 * - * API: POST /api/scheduletask - * 必填: fullName / executeType / executeContent (JNPF 列表和创建用同端点) + * v0.11+ Phase 2: webapi 化 (loadSchedule.create) + * 替代 v0.10 直接 c.postJson */ 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, loadSchedule } from '../../webapi/schedule.ts' interface CreateOpts { fullName: string @@ -20,7 +21,7 @@ interface CreateOpts { export function buildScheduleCreateCommand(): Command { const cmd = new Command('create') - .description('新建定时任务 (Quartz cron)') + .description('新建定时任务 (Quartz cron, v0.11+ webapi)') .requiredOption('--fullName ', '任务名称') .requiredOption('--enCode ', '任务编码') .requiredOption('--executeType ', '执行类型 (e.g. SQL/JavaScript/...)') @@ -29,6 +30,7 @@ export function buildScheduleCreateCommand(): Command { .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() + await initWebapi(c) const body: Record = { fullName: opts.fullName, enCode: opts.enCode, @@ -38,33 +40,23 @@ export function buildScheduleCreateCommand(): Command { sortCode: 0, } if (opts.cron) body.cron = opts.cron - const r = await c.postJson<{ id?: string }>('/scheduletask', body) - if (r.code !== 200) { + log.info(`loadSchedule.create (enCode=${opts.enCode})`) + const r = (await loadSchedule.create(body)) as { id?: string; code?: number; msg?: string; data?: { id?: string } } + if (r.code !== 200 && r.code !== undefined) { log.error(`schedule create 失败: ${r.msg}`) process.exit(1) } - log.info(`✓ 定时任务创建成功 id=${r.data?.id}`) - if (opts.json) printJson(r.data) + const id = r.id || r.data?.id + log.info(`✓ 定时任务创建成功 id=${id}`) + if (opts.json) printJson(r.data || r) }) installAiHelpHook(cmd, { purpose: '新建定时任务 (Quartz cron, 决策 9: 与工作流区别)', - required: { - '--fullName': '任务名称', - '--enCode': '任务编码', - '--executeType': '执行类型', - '--executeContent': '执行内容', - }, + required: { '--fullName': '任务名称', '--enCode': '任务编码', '--executeType': '执行类型', '--executeContent': '执行内容' }, optional: { '--cron': 'cron 表达式' }, example: 'dacli schedule create --fullName=daily --enCode=daily_task --executeType=SQL --executeContent="SELECT 1" --cron="0 0 0 * * ?"', - source: { - web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue', - api: 'POST /api/scheduletask', - ref: 'doc/v0.8-endpoints.md §2.5', - }, - notes: [ - '**决策 9**: 用 schedule (Quartz) 做"每天凌晨跑一次", 不用工作流', - '**反模式**: 业务审批用 workflow, 定时清理/缓存刷新用 schedule', - ], + source: { api: 'POST /api/scheduletask', ref: 'web/.../api/system/task.ts create()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadSchedule.create)', '**决策 9**: 用 schedule 做定时任务, 不用工作流'], }) return cmd } diff --git a/src/commands/schedule/info.ts b/src/commands/schedule/info.ts index 077a0c5..f59ce7e 100644 --- a/src/commands/schedule/info.ts +++ b/src/commands/schedule/info.ts @@ -1,12 +1,14 @@ /** * commands/schedule/info.ts — 定时任务详情 * - * API: GET /api/scheduletask/Info/{id} + * v0.11+ Phase 2: webapi 化 (loadSchedule.getInfo) + * 替代 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, loadSchedule } from '../../webapi/schedule.ts' interface InfoOpts { id: string @@ -15,25 +17,21 @@ interface InfoOpts { export function buildScheduleInfoCommand(): Command { const cmd = new Command('info') - .description('查看定时任务详情 (Quartz cron + 执行配置)') + .description('查看定时任务详情 (Quartz cron + 执行配置, v0.11+ webapi)') .requiredOption('--id ', '定时任务 id') .option('--json', '原始 JSON 输出', false) .action(async (opts: InfoOpts) => { const c = await JnpfClient.fromToken() - const r = await c.get>(`/scheduletask/Info/${opts.id}`) - if (r.code !== 200) { - log.error(`schedule info 失败: ${r.msg}`) - process.exit(1) - } - if (!r.data) { + await initWebapi(c) + const d = (await loadSchedule.getInfo(opts.id)) as Record + if (!d) { log.error(`schedule id=${opts.id} 不存在`) process.exit(1) } if (opts.json) { - printJson(r.data) + printJson(d) return } - const d = r.data as Record log.info(`定时任务 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`) console.log(`cron: ${d.cron || '-'}`) console.log(`executeType: ${d.executeType || '-'}`) @@ -47,8 +45,9 @@ export function buildScheduleInfoCommand(): Command { source: { web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue', api: 'GET /api/scheduletask/Info/{id}', - ref: 'doc/v0.8-endpoints.md §2.5', + ref: 'web/.../api/system/task.ts getInfo()', }, + notes: ['v0.11+ 改用 webapi 镜像 (loadSchedule.getInfo)'], }) return cmd } diff --git a/src/commands/schedule/list.ts b/src/commands/schedule/list.ts index 095793c..5c78e1c 100644 --- a/src/commands/schedule/list.ts +++ b/src/commands/schedule/list.ts @@ -20,6 +20,7 @@ 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, loadSchedule } from '../../webapi/schedule.ts' interface ListOpts { json?: boolean @@ -31,21 +32,23 @@ export function buildScheduleListCommand(): Command { .option('--json', '原始 JSON 输出', false) .action(async (opts: ListOpts) => { const c = await JnpfClient.fromToken() + await initWebapi(c) + // v0.11+ Phase 2: 改用 webapi (loadSchedule.getTaskList) // JNPF 6.2 端点 bug: GET 返 Content-Length:0, POST 是 create 端点 // 兜底: 提示用户用 info/log/trigger 配合 web 端拿到的 id - const r = await c.get('/scheduletask', { currentPage: 1, pageSize: 50 }) + const r = (await loadSchedule.getTaskList({ currentPage: 1, pageSize: 50 })) as { list?: unknown[] } log.warn('⚠ JNPF 6.2 schedule list 端点已知 bug (GET 返空 body, POST 是 create)') log.info(' 兜底方案:') log.info(' 1. dacli schedule info --id= 单点查 (从 web 端 任务调度 拿 id)') log.info(' 2. dacli schedule log --id= 查执行日志') log.info(' 3. dacli schedule create ... 建新任务') log.info(' 4. dacli schedule trigger --id= 手动触发') - if (r.data && (Array.isArray(r.data) || (typeof r.data === 'object' && 'list' in (r.data as object)))) { - printJson(r.data) + if (r && (Array.isArray(r) || (typeof r === 'object' && 'list' in r))) { + printJson(r) } else { log.info(' (data 为空 — JNPF 端点 bug 已知)') } - if (opts.json) printJson(r.data) + if (opts.json) printJson(r) }) installAiHelpHook(cmd, { purpose: '列定时任务 (JNPF 6.2 端点 bug, 兜底用 info/log 单点查)', diff --git a/src/commands/schedule/log.ts b/src/commands/schedule/log.ts index 8098088..80916b2 100644 --- a/src/commands/schedule/log.ts +++ b/src/commands/schedule/log.ts @@ -1,12 +1,18 @@ /** * commands/schedule/log.ts — 定时任务执行日志 * - * API: GET /api/scheduletask/{id}/TaskLog + * v0.11+ Phase 2: webapi 化 (loadSchedule.getTaskLogList) + * 替代 v0.10 直接 c.get + * + * 注: web task.ts 的 getTaskLogList 接受 (data) 不带 id 路径参数 + * 但 JNPF 端点是 /scheduletask/{id}/TaskLog (id 路径参数) + * 所以这里走 getTaskLogList({ taskId: opts.id }) 兼容 */ 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, loadSchedule } from '../../webapi/schedule.ts' interface LogOpts { id: string @@ -22,22 +28,17 @@ interface LogItem { export function buildScheduleLogCommand(): Command { const cmd = new Command('log') - .description('查看定时任务执行日志') + .description('查看定时任务执行日志 (v0.11+ webapi)') .requiredOption('--id ', '定时任务 id') .option('--json', '原始 JSON 输出', false) .action(async (opts: LogOpts) => { const c = await JnpfClient.fromToken() - const r = await c.get<{ list: LogItem[] }>(`/scheduletask/${opts.id}/TaskLog`, { - currentPage: 1, - pageSize: 20, - }) - if (r.code !== 200) { - log.error(`schedule log 失败: ${r.msg}`) - process.exit(1) - } - const list = r.data?.list || [] + await initWebapi(c) + // 注: web getTaskLogList(data) 接受 taskId 参数, 对应 JNPF 路径 /scheduletask/{id}/TaskLog + const r = (await loadSchedule.getTaskLogList({ taskId: opts.id })) as { list?: LogItem[] } + const list = r.list || [] if (opts.json) { - printJson(r.data) + printJson(r) return } log.info(`定时任务 id=${opts.id} 共 ${list.length} 条日志`) @@ -54,11 +55,8 @@ export function buildScheduleLogCommand(): Command { purpose: '查看定时任务执行日志', required: { '--id': '定时任务 id' }, example: 'dacli schedule log --id=1234567890', - source: { - web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/index.vue', - api: 'GET /api/scheduletask/{id}/TaskLog', - ref: 'doc/v0.8-endpoints.md §2.5', - }, + source: { api: 'GET /api/scheduletask/{id}/TaskLog', ref: 'web/.../api/system/task.ts getTaskLogList()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadSchedule.getTaskLogList)'], }) return cmd } diff --git a/src/webapi/flowMonitor.ts b/src/webapi/flowMonitor.ts new file mode 100644 index 0000000..2462e65 --- /dev/null +++ b/src/webapi/flowMonitor.ts @@ -0,0 +1,31 @@ +/** + * webapi/flowMonitor.ts — 镜像 web 端 flowMonitor.ts (v0.11+ Phase 2) + * + * 镜像 web/apps/jnpf-web-apps-main/src/api/workFlow/flowMonitor.ts 8 函数: + * getFlowMonitorList / delMonitorList / getLogList / cancel / assign / + * resurgence / getPauseType + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const FLOW_MONITOR_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/workFlow/flowMonitor.ts' + +let cached: any = null + +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + cached = await loadWebModule(FLOW_MONITOR_SRC) +} + +export function isWebapiLoaded(): boolean { + return cached !== null +} + +export const loadFlowMonitor: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) throw new Error('flowMonitor 模块未初始化, 请先 await initWebapi(client)') + return cached[prop] + }, +}) diff --git a/src/webapi/onlineUser.ts b/src/webapi/onlineUser.ts new file mode 100644 index 0000000..ab2a461 --- /dev/null +++ b/src/webapi/onlineUser.ts @@ -0,0 +1,30 @@ +/** + * webapi/onlineUser.ts — 镜像 web 端 onlineUser.ts (v0.11+ Phase 2) + * + * 镜像 web/apps/jnpf-web-apps-main/src/api/permission/onlineUser.ts 3 函数: + * getOnlineUser / batchDelOnlineUser / deleteOnlineUser + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const ONLINE_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/permission/onlineUser.ts' + +let cached: any = null + +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + cached = await loadWebModule(ONLINE_SRC) +} + +export function isWebapiLoaded(): boolean { + return cached !== null +} + +export const loadOnlineUser: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) throw new Error('onlineUser 模块未初始化, 请先 await initWebapi(client)') + return cached[prop] + }, +})