@newpeak/barista-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.eslintrc.json +23 -0
  2. package/.prettierrc +9 -0
  3. package/.sisyphus/notepads/liberica-employees/learnings.md +73 -0
  4. package/AGENTS.md +270 -0
  5. package/CONTRIBUTING.md +291 -0
  6. package/README.md +707 -0
  7. package/bin/barista +6 -0
  8. package/bin/barista.js +3 -0
  9. package/docs/ARCHITECTURE.md +184 -0
  10. package/docs/COMMANDS.md +352 -0
  11. package/docs/COMMAND_DESIGN_SPEC.md +811 -0
  12. package/docs/INTEGRATION_NOTES.md +270 -0
  13. package/docs/commands/REFERENCE.md +297 -0
  14. package/docs/commands/arabica/auth/index.md +296 -0
  15. package/docs/commands/liberica/auth/index.md +133 -0
  16. package/docs/commands/liberica/context/index.md +60 -0
  17. package/docs/commands/liberica/employees/create.md +185 -0
  18. package/docs/commands/liberica/employees/disable.md +138 -0
  19. package/docs/commands/liberica/employees/enable.md +137 -0
  20. package/docs/commands/liberica/employees/get.md +153 -0
  21. package/docs/commands/liberica/employees/list.md +168 -0
  22. package/docs/commands/liberica/employees/update.md +180 -0
  23. package/docs/commands/liberica/orgs/list.md +62 -0
  24. package/docs/commands/liberica/positions/list.md +61 -0
  25. package/docs/commands/liberica/roles/list.md +67 -0
  26. package/docs/commands/liberica/users/create.md +170 -0
  27. package/docs/commands/liberica/users/get.md +151 -0
  28. package/docs/commands/liberica/users/list.md +175 -0
  29. package/package.json +37 -0
  30. package/src/commands/arabica/auth/index.ts +277 -0
  31. package/src/commands/arabica/auth/login.ts +5 -0
  32. package/src/commands/arabica/auth/logout.ts +5 -0
  33. package/src/commands/arabica/auth/register.ts +5 -0
  34. package/src/commands/arabica/auth/status.ts +5 -0
  35. package/src/commands/arabica/index.ts +23 -0
  36. package/src/commands/auth.ts +107 -0
  37. package/src/commands/context.ts +60 -0
  38. package/src/commands/liberica/auth/index.ts +170 -0
  39. package/src/commands/liberica/context/index.ts +43 -0
  40. package/src/commands/liberica/employees/create.ts +275 -0
  41. package/src/commands/liberica/employees/delete.ts +122 -0
  42. package/src/commands/liberica/employees/disable.ts +97 -0
  43. package/src/commands/liberica/employees/enable.ts +97 -0
  44. package/src/commands/liberica/employees/get.ts +115 -0
  45. package/src/commands/liberica/employees/index.ts +23 -0
  46. package/src/commands/liberica/employees/list.ts +131 -0
  47. package/src/commands/liberica/employees/update.ts +157 -0
  48. package/src/commands/liberica/index.ts +36 -0
  49. package/src/commands/liberica/orgs/index.ts +35 -0
  50. package/src/commands/liberica/positions/index.ts +30 -0
  51. package/src/commands/liberica/roles/index.ts +59 -0
  52. package/src/commands/liberica/users/create.ts +132 -0
  53. package/src/commands/liberica/users/delete.ts +49 -0
  54. package/src/commands/liberica/users/disable.ts +41 -0
  55. package/src/commands/liberica/users/enable.ts +30 -0
  56. package/src/commands/liberica/users/get.ts +46 -0
  57. package/src/commands/liberica/users/index.ts +27 -0
  58. package/src/commands/liberica/users/list.ts +68 -0
  59. package/src/commands/liberica/users/me.ts +42 -0
  60. package/src/commands/liberica/users/reset-password.ts +42 -0
  61. package/src/commands/liberica/users/update.ts +48 -0
  62. package/src/core/api/client.ts +825 -0
  63. package/src/core/auth/token-manager.ts +183 -0
  64. package/src/core/config/manager.ts +164 -0
  65. package/src/index.ts +37 -0
  66. package/src/types/employee.ts +102 -0
  67. package/src/types/index.ts +75 -0
  68. package/src/types/org.ts +25 -0
  69. package/src/types/position.ts +24 -0
  70. package/src/types/user.ts +64 -0
  71. package/tests/unit/commands/arabica/auth.test.ts +230 -0
  72. package/tests/unit/commands/liberica/auth.test.ts +175 -0
  73. package/tests/unit/commands/liberica/context.test.ts +98 -0
  74. package/tests/unit/commands/liberica/employees/create.test.ts +463 -0
  75. package/tests/unit/commands/liberica/employees/disable.test.ts +82 -0
  76. package/tests/unit/commands/liberica/employees/enable.test.ts +82 -0
  77. package/tests/unit/commands/liberica/employees/get.test.ts +111 -0
  78. package/tests/unit/commands/liberica/employees/list.test.ts +294 -0
  79. package/tests/unit/commands/liberica/employees/update.test.ts +210 -0
  80. package/tests/unit/config.test.ts +141 -0
  81. package/tests/unit/types.test.ts +195 -0
  82. package/tsconfig.json +20 -0
@@ -0,0 +1,180 @@
1
+ # barista liberica employees update
2
+
3
+ 更新员工信息。
4
+
5
+ ## 2.1 命令元数据
6
+
7
+ | 字段 | 值 |
8
+ |------|-----|
9
+ | 完整命令 | `barista liberica employees update <id>` |
10
+ | 功能描述 | 更新员工信息 |
11
+ | HTTP方法 | POST |
12
+ | 是否需要认证 | ✅ 是 |
13
+ | 是否支持dry-run | ✅ 是 |
14
+
15
+ ## 2.2 后端接口引用
16
+
17
+ ### Controller位置
18
+ ```
19
+ coffee-liberica-end/
20
+ └── facade/liberica-facade-enterprise/
21
+ └── src/main/java/com/newpeak/liberica/facade/enterprise/controller/master/
22
+ └── EnterpriseEmployeeController.java
23
+ └── edit(@PostResource(path = "/edit", requiredPermission = true, requirePermissionCode = "EDIT_EMPLOYEE"))
24
+ └── public ResponseData<MasterEmployeeResponse> edit(
25
+ @RequestHeader("X-TENANT-ID") Long tenantId,
26
+ @RequestBody @Validated(BaseRequest.edit.class) MasterEmployeeRequest request
27
+ )
28
+ ```
29
+
30
+ ### Request DTO位置
31
+ ```
32
+ coffee-liberica-end/
33
+ └── business/liberica-business-master/master-api/
34
+ └── src/main/java/com/newpeak/liberica/master/api/pojo/request/
35
+ └── MasterEmployeeRequest.java
36
+ ├── employeeId: Long (@NotNull on edit) — 必须提供
37
+ ├── employeeCode: String (@NotBlank on edit)
38
+ ├── employeeName: String
39
+ ├── employeePhone: String
40
+ ├── employeeEmail: String
41
+ ├── employeeSex: SexEnum
42
+ ├── employeeIdType: String
43
+ ├── employeeIdNo: String
44
+ ├── employeeJoinedDate: Date
45
+ ├── employeeBirthday: Date
46
+ ├── organizationId: Long
47
+ ├── organizationManagerFlag: String
48
+ ├── positionId: String
49
+ ├── jobType: String
50
+ ├── jobLevelNo: Integer
51
+ ├── evaluator1: String
52
+ ├── evaluator2: String
53
+ ├── coach: String
54
+ ├── employeeBankAccount: String
55
+ └── employeeDepositBank: String
56
+ ```
57
+
58
+ ### Response DTO位置
59
+ ```
60
+ coffee-liberica-end/
61
+ └── business/liberica-business-master/master-api/
62
+ └── src/main/java/com/newpeak/liberica/master/api/pojo/response/
63
+ └── MasterEmployeeResponse.java
64
+ ├── employeeId: Long
65
+ ├── employeeCode: String
66
+ ├── employeeName: String
67
+ ├── employeeNo: String
68
+ ├── employeePhone: String
69
+ ├── employeeEmail: String
70
+ ├── employeeSex: SexEnum
71
+ ├── organizationId: Long
72
+ ├── orgName: String
73
+ ├── positionId: String
74
+ ├── positionName: String
75
+ ├── statusFlag: Integer (1=enable, 2=disable)
76
+ ├── createTime: String
77
+ └── updateTime: String
78
+ ```
79
+
80
+ ## 2.3 CLI参数设计
81
+
82
+ ### 命令结构
83
+ ```
84
+ barista liberica employees update <id> [options]
85
+ ```
86
+
87
+ ### 位置参数
88
+ | 参数 | 类型 | 必填 | 说明 |
89
+ |------|------|------|------|
90
+ | id | number | ✅ | 员工ID (employeeId) |
91
+
92
+ ### 全局选项
93
+ | 选项 | 类型 | 说明 |
94
+ |------|------|------|
95
+ | `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
96
+ | `--tenant` | string | 租户代码 |
97
+ | `--dry-run` | boolean | 预览模式(不实际调用API) |
98
+ | `--json` | boolean | JSON输出 |
99
+
100
+ ### 命令选项
101
+ | 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 | 对应DTO字段 |
102
+ |------|--------|------|------|--------|------|-------------|
103
+ | --name | -n | string | ⬜ | - | 员工姓名 | employeeName |
104
+ | --phone | -p | string | ⬜ | - | 手机号码 | employeePhone |
105
+ | --email | -e | string | ⬜ | - | 电子邮箱 | employeeEmail |
106
+ | --sex | -s | string | ⬜ | - | 性别 (M/F) | employeeSex |
107
+ | --position-id | — | string | ⬜ | - | 岗位ID | positionId |
108
+ | --joined-date | -d | string | ⬜ | - | 入职日期 (YYYY-MM-DD) | employeeJoinedDate |
109
+ | --org-id | — | number | ⬜ | - | 部门ID | organizationId |
110
+
111
+ **注意**:员工ID(employeeId)为必填,通过位置参数 `<id>` 传入。更新操作只发送变更的字段(部分更新)。
112
+
113
+ ## 2.4 字段映射表
114
+
115
+ | CLI参数 | DTO字段 | 类型转换 | 验证规则 |
116
+ |---------|---------|----------|----------|
117
+ | <id> (位置参数) | employeeId | string→Long | @NotNull |
118
+ | --name / -n | employeeName | 直接传递 | max=255 |
119
+ | --phone / -p | employeePhone | 直接传递 | 手机号格式 |
120
+ | --email / -e | employeeEmail | 直接传递 | 邮箱格式 |
121
+ | --sex / -s | employeeSex | 直接传递 | M 或 F |
122
+ | --position-id | positionId | 直接传递 | - |
123
+ | --joined-date / -d | employeeJoinedDate | string→Date | yyyy-MM-dd |
124
+ | --org-id | organizationId | string→Long | - |
125
+
126
+ ## 2.5 错误码引用
127
+
128
+ ### ExceptionEnum位置
129
+ ```
130
+ coffee-liberica-end/
131
+ └── business/liberica-business-master/master-api/
132
+ └── src/main/java/com/newpeak/liberica/master/api/exception/enums/
133
+ └── EmployeeExceptionEnum.java
134
+ ├── MASTER_EMPLOYEE_NOT_EXISTED("01001150001", "查询结果不存在")
135
+ ├── MASTER_EMPLOYEE_CODE_VALIDATE_NOT_EXIST_ERROR("01001150007", "指定{}不存在")
136
+ └── MASTER_EMPLOYEE_NAME_VALIDATE_NOT_EXIST_ERROR("01001150009", "指定{}不存在")
137
+ ```
138
+
139
+ ### 已知错误码
140
+ | 错误码 | 错误消息 | 触发条件 |
141
+ |--------|----------|----------|
142
+ | 01001150001 | 查询结果不存在 | employeeId 不存在或不属于当前租户 |
143
+ | 01001150007 | 指定xxx不存在 | 指定关联的员工编码不存在 |
144
+
145
+ ## 2.6 权限检查
146
+
147
+ | 检查项 | 位置 | 说明 |
148
+ |--------|------|------|
149
+ | PermissionConstants | `LibericaPermissionCodeConstants.EDIT_EMPLOYEE` | Controller层 `@PostResource(requirePermissionCode = "EDIT_EMPLOYEE")` |
150
+
151
+ ## 2.7 实现要点
152
+
153
+ 1. **部分更新**:只发送需要更新的字段,未提供的字段保持原值
154
+ 2. **必填位置参数**:`<id>` 必须指定,后端根据此ID定位记录
155
+ 3. **Dry-run支持**:使用 --dry-run 时构造请求体但不发送,显示预览信息
156
+ 4. **后端无预检**:edit() 方法直接调用 `updateById()`,不检查员工是否存在(由DB约束保证)
157
+
158
+ ## 2.8 示例用法
159
+
160
+ ```bash
161
+ # 更新员工姓名
162
+ barista liberica employees update 12345 --name "李四"
163
+
164
+ # 更新多个字段
165
+ barista liberica employees update 12345 \
166
+ --name "李四" \
167
+ --phone "13900139000" \
168
+ --email "lisi@example.com" \
169
+ --position-id "SENIOR_ENGINEER"
170
+
171
+ # Dry-run 预览
172
+ barista liberica employees update 12345 --name "李四" --dry-run
173
+
174
+ # JSON 输出
175
+ barista liberica employees update 12345 --name "李四" --json
176
+
177
+ # 员工不存在
178
+ barista liberica employees update 99999 --name "测试"
179
+ # 输出: Error: 员工不存在 (01001150001)
180
+ ```
@@ -0,0 +1,62 @@
1
+ # Orgs Command Design
2
+
3
+ ## Command Structure
4
+
5
+ ```
6
+ barista liberica orgs <subcommand>
7
+ ```
8
+
9
+ ## Subcommands
10
+
11
+ ### list
12
+
13
+ List all organizations (departments) in the system.
14
+
15
+ **Usage:**
16
+ ```bash
17
+ barista liberica orgs list [options]
18
+ ```
19
+
20
+ **Options:**
21
+ - `--json` - Output as JSON format
22
+
23
+ **Examples:**
24
+ ```bash
25
+ # List all organizations
26
+ barista liberica orgs list
27
+
28
+ # Output as JSON
29
+ barista liberica orgs list --json
30
+ ```
31
+
32
+ **API Endpoint:**
33
+ - `GET /api/enterprise/master/org/all`
34
+
35
+ **Implementation:**
36
+ ```typescript
37
+ // src/commands/liberica/orgs/index.ts
38
+ // src/core/api/client.ts - listOrganizations()
39
+ ```
40
+
41
+ ## Output Format
42
+
43
+ | Field | Description |
44
+ |-------|-------------|
45
+ | id | Organization ID |
46
+ | name | Organization name |
47
+
48
+ ## Known Organizations (Shanghai Tenant)
49
+
50
+ | ID | Name |
51
+ |----|------|
52
+ | 2006228218445156353 | 人事部 |
53
+ | 1890201570712793090 | 销售部 |
54
+ | 1890201570712793091 | 生产部 |
55
+ | 1890201570712793092 | 采购部 |
56
+ | 1890201570712793093 | 财务部 |
57
+
58
+ ## Notes
59
+
60
+ - Organizations are company departments
61
+ - Used as reference for user management
62
+ - The `userOrgList.orgId` in user creation maps to these organization IDs
@@ -0,0 +1,61 @@
1
+ # Positions Command Design
2
+
3
+ ## Command Structure
4
+
5
+ ```
6
+ barista liberica positions <subcommand>
7
+ ```
8
+
9
+ ## Subcommands
10
+
11
+ ### list
12
+
13
+ List all positions in the system.
14
+
15
+ **Usage:**
16
+ ```bash
17
+ barista liberica positions list [options]
18
+ ```
19
+
20
+ **Options:**
21
+ - `--json` - Output as JSON format
22
+
23
+ **Examples:**
24
+ ```bash
25
+ # List all positions
26
+ barista liberica positions list
27
+
28
+ # Output as JSON
29
+ barista liberica positions list --json
30
+ ```
31
+
32
+ **API Endpoint:**
33
+ - `GET /api/enterprise/master/position/all`
34
+
35
+ **Implementation:**
36
+ ```typescript
37
+ // src/commands/liberica/positions/index.ts
38
+ // src/core/api/client.ts - listPositions()
39
+ ```
40
+
41
+ ## Output Format
42
+
43
+ | Field | Description |
44
+ |-------|-------------|
45
+ | id | Position ID |
46
+ | name | Position name |
47
+
48
+ ## Known Positions (Shanghai Tenant)
49
+
50
+ | ID | Name |
51
+ |----|------|
52
+ | 2039948606182752257 | 总经理 |
53
+ | 2039948606186946562 | 部门经理 |
54
+ | 2039948606191140865 | 组长 |
55
+
56
+ ## Notes
57
+
58
+ - Positions represent job titles within the organization
59
+ - The default system position ID is `1671418731163627522`
60
+ - Used as reference for user management
61
+ - The `userOrgList.positionId` in user creation maps to these position IDs
@@ -0,0 +1,67 @@
1
+ # Roles Command Design
2
+
3
+ ## Command Structure
4
+
5
+ ```
6
+ barista liberica roles <subcommand>
7
+ ```
8
+
9
+ ## Subcommands
10
+
11
+ ### list
12
+
13
+ List all available roles in the system.
14
+
15
+ **Usage:**
16
+ ```bash
17
+ barista liberica roles list [options]
18
+ ```
19
+
20
+ **Options:**
21
+ - `--json` - Output as JSON format
22
+
23
+ **Examples:**
24
+ ```bash
25
+ # List all roles
26
+ barista liberica roles list
27
+
28
+ # Output as JSON
29
+ barista liberica roles list --json
30
+ ```
31
+
32
+ **API Endpoint:**
33
+ - `GET /api/enterprise/sysRole/list`
34
+
35
+ **Implementation:**
36
+ ```typescript
37
+ // src/commands/liberica/roles/index.ts
38
+ // src/core/api/client.ts - listRoles()
39
+ ```
40
+
41
+ ## Output Format
42
+
43
+ | Field | Description |
44
+ |-------|-------------|
45
+ | ID | Role ID (e.g., 9000, 9001) |
46
+ | Role Code | System code (e.g., tenantAdmin, tenantEmployee) |
47
+ | Role Name | Display name (e.g., 租户管理员, 租户人员) |
48
+ | Status | Enabled or Disabled |
49
+
50
+ ## Known Roles (Shanghai Tenant)
51
+
52
+ | ID | Code | Name |
53
+ |----|------|------|
54
+ | 9000 | tenantAdmin | 租户管理员 |
55
+ | 9001 | tenantEmployee | 租户人员 |
56
+ | 9100 | tenantKpiParticipant | 租户人事考核参与人 |
57
+ | 9101 | tenantHr | 租户人事 |
58
+ | 9102 | tenantDeptManager | 租户部门负责人 |
59
+ | 9103 | tenantKpiEvaluator | 租户人事考核评价人 |
60
+ | 9104 | tenantCeo | 租户首席执行官 |
61
+ | 9105 | tenantSales | 租户销售 |
62
+ | 9106 | tenantPurchase | 租户采购 |
63
+
64
+ ## Notes
65
+
66
+ - Roles are used when creating users with `barista liberica users create -r <role-id>`
67
+ - Multiple roles can be specified as comma-separated IDs: `-r 9001,9105`
@@ -0,0 +1,170 @@
1
+ # barista liberica users create
2
+
3
+ 创建新用户。
4
+
5
+ ## 2.1 命令元数据
6
+
7
+ | 字段 | 值 |
8
+ |------|-----|
9
+ | 完整命令 | `barista liberica users create` |
10
+ | 功能描述 | 创建新用户 |
11
+ | HTTP方法 | POST |
12
+ | 是否需要认证 | ✅ 是 |
13
+ | 是否支持dry-run | ✅ 是 |
14
+
15
+ ## 2.2 后端接口引用
16
+
17
+ ### Controller位置
18
+ ```
19
+ coffee-liberica-end/
20
+ └── facade/liberica-facade-enterprise/
21
+ └── src/main/java/com/newpeak/liberica/facade/enterprise/controller/
22
+ └── EnterpriseSysUserController.java
23
+ └── add(@PostResource(path = "/add", requiredPermission = true, requirePermissionCode = ErpPermissionCodeConstants.ERP_ADD_USER))
24
+ └── public ResponseData add(
25
+ @RequestBody @Validated(ErpSysUserRequest.add.class) ErpSysUserRequest sysUserRequest
26
+ )
27
+ ```
28
+
29
+ ### Request DTO位置
30
+ ```
31
+ coffee-liberica-end/
32
+ └── business/liberica-business-auth/
33
+ └── src/main/java/com/newpeak/liberica/business/auth/pojo/request/
34
+ └── ErpSysUserRequest.java
35
+ ├── userId: Long (@NotNull on edit/delete/detail/updateStatus/resetPassword)
36
+ ├── realName: String (@NotBlank on add/edit/updateInfo)
37
+ ├── account: String (@NotBlank on add/edit, unique validation)
38
+ ├── newPassword: String (@NotBlank on updatePwd)
39
+ ├── avatar: Long (@NotNull on updateAvatar)
40
+ ├── email: String (@Email validation)
41
+ ├── roleIdList: Set<Long> (@NotEmpty on add/edit)
42
+ ├── userIdList: Set<Long> (@NotEmpty on batchDelete)
43
+ └── employeeId: Long
44
+ ```
45
+
46
+ ### Response DTO位置
47
+ ```
48
+ coffee-liberica-end/
49
+ └── business/liberica-business-auth/
50
+ └── src/main/java/com/newpeak/liberica/business/auth/pojo/
51
+ └── SysUserDto.java
52
+ ├── userId: Long
53
+ ├── realName: String
54
+ ├── account: String
55
+ ├── email: String
56
+ ├── employeeId: Long
57
+ ├── employeeNumber: String
58
+ ├── employeeName: String
59
+ ├── roleNameList: List<String>
60
+ ├── statusFlag: Integer (1=enable, 2=disable)
61
+ ├── createTime: Date
62
+ └── readOnly: Boolean
63
+ ```
64
+
65
+ ## 2.3 CLI参数设计
66
+
67
+ ### 命令结构
68
+ ```
69
+ barista liberica users create [options]
70
+ ```
71
+
72
+ ### 全局选项
73
+ | 选项 | 类型 | 说明 |
74
+ |------|------|------|
75
+ | `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
76
+ | `--tenant` | string | 租户代码 |
77
+ | `--dry-run` | boolean | 预览模式(不实际调用API) |
78
+ | `--json` | boolean | JSON输出 |
79
+
80
+ ### 命令选项
81
+ | 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 | 对应DTO字段 |
82
+ |------|--------|------|------|--------|------|-------------|
83
+ | --name | -n | string | ✅ | - | 用户姓名 | realName |
84
+ | --account | -a | string | ✅ | - | 用户账号(不包含@) | account |
85
+ | --email | -e | string | ⬜ | - | 电子邮箱 | email |
86
+ | --role-ids | -r | string | ✅ | - | 角色ID列表(逗号分隔) | roleIdList |
87
+ | --employee-id | — | number | ⬜ | - | 关联职员ID | employeeId |
88
+
89
+ ## 2.4 字段映射表
90
+
91
+ | CLI参数 | DTO字段 | 类型转换 | 验证规则 |
92
+ |---------|---------|----------|----------|
93
+ | --name / -n | realName | 直接传递 | @NotBlank, max=255 |
94
+ | --account / -a | account | 直接传递 | @NotBlank, 不包含@符号, 唯一性校验 |
95
+ | --email / -e | email | 直接传递 | 邮箱格式验证 |
96
+ | --role-ids / -r | roleIdList | string→Set<Long> | @NotEmpty, 逗号分隔 |
97
+ | --employee-id | employeeId | string→Long | - |
98
+
99
+ **自动填充字段(不通过CLI参数):**
100
+ | 字段 | 值 |
101
+ |------|-----|
102
+ | tenantId | 来自JWT token,无需显式传递 |
103
+ | statusFlag | 默认 1 (启用) |
104
+
105
+ ## 2.5 错误码引用
106
+
107
+ ### ExceptionEnum位置
108
+ ```
109
+ coffee-liberica-end/
110
+ └── business/liberica-business-auth/
111
+ └── src/main/java/com/newpeak/liberica/business/auth/enums/exception/
112
+ └── ErpUserExceptionEnum.java
113
+ ├── UPDATE_SELF_PSW_FORBIDDEN("010011510001", "不能重置自己的密码")
114
+ ├── DEL_SELF_FORBIDDEN("010011510002", "不能删除自己的账号")
115
+ ├── UPDATE_ADMIN_FORBIDDEN("010011510003", "不能更新管理员账号")
116
+ ├── UPDATE_SELF_ACCOUNT("010011510004", "不能更新自己的账号")
117
+ ├── WRONG_STATUS_FLAG("010011510005", "错误的statusFlag")
118
+ ├── WRONG_ACCOUNT("010011510006", "错误的账号")
119
+ ├── TOKEN_EXPIRED("010011510007", "链接已过期")
120
+ ├── EMAIL_INCONSISTENT("010011510008", "账号不一致")
121
+ ├── ACCOUNT_DUPLICATED("010011510009", "已存在相同账号")
122
+ ├── SEND_EMAIL_FAILED("010011510010", "发送邮件失败")
123
+ ├── BOUND_USER_DEL_FORBID("010011510011", "已绑定用户职员不能被删除")
124
+ └── ERP_NOT_EXIST("010011510012", "对应erp不存在")
125
+ ```
126
+
127
+ ### 已知错误码
128
+ | 错误码 | 错误消息 | 触发条件 |
129
+ |--------|----------|----------|
130
+ | 010011510009 | 已存在相同账号 | account 已存在 |
131
+ | 010011510008 | 账号不一致 | 邮件与账号不匹配 |
132
+
133
+ ## 2.6 权限检查
134
+
135
+ | 检查项 | 位置 | 说明 |
136
+ |--------|------|------|
137
+ | PermissionConstants | `ErpPermissionCodeConstants.ERP_ADD_USER` | Controller层 `@PostResource(requirePermissionCode = ErpPermissionCodeConstants.ERP_ADD_USER)` |
138
+
139
+ ## 2.7 实现要点
140
+
141
+ 1. **必填字段**:--name, --account, --role-ids 必须提供
142
+ 2. **角色ID格式**:--role-ids 接受逗号分隔的ID列表,如 "1,2,3"
143
+ 3. **账号规则**:account 不能包含@符号,后端会自动拼接租户域名
144
+ 4. **Dry-run支持**:使用 --dry-run 时构造请求体但不发送,显示预览信息
145
+ 5. **默认statusFlag**:新建用户默认为启用状态(statusFlag=1)
146
+ 6. **tenantId来源**:来自JWT token,不通过请求体传递
147
+
148
+ ## 2.8 示例用法
149
+
150
+ ```bash
151
+ # 交互式创建(引导输入必填字段)
152
+ barista liberica users create
153
+
154
+ # 指定姓名、账号和角色
155
+ barista liberica users create --name "张三" --account "zhangsan" --role-ids "1,2"
156
+
157
+ # 完整选项
158
+ barista liberica users create \
159
+ --name "张三" \
160
+ --account "zhangsan" \
161
+ --email "zhangsan@example.com" \
162
+ --role-ids "1,2,3" \
163
+ --employee-id 1001
164
+
165
+ # Dry-run 预览
166
+ barista liberica users create --name "张三" --account "zhangsan" --role-ids "1" --dry-run
167
+
168
+ # JSON 输出
169
+ barista liberica users create --name "张三" --account "zhangsan" --role-ids "1" --json
170
+ ```
@@ -0,0 +1,151 @@
1
+ # barista liberica users get
2
+
3
+ 获取单个用户详情。
4
+
5
+ ## 2.1 命令元数据
6
+
7
+ | 字段 | 值 |
8
+ |------|-----|
9
+ | 完整命令 | `barista liberica users get <id>` |
10
+ | 功能描述 | 获取单个用户详情 |
11
+ | HTTP方法 | GET |
12
+ | 是否需要认证 | ✅ 是 |
13
+ | 是否支持dry-run | ⬜ 否 |
14
+
15
+ ## 2.2 后端接口引用
16
+
17
+ ### Controller位置
18
+ ```
19
+ coffee-liberica-end/
20
+ └── facade/liberica-facade-enterprise/
21
+ └── src/main/java/com/newpeak/liberica/facade/enterprise/controller/
22
+ └── EnterpriseSysUserController.java
23
+ └── detail(@GetResource(name = "查看用户详情", path = "/detail"))
24
+ └── public ResponseData<SysUser> detail(
25
+ @Validated(SysUserRequest.detail.class) ErpSysUserRequest sysUserRequest
26
+ )
27
+ ```
28
+
29
+ ### Request DTO位置
30
+ ```
31
+ coffee-liberica-end/
32
+ └── business/liberica-business-auth/
33
+ └── src/main/java/com/newpeak/liberica/business/auth/pojo/request/
34
+ └── ErpSysUserRequest.java
35
+ └── userId: Long (@NotNull on detail)
36
+ ```
37
+
38
+ ### Response DTO位置
39
+ ```
40
+ coffee-liberica-end/
41
+ └── business/liberica-business-auth/
42
+ └── src/main/java/com/newpeak/liberica/business/auth/pojo/
43
+ └── SysUserDto.java
44
+ ├── userId: Long
45
+ ├── realName: String
46
+ ├── account: String
47
+ ├── email: String
48
+ ├── employeeId: Long
49
+ ├── employeeNumber: String
50
+ ├── employeeName: String
51
+ ├── roleNameList: List<String>
52
+ ├── statusFlag: Integer (1=enable, 2=disable)
53
+ ├── createTime: Date
54
+ └── readOnly: Boolean
55
+ ```
56
+
57
+ ### Entity位置
58
+ ```
59
+ cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUser
60
+ ├── userId: Long
61
+ ├── realName: String
62
+ ├── account: String
63
+ ├── email: String
64
+ ├── statusFlag: Integer
65
+ └── createTime: Date
66
+ ```
67
+
68
+ ## 2.3 CLI参数设计
69
+
70
+ ### 命令结构
71
+ ```
72
+ barista liberica users get <id> [options]
73
+ ```
74
+
75
+ ### 位置参数
76
+ | 参数 | 类型 | 必填 | 说明 |
77
+ |------|------|------|------|
78
+ | id | number | ✅ | 用户ID (userId) |
79
+
80
+ ### 全局选项
81
+ | 选项 | 类型 | 说明 |
82
+ |------|------|------|
83
+ | `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
84
+ | `--tenant` | string | 租户代码 |
85
+ | `--json` | boolean | JSON输出 |
86
+
87
+ ### 命令选项
88
+ | 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 |
89
+ |------|--------|------|------|--------|------|
90
+ | — | — | — | — | — | 此命令无额外选项,ID 通过位置参数传入 |
91
+
92
+ ## 2.4 字段映射表
93
+
94
+ | CLI参数 | DTO字段 | 类型转换 | 验证规则 |
95
+ |---------|---------|----------|----------|
96
+ | <id> (位置参数) | userId | string→Long | @NotNull, 必须为正整数 |
97
+
98
+ ## 2.5 错误码引用
99
+
100
+ ### ExceptionEnum位置
101
+ ```
102
+ coffee-liberica-end/
103
+ └── business/liberica-business-auth/
104
+ └── src/main/java/com/newpeak/liberica/business/auth/enums/exception/
105
+ └── ErpUserExceptionEnum.java
106
+ ├── UPDATE_SELF_PSW_FORBIDDEN("010011510001", "不能重置自己的密码")
107
+ ├── DEL_SELF_FORBIDDEN("010011510002", "不能删除自己的账号")
108
+ ├── UPDATE_ADMIN_FORBIDDEN("010011510003", "不能更新管理员账号")
109
+ ├── UPDATE_SELF_ACCOUNT("010011510004", "不能更新自己的账号")
110
+ ├── WRONG_STATUS_FLAG("010011510005", "错误的statusFlag")
111
+ ├── WRONG_ACCOUNT("010011510006", "错误的账号")
112
+ ├── TOKEN_EXPIRED("010011510007", "链接已过期")
113
+ ├── EMAIL_INCONSISTENT("010011510008", "账号不一致")
114
+ ├── ACCOUNT_DUPLICATED("010011510009", "已存在相同账号")
115
+ ├── SEND_EMAIL_FAILED("010011510010", "发送邮件失败")
116
+ ├── BOUND_USER_DEL_FORBID("010011510011", "已绑定用户职员不能被删除")
117
+ └── ERP_NOT_EXIST("010011510012", "对应erp不存在")
118
+ ```
119
+
120
+ ### 已知错误码
121
+ | 错误码 | 错误消息 | 触发条件 |
122
+ |--------|----------|----------|
123
+ | 010011510006 | 错误的账号 | userId 不存在或不属于当前租户 |
124
+
125
+ ## 2.6 权限检查
126
+
127
+ | 检查项 | 位置 | 说明 |
128
+ |--------|------|------|
129
+ | 注解 | `@GetResource(path = "/detail")` | 无 requiredPermission |
130
+
131
+ ## 2.7 实现要点
132
+
133
+ 1. **位置参数**:`get` 命令使用 `<id>` 位置参数指定用户ID
134
+ 2. **错误处理**:用户不存在时抛出错误,CLI 显示友好错误信息
135
+ 3. **tenantId来源**:来自JWT token,后端自动按租户隔离数据
136
+ 4. **返回字段**:包含用户基本信息、关联职员信息、角色列表等
137
+ 5. **角色显示**:roleNameList 以列表形式展示用户拥有的所有角色
138
+
139
+ ## 2.8 示例用法
140
+
141
+ ```bash
142
+ # 获取用户详情
143
+ barista liberica users get 12345
144
+
145
+ # JSON 输出
146
+ barista liberica users get 12345 --json
147
+
148
+ # 用户不存在
149
+ barista liberica users get 99999
150
+ # 输出: Error: 用户不存在 (010011510006)
151
+ ```