rbac_group.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package dbmodel
  2. import (
  3. "encoding/json"
  4. "github.com/astaxie/beego/orm"
  5. )
  6. type TGdAdminRbacGroup struct {
  7. Id int64 `json:"id"`
  8. Name string `json:"name"`
  9. RbacNodeList string `json:"rbac_node_list"`
  10. Custom int `json:"custom"`
  11. CreatedAt string `json:"created_at"`
  12. UpdatedAt string `json:"updated_at"`
  13. }
  14. func (p *TGdAdminRbacGroup) TableName() string {
  15. return "t_gd_admin_rbac_group"
  16. }
  17. func (p TGdAdminRbacGroup) String() string {
  18. vals, _ := json.Marshal(p)
  19. return string(vals)
  20. }
  21. func (p *TGdAdminRbacGroup) Create(db orm.Ormer) (int64, error) {
  22. return db.Insert(p)
  23. }
  24. func (p *TGdAdminRbacGroup) Fetch(db orm.Ormer, mapFilter map[string]interface{}) error {
  25. qs := db.QueryTable(p.TableName())
  26. for k, v := range mapFilter {
  27. qs = qs.Filter(k, v)
  28. }
  29. return qs.One(p)
  30. }
  31. func (p *TGdAdminRbacGroup) FetchAll(db orm.Ormer, mapFilter map[string]interface{}, cols []string) (lists []TGdAdminRbacGroup, err error) {
  32. qa := db.QueryTable(p.TableName())
  33. for k, v := range mapFilter {
  34. qa = qa.Filter(k, v)
  35. }
  36. _, err = qa.All(&lists, cols...)
  37. return
  38. }
  39. func (p *TGdAdminRbacGroup) Save(db orm.Ormer, mapFilter, values map[string]interface{}) (int64, error) {
  40. params := orm.Params{}
  41. //不判断参数为空的情况
  42. for k, v := range values {
  43. //if v != nil {
  44. params[k] = v
  45. //}
  46. }
  47. qs := db.QueryTable(p.TableName())
  48. for k, v := range mapFilter {
  49. qs = qs.Filter(k, v)
  50. }
  51. return qs.Update(params)
  52. }
  53. func (p *TGdAdminRbacGroup) Delete(db orm.Ormer, mapFilter map[string]interface{}) (int64, error) {
  54. qs := db.QueryTable(p.TableName())
  55. for k, v := range mapFilter {
  56. qs = qs.Filter(k, v)
  57. }
  58. return qs.Delete()
  59. }