Commit 6c97d7ef1eb0bd6dd53ddc4c6f570c1c08d392f2

Authored by zichun
1 parent c8f6f04e

chore(usr): docs/05 去 password 字段 + ErrorCode 新增 40301/40901/40902 REQ-USR-002

backend/src/main/java/com/xly/erp/common/response/ErrorCode.java
@@ -16,8 +16,13 @@ public final class ErrorCode { @@ -16,8 +16,13 @@ public final class ErrorCode {
16 public static final int BAD_CREDENTIALS = 40101; 16 public static final int BAD_CREDENTIALS = 40101;
17 public static final int ACCOUNT_DELETED = 40103; 17 public static final int ACCOUNT_DELETED = 40103;
18 18
  19 + public static final int FORBIDDEN = 40301;
  20 +
19 public static final int ACCOUNT_LOCKED = 42301; 21 public static final int ACCOUNT_LOCKED = 42301;
20 22
  23 + public static final int CONFLICT_USERNAME = 40901;
  24 + public static final int CONFLICT_USERCODE = 40902;
  25 +
21 public static final int INTERNAL_ERROR = 50000; 26 public static final int INTERNAL_ERROR = 50000;
22 27
23 /** 28 /**
@@ -31,6 +36,7 @@ public final class ErrorCode { @@ -31,6 +36,7 @@ public final class ErrorCode {
31 if (hundreds == 401) return 401; 36 if (hundreds == 401) return 401;
32 if (hundreds == 403) return 403; 37 if (hundreds == 403) return 403;
33 if (hundreds == 404) return 404; 38 if (hundreds == 404) return 404;
  39 + if (hundreds == 409) return 409;
34 if (hundreds == 423) return 423; 40 if (hundreds == 423) return 423;
35 if (hundreds == 500) return 500; 41 if (hundreds == 500) return 500;
36 return 500; 42 return 500;
backend/src/test/java/com/xly/erp/common/response/ErrorCodeTest.java 0 → 100644
  1 +package com.xly.erp.common.response;
  2 +
  3 +import org.junit.jupiter.api.Test;
  4 +
  5 +import static org.junit.jupiter.api.Assertions.assertEquals;
  6 +
  7 +class ErrorCodeTest {
  8 +
  9 + @Test
  10 + void httpMappings_coverNewCodes() {
  11 + assertEquals(403, ErrorCode.toHttpStatus(ErrorCode.FORBIDDEN));
  12 + assertEquals(409, ErrorCode.toHttpStatus(ErrorCode.CONFLICT_USERNAME));
  13 + assertEquals(409, ErrorCode.toHttpStatus(ErrorCode.CONFLICT_USERCODE));
  14 + assertEquals(40301, ErrorCode.FORBIDDEN);
  15 + assertEquals(40901, ErrorCode.CONFLICT_USERNAME);
  16 + assertEquals(40902, ErrorCode.CONFLICT_USERCODE);
  17 + }
  18 +
  19 + @Test
  20 + void httpMappings_existingCodes_unchanged() {
  21 + assertEquals(200, ErrorCode.toHttpStatus(ErrorCode.OK));
  22 + assertEquals(400, ErrorCode.toHttpStatus(ErrorCode.BAD_REQUEST));
  23 + assertEquals(400, ErrorCode.toHttpStatus(ErrorCode.COMPANY_NOT_FOUND));
  24 + assertEquals(401, ErrorCode.toHttpStatus(ErrorCode.BAD_CREDENTIALS));
  25 + assertEquals(401, ErrorCode.toHttpStatus(ErrorCode.ACCOUNT_DELETED));
  26 + assertEquals(423, ErrorCode.toHttpStatus(ErrorCode.ACCOUNT_LOCKED));
  27 + assertEquals(500, ErrorCode.toHttpStatus(ErrorCode.INTERNAL_ERROR));
  28 + }
  29 +}
docs/05-API接口契约.md
@@ -71,16 +71,16 @@ BasePath: `/api/v1` @@ -71,16 +71,16 @@ BasePath: `/api/v1`
71 - **Method**: POST 71 - **Method**: POST
72 - **Path**: `/api/v1/users` 72 - **Path**: `/api/v1/users`
73 - **Auth**: Bearer Token;仅 `userType=SUPER_ADMIN` 可调用 73 - **Auth**: Bearer Token;仅 `userType=SUPER_ADMIN` 可调用
74 -- **请求**: JSON body `CreateUserReq { username: string (3-20), userCode: string, password: string (8-20 含大小写字母和数字), userType: "NORMAL"|"SUPER_ADMIN", language: "zh-CN"|"en-US"|"zh-TW", canEditDocument: boolean, employeeId?: int, permissionCategoryIds: int[] }`  
75 -- **响应**: JSON `UserVo { userId: int, username: string }`(HTTP 201) 74 +- **请求**: JSON body `CreateUserReq { username: string (3-20,正则 ^[A-Za-z0-9_]{3,20}$), userCode: string (max 50), userType: "NORMAL"|"SUPER_ADMIN", language: "zh-CN"|"en-US"|"zh-TW", canEditDocument: boolean, employeeId?: int, permissionCategoryIds?: int[] }`。**初始密码由系统统一设为 `"666666"`(BCrypt 哈希后入库),请求体不接受 `password` 字段(出现即返 40001)。**
  75 +- **响应**: JSON `CreateUserVo { userId: int, username: string, userCode: string }`(HTTP 201)
76 76
77 #### 错误码 77 #### 错误码
78 -- `40001` — 必填字段缺失或格式错误  
79 -- `40002` — 密码强度不满足(少于 8 位 / 缺大小写字母 / 缺数字) 78 +- `40001` — 必填字段缺失或格式错误(含携带未知字段如 `password`)
  79 +- `40004` — 指定的员工 / 权限分类不存在
  80 +- `40101` — 未携带或无效 Token
80 - `40301` — 当前用户非超级管理员,无权调用 81 - `40301` — 当前用户非超级管理员,无权调用
81 - `40901` — 用户名已存在 82 - `40901` — 用户名已存在
82 - `40902` — 用户号已存在 83 - `40902` — 用户号已存在
83 -- `40004` — 指定的员工 / 权限分类不存在  
84 84
85 ### REQ-USR-003 修改用户 85 ### REQ-USR-003 修改用户
86 86