1234567891011121314151617181920212223242526272829 |
- package media
- import (
- "eta/eta_mini_ht_api/models"
- )
- // MediaPermissionMapping 表示媒体权限映射
- type MediaPermissionMapping struct {
- ID int `gorm:"primaryKey;autoIncrement;column:id"` // 主键
- PermissionID int `gorm:"column:permission_id;not null"` // 权限 ID
- MediaID int `gorm:"column:media_id;not null"` // 媒体 ID
- MediaType MediaType `gorm:"column:media_type;not null"` // 媒体类型
- }
- func GetMediaPermissionMappingByPermissionId(mediaType string, permissionIds []int) (mediaIds []int, err error) {
- db := models.Main()
- query := db.Model(&MediaPermissionMapping{}).Select("DISTINCT media_id").Where("deleted =? and permission_id in ?", false, permissionIds)
- if mediaType != "" {
- query.Where("media_type = ?", mediaType)
- }
- err = query.Scan(&mediaIds).Error
- return
- }
- func GetMediaPermissionMappingByMedia(mediaType string, mediaId int) (permissionIds []int, err error) {
- db := models.Main()
- err = db.Model(&MediaPermissionMapping{}).Select("DISTINCT permission_id").Where(" deleted =? and media_id = ? and media_type = ?", false, mediaId, mediaType).Scan(&permissionIds).Error
- return
- }
|