Files
jx-callback/business/jxstore/cms/permission.go
苏尹岚 49ef3ed9e0 改名
2020-09-27 13:55:31 +08:00

41 lines
982 B
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.
package cms
import (
"fmt"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
)
func GetMenu(ctx *jxcontext.Context) (menus []*model.Menu, err error) {
return dao.GetMenu(dao.GetDB(), "", 0)
}
func AddMenu(ctx *jxcontext.Context, menu *model.Menu) (err error) {
var (
db = dao.GetDB()
)
if menu == nil {
return fmt.Errorf("添加失败function nil")
}
if menu.Name == "" || menu.Level == 0 {
return fmt.Errorf("添加失败function 名称和等级必须有值!")
}
menus, err := dao.GetMenu(db, menu.Name, menu.Level)
if len(menus) > 0 {
return fmt.Errorf("添加失败!已存在相同名称的 fuction name : %v", menu.Name)
}
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
dao.WrapAddIDCULDEntity(menu, ctx.GetUserName())
err = dao.CreateEntity(db, menu)
dao.Commit(db)
return err
}