media_permission_mapping.go 1.2 KB

1234567891011121314151617181920212223242526272829
  1. package media
  2. import (
  3. "eta/eta_mini_ht_api/models"
  4. )
  5. // MediaPermissionMapping 表示媒体权限映射
  6. type MediaPermissionMapping struct {
  7. ID int `gorm:"primaryKey;autoIncrement;column:id"` // 主键
  8. PermissionID int `gorm:"column:permission_id;not null"` // 权限 ID
  9. MediaID int `gorm:"column:media_id;not null"` // 媒体 ID
  10. MediaType MediaType `gorm:"column:media_type;not null"` // 媒体类型
  11. }
  12. func GetMediaPermissionMappingByPermissionId(mediaType string, permissionIds []int) (mediaIds []int, err error) {
  13. db := models.Main()
  14. query := db.Model(&MediaPermissionMapping{}).Select("DISTINCT media_id").Where("deleted =? and permission_id in ?", false, permissionIds)
  15. if mediaType != "" {
  16. query.Where("media_type = ?", mediaType)
  17. }
  18. err = query.Scan(&mediaIds).Error
  19. return
  20. }
  21. func GetMediaPermissionMappingByMedia(mediaType string, mediaId int) (permissionIds []int, err error) {
  22. db := models.Main()
  23. err = db.Model(&MediaPermissionMapping{}).Select("DISTINCT permission_id").Where(" deleted =? and media_id = ? and media_type = ?", false, mediaId, mediaType).Scan(&permissionIds).Error
  24. return
  25. }