service.xpcool.com/internal/dao/internal/admin_user.go
夏犀麟 3d24dbd8cb feat(auth): 认证链路联调修复——401 语义化 + 登出撤销会话 + 零配置兜底
- 未授权响应改为 HTTP 401(原 200+code10002 vben 拦截器不识别,
  token 过期永远不触发静默刷新/重登)
- 新增 response.JSONWithStatus;三处 401(UserAuth/AdminAuthOnly/AdminAuth)切换
- LogoutReq 支持 refreshToken:登出时撤销刷新会话(幂等),阻止设备续期;
  Refresh 时顺带清理已过期会话行
- IAdminAuth 新增 Revoke;dao/internal/admin_user.go 补 bark_device_id/
  pushplus_token 列映射(与 016 SQL/0569c70 对齐,恢复 int/gtime 类型映射)
- injectEnv 开发模式兜底: 等占位符未注入 env 时回填本地默认 DSN,
  任何启动方式(GoLand/命令行/go run)零配置可跑;prod 不兜底
2026-08-27 23:00:53 +08:00

100 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==========================================================================
// 本文件由 GoFrame CLI 工具生成并维护,请勿编辑。
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// AdminUserDao 是表 admin_user 的数据访问对象。
type AdminUserDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns AdminUserColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// AdminUserColumns 定义并存储表 admin_user 的列名。
type AdminUserColumns struct {
Id string //
Username string //
PasswordHash string //
Nickname string //
Status string //
BarkDeviceId string //
PushplusToken string //
LastLoginAt string //
CreatedAt string //
UpdatedAt string //
DeletedAt string //
}
// adminUserColumns 保存表 admin_user 的列信息。
var adminUserColumns = AdminUserColumns{
Id: "id",
Username: "username",
PasswordHash: "password_hash",
Nickname: "nickname",
Status: "status",
BarkDeviceId: "bark_device_id",
PushplusToken: "pushplus_token",
LastLoginAt: "last_login_at",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewAdminUserDao 创建并返回一个新的表数据访问 DAO 对象。
func NewAdminUserDao(handlers ...gdb.ModelHandler) *AdminUserDao {
return &AdminUserDao{
group: "default",
table: "admin_user",
columns: adminUserColumns,
handlers: handlers,
}
}
// DB 获取并返回当前 DAO 的底层原始数据库管理对象。
func (dao *AdminUserDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table 返回当前 DAO 的表名。
func (dao *AdminUserDao) Table() string {
return dao.table
}
// Columns 返回当前 DAO 的全部列名。
func (dao *AdminUserDao) Columns() AdminUserColumns {
return dao.columns
}
// Group 返回当前 DAO 的数据库配置组名。
func (dao *AdminUserDao) Group() string {
return dao.group
}
// Ctx 为当前 DAO 创建并返回一个 Model自动设置本次操作的上下文。
func (dao *AdminUserDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction 使用函数 f 包裹事务逻辑。
// 若 f 返回非 nil 错误,则回滚事务并返回该错误。
// 若 f 返回 nil则提交事务并返回 nil。
//
// 注意:请勿在函数 f 内提交或回滚事务,
// 该函数会自动处理。
func (dao *AdminUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}