commit
19b174f858
|
@ -70,7 +70,7 @@ func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
|
|||
response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c)
|
||||
}
|
||||
|
||||
// Packaged
|
||||
// InitMenu
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 打包插件
|
||||
// @Security ApiKeyAuth
|
||||
|
@ -94,7 +94,7 @@ func (a *AutoCodePluginApi) InitMenu(c *gin.Context) {
|
|||
response.OkWithMessage("文件变更成功", c)
|
||||
}
|
||||
|
||||
// Packaged
|
||||
// InitAPI
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 打包插件
|
||||
// @Security ApiKeyAuth
|
||||
|
|
|
@ -82,7 +82,7 @@ func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// Create
|
||||
// AddFunc
|
||||
// @Tags AddFunc
|
||||
// @Summary 增加方法
|
||||
// @Security ApiKeyAuth
|
||||
|
|
|
@ -18,7 +18,7 @@ func init() {
|
|||
system.RegisterInit(initOrderEnsureTables, &ensureTables{})
|
||||
}
|
||||
|
||||
func (ensureTables) InitializerName() string {
|
||||
func (e *ensureTables) InitializerName() string {
|
||||
return "ensure_tables_created"
|
||||
}
|
||||
func (e *ensureTables) InitializeData(ctx context.Context) (next context.Context, err error) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
package initialize
|
||||
|
||||
/*
|
||||
* @Author: 逆光飞翔 191180776@qq.com
|
||||
* @Date: 2022-12-08 17:25:49
|
||||
|
@ -6,7 +8,6 @@
|
|||
* @FilePath: \server\initialize\gorm_mssql.go
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/config"
|
||||
|
@ -44,8 +45,8 @@ func GormMssqlByConfig(m config.Mssql) *gorm.DB {
|
|||
return nil
|
||||
}
|
||||
mssqlConfig := sqlserver.Config{
|
||||
DSN: m.Dsn(), // DSN data source name
|
||||
DefaultStringSize: 191, // string 类型字段的默认长度
|
||||
DSN: m.Dsn(), // DSN data source name
|
||||
DefaultStringSize: 191, // string 类型字段的默认长度
|
||||
}
|
||||
if db, err := gorm.Open(sqlserver.New(mssqlConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package request
|
||||
|
||||
// Casbin info structure
|
||||
// CasbinInfo Casbin info structure
|
||||
type CasbinInfo struct {
|
||||
Path string `json:"path"` // 路径
|
||||
Method string `json:"method"` // 方法
|
||||
}
|
||||
|
||||
// Casbin structure for input parameters
|
||||
// CasbinInReceive Casbin structure for input parameters
|
||||
type CasbinInReceive struct {
|
||||
AuthorityId uint `json:"authorityId"` // 权限id
|
||||
CasbinInfos []CasbinInfo `json:"casbinInfos"`
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
)
|
||||
|
||||
// Add menu authority info structure
|
||||
// AddMenuAuthorityInfo Add menu authority info structure
|
||||
type AddMenuAuthorityInfo struct {
|
||||
Menus []system.SysBaseMenu `json:"menus"`
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
|
|
|
@ -18,7 +18,7 @@ type Register struct {
|
|||
Email string `json:"email" example:"电子邮箱"`
|
||||
}
|
||||
|
||||
// User login structure
|
||||
// Login User login structure
|
||||
type Login struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
|
@ -26,19 +26,19 @@ type Login struct {
|
|||
CaptchaId string `json:"captchaId"` // 验证码ID
|
||||
}
|
||||
|
||||
// Modify password structure
|
||||
// ChangePasswordReq Modify password structure
|
||||
type ChangePasswordReq struct {
|
||||
ID uint `json:"-"` // 从 JWT 中提取 user id,避免越权
|
||||
Password string `json:"password"` // 密码
|
||||
NewPassword string `json:"newPassword"` // 新密码
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
// SetUserAuth Modify user's auth structure
|
||||
type SetUserAuth struct {
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
// SetUserAuthorities Modify user's auth structure
|
||||
type SetUserAuthorities struct {
|
||||
ID uint
|
||||
AuthorityIds []uint `json:"authorityIds"` // 角色ID
|
||||
|
|
|
@ -58,7 +58,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st
|
|||
func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, filePath string) error {
|
||||
var chunks []example.ExaFileChunk
|
||||
var file example.ExaFile
|
||||
err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file).
|
||||
err := global.GVA_DB.Where("file_md5 = ?", fileMd5).First(&file).
|
||||
Updates(map[string]interface{}{
|
||||
"IsFinish": true,
|
||||
"file_path": filePath,
|
||||
|
|
|
@ -169,8 +169,8 @@ func (casbinService *CasbinService) AddPolicies(db *gorm.DB, rules [][]string) e
|
|||
return db.Create(&casbinRules).Error
|
||||
}
|
||||
|
||||
func (CasbinService *CasbinService) FreshCasbin() (err error) {
|
||||
e := CasbinService.Casbin()
|
||||
func (casbinService *CasbinService) FreshCasbin() (err error) {
|
||||
e := casbinService.Casbin()
|
||||
err = e.LoadPolicy()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (i *initExaFileMysql) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&example.ExaFileUploadAndDownload{})
|
||||
}
|
||||
|
||||
func (i initExaFileMysql) InitializerName() string {
|
||||
func (i *initExaFileMysql) InitializerName() string {
|
||||
return example.ExaFileUploadAndDownload{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderApi, &initApi{})
|
||||
}
|
||||
|
||||
func (i initApi) InitializerName() string {
|
||||
func (i *initApi) InitializerName() string {
|
||||
return sysModel.SysApi{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderApiIgnore, &initApiIgnore{})
|
||||
}
|
||||
|
||||
func (i initApiIgnore) InitializerName() string {
|
||||
func (i *initApiIgnore) InitializerName() string {
|
||||
return sysModel.SysIgnoreApi{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ func (i *initMenuAuthority) TableCreated(ctx context.Context) bool {
|
|||
return false // always replace
|
||||
}
|
||||
|
||||
func (i initMenuAuthority) InitializerName() string {
|
||||
func (i *initMenuAuthority) InitializerName() string {
|
||||
return "sys_menu_authorities"
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,13 @@ func (i *initMenuAuthority) InitializeData(ctx context.Context) (next context.Co
|
|||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
authorities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority)
|
||||
initAuth := &initAuthority{}
|
||||
authorities, ok := ctx.Value(initAuth.InitializerName()).([]sysModel.SysAuthority)
|
||||
if !ok {
|
||||
return ctx, errors.Wrap(system.ErrMissingDependentContext, "创建 [菜单-权限] 关联失败, 未找到权限表初始化数据")
|
||||
}
|
||||
menus, ok := ctx.Value(initMenu{}.InitializerName()).([]sysModel.SysBaseMenu)
|
||||
initMen := &initMenu{}
|
||||
menus, ok := ctx.Value(initMen.InitializerName()).([]sysModel.SysBaseMenu)
|
||||
if !ok {
|
||||
return next, errors.Wrap(errors.New(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initAuthority) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysAuthority{})
|
||||
}
|
||||
|
||||
func (i initAuthority) InitializerName() string {
|
||||
func (i *initAuthority) InitializerName() string {
|
||||
return sysModel.SysAuthority{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initCasbin) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&adapter.CasbinRule{})
|
||||
}
|
||||
|
||||
func (i initCasbin) InitializerName() string {
|
||||
func (i *initCasbin) InitializerName() string {
|
||||
var entity adapter.CasbinRule
|
||||
return entity.TableName()
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (i *initDict) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysDictionary{})
|
||||
}
|
||||
|
||||
func (i initDict) InitializerName() string {
|
||||
func (i *initDict) InitializerName() string {
|
||||
return sysModel.SysDictionary{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initDictDetail) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysDictionaryDetail{})
|
||||
}
|
||||
|
||||
func (i initDictDetail) InitializerName() string {
|
||||
func (i *initDictDetail) InitializerName() string {
|
||||
return sysModel.SysDictionaryDetail{}.TableName()
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,9 @@ func (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, e
|
|||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary)
|
||||
dictKey := (&initDict{}).InitializerName()
|
||||
dicts, ok := ctx.Value(dictKey).([]sysModel.SysDictionary)
|
||||
//dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary)
|
||||
if !ok {
|
||||
return ctx, errors.Wrap(system.ErrMissingDependentContext,
|
||||
fmt.Sprintf("未找到 %s 表初始化数据", sysModel.SysDictionary{}.TableName()))
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{})
|
||||
}
|
||||
|
||||
func (i initExcelTemplate) InitializerName() string {
|
||||
func (i *initExcelTemplate) InitializerName() string {
|
||||
return "sys_export_templates"
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ func init() {
|
|||
system.RegisterInit(initOrderMenu, &initMenu{})
|
||||
}
|
||||
|
||||
func (i initMenu) InitializerName() string {
|
||||
func (i *initMenu) InitializerName() string {
|
||||
return SysBaseMenu{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func (i *initUser) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysUser{})
|
||||
}
|
||||
|
||||
func (i initUser) InitializerName() string {
|
||||
func (i *initUser) InitializerName() string {
|
||||
return sysModel.SysUser{}.TableName()
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ func (i *initUser) InitializeData(ctx context.Context) (next context.Context, er
|
|||
return ctx, errors.Wrap(err, sysModel.SysUser{}.TableName()+"表数据初始化失败!")
|
||||
}
|
||||
next = context.WithValue(ctx, i.InitializerName(), entities)
|
||||
authorityEntities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority)
|
||||
initAuth := &initAuthority{}
|
||||
authorityEntities, ok := ctx.Value(initAuth.InitializerName()).([]sysModel.SysAuthority)
|
||||
if !ok {
|
||||
return next, errors.Wrap(system.ErrMissingDependentContext, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据")
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ func CreateApiStructAst(apis []system.SysApi) *[]ast.Expr {
|
|||
return &apiElts
|
||||
}
|
||||
|
||||
// 检查是否存在Import
|
||||
// CheckImport 检查是否存在Import
|
||||
func CheckImport(file *ast.File, importPath string) bool {
|
||||
for _, imp := range file.Imports {
|
||||
// Remove quotes around the import path
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// 自动为 gorm.go 注册一个自动迁移
|
||||
// AddRegisterTablesAst 自动为 gorm.go 注册一个自动迁移
|
||||
func AddRegisterTablesAst(path, funcName, pk, varName, dbName, model string) {
|
||||
modelPk := fmt.Sprintf("github.com/flipped-aurora/gin-vue-admin/server/model/%s", pk)
|
||||
src, err := os.ReadFile(path)
|
||||
|
@ -147,7 +147,7 @@ func addAutoMigrate(astBody *ast.BlockStmt, dbname string, pk string, model stri
|
|||
}
|
||||
}
|
||||
|
||||
// 为automigrate增加实参
|
||||
// NeedAppendModel 为automigrate增加实参
|
||||
func NeedAppendModel(callNode ast.Node, pk string, model string) bool {
|
||||
flag := true
|
||||
ast.Inspect(callNode, func(node ast.Node) bool {
|
||||
|
|
|
@ -68,7 +68,7 @@ func MaheHump(s string) string {
|
|||
return strings.Join(words, "")
|
||||
}
|
||||
|
||||
// 随机字符串
|
||||
// RandomString 随机字符串
|
||||
func RandomString(n int) string {
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
b := make([]rune, n)
|
||||
|
|
|
@ -43,7 +43,7 @@ func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims {
|
|||
return claims
|
||||
}
|
||||
|
||||
// 创建一个token
|
||||
// CreateToken 创建一个token
|
||||
func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString(j.SigningKey)
|
||||
|
@ -57,7 +57,7 @@ func (j *JWT) CreateTokenByOldToken(oldToken string, claims request.CustomClaims
|
|||
return v.(string), err
|
||||
}
|
||||
|
||||
// 解析 token
|
||||
// ParseToken 解析 token
|
||||
func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error) {
|
||||
token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (i interface{}, e error) {
|
||||
return j.SigningKey, nil
|
||||
|
|
|
@ -72,7 +72,7 @@ func (t *timer) AddTaskByFunc(cronName string, spec string, fun func(), taskName
|
|||
return id, err
|
||||
}
|
||||
|
||||
// AddTaskByFuncWithSeconds 通过函数的方法使用WithSeconds添加任务
|
||||
// AddTaskByFuncWithSecond 通过函数的方法使用WithSeconds添加任务
|
||||
func (t *timer) AddTaskByFuncWithSecond(cronName string, spec string, fun func(), taskName string, option ...cron.Option) (cron.EntryID, error) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
@ -186,7 +186,7 @@ func (t *timer) StopCron(cronName string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Remove 从cronName 删除指定任务
|
||||
// RemoveTask 从cronName 删除指定任务
|
||||
func (t *timer) RemoveTask(cronName string, id int) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
|
Loading…
Reference in New Issue