activity_permission.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ActivityPermission 活动权限表结构体
  7. type ActivityPermission struct {
  8. ActivityPermissionId int `orm:"column(activity_permission_id);pk" description:"活动权限ID"`
  9. ActivityId int ` description:"活动ID"`
  10. PermissionId int ` description:"权限ID"`
  11. PermissionName string `description:"权限名称"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. // TableName 表名变更
  15. func (activityPermission *ActivityPermission) TableName() string {
  16. return "yb_activity_permission"
  17. }
  18. // DelPermissionByActivityId 根据活动id删除所有权限
  19. func DelPermissionByActivityId(activityId int) (err error) {
  20. o := orm.NewOrm()
  21. sql := "delete from yb_activity_permission where activity_id=?"
  22. _, err = o.Raw(sql, activityId).Exec()
  23. return
  24. }
  25. // AddActivityPermission 新增活动权限
  26. func AddActivityPermission(activityPermissionInfo *ActivityPermission) (err error) {
  27. o := orm.NewOrm()
  28. _, err = o.Insert(activityPermissionInfo)
  29. return
  30. }
  31. // AddActivityPermissionMulti 批量新增活动权限
  32. func AddActivityPermissionMulti(activityPermissionList []*ActivityPermission) (err error) {
  33. o := orm.NewOrm()
  34. _, err = o.InsertMulti(len(activityPermissionList), activityPermissionList)
  35. return
  36. }
  37. // GetPermissionListByActivityIds 根据活动id集合获取权限列表
  38. func GetPermissionListByActivityIds(activityIds string) (list []*ActivityPermission, err error) {
  39. if activityIds == "" {
  40. return
  41. }
  42. o := orm.NewOrm()
  43. sql := `select * from yb_activity_permission where activity_id in (` + activityIds + `) `
  44. _, err = o.Raw(sql).QueryRows(&list)
  45. return
  46. }
  47. // GetPermissionListByActivityId 根据活动id获取权限列表
  48. func GetPermissionListByActivityId(activityId int) (list []*ActivityPermission, err error) {
  49. o := orm.NewOrm()
  50. sql := `select * from yb_activity_permission where activity_id = ? `
  51. _, err = o.Raw(sql, activityId).QueryRows(&list)
  52. return
  53. }