media_permission_mapping.go 1.2 KB

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