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
}

View File

@@ -5,10 +5,10 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func GetFunction(db *DaoDB, name string, level int) (functions []*model.Function, err error) {
func GetMenu(db *DaoDB, name string, level int) (menus []*model.Menu, err error) {
sql := `
SELECT *
FROM function
FROM menu
WHERE deleted_at = ?
`
sqlParams := []interface{}{
@@ -22,6 +22,6 @@ func GetFunction(db *DaoDB, name string, level int) (functions []*model.Function
sql += " AND level = ?"
sqlParams = append(sqlParams, level)
}
err = GetRows(db, &functions, sql, sqlParams)
return functions, err
err = GetRows(db, &menus, sql, sqlParams)
return menus, err
}

View File

@@ -14,15 +14,15 @@ type PowerController struct {
// @Title 添加功能(菜单)
// @Description 添加功能(菜单)
// @Param token header string true "认证token"
// @Param payload formData string true "Function json实体"
// @Param payload formData string true "Menu json实体"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /AddFunction [post]
func (c *PowerController) AddFunction() {
c.callAddFunction(func(params *tPowerAddFunctionParams) (retVal interface{}, errCode string, err error) {
function := &model.Function{}
if err = utils.UnmarshalUseNumber([]byte(params.Payload), function); err == nil {
err = cms.AddFunction(params.Ctx, function)
// @router /AddMenu [post]
func (c *PowerController) AddMenu() {
c.callAddMenu(func(params *tPowerAddMenuParams) (retVal interface{}, errCode string, err error) {
menu := &model.Menu{}
if err = utils.UnmarshalUseNumber([]byte(params.Payload), menu); err == nil {
err = cms.AddMenu(params.Ctx, menu)
}
return retVal, "", err
})
@@ -33,10 +33,10 @@ func (c *PowerController) AddFunction() {
// @Param token header string true "认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetFunction [post]
func (c *PowerController) GetFunction() {
c.callGetFunction(func(params *tPowerGetFunctionParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetFunction(params.Ctx)
// @router /GetMenu [post]
func (c *PowerController) GetMenu() {
c.callGetMenu(func(params *tPowerGetMenuParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetMenu(params.Ctx)
return retVal, "", err
})
}

View File

@@ -1433,8 +1433,8 @@ func init() {
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PowerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PowerController"],
beego.ControllerComments{
Method: "AddFunction",
Router: `/AddFunction`,
Method: "AddMenu",
Router: `/AddMenu`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
@@ -1442,8 +1442,8 @@ func init() {
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PowerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PowerController"],
beego.ControllerComments{
Method: "GetFunction",
Router: `/GetFunction`,
Method: "GetMenu",
Router: `/GetMenu`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,