@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,296 @@
1
+ # arabica auth
2
+
3
+ Manage Arabica authentication.
4
+
5
+ ## Overview
6
+
7
+ The `arabica auth` command group provides authentication management for the Arabica sales platform. Arabica is a single-tenant SaaS platform, which means it does not require tenant context like Liberica. Authentication uses the standard `POST /api/login` endpoint for login and `POST /api/member/user/register` for user registration.
8
+
9
+ Key differences from Liberica authentication:
10
+
11
+ - **No tenant concept**: Arabica operates as a single-tenant platform
12
+ - **Account-based login**: Uses account (username or email) instead of username/tenant pair
13
+ - **Registration support**: Includes user registration functionality
14
+ - **Remember me option**: Supports persistent login sessions
15
+
16
+ ## Commands
17
+
18
+ ### login
19
+
20
+ Login to Arabica with account credentials.
21
+
22
+ **Usage:**
23
+ ```
24
+ barista arabica auth login [env] [account] [password] [options]
25
+ ```
26
+
27
+ **Arguments:**
28
+
29
+ | Argument | Type | Required | Description |
30
+ |----------|------|----------|-------------|
31
+ | env | string | No | Target environment (dev\|test\|prod-cn\|prod-jp) |
32
+ | account | string | No | Account username or email |
33
+ | password | string | No | Account password |
34
+
35
+ **Options:**
36
+
37
+ | Option | Type | Required | Default | Description |
38
+ |--------|------|----------|---------|-------------|
39
+ | --env | string | No | Current context | Target environment |
40
+ | --account | string | No | Interactive input | Account username or email |
41
+ | --password | string | No | Interactive input | Account password |
42
+ | --remember | boolean | No | false | Remember login status |
43
+
44
+ **Examples:**
45
+
46
+ Interactive mode (all fields prompted):
47
+ ```bash
48
+ barista arabica auth login
49
+ ```
50
+
51
+ With positional arguments:
52
+ ```bash
53
+ barista arabica auth login dev user@example.com mypassword
54
+ ```
55
+
56
+ With options:
57
+ ```bash
58
+ barista arabica auth login --env dev --account user@example.com --password mypassword --remember
59
+ ```
60
+
61
+ Mixed (positional + options):
62
+ ```bash
63
+ barista arabica auth login dev --account user@example.com --password mypassword
64
+ ```
65
+
66
+ **API Endpoint:**
67
+ - **Method**: `POST /api/login`
68
+ - **Body**: `{ account: string, password: string, rememberMe: boolean }`
69
+ - **Response**: `{ success: boolean, data: { token: string, expiresAt?: string } }`
70
+
71
+ **Error Handling:**
72
+
73
+ | Error Code | Description | Trigger Condition |
74
+ |------------|-------------|-------------------|
75
+ | INVALID_CREDENTIALS | Invalid account or password | Wrong account/password combination |
76
+ | ACCOUNT_LOCKED | Account is locked | Multiple failed login attempts |
77
+ | NETWORK_ERROR | Network connection failed | Cannot reach Arabica server |
78
+
79
+ **Implementation Notes:**
80
+ - Interactive prompts use `inquirer` for secure password input (masked)
81
+ - Successful login stores token via `tokenManager.setToken()` in system keychain
82
+ - Token format in keychain: `arabica:{environment}` (no tenant component)
83
+ - The `--remember` flag extends token validity on the server side
84
+
85
+ ---
86
+
87
+ ### register
88
+
89
+ Register a new Arabica account.
90
+
91
+ **Usage:**
92
+ ```
93
+ barista arabica auth register [options]
94
+ ```
95
+
96
+ **Options:**
97
+
98
+ | Option | Type | Required | Default | Description |
99
+ |--------|------|----------|---------|-------------|
100
+ | --env | string | No | Current context | Target environment |
101
+ | --email | string | No | Interactive input | Email address |
102
+ | --account | string | No | Interactive input | Account username |
103
+ | --password | string | No | Interactive input | Account password |
104
+ | --phone | string | No | Interactive input | Phone number (optional) |
105
+
106
+ **Examples:**
107
+
108
+ Interactive mode (all fields prompted):
109
+ ```bash
110
+ barista arabica auth register
111
+ ```
112
+
113
+ With all options:
114
+ ```bash
115
+ barista arabica auth register \
116
+ --env dev \
117
+ --email newuser@example.com \
118
+ --account newuser \
119
+ --password mypassword \
120
+ --phone "+86 13800138000"
121
+ ```
122
+
123
+ Minimal registration (prompts for missing fields):
124
+ ```bash
125
+ barista arabica auth register --email newuser@example.com --account newuser
126
+ ```
127
+
128
+ **API Endpoint:**
129
+ - **Method**: `POST /api/member/user/register`
130
+ - **Body**: `{ email: string, account: string, password: string, phone?: string }`
131
+ - **Response**: `{ success: boolean, data: { userId?: string } }`
132
+
133
+ **Error Handling:**
134
+
135
+ | Error Code | Description | Trigger Condition |
136
+ |------------|-------------|-------------------|
137
+ | EMAIL_EXISTS | Email already registered | Duplicate email address |
138
+ | ACCOUNT_EXISTS | Account username taken | Duplicate account name |
139
+ | INVALID_EMAIL | Invalid email format | Email format validation failed |
140
+ | WEAK_PASSWORD | Password too weak | Password does not meet requirements |
141
+
142
+ **Implementation Notes:**
143
+ - Email and account are both required and must be unique
144
+ - Phone number is optional but recommended for account recovery
145
+ - After successful registration, user must login separately to obtain token
146
+ - Registration does not automatically authenticate the user
147
+
148
+ ---
149
+
150
+ ### status
151
+
152
+ Check Arabica authentication status across all environments.
153
+
154
+ **Usage:**
155
+ ```
156
+ barista arabica auth status
157
+ ```
158
+
159
+ **Output:**
160
+ ```
161
+ 🔐 Arabica Authentication Status
162
+
163
+ ✓ arabica (dev): Logged in
164
+ ✗ arabica (test): Not logged in
165
+ ✗ arabica (prod-cn): Not logged in
166
+ ✗ arabica (prod-jp): Not logged in
167
+ ```
168
+
169
+ **Implementation Notes:**
170
+ - Checks all four environments (dev, test, prod-cn, prod-jp)
171
+ - Uses `tokenManager.getToken({ service: 'arabica', environment })` for each environment
172
+ - No tenant component in token key since Arabica is single-tenant
173
+ - Output uses chalk for colored status indicators (green checkmark for logged in, red X for not logged in)
174
+
175
+ ---
176
+
177
+ ### logout
178
+
179
+ Logout from Arabica and clear stored tokens.
180
+
181
+ **Usage:**
182
+ ```
183
+ barista arabica auth logout [options]
184
+ ```
185
+
186
+ **Options:**
187
+
188
+ | Option | Type | Required | Default | Description |
189
+ |--------|------|----------|---------|-------------|
190
+ | --env | string | No | Current context | Target environment to logout from |
191
+ | --all | boolean | No | false | Clear all Arabica tokens across environments |
192
+
193
+ **Examples:**
194
+
195
+ Logout from current environment:
196
+ ```bash
197
+ barista arabica auth logout
198
+ ```
199
+
200
+ Logout from specific environment:
201
+ ```bash
202
+ barista arabica auth logout --env dev
203
+ ```
204
+
205
+ Logout from all environments:
206
+ ```bash
207
+ barista arabica auth logout --all
208
+ ```
209
+
210
+ **Implementation Notes:**
211
+ - Without `--all`, clears token for the specified (or current) environment only
212
+ - With `--all`, iterates through all credentials in keychain and deletes those with `arabica:*` prefix
213
+ - Uses `tokenManager.deleteToken()` for single environment logout
214
+ - Uses `tokenManager.findAllTokens()` and filters by service name for `--all` logout
215
+
216
+ ---
217
+
218
+ ## Arabica vs Liberica Comparison Table
219
+
220
+ | Feature | Arabica Auth | Liberica Auth |
221
+ |---------|--------------|---------------|
222
+ | **Platform Type** | Single-tenant SaaS | Multi-tenant SaaS |
223
+ | **Tenant Required** | No | Yes (required) |
224
+ | **Login Identifier** | Account (username/email) | Username + Tenant |
225
+ | **Registration** | Supported | Not supported (admin only) |
226
+ | **Remember Me** | Supported | Not supported |
227
+ | **Token Key Format** | `arabica:{environment}` | `liberica:{environment}:{tenant}` |
228
+ | **Login Endpoint** | `POST /api/login` | `POST /api/enterprise/loginApi` |
229
+ | **Register Endpoint** | `POST /api/member/user/register` | N/A |
230
+
231
+ ## File Structure
232
+
233
+ ```
234
+ src/commands/arabica/auth/
235
+ ├── index.ts # Main auth command with login, register, status, logout implementations
236
+ ├── login.ts # Login command factory (stub for future expansion)
237
+ ├── register.ts # Register command factory (stub for future expansion)
238
+ ├── status.ts # Status command factory (stub for future expansion)
239
+ └── logout.ts # Logout command factory (stub for future expansion)
240
+ ```
241
+
242
+ **Implementation Pattern:**
243
+
244
+ All four subcommands are implemented directly in `index.ts` using Commander.js `.command()` chaining. The individual files (`login.ts`, `register.ts`, `status.ts`, `logout.ts`) export factory functions that create empty Command instances for potential future refactoring.
245
+
246
+ ```typescript
247
+ // index.ts pattern
248
+ authCommand
249
+ .command('login')
250
+ .description('Login to Arabica')
251
+ .arguments('<env> [account] [password]')
252
+ .option('--env <environment>', 'Environment')
253
+ .option('--account <account>', 'Account')
254
+ .option('--password <password>', 'Password')
255
+ .option('--remember', 'Remember login status')
256
+ .action(async (env, account, password, options) => {
257
+ // Implementation
258
+ });
259
+ ```
260
+
261
+ ## Unit Tests
262
+
263
+ Test file: `tests/unit/commands/arabica/auth.test.ts`
264
+
265
+ **Test Coverage:**
266
+
267
+ | Test Case | Description |
268
+ |-----------|-------------|
269
+ | Command creation | Verifies auth command is created with correct name and description |
270
+ | Login subcommand | Tests login command existence, description, and all options (--env, --account, --password, --remember) |
271
+ | Register subcommand | Tests register command existence, description, and all options (--env, --email, --account, --password, --phone) |
272
+ | Status subcommand | Tests status command existence, description, and zero options |
273
+ | Logout subcommand | Tests logout command existence, description, and options (--env, --all) |
274
+ | No tenant option | Verifies Arabica login does NOT have --tenant option (unlike Liberica) |
275
+ | Integration mocks | Verifies apiClient and tokenManager methods are called correctly |
276
+
277
+ **Mock Strategy:**
278
+
279
+ ```typescript
280
+ // Key modules are mocked for unit testing
281
+ vi.mock('../../../../src/core/config/manager.js');
282
+ vi.mock('../../../../src/core/auth/token-manager.js');
283
+ vi.mock('../../../../src/core/api/client.js');
284
+ vi.mock('chalk');
285
+ vi.mock('inquirer');
286
+ ```
287
+
288
+ **Running Tests:**
289
+
290
+ ```bash
291
+ # Run all Arabica auth tests
292
+ npm test -- tests/unit/commands/arabica/auth.test.ts
293
+
294
+ # Run with coverage
295
+ npm run test:coverage -- tests/unit/commands/arabica/auth.test.ts
296
+ ```
@@ -0,0 +1,133 @@
1
+ # liberica auth
2
+
3
+ 管理 Liberica 租户身份认证。
4
+
5
+ ## Commands
6
+
7
+ ### login
8
+
9
+ 登录 Liberica 租户账户。
10
+
11
+ **Usage:**
12
+ ```
13
+ barista liberica auth login [env] [tenant] [username] [password] [options]
14
+ ```
15
+
16
+ **Arguments:**
17
+ | 参数 | 类型 | 必填 | 说明 |
18
+ |------|------|------|------|
19
+ | env | string | ⬜ | 目标环境 (dev\|test\|prod-cn\|prod-jp) |
20
+ | tenant | string | ⬜ | 租户名称 |
21
+ | username | string | ⬜ | 用户名 |
22
+ | password | string | ⬜ | 密码 |
23
+
24
+ **Options:**
25
+ | 选项 | 类型 | 必填 | 默认值 | 说明 |
26
+ |------|------|------|--------|------|
27
+ | --env | string | ⬜ | 当前上下文 | 目标环境 |
28
+ | --tenant | string | ⬜ | 当前上下文 | 租户名称 |
29
+ | --username | string | ⬜ | 交互输入 | 用户名 |
30
+ | --password | string | ⬜ | 交互输入 | 密码 |
31
+
32
+ **Examples:**
33
+
34
+ Interactive mode (all args prompted):
35
+ ```bash
36
+ barista liberica auth login
37
+ ```
38
+
39
+ With positional arguments:
40
+ ```bash
41
+ barista liberica auth login dev shanghai admin@shanghai.newpeaksh.com 123456
42
+ ```
43
+
44
+ With options:
45
+ ```bash
46
+ barista liberica auth login --env dev --tenant shanghai --username admin@shanghai.newpeaksh.com --password 123456
47
+ ```
48
+
49
+ Mixed (positional + options):
50
+ ```bash
51
+ barista liberica auth login dev --tenant shanghai --username admin@shanghai.newpeaksh.com --password 123456
52
+ ```
53
+
54
+ **API:**
55
+ - Endpoint: `POST /api/v1/auth/login`
56
+ - Body: `{ username, password, tenant, service, environment }`
57
+ - Response: `{ success: true, data: { token, expiresAt } }`
58
+
59
+ **Error Codes:**
60
+ | 错误码 | 错误消息 | 触发条件 |
61
+ |--------|----------|----------|
62
+ | USER_NOT_EXIST | 用户不存在 | 用户名未注册 |
63
+ | PASSWORD_ERROR | 密码错误 | 密码不匹配 |
64
+ | NETWORK_ERROR | 网络错误 | 无法连接到服务器 |
65
+
66
+ **Implementation Notes:**
67
+ - 交互式补全:tenant/username/password 未提供时使用 inquirer 交互输入
68
+ - Token存储:成功登录后调用 `tokenManager.setToken()` 存入系统密钥链
69
+ - 上下文更新:调用 `configManager.setTenant()` 更新默认租户
70
+
71
+ ---
72
+
73
+ ### status
74
+
75
+ 检查 Liberica 认证状态。
76
+
77
+ **Usage:**
78
+ ```
79
+ barista liberica auth status
80
+ ```
81
+
82
+ **Output:**
83
+ ```
84
+ 🔐 Liberica Authentication Status
85
+
86
+ ✓ liberica (electionjp) (dev): Logged in
87
+ ✗ liberica (electionjp) (test): Not logged in
88
+ ✗ liberica (electionjp) (prod-cn): Not logged in
89
+ ✗ liberica (electionjp) (prod-jp): Not logged in
90
+ ```
91
+
92
+ **Implementation Notes:**
93
+ - 遍历所有环境检查 Token 状态
94
+ - 使用 `tokenManager.getToken()` 检查密钥链
95
+
96
+ ---
97
+
98
+ ### logout
99
+
100
+ 登出并清除 Token。
101
+
102
+ **Usage:**
103
+ ```
104
+ barista liberica auth logout [options]
105
+ ```
106
+
107
+ **Options:**
108
+ | 选项 | 类型 | 必填 | 默认值 | 说明 |
109
+ |------|------|------|--------|------|
110
+ | --env | string | ⬜ | 当前上下文 | 目标环境 |
111
+ | --all | boolean | ⬜ | false | 清除所有 Liberica Token |
112
+
113
+ **Examples:**
114
+
115
+ Logout current environment:
116
+ ```bash
117
+ barista liberica auth logout --env dev
118
+ ```
119
+
120
+ Logout all environments:
121
+ ```bash
122
+ barista liberica auth logout --all
123
+ ```
124
+
125
+ **Implementation Notes:**
126
+ - 使用 `tokenManager.deleteToken()` 删除指定环境的 Token
127
+ - 使用 `tokenManager.findAllTokens()` 遍历所有 Token
128
+
129
+ ---
130
+
131
+ ## Design Reference
132
+
133
+ 完整设计文档见:[命令设计规范](../../COMMAND_DESIGN_SPEC.md#61-示例liberica-auth-login-命令)
@@ -0,0 +1,60 @@
1
+ # liberica context
2
+
3
+ 管理 Liberica 上下文(租户、环境)。
4
+
5
+ ## Commands
6
+
7
+ ### show
8
+
9
+ 显示当前 Liberica 上下文。
10
+
11
+ **Usage:**
12
+ ```
13
+ barista liberica context show
14
+ ```
15
+
16
+ **Output:**
17
+ ```
18
+ 📋 Liberica Context
19
+
20
+ Environment: dev
21
+ Tenant: electionjp
22
+ Auth Status: ✓ Logged in
23
+ ```
24
+
25
+ **Implementation Notes:**
26
+ - 无 API 调用,仅读取本地配置
27
+ - 使用 `configManager.getCurrentContext()` 获取当前上下文
28
+ - 使用 `tokenManager.getToken()` 检查认证状态
29
+
30
+ ---
31
+
32
+ ### use-enterprise
33
+
34
+ 切换 Liberica 租户。
35
+
36
+ **Usage:**
37
+ ```
38
+ barista liberica context use-enterprise <tenant>
39
+ ```
40
+
41
+ **Arguments:**
42
+ | 参数 | 类型 | 必填 | 说明 |
43
+ |------|------|------|------|
44
+ | tenant | string | ✅ | 租户名称 |
45
+
46
+ **Examples:**
47
+ ```bash
48
+ barista liberica context use-enterprise electionjp
49
+ barista liberica context use-enterprise newtenant
50
+ ```
51
+
52
+ **Implementation Notes:**
53
+ - 使用 `configManager.setTenant()` 更新默认租户
54
+ - 租户变更后不影响当前已存储的 Token
55
+
56
+ ---
57
+
58
+ ## Design Reference
59
+
60
+ 完整设计文档见:[命令设计规范](../../COMMAND_DESIGN_SPEC.md#62-示例liberica-context-show-命令)
@@ -0,0 +1,185 @@
1
+ # barista liberica employees create
2
+
3
+ 创建新员工。
4
+
5
+ ## 2.1 命令元数据
6
+
7
+ | 字段 | 值 |
8
+ |------|-----|
9
+ | 完整命令 | `barista liberica employees 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/master/
22
+ └── EnterpriseEmployeeController.java
23
+ └── add(@PostResource(path = "/add", requiredPermission = true, requirePermissionCode = "ADD_EMPLOYEE"))
24
+ └── public ResponseData<MasterEmployeeResponse> add(
25
+ @RequestHeader("X-TENANT-ID") Long tenantId,
26
+ @RequestBody @Validated(BaseRequest.add.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
+ ├── employeeCode: String (@NotBlank on add)
37
+ ├── employeeName: String (@NotBlank on add)
38
+ ├── employeeNo: String (@NotBlank on add)
39
+ ├── employeePhone: String
40
+ ├── employeeEmail: String
41
+ ├── employeeSex: SexEnum (M/F)
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
+ ```
78
+
79
+ ## 2.3 CLI参数设计
80
+
81
+ ### 命令结构
82
+ ```
83
+ barista liberica employees create [options]
84
+ ```
85
+
86
+ ### 全局选项
87
+ | 选项 | 类型 | 说明 |
88
+ |------|------|------|
89
+ | `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
90
+ | `--tenant` | string | 租户代码 |
91
+ | `--dry-run` | boolean | 预览模式(不实际调用API) |
92
+ | `--json` | boolean | JSON输出 |
93
+
94
+ ### 命令选项
95
+ | 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 | 对应DTO字段 |
96
+ |------|--------|------|------|--------|------|-------------|
97
+ | --name | -n | string | ✅ | - | 员工姓名 | employeeName |
98
+ | --code | -c | string | ⬜ | 空(自动生成) | 员工编码 | employeeCode |
99
+ | --phone | -p | string | ⬜ | - | 手机号码 | employeePhone |
100
+ | --email | -e | string | ⬜ | - | 电子邮箱 | employeeEmail |
101
+ | --sex | -s | string | ⬜ | - | 性别 (M/F) | employeeSex |
102
+ | --org-id | — | number | ⬜ | - | 部门ID | organizationId |
103
+ | --position-id | — | string | ⬜ | - | 岗位ID | positionId |
104
+ | --joined-date | -d | string | ⬜ | - | 入职日期 (YYYY-MM-DD) | employeeJoinedDate |
105
+
106
+ ## 2.4 字段映射表
107
+
108
+ | CLI参数 | DTO字段 | 类型转换 | 验证规则 |
109
+ |---------|---------|----------|----------|
110
+ | --name / -n | employeeName | 直接传递 | @NotBlank, max=255 |
111
+ | --code / -c | employeeCode | 直接传递 | 可选,为空则自动生成 |
112
+ | --phone / -p | employeePhone | 直接传递 | 手机号格式 |
113
+ | --email / -e | employeeEmail | 直接传递 | 邮箱格式 |
114
+ | --sex / -s | employeeSex | 直接传递 | M 或 F |
115
+ | --org-id | organizationId | string→Long | - |
116
+ | --position-id | positionId | 直接传递 | - |
117
+ | --joined-date / -d | employeeJoinedDate | string→Date | yyyy-MM-dd |
118
+
119
+ **自动填充字段(不通过CLI参数):**
120
+ | 字段 | 值 |
121
+ |------|-----|
122
+ | tenantId | 来自 X-TENANT-ID header |
123
+ | statusFlag | 默认 1 (启用) |
124
+ | employeeNo | 必填,从 --no 参数获取或交互输入 |
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_CODE_FORMAT_CANNOT_EMPTY("01001150003", "职员编码规则不能为空")
135
+ ├── MASTER_EMPLOYEE_CODE_FORMAT_NOT_CORRECT("01001150004", "职员编码规则格式不正确")
136
+ ├── MASTER_EMPLOYEE_CODE_VALIDATE_EMPTY_ERROR("01001150006", "{}不能为空")
137
+ └── MASTER_EMPLOYEE_CODE_VALIDATE_NOT_EXIST_ERROR("01001150007", "指定{}不存在")
138
+ ```
139
+
140
+ ### 已知错误码
141
+ | 错误码 | 错误消息 | 触发条件 |
142
+ |--------|----------|----------|
143
+ | 01001150003 | 职员编码规则不能为空 | employeeCode 为空且系统未配置自动生成规则 |
144
+ | 01001150006 | xxx不能为空 | 必填字段缺失 |
145
+
146
+ ## 2.6 权限检查
147
+
148
+ | 检查项 | 位置 | 说明 |
149
+ |--------|------|------|
150
+ | PermissionConstants | `LibericaPermissionCodeConstants.ADD_EMPLOYEE` | Controller层 `@PostResource(requirePermissionCode = "ADD_EMPLOYEE")` |
151
+
152
+ ## 2.7 实现要点
153
+
154
+ 1. **必填字段**:--name 必须提供;employeeNo 通过位置参数或交互输入获取
155
+ 2. **自动生成编码**:employeeCode 为空时后端自动生成
156
+ 3. **Dry-run支持**:使用 --dry-run 时构造请求体但不发送,显示预览信息
157
+ 4. **默认statusFlag**:新建员工默认为启用状态(statusFlag=1)
158
+ 5. **tenantId来源**:来自 X-TENANT-ID header,不通过请求体传递
159
+
160
+ ## 2.8 示例用法
161
+
162
+ ```bash
163
+ # 交互式创建(引导输入必填字段)
164
+ barista liberica employees create
165
+
166
+ # 指定姓名和必填字段
167
+ barista liberica employees create --name "张三" --no "EMP001"
168
+
169
+ # 完整选项
170
+ barista liberica employees create \
171
+ --name "张三" \
172
+ --code "EMP001" \
173
+ --phone "13800138000" \
174
+ --email "zhangsan@example.com" \
175
+ --sex M \
176
+ --org-id 1001 \
177
+ --position-id "MANAGER" \
178
+ --joined-date 2024-01-15
179
+
180
+ # Dry-run 预览
181
+ barista liberica employees create --name "张三" --no "EMP001" --dry-run
182
+
183
+ # JSON 输出
184
+ barista liberica employees create --name "张三" --no "EMP001" --json
185
+ ```