diff --git a/src/commands/msg/index.ts b/src/commands/msg/index.ts index 3d2bf60..2c151bc 100644 --- a/src/commands/msg/index.ts +++ b/src/commands/msg/index.ts @@ -5,26 +5,38 @@ * * 决策 8: 通知通道 site/email/sms/webhook/dingTalk/weCom * - * 子命令: + * v0.11+ Phase 2: 9 子命令 (闭环 CRUD) * noticelist 通知列表 * noticecreate 新建通知 + * noticeupdate 改通知 (P0 v0.11+) + * noticedelete 删通知 (P0 v0.11+) * noticesend 发送通知 * templatelist 模板列表 * templatecreate 新建模板 + * templateupdate 改模板 (P0 v0.11+) + * templatedelete 删模板 (P0 v0.11+) */ import { Command } from 'commander' import { buildMsgNoticeListCommand } from './noticelist.ts' import { buildMsgNoticeCreateCommand } from './noticecreate.ts' +import { buildMsgNoticeUpdateCommand } from './noticeupdate.ts' +import { buildMsgNoticeDeleteCommand } from './noticedelete.ts' import { buildMsgNoticeSendCommand } from './noticesend.ts' import { buildMsgTemplateListCommand } from './templatelist.ts' import { buildMsgTemplateCreateCommand } from './templatecreate.ts' +import { buildMsgTemplateUpdateCommand } from './templateupdate.ts' +import { buildMsgTemplateDeleteCommand } from './templatedelete.ts' export function buildMsgCommand(): Command { - const cmd = new Command('msg').description('消息中心 (通知 + 模板, msgCenter)') + const cmd = new Command('msg').description('消息中心 (通知 + 模板 CRUD, msgCenter)') cmd.addCommand(buildMsgNoticeListCommand()) cmd.addCommand(buildMsgNoticeCreateCommand()) + cmd.addCommand(buildMsgNoticeUpdateCommand()) + cmd.addCommand(buildMsgNoticeDeleteCommand()) cmd.addCommand(buildMsgNoticeSendCommand()) cmd.addCommand(buildMsgTemplateListCommand()) cmd.addCommand(buildMsgTemplateCreateCommand()) + cmd.addCommand(buildMsgTemplateUpdateCommand()) + cmd.addCommand(buildMsgTemplateDeleteCommand()) return cmd } diff --git a/src/commands/msg/noticedelete.ts b/src/commands/msg/noticedelete.ts new file mode 100644 index 0000000..1e68f13 --- /dev/null +++ b/src/commands/msg/noticedelete.ts @@ -0,0 +1,42 @@ +/** + * commands/msg/noticedelete.ts — 通知公告删除 + * + * v0.11+ Phase 2 新增: msg 公告 CRUD 闭环 + * + * API: DELETE /api/message/Notice/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log } from '../../core/log.ts' + +interface Opts { id: string; yes?: boolean } + +export function buildMsgNoticeDeleteCommand(): Command { + const cmd = new Command('noticeDelete') + .alias('notice-delete') + .description('通知公告删除 (硬删)') + .requiredOption('--id ', '公告 id') + .option('--yes', '跳过确认', false) + .action(async (opts: Opts) => { + if (!opts.yes) { + log.warn(`即将删除公告 id=${opts.id}, 加 --yes 跳过确认`) + process.exit(2) + } + const c = await JnpfClient.fromToken() + const r = await c.del(`/message/Notice/${opts.id}`) + if (r.code !== 200) { + log.error(`msg noticeDelete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 公告已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '通知公告删除', + required: { '--id': '公告 id', '--yes': '跳过确认' }, + example: 'dacli msg noticeDelete --id=123 --yes', + source: { api: 'DELETE /api/message/Notice/{id}' }, + notes: ['v0.11+ P0 新增, 谨慎操作'], + }) + return cmd +} diff --git a/src/commands/msg/noticeupdate.ts b/src/commands/msg/noticeupdate.ts new file mode 100644 index 0000000..e008345 --- /dev/null +++ b/src/commands/msg/noticeupdate.ts @@ -0,0 +1,63 @@ +/** + * commands/msg/noticeupdate.ts — 通知公告修改 + * + * v0.11+ Phase 2 新增: msg 公告 CRUD 闭环 (P0) + * + * API: PUT /api/message/Notice/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' + +interface Opts { + id: string + fullName?: string + enCode?: string + body?: string + category?: string + json?: boolean +} + +export function buildMsgNoticeUpdateCommand(): Command { + const cmd = new Command('noticeUpdate') + .alias('notice-update') + .description('通知公告修改 (PUT 语义)') + .requiredOption('--id ', '公告 id') + .option('--fullName ', '公告名') + .option('--enCode ', '英文编码') + .option('--body ', '公告内容') + .option('--category ', '分类 (1=系统 2=业务)') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const origR = await c.get | null>(`/message/Notice/${opts.id}`) + if (origR.code !== 200 || !origR.data) { + log.error(`msg noticeUpdate 失败: 拉原公告 id=${opts.id} 失败`) + process.exit(1) + } + const body: Record = { ...(origR.data as Record), id: opts.id } + if (opts.fullName) body.fullName = opts.fullName + if (opts.enCode) body.enCode = opts.enCode + if (opts.body) body.body = opts.body + if (opts.category) body.category = opts.category + log.info(`PUT /message/Notice/${opts.id}`) + const r = await c.putJson(`/message/Notice/${opts.id}`, body) + if (r.code !== 200) { + log.error(`msg noticeUpdate 失败 (code=${r.code}): ${r.msg}`) + if (opts.json) printJson(r) + process.exit(1) + } + log.ok(`✓ 公告更新成功 (id=${opts.id})`) + if (opts.json) printJson(r.data) + }) + installAiHelpHook(cmd, { + purpose: '通知公告修改. 改 fullName/enCode/body/category, PUT 语义, 未传保留.', + required: { '--id': '公告 id' }, + optional: { '--fullName': '公告名', '--enCode': '英文编码', '--body': '公告内容', '--category': '分类' }, + example: 'dacli msg noticeUpdate --id=123 --body="新内容"', + source: { api: 'PUT /api/message/Notice/{id}' }, + notes: ['v0.11+ P0 新增', '未传字段保留 (PUT 语义)'], + }) + return cmd +} diff --git a/src/commands/msg/templatedelete.ts b/src/commands/msg/templatedelete.ts new file mode 100644 index 0000000..0eb2146 --- /dev/null +++ b/src/commands/msg/templatedelete.ts @@ -0,0 +1,42 @@ +/** + * commands/msg/templatedelete.ts — 消息模板删除 + * + * v0.11+ Phase 2 新增: msg 模板 CRUD 闭环 + * + * API: DELETE /api/message/MessageTemplateConfig/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log } from '../../core/log.ts' + +interface Opts { id: string; yes?: boolean } + +export function buildMsgTemplateDeleteCommand(): Command { + const cmd = new Command('templateDelete') + .alias('template-delete') + .description('消息模板删除 (硬删)') + .requiredOption('--id ', '模板 id') + .option('--yes', '跳过确认', false) + .action(async (opts: Opts) => { + if (!opts.yes) { + log.warn(`即将删除模板 id=${opts.id}, 加 --yes 跳过确认`) + process.exit(2) + } + const c = await JnpfClient.fromToken() + const r = await c.del(`/message/MessageTemplateConfig/${opts.id}`) + if (r.code !== 200) { + log.error(`msg templateDelete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 模板已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '消息模板删除', + required: { '--id': '模板 id', '--yes': '跳过确认' }, + example: 'dacli msg templateDelete --id=123 --yes', + source: { api: 'DELETE /api/message/MessageTemplateConfig/{id}' }, + notes: ['v0.11+ P0 新增, 谨慎操作'], + }) + return cmd +} diff --git a/src/commands/msg/templateupdate.ts b/src/commands/msg/templateupdate.ts new file mode 100644 index 0000000..e396113 --- /dev/null +++ b/src/commands/msg/templateupdate.ts @@ -0,0 +1,66 @@ +/** + * commands/msg/templateupdate.ts — 消息模板修改 + * + * v0.11+ Phase 2 新增: msg 模板 CRUD 闭环 (P0) + * + * API: PUT /api/message/MessageTemplateConfig/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' + +interface Opts { + id: string + fullName?: string + enCode?: string + category?: string + content?: string + enabledMark?: string + json?: boolean +} + +export function buildMsgTemplateUpdateCommand(): Command { + const cmd = new Command('templateUpdate') + .alias('template-update') + .description('消息模板修改 (PUT 语义)') + .requiredOption('--id ', '模板 id') + .option('--fullName ', '模板名') + .option('--enCode ', '英文编码') + .option('--category ', '分类 (1=系统 2=业务)') + .option('--content ', '模板内容') + .option('--enabledMark <0|1>', '启用/禁用') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const origR = await c.get | null>(`/message/MessageTemplateConfig/${opts.id}`) + if (origR.code !== 200 || !origR.data) { + log.error(`msg templateUpdate 失败: 拉原模板 id=${opts.id} 失败`) + process.exit(1) + } + const body: Record = { ...(origR.data as Record), id: opts.id } + if (opts.fullName) body.fullName = opts.fullName + if (opts.enCode) body.enCode = opts.enCode + if (opts.category) body.category = opts.category + if (opts.content) body.content = opts.content + if (opts.enabledMark !== undefined) body.enabledMark = parseInt(opts.enabledMark, 10) + log.info(`PUT /message/MessageTemplateConfig/${opts.id}`) + const r = await c.putJson(`/message/MessageTemplateConfig/${opts.id}`, body) + if (r.code !== 200) { + log.error(`msg templateUpdate 失败 (code=${r.code}): ${r.msg}`) + if (opts.json) printJson(r) + process.exit(1) + } + log.ok(`✓ 模板更新成功 (id=${opts.id})`) + if (opts.json) printJson(r.data) + }) + installAiHelpHook(cmd, { + purpose: '消息模板修改', + required: { '--id': '模板 id' }, + optional: { '--fullName': '模板名', '--enCode': '英文编码', '--category': '分类', '--content': '内容', '--enabledMark': '启用/禁用' }, + example: 'dacli msg templateUpdate --id=123 --content="新内容"', + source: { api: 'PUT /api/message/MessageTemplateConfig/{id}' }, + notes: ['v0.11+ P0 新增', '未传字段保留 (PUT 语义)'], + }) + return cmd +} diff --git a/src/commands/schedule/delete.ts b/src/commands/schedule/delete.ts new file mode 100644 index 0000000..1f3e6ea --- /dev/null +++ b/src/commands/schedule/delete.ts @@ -0,0 +1,41 @@ +/** + * commands/schedule/delete.ts — 定时任务删除 + * + * v0.11+ Phase 2 新增: 定时任务 CRUD 闭环 + * + * API: DELETE /api/scheduletask/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log } from '../../core/log.ts' + +interface Opts { id: string; yes?: boolean } + +export function buildScheduleDeleteCommand(): Command { + const cmd = new Command('delete') + .description('定时任务删除 (硬删)') + .requiredOption('--id ', '任务 id') + .option('--yes', '跳过确认', false) + .action(async (opts: Opts) => { + if (!opts.yes) { + log.warn(`即将删除定时任务 id=${opts.id}, 加 --yes 跳过确认`) + process.exit(2) + } + const c = await JnpfClient.fromToken() + const r = await c.del(`/scheduletask/${opts.id}`) + if (r.code !== 200) { + log.error(`schedule delete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 定时任务已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '定时任务删除. 任务调度会停.', + required: { '--id': '任务 id', '--yes': '跳过确认' }, + example: 'dacli schedule delete --id=123 --yes', + source: { api: 'DELETE /api/scheduletask/{id}' }, + notes: ['v0.11+ P0 新增, 谨慎操作'], + }) + return cmd +} diff --git a/src/commands/schedule/index.ts b/src/commands/schedule/index.ts index bc5a7cd..7446400 100644 --- a/src/commands/schedule/index.ts +++ b/src/commands/schedule/index.ts @@ -6,10 +6,12 @@ * 决策 9: 定时报表生成/数据清理/缓存刷新用 schedule (cron), * 业务审批用 workflow (人工发起/事件触发) * - * 子命令: + * v0.11+ Phase 2: 7 子命令 (闭环 CRUD) * list 列表 (JNPF 端点已知返空, 用 info 兜底) * info 详情 * create 新建 + * update 修改 (P0 v0.11+, 改 cron 不必 delete+create) + * delete 删除 (P0 v0.11+) * trigger 手动触发 * log 执行日志 */ @@ -17,6 +19,8 @@ import { Command } from 'commander' import { buildScheduleListCommand } from './list.ts' import { buildScheduleInfoCommand } from './info.ts' import { buildScheduleCreateCommand } from './create.ts' +import { buildScheduleUpdateCommand } from './update.ts' +import { buildScheduleDeleteCommand } from './delete.ts' import { buildScheduleTriggerCommand } from './trigger.ts' import { buildScheduleLogCommand } from './log.ts' @@ -25,6 +29,8 @@ export function buildScheduleCommand(): Command { cmd.addCommand(buildScheduleListCommand()) cmd.addCommand(buildScheduleInfoCommand()) cmd.addCommand(buildScheduleCreateCommand()) + cmd.addCommand(buildScheduleUpdateCommand()) + cmd.addCommand(buildScheduleDeleteCommand()) cmd.addCommand(buildScheduleTriggerCommand()) cmd.addCommand(buildScheduleLogCommand()) return cmd diff --git a/src/commands/schedule/update.ts b/src/commands/schedule/update.ts new file mode 100644 index 0000000..cec98e2 --- /dev/null +++ b/src/commands/schedule/update.ts @@ -0,0 +1,75 @@ +/** + * commands/schedule/update.ts — 定时任务修改 + * + * v0.11+ Phase 2 新增: 定时任务 CRUD 闭环 (P0, 改 cron 不必 delete+create) + * + * API: PUT /api/scheduletask/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' + +interface Opts { + id: string + fullName?: string + enCode?: string + cron?: string + executeContent?: string + enabledMark?: string + json?: boolean +} + +export function buildScheduleUpdateCommand(): Command { + const cmd = new Command('update') + .description('定时任务修改 (改 cron/executeContent/enabledMark, 避免 delete+create)') + .requiredOption('--id ', '任务 id') + .option('--fullName ', '任务名') + .option('--enCode ', '英文编码') + .option('--cron ', 'cron 表达式 (如 "0 0 * * * ?")') + .option('--executeContent ', '执行内容 (Quartz class 全名 + 参数)') + .option('--enabledMark <0|1>', '启用/禁用 (JNPF 无独立 pause/resume API, 用此替代)') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + // 拉原任务 + const origR = await c.get | null>(`/scheduletask/Info/${opts.id}`) + if (origR.code !== 200 || !origR.data) { + log.error(`schedule update 失败: 拉原任务 id=${opts.id} 失败 (id 不存在?)`) + process.exit(1) + } + const body: Record = { ...(origR.data as Record), id: opts.id } + if (opts.fullName) body.fullName = opts.fullName + if (opts.enCode) body.enCode = opts.enCode + if (opts.cron) body.cron = opts.cron + if (opts.executeContent) body.executeContent = opts.executeContent + if (opts.enabledMark !== undefined) body.enabledMark = parseInt(opts.enabledMark, 10) + log.info(`PUT /scheduletask/${opts.id}`) + const r = await c.putJson(`/scheduletask/${opts.id}`, body) + if (r.code !== 200) { + log.error(`schedule update 失败 (code=${r.code}): ${r.msg}`) + if (opts.json) printJson(r) + process.exit(1) + } + log.ok(`✓ 定时任务更新成功 (id=${opts.id})`) + if (opts.json) printJson(r.data) + }) + installAiHelpHook(cmd, { + purpose: '定时任务修改 (改 cron/executeContent/enabledMark, 避免 delete+create 浪费 + enCode 冲突风险).', + required: { '--id': '任务 id' }, + optional: { + '--fullName': '任务名', + '--enCode': '英文编码', + '--cron': 'cron 表达式', + '--executeContent': '执行内容 (Quartz class + 参数)', + '--enabledMark': '启用/禁用 0|1 (替代 pause/resume)', + }, + example: [ + 'dacli schedule update --id=123 --cron="0 0 2 * * ?"', + 'dacli schedule update --id=123 --enabledMark=0 (禁用)', + ], + source: { api: 'PUT /api/scheduletask/{id}' }, + notes: ['v0.11+ P0 新增', 'enabledMark 替代 pause/resume (JNPF 无独立 API)'], + }) + return cmd +}