media_permission_mapping.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package models
  2. import (
  3. "eta/eta_mini_crm_ht/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type MediaPermissionMapping struct {
  8. Id int `orm:"pk" description:"id"` // 主键
  9. PermissionId int `description:"权限ID"` // 权限 ID
  10. MediaId int `description:"媒体ID"` // 媒体 ID
  11. MediaType MediaType `description:"媒体类型"` // 媒体类型
  12. Deleted int `description:"是否删除"`
  13. CreatedTime time.Time `description:"创建时间"`
  14. UpdatedTime time.Time `description:"更新时间"`
  15. }
  16. // TableName returns the table name for this model.
  17. func (mp *MediaPermissionMapping) TableName() string {
  18. return "media_permission_mappings"
  19. }
  20. func DeleteMappingsById(mediaId int) (err error) {
  21. o := orm.NewOrm()
  22. _, err = o.QueryTable(new(MediaPermissionMapping)).Filter("media_id", mediaId).Update(orm.Params{"deleted": 1})
  23. return
  24. }
  25. func GetMappingsByCondition(condition string, pars []interface{}) (items []int64, err error) {
  26. o := orm.NewOrm()
  27. sql := `SELECT distinct media_id FROM media_permission_mappings WHERE DELETED=0 `
  28. if condition != "" {
  29. sql += condition
  30. }
  31. _, err = o.Raw(sql, pars).QueryRows(&items)
  32. return
  33. }
  34. func GetPermissionIdsByMediaId(mediaType MediaType, mediaId int) (ids []int, err error) {
  35. o := orm.NewOrm()
  36. sql := `SELECT distinct permission_id FROM media_permission_mappings WHERE media_id=? and media_type=? and DELETED=0 `
  37. _, err = o.Raw(sql, mediaId, mediaType).QueryRows(&ids)
  38. return
  39. }
  40. func GetMediaIdIdsByPermissionId(permissionIds []int) (ids []int, err error) {
  41. o := orm.NewOrm()
  42. condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(permissionIds)) + ")"
  43. sql := `SELECT distinct media_id FROM media_permission_mappings WHERE` + condition + `and DELETED=0 `
  44. _, err = o.Raw(sql, permissionIds).QueryRows(&ids)
  45. return
  46. }