Version: 0.9.66.dev.260504
后端: 1. 阶段 2 user/auth 服务边界落地,新增 `cmd/userauth` go-zero zrpc 服务、`services/userauth` 核心实现、gateway user API/zrpc client 与 shared contracts/ports,迁移注册、登录、刷新 token、登出、JWT、黑名单和 token 额度治理 2. gateway 与启动装配切流,`cmd/all` 只保留边缘路由、鉴权和轻量组合,通过 userauth zrpc 访问核心用户能力;拆分 MySQL/Redis 初始化与 AutoMigrate 边界,`userauth` 自迁 `users` 和 token 记账幂等表,`all` 不再迁用户表 3. 清退 Gin 单体旧 user/auth DAO、model、service、router、middleware 和 JWT handler,并同步调整 agent/schedule/cache/outbox 相关调用依赖 4. 补齐 refresh token 防并发重放、MySQL 幂等 token 记账、额度 `>=` 拦截和 RPC 错误映射,避免重复记账与内部错误透出 文档: 1. 新增《学习计划论坛与Token商店PRD》
This commit is contained in:
20
backend/services/userauth/model/token_usage_adjustment.go
Normal file
20
backend/services/userauth/model/token_usage_adjustment.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// TokenUsageAdjustment 是 user/auth 服务内的 token 账本幂等表。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只记录“某个 outbox/event_id 是否已经调整过 users.token_usage”;
|
||||
// 2. 不保存 agent 会话 token_total,那个统计仍属于 agent 领域;
|
||||
// 3. event_id 作为主键,配合 users.token_usage 更新放在同一个 MySQL 事务里,避免并发重放重复记账。
|
||||
type TokenUsageAdjustment struct {
|
||||
EventID string `gorm:"column:event_id;type:varchar(64);primaryKey;comment:来源事件ID"`
|
||||
UserID int `gorm:"column:user_id;not null;index:idx_userauth_token_adjust_user;comment:用户ID"`
|
||||
TokenDelta int `gorm:"column:token_delta;not null;comment:本次增加的 token 用量"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime;comment:创建时间"`
|
||||
}
|
||||
|
||||
func (TokenUsageAdjustment) TableName() string {
|
||||
return "user_token_usage_adjustments"
|
||||
}
|
||||
19
backend/services/userauth/model/user.go
Normal file
19
backend/services/userauth/model/user.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// User 是 user/auth 服务内部拥有的 users 表模型。
|
||||
// 职责边界:只覆盖 user/auth 需要维护的字段,不承载 gateway 或其他领域规则。
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Username string `gorm:"type:varchar(255);not null;unique" json:"username"`
|
||||
Password string `gorm:"type:varchar(255);not null" json:"-"`
|
||||
PhoneNumber string `gorm:"type:varchar(255)" json:"phone_number"`
|
||||
TokenLimit int `gorm:"default:100000" json:"token_limit"`
|
||||
TokenUsage int `gorm:"default:0" json:"token_usage"`
|
||||
LastResetAt time.Time `json:"last_reset_at"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
Reference in New Issue
Block a user