fix(admin): standardize resource initialization and lists
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -11,16 +12,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// PlatformRootUsername 是平台总后台的内置根账号名称。
|
||||
PlatformRootUsername = "root"
|
||||
// PlatformRootPassword 是仅用于首次启动的初始密码,首次登录后必须修改。
|
||||
PlatformRootPassword = "Heqi@Root2026"
|
||||
// PlatformRootRoleCode 表示根账号的平台角色。
|
||||
PlatformRootRoleCode = "root"
|
||||
)
|
||||
|
||||
// InitPlatformAccess 幂等初始化 root 角色;菜单定义位于逻辑层静态数据中。
|
||||
func InitPlatformAccess(database *gorm.DB) error {
|
||||
// InitPlatformAccess 幂等初始化平台根角色;菜单定义位于逻辑层静态数据中。
|
||||
func InitPlatformAccess() error {
|
||||
rootRole := models.PlatformRole{
|
||||
Entity: models.Entity{Identity: models.NewIdentity(), Status: common.StatusEnable},
|
||||
RoleCode: PlatformRootRoleCode,
|
||||
@@ -28,13 +26,13 @@ func InitPlatformAccess(database *gorm.DB) error {
|
||||
LocationScope: "precise",
|
||||
IsSystem: true,
|
||||
}
|
||||
return database.Where("role_code = ?", rootRole.RoleCode).FirstOrCreate(&rootRole).Error
|
||||
return impl.DBService.Where("role_code = ?", rootRole.RoleCode).FirstOrCreate(&rootRole).Error
|
||||
}
|
||||
|
||||
// InitPlatformRoot 幂等创建平台总后台 root 账号。
|
||||
func InitPlatformRoot(database *gorm.DB) error {
|
||||
// InitPlatformRoot 幂等创建平台总后台 root 账户。
|
||||
func InitPlatformRoot() error {
|
||||
var account models.PlatformAccount
|
||||
err := database.Where("username = ?", PlatformRootUsername).First(&account).Error
|
||||
err := impl.DBService.Where("username = ?", PlatformRootUsername).First(&account).Error
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -55,7 +53,7 @@ func InitPlatformRoot(database *gorm.DB) error {
|
||||
PlatformRoleCode: PlatformRootRoleCode,
|
||||
Phone: "",
|
||||
}
|
||||
return database.Create(&account).Error
|
||||
return impl.DBService.Create(&account).Error
|
||||
}
|
||||
|
||||
// platformRootPassword 优先读取部署环境传入的 root 初始密码。
|
||||
|
||||
Reference in New Issue
Block a user