feat(v0.11+): dict typeUpdate/typeDelete/dataUpdate/dataDelete (4 个 P0 NEW-CMD)

Phase 1 审计 (cmd-review/dict.md) 标记 P0:
- dict 之前 4 子 (typeList/typeCreate/dataList/dataCreate) 缺 update/delete
- 字典改名/禁用/排序无原子化路径

新增 4 子命令:
- dict typeUpdate (改 fullName/enCode/category/isTree/sortCode)
- dict typeDelete (级联删字典项)
- dict dataUpdate (改 enCode/fullName/sortCode/enabledMark)
- dict dataDelete (硬删)
- 累计 dict 8 子命令 (从 4 → 8), 完整 CRUD 闭环

注: BS-47 dict 全平台唯一 由 L2 guard 自动防御

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:24:14 +08:00
1 parent af9e5a6f08
commit d31fa51c38
4 files changed
+216

No files matched your search

+42
View File
@@ -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>', '字典项 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
}
+66
View File
@@ -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>', '字典项 id')
.option('--enCode <e>', '字典项编码')
.option('--fullName <n>', '字典项名')
.option('--sortCode <s>', '排序', (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<Record<string, unknown> | 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<string, unknown> = { ...(origR.data as Record<string, unknown>), 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<unknown>(`/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
}
+42
View File
@@ -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>', '字典类型 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
}
+66
View File
@@ -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>', '字典类型 id')
.option('--fullName <n>', '字典名')
.option('--enCode <e>', '字典编码')
.option('--category <c>', '分类 (0=业务 1=系统)')
.option('--isTree <0|1>', '是否树形', (v) => parseInt(v, 10))
.option('--sortCode <s>', '排序', (v) => parseInt(v, 10))
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
const c = await JnpfClient.fromToken()
const origR = await c.get<Record<string, unknown> | null>(`/system/DictionaryType/${opts.id}`)
if (origR.code !== 200 || !origR.data) {
log.error(`dict typeUpdate 失败: 拉原字典类型 id=${opts.id} 失败`)
process.exit(1)
}
const body: Record<string, unknown> = { ...(origR.data as Record<string, unknown>), 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<unknown>(`/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
}