This commit is contained in:
苏尹岚
2020-09-27 13:55:31 +08:00
parent 8f93d2f8de
commit 49ef3ed9e0
4 changed files with 29 additions and 29 deletions

View File

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