feat(role): v0.11e+ Phase A3 跨命令事务 --user-ids
role/create.ts 加 --user-ids 选项: - 逗号分隔 id 列表 (例: --user-ids=1,2,3) - 镜像 web roleRelationService.create 模式 (建角色后批量绑用户) - 创建 body.userIds 直接传 JNPF /api/permission/Role (一次 API 完成) - 成功输出含 '(含 N 个用户绑定)' 简化版跨命令事务 (JNPF /permission/Role 接口支持 userIds 字段, 所以 1 次 create API 即可完成, 不需要后续 bindUsers 调用) dict items 已存在 (v0.11d+ BS-41 修复): --items JSON 批量建字典项 menu --button-ids: 暂跳过 (JNPF menu 不支持 buttonIds 字段, 按钮在 ModuleButton 表, 需独立 ModuleButtonCreate 命令, 超出 Phase A3 1 天范围) selfcheck role/create.ts: 8/8 pass (待后续验证) src/commands/ 0 TS error (pre-existing test file 错误忽略)
This commit is contained in:
1 parent
046ba044f9
commit
fefa6014a0
1 file changed
+14
-5
@@ -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 <name>', '角色名称')
|
||||
.requiredOption('--enCode <code>', '角色编码')
|
||||
.option('--type <t>', '角色类型: 0=全局 1=业务', '0')
|
||||
// v0.11e+ Phase A3: 跨命令事务 — 镜像 web roleRelationService.create (建角色后批量绑用户)
|
||||
.option('--user-ids <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',
|
||||
|
||||
Reference in new issue
Block a user