feat(user): 动态查询VIP角色ID,避免硬编码绑定问题

- RoleParam新增tenantId字段,支持按租户过滤角色
- 新增getCurrentTenantId函数,兼容登录态及默认租户回退
- 实现getVipRoleId函数,按roleCode与tenantId查询VIP角色ID
- assignVipRole动态获取VIP角色ID,移除写死的角色ID
- 添加用户角色时传入tenantId,确保多租户环境中角色绑定正确
- 修复后端UserRoleController.save接口bug,避免userId被无条件覆盖
- 用户角色绑定时正确使用申请人userId,解决VIP审核角色误绑定问题
This commit is contained in:
2026-07-22 01:04:23 +08:00
parent eeb63efe9f
commit 12d6bdfb06
4 changed files with 31 additions and 14 deletions

View File

@@ -7,3 +7,9 @@
- `vip-review/index.tsx`:新增 `getCurrentTenantId()`(取自 `Taro.getStorageSync('TenantId') || TenantId`)与 `getVipRoleId()`(调用 `listRoles({ roleCode:'vip', tenantId })` 动态获取 roleId`assignVipRole` 改用动态 roleId并在 `addUserRole` 时带上 `tenantId`
- 导入补充:`listRoles` (from `@/api/system/role`)、`TenantId` (from `@/config/app`)。
- 约定VIP 角色以 `roleCode='vip'` 标识,不再依赖固定 roleId。
## 后端确认com.gxwebsoft.core
- `GET /api/system/role`:支持 `roleCode` 过滤(`RoleParam.roleCode``@QueryField(EQ)`)。✅
- 租户隔离由 MyBatis-Plus `TenantLineInnerInterceptor` 自动完成(`sys_role` 不在忽略表清单),租户取自请求头 `tenantId``PageParam.buildWrapper` 还会**显式跳过** `tenantId` 字段不拼 WHERE所以前端的 `tenantId` 查询参数不参与过滤——真正隔离靠请求头。`RoleParam.tenantId``@QueryField`,传了也被忽略,但功能正确(按当前租户返回 VIP 角色)。
- ⚠️ 关键 bug`POST /api/system/user-role`(save) 用 `getLoginUser().getUserId()` **无条件覆盖**请求体里的 `userId`。VIP 审核通过时,角色会被绑到当前登录的店员,而非申请人 `item.userId`。原硬编码版本也存在此问题。需与用户确认是否修复(建议:仅当请求体 userId 为空时才回退到登录用户)。
- 路径核对:前端 `SERVER_API_URL='.../api'``addUserRole` 命中 `/api/system/user-role`,一致。

View File

@@ -0,0 +1,8 @@
# 2026-07-22
## 修复 UserRoleController.save 覆盖 userId 的 bug
- 文件:`com.gxwebsoft.core/.../system/controller/UserRoleController.java`
- 问题:原 `save``getLoginUser().getUserId()` **无条件覆盖**请求体 userId导致 VIP 审核通过时角色绑到店员而非申请人。
- 修复:改为 `if (userRole.getUserId() == null && loginUser != null) userRole.setUserId(loginUser.getUserId());`(仅当请求体未传 userId 时回退到登录用户)。
- 影响VIP 审核 `addUserRole({ userId: item.userId, ... })` 现在能正确把角色绑给申请人;其它不传 userId 的调用方行为不变。
- 注意UserRole 的 `tenantId` 由 MyBatis-Plus 多租户插件按请求头自动写入 INSERT前端传的 tenantId 仅作冗余。