From 1881bec3010eedb82546cff8bce186bbc324bcad Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 03:35:34 +0800 Subject: [PATCH] feat(schedule): v0.11e+ wire up _validate.ts + enhanceFromBackend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit schedule/create.ts (Phase C1 集成): - import validateScheduleCreate + enhanceFromBackend/formatErrorLine - 加 --startTime/--endTime/--enabledMark 选项 - 跑 step machine (cron 格式校验 + SYS131 时间关系) - catch 后端错时 enhanceFromBackend --- src/commands/schedule/create.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/commands/schedule/create.ts b/src/commands/schedule/create.ts index 1d9861c..cc5f24b 100644 --- a/src/commands/schedule/create.ts +++ b/src/commands/schedule/create.ts @@ -9,6 +9,8 @@ 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' +import { validateScheduleCreate } from './_validate.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' interface CreateOpts { fullName: string @@ -16,21 +18,47 @@ interface CreateOpts { executeType: string executeContent: string cron?: string + startTime?: string + endTime?: string + enabledMark?: string json?: boolean } export function buildScheduleCreateCommand(): Command { const cmd = new Command('create') - .description('新建定时任务 (Quartz cron, v0.11+ webapi)') + .description('新建定时任务 (Quartz cron, v0.11+ webapi + v0.11e+ step machine)') .requiredOption('--fullName ', '任务名称') .requiredOption('--enCode ', '任务编码') .requiredOption('--executeType ', '执行类型 (e.g. SQL/JavaScript/...)') .requiredOption('--executeContent ', '执行内容 (SQL 脚本/JS 代码)') .option('--cron ', 'cron 表达式 (e.g. "0 0 0 * * ?")') + .option('--startTime ', 'v0.11e+ Phase C1: 开始时间 (ISO 格式, SYS131 校验)') + .option('--endTime ', 'v0.11e+ Phase C1: 结束时间 (ISO 格式, SYS131 校验)') + .option('--enabledMark ', 'v0.11e+ Phase C1: 0/1', '1') .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() await initWebapi(c) + + // v0.11e+ Phase C1: step machine 校验 (cron 格式 + SYS131 时间关系) + const validation = validateScheduleCreate({ + fullName: opts.fullName, + enCode: opts.enCode, + cron: opts.cron, + startTime: opts.startTime, + endTime: opts.endTime, + enabledMark: opts.enabledMark, + }) + if (!validation.ok) { + for (const s of validation.steps) { + for (const e of s.errors) { + log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) + } + } + process.exit(1) + } + log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) + const body: Record = { fullName: opts.fullName, enCode: opts.enCode, @@ -43,7 +71,8 @@ export function buildScheduleCreateCommand(): Command { 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}`) + const enhanced = enhanceFromBackend(r.msg || '', 'schedule', { entity: 'schedule' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) process.exit(1) } const id = r.id || r.data?.id