All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m2s
- 移除 RegisterDataPermissionCallback 和 SkipDataPermission 机制 - 在 Auth 中间件预计算 SubordinateShopIDs 并注入 Context - 新增 ApplyShopFilter/ApplyEnterpriseFilter/ApplyOwnerShopFilter 等 Helper 函数 - 所有 Store 层查询方法显式调用数据权限过滤函数 - 权限检查函数 CanManageShop/CanManageEnterprise 改为从 Context 获取数据 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model"
|
|
"github.com/break/junhong_cmp_fiber/pkg/config"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func initDefaultAdmin(deps *Dependencies, services *services) error {
|
|
logger := deps.Logger
|
|
cfg := config.Get()
|
|
|
|
ctx := context.Background()
|
|
|
|
var count int64
|
|
if err := deps.DB.WithContext(ctx).Model(&model.Account{}).Where("user_type = ?", constants.UserTypeSuperAdmin).Count(&count).Error; err != nil {
|
|
logger.Error("检查超级管理员账号失败", zap.Error(err))
|
|
return nil
|
|
}
|
|
|
|
if count > 0 {
|
|
logger.Info("超级管理员账号已存在,跳过初始化", zap.Int64("count", count))
|
|
return nil
|
|
}
|
|
|
|
username := constants.DefaultAdminUsername
|
|
password := constants.DefaultAdminPassword
|
|
phone := constants.DefaultAdminPhone
|
|
|
|
if cfg.DefaultAdmin.Username != "" {
|
|
username = cfg.DefaultAdmin.Username
|
|
}
|
|
if cfg.DefaultAdmin.Password != "" {
|
|
password = cfg.DefaultAdmin.Password
|
|
}
|
|
if cfg.DefaultAdmin.Phone != "" {
|
|
phone = cfg.DefaultAdmin.Phone
|
|
}
|
|
|
|
account := &model.Account{
|
|
Username: username,
|
|
Phone: phone,
|
|
Password: password,
|
|
UserType: constants.UserTypeSuperAdmin,
|
|
Status: constants.StatusEnabled,
|
|
}
|
|
|
|
if err := services.Account.CreateSystemAccount(ctx, account); err != nil {
|
|
logger.Error("创建默认超级管理员失败", zap.Error(err), zap.String("username", username))
|
|
return nil
|
|
}
|
|
|
|
logger.Info("默认超级管理员创建成功", zap.String("username", username), zap.String("phone", phone))
|
|
return nil
|
|
}
|