From bed941bac7452a9af2c01927f29f2e4a634441cd Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 25 Jun 2026 15:26:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(v0.11+):=20dict=20NEW-CMD=204=20?= =?UTF-8?q?=E4=B8=AA=E8=B5=B0=20webapi=20=E9=95=9C=E5=83=8F=20(loadDict)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 响应用户反馈 '应该走 webapi 吗, 为什么现在都走平台 api': - 之前 dict typeUpdate/typeDelete/dataUpdate/dataDelete 用 c.putJson/c.del - 本 commit 切到 loadDict.updateDictionaryType/delDictionaryType/updateDictionaryData/delDictionaryData - 走 web 端真实端点 + 函数签名, 与 v0.11+ 架构对齐 Co-Authored-By: Claude --- src/commands/dict/datadelete.ts | 18 ++++++++++-------- src/commands/dict/dataupdate.ts | 26 ++++++++++++++------------ src/commands/dict/typedelete.ts | 18 ++++++++++-------- src/commands/dict/typeupdate.ts | 26 ++++++++++++++------------ 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/commands/dict/datadelete.ts b/src/commands/dict/datadelete.ts index bbafc07..e1fc332 100644 --- a/src/commands/dict/datadelete.ts +++ b/src/commands/dict/datadelete.ts @@ -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') .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 } diff --git a/src/commands/dict/dataupdate.ts b/src/commands/dict/dataupdate.ts index faecb84..404cada 100644 --- a/src/commands/dict/dataupdate.ts +++ b/src/commands/dict/dataupdate.ts @@ -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') .option('--enCode ', '字典项编码') .option('--fullName ', '字典项名') @@ -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 | 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 + if (!orig) { log.error(`dict dataUpdate 失败: 拉原字典项 id=${opts.id} 失败`) process.exit(1) } - const body: Record = { ...(origR.data as Record), id: opts.id } + const body: Record = { ...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(`/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 } diff --git a/src/commands/dict/typedelete.ts b/src/commands/dict/typedelete.ts index bd9320c..d00dd08 100644 --- a/src/commands/dict/typedelete.ts +++ b/src/commands/dict/typedelete.ts @@ -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') .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 } diff --git a/src/commands/dict/typeupdate.ts b/src/commands/dict/typeupdate.ts index b570939..9e689bd 100644 --- a/src/commands/dict/typeupdate.ts +++ b/src/commands/dict/typeupdate.ts @@ -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') .option('--fullName ', '字典名') .option('--enCode ', '字典编码') @@ -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 | 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 + if (!orig) { log.error(`dict typeUpdate 失败: 拉原字典类型 id=${opts.id} 失败`) process.exit(1) } - const body: Record = { ...(origR.data as Record), id: opts.id } + const body: Record = { ...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(`/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 }