feat: 添加角色类型常量及用户主角色获取方法

This commit is contained in:
unclesam committed 2026-07-08 08:19:51 +08:00
1 parent c5977ce354
commit 20ad8115da
14 files changed
+123 -64

No files matched your search

+3 -2
View File
@@ -5,6 +5,7 @@ import (
"EnGin/internal/ent"
"EnGin/internal/ent/role"
"EnGin/internal/global"
"EnGin/internal/utils/ctype"
"EnGin/internal/utils/pwd"
"bufio"
"context"
@@ -52,14 +53,14 @@ var userCreateCmd = &cobra.Command{
// 尝试查询 admin 角色
adminRole, err := db.Client.Role.Query().
Where(role.CodeEQ("admin")).
Where(role.CodeEQ(ctype.Admin)).
Only(ctx)
if err != nil {
if ent.IsNotFound(err) {
// 如果不存在 admin 角色,自动创建
adminRole, err = db.Client.Role.Create().
SetCode("admin").
SetCode(ctype.Admin).
SetName("超级管理员").
Save(ctx)
if err != nil {