refactor(v0.11+): dict NEW-CMD 4 个走 webapi 镜像 (loadDict)
响应用户反馈 '应该走 webapi 吗, 为什么现在都走平台 api': - 之前 dict typeUpdate/typeDelete/dataUpdate/dataDelete 用 c.putJson/c.del - 本 commit 切到 loadDict.updateDictionaryType/delDictionaryType/updateDictionaryData/delDictionaryData - 走 web 端真实端点 + 函数签名, 与 v0.11+ 架构对齐 Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
8fb0faac27
commit
bed941bac7
4 files changed
+48
-40
No files matched your search
@@ -1,21 +1,21 @@
|
||||
/**
|
||||
* commands/dict/datadelete.ts — 字典项删除
|
||||
*
|
||||
* v0.11+ Phase 2 新增: 字典 CRUD 闭环
|
||||
*
|
||||
* API: DELETE /api/system/DictionaryData/{id}
|
||||
* v0.11+ Phase 2: webapi 化 (loadDict.delDictionaryData)
|
||||
* 替代 v0.10 直接 c.del
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { initWebapi, loadDict } from '../../webapi/dict.ts'
|
||||
|
||||
interface Opts { id: string; yes?: boolean }
|
||||
|
||||
export function buildDictDataDeleteCommand(): Command {
|
||||
const cmd = new Command('dataDelete')
|
||||
.alias('data-delete')
|
||||
.description('字典项删除 (硬删)')
|
||||
.description('字典项删除 (硬删, v0.11+ webapi)')
|
||||
.requiredOption('--id <id>', '字典项 id')
|
||||
.option('--yes', '跳过确认', false)
|
||||
.action(async (opts: Opts) => {
|
||||
@@ -24,8 +24,10 @@ export function buildDictDataDeleteCommand(): Command {
|
||||
process.exit(2)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.del(`/system/DictionaryData/${opts.id}`)
|
||||
if (r.code !== 200) {
|
||||
await initWebapi(c)
|
||||
log.info(`loadDict.delDictionaryData (id=${opts.id})`)
|
||||
const r = (await loadDict.delDictionaryData(opts.id)) as { code?: number; msg?: string }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`dict dataDelete 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
@@ -35,8 +37,8 @@ export function buildDictDataDeleteCommand(): Command {
|
||||
purpose: '字典项删除',
|
||||
required: { '--id': '字典项 id', '--yes': '跳过确认' },
|
||||
example: 'dacli dict dataDelete --id=123 --yes',
|
||||
source: { api: 'DELETE /api/system/DictionaryData/{id}' },
|
||||
notes: ['v0.11+ P0 闭环, 谨慎操作'],
|
||||
source: { api: 'DELETE /api/system/DictionaryData/{id}', ref: 'web/.../api/systemData/dictionary.ts delDictionaryData()' },
|
||||
notes: ['v0.11+ 改用 webapi 镜像 (loadDict.delDictionaryData)', '谨慎操作'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* commands/dict/dataupdate.ts — 字典项修改
|
||||
*
|
||||
* v0.11+ Phase 2 新增: 字典 CRUD 闭环
|
||||
*
|
||||
* API: PUT /api/system/DictionaryData/{id}
|
||||
* v0.11+ Phase 2: webapi 化 (loadDict.updateDictionaryData)
|
||||
* 替代 v0.10 直接 c.putJson
|
||||
*/
|
||||
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, loadDict } from '../../webapi/dict.ts'
|
||||
|
||||
interface Opts {
|
||||
id: string
|
||||
@@ -22,7 +22,7 @@ interface Opts {
|
||||
export function buildDictDataUpdateCommand(): Command {
|
||||
const cmd = new Command('dataUpdate')
|
||||
.alias('data-update')
|
||||
.description('字典项修改 (改 enCode/fullName/sortCode/enabledMark, PUT 语义)')
|
||||
.description('字典项修改 (改名/排序/启用, PUT 语义, v0.11+ webapi)')
|
||||
.requiredOption('--id <id>', '字典项 id')
|
||||
.option('--enCode <e>', '字典项编码')
|
||||
.option('--fullName <n>', '字典项名')
|
||||
@@ -31,19 +31,21 @@ export function buildDictDataUpdateCommand(): Command {
|
||||
.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) {
|
||||
await initWebapi(c)
|
||||
// v0.11+ Phase 2: 用 webapi 镜像 (loadDict.getDictionaryDataInfo + updateDictionaryData)
|
||||
const orig = (await loadDict.getDictionaryDataInfo(opts.id)) as Record<string, unknown>
|
||||
if (!orig) {
|
||||
log.error(`dict dataUpdate 失败: 拉原字典项 id=${opts.id} 失败`)
|
||||
process.exit(1)
|
||||
}
|
||||
const body: Record<string, unknown> = { ...(origR.data as Record<string, unknown>), id: opts.id }
|
||||
const body: Record<string, unknown> = { ...orig, 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.info(`loadDict.updateDictionaryData (id=${opts.id})`)
|
||||
const r = (await loadDict.updateDictionaryData(body)) as { code?: number; msg?: string; data?: unknown }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`dict dataUpdate 失败 (code=${r.code}): ${r.msg}`)
|
||||
if (opts.json) printJson(r)
|
||||
process.exit(1)
|
||||
@@ -59,8 +61,8 @@ export function buildDictDataUpdateCommand(): Command {
|
||||
'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 语义)'],
|
||||
source: { api: 'PUT /api/system/DictionaryData/{id}', ref: 'web/.../api/systemData/dictionary.ts updateDictionaryData()' },
|
||||
notes: ['v0.11+ 改用 webapi 镜像 (loadDict.updateDictionaryData)'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
/**
|
||||
* commands/dict/typedelete.ts — 字典类型删除
|
||||
*
|
||||
* v0.11+ Phase 2 新增: 字典 CRUD 闭环
|
||||
*
|
||||
* API: DELETE /api/system/DictionaryType/{id}
|
||||
* v0.11+ Phase 2: webapi 化 (loadDict.delDictionaryType)
|
||||
* 替代 v0.10 直接 c.del
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { initWebapi, loadDict } from '../../webapi/dict.ts'
|
||||
|
||||
interface Opts { id: string; yes?: boolean }
|
||||
|
||||
export function buildDictTypeDeleteCommand(): Command {
|
||||
const cmd = new Command('typeDelete')
|
||||
.alias('type-delete')
|
||||
.description('字典类型删除 (递归删字典项)')
|
||||
.description('字典类型删除 (递归删字典项, v0.11+ webapi)')
|
||||
.requiredOption('--id <id>', '字典类型 id')
|
||||
.option('--yes', '跳过确认', false)
|
||||
.action(async (opts: Opts) => {
|
||||
@@ -24,8 +24,10 @@ export function buildDictTypeDeleteCommand(): Command {
|
||||
process.exit(2)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.del(`/system/DictionaryType/${opts.id}`)
|
||||
if (r.code !== 200) {
|
||||
await initWebapi(c)
|
||||
log.info(`loadDict.delDictionaryType (id=${opts.id})`)
|
||||
const r = (await loadDict.delDictionaryType(opts.id)) as { code?: number; msg?: string }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`dict typeDelete 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
@@ -35,8 +37,8 @@ export function buildDictTypeDeleteCommand(): Command {
|
||||
purpose: '字典类型删除 (级联删字典项)',
|
||||
required: { '--id': '字典类型 id', '--yes': '跳过确认' },
|
||||
example: 'dacli dict typeDelete --id=123 --yes',
|
||||
source: { api: 'DELETE /api/system/DictionaryType/{id}' },
|
||||
notes: ['v0.11+ P0 闭环, 谨慎操作 (会级联删字典项)'],
|
||||
source: { api: 'DELETE /api/system/DictionaryType/{id}', ref: 'web/.../api/systemData/dictionary.ts delDictionaryType()' },
|
||||
notes: ['v0.11+ 改用 webapi 镜像 (loadDict.delDictionaryType)', '谨慎操作 (会级联删字典项)'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* commands/dict/typeupdate.ts — 字典类型修改
|
||||
*
|
||||
* v0.11+ Phase 2 新增: 字典 CRUD 闭环
|
||||
*
|
||||
* API: PUT /api/system/DictionaryType/{id}
|
||||
* v0.11+ Phase 2: webapi 化 (loadDict.updateDictionaryType)
|
||||
* 替代 v0.10 直接 c.putJson
|
||||
*/
|
||||
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, loadDict } from '../../webapi/dict.ts'
|
||||
|
||||
interface Opts {
|
||||
id: string
|
||||
@@ -23,7 +23,7 @@ interface Opts {
|
||||
export function buildDictTypeUpdateCommand(): Command {
|
||||
const cmd = new Command('typeUpdate')
|
||||
.alias('type-update')
|
||||
.description('字典类型修改 (改名/分类/树形, PUT 语义)')
|
||||
.description('字典类型修改 (改名/分类/树形, PUT 语义, v0.11+ webapi)')
|
||||
.requiredOption('--id <id>', '字典类型 id')
|
||||
.option('--fullName <n>', '字典名')
|
||||
.option('--enCode <e>', '字典编码')
|
||||
@@ -33,20 +33,22 @@ export function buildDictTypeUpdateCommand(): Command {
|
||||
.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) {
|
||||
await initWebapi(c)
|
||||
// v0.11+ Phase 2: 用 webapi 镜像 (loadDict.getDictionaryTypeInfo + updateDictionaryType)
|
||||
const orig = (await loadDict.getDictionaryTypeInfo(opts.id)) as Record<string, unknown>
|
||||
if (!orig) {
|
||||
log.error(`dict typeUpdate 失败: 拉原字典类型 id=${opts.id} 失败`)
|
||||
process.exit(1)
|
||||
}
|
||||
const body: Record<string, unknown> = { ...(origR.data as Record<string, unknown>), id: opts.id }
|
||||
const body: Record<string, unknown> = { ...orig, 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.info(`loadDict.updateDictionaryType (id=${opts.id})`)
|
||||
const r = (await loadDict.updateDictionaryType(body)) as { code?: number; msg?: string; data?: unknown }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`dict typeUpdate 失败 (code=${r.code}): ${r.msg}`)
|
||||
if (opts.json) printJson(r)
|
||||
process.exit(1)
|
||||
@@ -59,8 +61,8 @@ export function buildDictTypeUpdateCommand(): Command {
|
||||
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 语义)'],
|
||||
source: { api: 'PUT /api/system/DictionaryType/{id}', ref: 'web/.../api/systemData/dictionary.ts updateDictionaryType()' },
|
||||
notes: ['v0.11+ 改用 webapi 镜像 (loadDict.updateDictionaryType)'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user