diff --git a/src/commands/role/create.ts b/src/commands/role/create.ts index 126b683..98b696b 100644 --- a/src/commands/role/create.ts +++ b/src/commands/role/create.ts @@ -14,6 +14,7 @@ interface CreateOpts { fullName: string enCode: string type?: string + userIds?: string json?: boolean } @@ -23,6 +24,8 @@ export function buildRoleCreateCommand(): Command { .requiredOption('--fullName ', '角色名称') .requiredOption('--enCode ', '角色编码') .option('--type ', '角色类型: 0=全局 1=业务', '0') + // v0.11e+ Phase A3: 跨命令事务 — 镜像 web roleRelationService.create (建角色后批量绑用户) + .option('--user-ids ', '关联用户 id 列表 (逗号分隔, 例: 1,2,3). v0.11e+ Phase A3 跨命令事务 (镜像 web roleRelationService.create)') .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() @@ -37,6 +40,9 @@ export function buildRoleCreateCommand(): Command { sortCode: 0, }) + // 解析 --user-ids (Phase A3 跨命令事务) + const userIdsArray = opts.userIds ? opts.userIds.split(',').map((s) => s.trim()).filter(Boolean) : [] + const body = { fullName: opts.fullName, enCode: opts.enCode, @@ -45,7 +51,7 @@ export function buildRoleCreateCommand(): Command { sortCode: 0, organizeIds: [], positionIds: [], - userIds: [], + userIds: userIdsArray, } const r = await c.postJson<{ id?: string }>('/permission/Role', body) if (r.code !== 200) { @@ -66,14 +72,17 @@ export function buildRoleCreateCommand(): Command { ) id = found?.id } - log.info(`✓ 角色创建成功 id=${id}`) + log.info(`✓ 角色创建成功 id=${id}${userIdsArray.length > 0 ? ` (含 ${userIdsArray.length} 个用户绑定)` : ''}`) if (opts.json) printJson({ ...(r.data as object), id }) }) installAiHelpHook(cmd, { - purpose: '新建角色 (P1 权限三角核心). v0.11d+ 加 step machine 校验 (3 step 镜像 web role/Form.vue + 后端 RoleController.create, BS-47 唯一性预校验, 约束字段联动校验, 聚合错误)', + purpose: '新建角色 (P1 权限三角核心). v0.11d+ 加 step machine 校验 (3 step 镜像 web role/Form.vue + 后端 RoleController.create, BS-47 唯一性预校验, 约束字段联动校验, 聚合错误). v0.11e+ Phase A3 加 --user-ids 跨命令事务 (建角色后批量绑用户, 镜像 web roleRelationService.create).', required: { '--fullName': '角色名称', '--enCode': '角色编码' }, - optional: { '--type': '0=全局 1=业务' }, - example: 'dacli role create --fullName=测试角色 --enCode=dacli_test_role', + optional: { '--type': '0=全局 1=业务', '--user-ids': '关联用户 id 列表 (A3 跨命令事务)' }, + example: [ + 'dacli role create --fullName=测试角色 --enCode=dacli_test_role', + 'dacli role create --fullName=运营 --enCode=ops --type=1 --user-ids=1,2,3 (A3: 建角色 + 批量绑用户)', + ], source: { web: 'web/apps/jnpf-web-apps-main/src/views/permission/role/Form.vue (后端: jnpf/.../RoleController.java:124-161)', api: 'POST /api/permission/Role',