refactor(v0.11+): schedule 4 子命令 + 新建 onlineUser/flowMonitor webapi

- 新建 webapi/onlineUser.ts (3 函数, 镜像 web/api/permission/onlineUser.ts)
- 新建 webapi/flowMonitor.ts (8 函数, 镜像 web/api/workFlow/flowMonitor.ts)
- schedule/list: c.get → loadSchedule.getTaskList
- schedule/info: c.get → loadSchedule.getInfo
- schedule/create: c.postJson → loadSchedule.create
- schedule/log: c.get → loadSchedule.getTaskLogList

注: schedule/trigger 保留 c.postJson (white/trigger 是 dacli 专属端点, web task.ts 无)

webapi 模块累计 16 个

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:36:11 +08:00
1 parent e79520cd9e
commit bd11e1b388
6 files changed
+107 -54

No files matched your search

+14 -22
View File
@@ -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 <name>', '任务名称')
.requiredOption('--enCode <code>', '任务编码')
.requiredOption('--executeType <t>', '执行类型 (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<string, unknown> = {
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
}
+10 -11
View File
@@ -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>', '定时任务 id')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: InfoOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/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<string, unknown>
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<string, unknown>
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
}
+7 -4
View File
@@ -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<unknown>('/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=<id> 单点查 (从 web 端 任务调度 拿 id)')
log.info(' 2. dacli schedule log --id=<id> 查执行日志')
log.info(' 3. dacli schedule create ... 建新任务')
log.info(' 4. dacli schedule trigger --id=<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 单点查)',
+15 -17
View File
@@ -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>', '定时任务 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
}
+31
View File
@@ -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<void> {
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]
},
})
+30
View File
@@ -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<void> {
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]
},
})