diff --git a/src/commands/dict/datadelete.ts b/src/commands/dict/datadelete.ts new file mode 100644 index 0000000..bbafc07 --- /dev/null +++ b/src/commands/dict/datadelete.ts @@ -0,0 +1,42 @@ +/** + * commands/dict/datadelete.ts — 字典项删除 + * + * v0.11+ Phase 2 新增: 字典 CRUD 闭环 + * + * API: DELETE /api/system/DictionaryData/{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 buildDictDataDeleteCommand(): Command { + const cmd = new Command('dataDelete') + .alias('data-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(`/system/DictionaryData/${opts.id}`) + if (r.code !== 200) { + log.error(`dict dataDelete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 字典项已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '字典项删除', + required: { '--id': '字典项 id', '--yes': '跳过确认' }, + example: 'dacli dict dataDelete --id=123 --yes', + source: { api: 'DELETE /api/system/DictionaryData/{id}' }, + notes: ['v0.11+ P0 闭环, 谨慎操作'], + }) + return cmd +} diff --git a/src/commands/dict/dataupdate.ts b/src/commands/dict/dataupdate.ts new file mode 100644 index 0000000..faecb84 --- /dev/null +++ b/src/commands/dict/dataupdate.ts @@ -0,0 +1,66 @@ +/** + * commands/dict/dataupdate.ts — 字典项修改 + * + * v0.11+ Phase 2 新增: 字典 CRUD 闭环 + * + * API: PUT /api/system/DictionaryData/{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 + enCode?: string + fullName?: string + sortCode?: string + enabledMark?: string + json?: boolean +} + +export function buildDictDataUpdateCommand(): Command { + const cmd = new Command('dataUpdate') + .alias('data-update') + .description('字典项修改 (改 enCode/fullName/sortCode/enabledMark, PUT 语义)') + .requiredOption('--id ', '字典项 id') + .option('--enCode ', '字典项编码') + .option('--fullName ', '字典项名') + .option('--sortCode ', '排序', (v) => parseInt(v, 10)) + .option('--enabledMark <0|1>', '启用/禁用') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const origR = await c.get | null>(`/system/DictionaryData/${opts.id}/Info`) + if (origR.code !== 200 || !origR.data) { + log.error(`dict dataUpdate 失败: 拉原字典项 id=${opts.id} 失败`) + process.exit(1) + } + const body: Record = { ...(origR.data as Record), id: opts.id } + if (opts.enCode) body.enCode = opts.enCode + if (opts.fullName) body.fullName = opts.fullName + if (opts.sortCode !== undefined) body.sortCode = opts.sortCode + if (opts.enabledMark !== undefined) body.enabledMark = parseInt(opts.enabledMark, 10) + log.info(`PUT /system/DictionaryData/${opts.id}`) + const r = await c.putJson(`/system/DictionaryData/${opts.id}`, body) + if (r.code !== 200) { + log.error(`dict dataUpdate 失败 (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: '字典项修改 (改名/排序/启用). PUT 语义, 未传保留.', + required: { '--id': '字典项 id' }, + optional: { '--enCode': '编码', '--fullName': '名', '--sortCode': '排序', '--enabledMark': '启用/禁用' }, + example: [ + 'dacli dict dataUpdate --id=123 --fullName=新名', + 'dacli dict dataUpdate --id=123 --enabledMark=0 (禁用)', + ], + source: { api: 'PUT /api/system/DictionaryData/{id}' }, + notes: ['v0.11+ P0 闭环, 未传字段保留 (PUT 语义)'], + }) + return cmd +} diff --git a/src/commands/dict/typedelete.ts b/src/commands/dict/typedelete.ts new file mode 100644 index 0000000..bd9320c --- /dev/null +++ b/src/commands/dict/typedelete.ts @@ -0,0 +1,42 @@ +/** + * commands/dict/typedelete.ts — 字典类型删除 + * + * v0.11+ Phase 2 新增: 字典 CRUD 闭环 + * + * API: DELETE /api/system/DictionaryType/{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 buildDictTypeDeleteCommand(): Command { + const cmd = new Command('typeDelete') + .alias('type-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(`/system/DictionaryType/${opts.id}`) + if (r.code !== 200) { + log.error(`dict typeDelete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 字典类型已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '字典类型删除 (级联删字典项)', + required: { '--id': '字典类型 id', '--yes': '跳过确认' }, + example: 'dacli dict typeDelete --id=123 --yes', + source: { api: 'DELETE /api/system/DictionaryType/{id}' }, + notes: ['v0.11+ P0 闭环, 谨慎操作 (会级联删字典项)'], + }) + return cmd +} diff --git a/src/commands/dict/typeupdate.ts b/src/commands/dict/typeupdate.ts new file mode 100644 index 0000000..b570939 --- /dev/null +++ b/src/commands/dict/typeupdate.ts @@ -0,0 +1,66 @@ +/** + * commands/dict/typeupdate.ts — 字典类型修改 + * + * v0.11+ Phase 2 新增: 字典 CRUD 闭环 + * + * API: PUT /api/system/DictionaryType/{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 + isTree?: string + sortCode?: string + json?: boolean +} + +export function buildDictTypeUpdateCommand(): Command { + const cmd = new Command('typeUpdate') + .alias('type-update') + .description('字典类型修改 (改名/分类/树形, PUT 语义)') + .requiredOption('--id ', '字典类型 id') + .option('--fullName ', '字典名') + .option('--enCode ', '字典编码') + .option('--category ', '分类 (0=业务 1=系统)') + .option('--isTree <0|1>', '是否树形', (v) => parseInt(v, 10)) + .option('--sortCode ', '排序', (v) => parseInt(v, 10)) + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const origR = await c.get | null>(`/system/DictionaryType/${opts.id}`) + if (origR.code !== 200 || !origR.data) { + log.error(`dict typeUpdate 失败: 拉原字典类型 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.isTree !== undefined) body.isTree = opts.isTree + if (opts.sortCode !== undefined) body.sortCode = opts.sortCode + log.info(`PUT /system/DictionaryType/${opts.id}`) + const r = await c.putJson(`/system/DictionaryType/${opts.id}`, body) + if (r.code !== 200) { + log.error(`dict typeUpdate 失败 (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: '字典类型修改 (改名/分类/树形/排序). PUT 语义, 未传保留.', + required: { '--id': '字典类型 id' }, + optional: { '--fullName': '名', '--enCode': '编码', '--category': '分类', '--isTree': '树形', '--sortCode': '排序' }, + example: 'dacli dict typeUpdate --id=123 --fullName=新名', + source: { api: 'PUT /api/system/DictionaryType/{id}' }, + notes: ['v0.11+ P0 闭环, 未传字段保留 (PUT 语义)'], + }) + return cmd +}