role_menu.go
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type RoleMenu struct {
Id int64 `orm:"column(id);auto" description:"主键"`
RoleId int64 `orm:"column(role_id);null" description:"role.id"`
MenuId int `orm:"column(menu_id);null" description:"menu.id"`
Opption string `orm:"column(opption);size(500);null" description:"配置"`
Code string `orm:"column(code)"`
}
func (t *RoleMenu) TableName() string {
return "role_menu"
}
func init() {
orm.RegisterModel(new(RoleMenu))
}
func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
var (
list []RoleMenu
err error
)
o := orm.NewOrm()
_, err = o.QueryTable(&RoleMenu{}).
Filter("role_id", roleid).
All(&list)
if err == orm.ErrNoRows {
return list, nil
}
return list, err
}
func GetRoleMenuByCode(roleId int64, code string) (*RoleMenu, error) {
var data RoleMenu
o := orm.NewOrm()
err := o.QueryTable(&RoleMenu{}).
Filter("role_id", roleId).
Filter("code", code).
One(&data)
fmt.Println(err)
if err != nil {
return nil, err
}
return &data, nil
}
func AddRoleMenu(m *RoleMenu, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
id, err = o.Insert(m)
return
}
func UpdateRoleMenuById(m *RoleMenu, col []string) error {
o := orm.NewOrm()
_, err := o.Update(m, col...)
return err
}