本次提交完成了角色权限体系的重构,主要包括: 1. 数据库迁移 - 添加 tb_permission.platform 字段(all/web/h5) - 更新 tb_role.role_type 注释(1=平台角色,2=客户角色) 2. GORM 模型更新 - Permission 模型添加 Platform 字段 - Role 模型更新 RoleType 注释 3. 常量定义 - 新增角色类型常量(RoleTypePlatform, RoleTypeCustomer) - 新增权限端口常量(PlatformAll, PlatformWeb, PlatformH5) - 添加角色类型与用户类型匹配规则函数 4. Store 层实现 - Permission Store 支持按 platform 过滤 - Account Role Store 添加 CountByAccountID 方法 5. Service 层实现 - 角色分配支持类型匹配校验 - 角色分配支持数量限制(超级管理员0个,平台用户无限制,代理/企业1个) - Permission Service 支持 platform 过滤 6. 权限校验中间件 - 实现 RequirePermission、RequireAnyPermission、RequireAllPermissions - 支持 platform 字段过滤 - 支持跳过超级管理员检查 7. 测试用例 - 角色类型匹配规则单元测试 - 角色分配数量限制单元测试 - 权限 platform 过滤单元测试 - 权限校验中间件集成测试(占位) 8. 代码清理 - 删除过时的 subordinate 测试文件 - 移除 Account.ParentID 相关引用 - 更新 DTO 验证规则 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
package constants
|
||
|
||
import "time"
|
||
|
||
// Fiber Locals 的上下文键
|
||
const (
|
||
ContextKeyRequestID = "requestid" // 请求记录ID
|
||
ContextKeyStartTime = "start_time" //请求开始时间
|
||
ContextKeyUserID = "user_id" // 用户ID
|
||
ContextKeyUserType = "user_type" //用户类型
|
||
ContextKeyShopID = "shop_id" //店铺ID
|
||
ContextKeyUserInfo = "user_info" //完整的用户信息
|
||
)
|
||
|
||
// 配置环境变量
|
||
const (
|
||
EnvConfigPath = "CONFIG_PATH"
|
||
EnvConfigEnv = "CONFIG_ENV" // dev, staging, prod
|
||
)
|
||
|
||
// 默认配置值
|
||
const (
|
||
DefaultConfigPath = "configs/config.yaml"
|
||
DefaultServerAddr = ":3000"
|
||
DefaultRedisAddr = "localhost:6379"
|
||
)
|
||
|
||
// 数据库配置常量
|
||
const (
|
||
DefaultMaxOpenConns = 25
|
||
DefaultMaxIdleConns = 10
|
||
DefaultConnMaxLifetime = 5 * time.Minute
|
||
DefaultPageSize = 20
|
||
MaxPageSize = 100
|
||
SlowQueryThreshold = 100 * time.Millisecond
|
||
)
|
||
|
||
// 任务类型常量
|
||
const (
|
||
TaskTypeEmailSend = "email:send" // 发送邮件
|
||
TaskTypeDataSync = "data:sync" // 数据同步
|
||
TaskTypeSIMStatusSync = "sim:status:sync" // SIM 卡状态同步
|
||
TaskTypeCommission = "commission:calculate" // 分佣计算
|
||
)
|
||
|
||
// 用户状态常量
|
||
const (
|
||
UserStatusActive = "active" // 激活
|
||
UserStatusInactive = "inactive" // 未激活
|
||
UserStatusSuspended = "suspended" // 暂停
|
||
)
|
||
|
||
// RBAC 用户类型常量
|
||
const (
|
||
UserTypeSuperAdmin = 1 // 超级管理员(跳过数据权限过滤)
|
||
UserTypePlatform = 2 // 平台用户
|
||
UserTypeAgent = 3 // 代理账号
|
||
UserTypeEnterprise = 4 // 企业账号
|
||
)
|
||
|
||
// RBAC 角色类型常量
|
||
const (
|
||
RoleTypePlatform = 1 // 平台角色(适用于平台用户)
|
||
RoleTypeCustomer = 2 // 客户角色(适用于代理/企业账号)
|
||
)
|
||
|
||
// RBAC 权限类型常量
|
||
const (
|
||
PermissionTypeMenu = 1 // 菜单权限
|
||
PermissionTypeButton = 2 // 按钮权限
|
||
)
|
||
|
||
// RBAC 权限端口常量
|
||
const (
|
||
PlatformAll = "all" // 全部端口(Web + H5)
|
||
PlatformWeb = "web" // Web 后台
|
||
PlatformH5 = "h5" // H5 端
|
||
)
|
||
|
||
// RBAC 状态常量
|
||
const (
|
||
StatusDisabled = 0 // 禁用
|
||
StatusEnabled = 1 // 启用
|
||
)
|
||
|
||
// 订单状态常量
|
||
const (
|
||
OrderStatusPending = "pending" // 待支付
|
||
OrderStatusPaid = "paid" // 已支付
|
||
OrderStatusProcessing = "processing" // 处理中
|
||
OrderStatusCompleted = "completed" // 已完成
|
||
OrderStatusCancelled = "cancelled" // 已取消
|
||
)
|
||
|
||
// 队列配置常量
|
||
const (
|
||
QueueCritical = "critical" // 关键任务队列
|
||
QueueDefault = "default" // 默认队列
|
||
QueueLow = "low" // 低优先级队列
|
||
DefaultRetryMax = 5
|
||
DefaultTimeout = 10 * time.Minute
|
||
DefaultConcurrency = 10
|
||
)
|
||
|
||
// 店铺配置常量
|
||
const (
|
||
MaxShopLevel = 7 // 店铺最大层级
|
||
)
|