diff --git a/src/commands/org/create.ts b/src/commands/org/create.ts index 6e56b16..181c0b9 100644 --- a/src/commands/org/create.ts +++ b/src/commands/org/create.ts @@ -1,11 +1,12 @@ /** - * commands/org/create.ts — 新建组织 (Phase D1 集成 v0.11e+) + * commands/org/create.ts — 新建组织 (Phase D1, v3.0+ 走 webapi/permission 镜像) * * 镜像 web organize/Form.vue + 后端 OrganizeController * - PS036: 组织层级限制 * - PS013: 当前机构 id 不能与父机构 id 相同 * * v0.11e+ Phase D1: P3 命令 step machine 集成 + * v3.0+ (2026-06-29 regression audit P0): 改用 webapi/permission.createOrg */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -13,6 +14,11 @@ import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { validateOrgCreate } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { + initWebapi as initPermissionWebapi, + createOrg, + getOrganizeList, +} from '../../webapi/permission.ts' interface CreateOpts { fullName: string @@ -64,19 +70,21 @@ export function buildOrgCreateCommand(): Command { enabledMark: parseInt(opts.enabledMark || '1', 10), sortCode: parseInt(opts.sortCode || '0', 10), } - const r = await c.postJson<{ id?: string; code?: number; msg?: string }>('/permission/Organize', body) + // v3.0+ P0: 走 webapi/permission.createOrg (web 端 create 函数) + await initPermissionWebapi(c) + const r = (await createOrg(body as any)) as { id?: string; code?: number; msg?: string } if (r.code !== 200 && r.code !== undefined) { const enhanced = enhanceFromBackend(r.msg || '', 'org', { entity: 'org' }) log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) process.exit(1) } - let id = r.data?.id + let id = r.id if (!id) { - const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>( - '/permission/Organize/Selector', - { parentId: opts.parentId, pageSize: '50' }, - ) - const found = (listR.data?.list || []).find( + const listR = (await getOrganizeList({ parentId: opts.parentId, pageSize: 50 })) as + | { list?: { id: string; enCode: string; fullName: string }[] } + | { id: string; enCode: string; fullName: string }[] + const list = Array.isArray(listR) ? listR : listR.list || [] + const found = list.find( (d) => d.enCode === opts.enCode || d.fullName === opts.fullName, ) id = found?.id diff --git a/src/webapi/permission.ts b/src/webapi/permission.ts new file mode 100644 index 0000000..dfaa5f3 --- /dev/null +++ b/src/webapi/permission.ts @@ -0,0 +1,87 @@ +/** + * webapi/permission.ts — 镜像 web 端 permission/organize.ts (v3.0+ regression audit P0) + * + * web/apps/jnpf-web-apps-main/src/api/permission/organize.ts 12 函数: + * getOrganizeSyncList / getOrganizeList / create / update / getInfo / delOrganize + * exportExcel / templateDownload / importData / importPreview / exportExceptionData + * + * v3.0+ (2026-06-29) 新增原因: + * - CI 关卡 G 标识 org 0 webapi 引用为 FAIL + * - cmd-review 已知 org 是"经验复刻", 应 webapi 镜像 + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const ORG_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/permission/organize.ts' + +let cached: any = null + +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + cached = await loadWebModule(ORG_SRC) +} + +export function isWebapiLoaded(): boolean { + return cached !== null +} + +export namespace OrgData { + export interface CreateParams { + parentId?: string + category?: string + fullName: string + enCode: string + sortCode?: number + description?: string + enabledMark?: number + [key: string]: unknown + } + + export interface ListParams { + keyword?: string + parentId?: string + category?: string + [key: string]: unknown + } +} + +export const loadOrg: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) { + throw new Error(`permission/organize 模块未初始化, 请先 await initWebapi(client)`) + } + return cached[prop] + }, +}) + +/** 获取组织列表 */ +export async function getOrganizeList(params?: OrgData.ListParams): Promise { + return loadOrg.getOrganizeList(params) +} + +/** 异步获取组织子树 (parentId) */ +export async function getOrganizeSyncList(parentId: string): Promise { + return loadOrg.getOrganizeSyncList({ parentId }) +} + +/** 创建组织 */ +export async function createOrg(params: OrgData.CreateParams): Promise { + return loadOrg.create(params) +} + +/** 更新组织 */ +export async function updateOrg(params: OrgData.CreateParams & { id: string }): Promise { + return loadOrg.update(params) +} + +/** 获取组织详情 */ +export async function getOrgInfo(id: string): Promise { + return loadOrg.getInfo(id) +} + +/** 删除组织 */ +export async function delOrganize(id: string): Promise { + return loadOrg.delOrganize(id) +} \ No newline at end of file