12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package models
- import (
- "eta/eta_mini_crm_ht/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type MediaPermissionMapping struct {
- Id int `orm:"pk" description:"id"` // 主键
- PermissionId int `description:"权限ID"` // 权限 ID
- MediaId int `description:"媒体ID"` // 媒体 ID
- MediaType MediaType `description:"媒体类型"` // 媒体类型
- Deleted int `description:"是否删除"`
- CreatedTime time.Time `description:"创建时间"`
- UpdatedTime time.Time `description:"更新时间"`
- }
- // TableName returns the table name for this model.
- func (mp *MediaPermissionMapping) TableName() string {
- return "media_permission_mappings"
- }
- func DeleteMappingsById(mediaId int) (err error) {
- o := orm.NewOrm()
- _, err = o.QueryTable(new(MediaPermissionMapping)).Filter("media_id", mediaId).Update(orm.Params{"deleted": 1})
- return
- }
- func GetMappingsByCondition(condition string, pars []interface{}) (items []int64, err error) {
- o := orm.NewOrm()
- sql := `SELECT distinct media_id FROM media_permission_mappings WHERE DELETED=0 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetPermissionIdsByMediaId(mediaType MediaType, mediaId int) (ids []int, err error) {
- o := orm.NewOrm()
- var sql string
- if mediaType == "" {
- sql = `SELECT distinct permission_id FROM media_permission_mappings WHERE media_id=? and DELETED=0 `
- _, err = o.Raw(sql, mediaId).QueryRows(&ids)
- } else {
- sql = `SELECT distinct permission_id FROM media_permission_mappings WHERE media_id=? and media_type=? and DELETED=0 `
- _, err = o.Raw(sql, mediaId, mediaType).QueryRows(&ids)
- }
- return
- }
- func GetMediaIdIdsByPermissionId(permissionIds []int) (ids []int, err error) {
- o := orm.NewOrm()
- condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(permissionIds)) + ")"
- sql := `SELECT distinct media_id FROM media_permission_mappings WHERE` + condition + `and DELETED=0 `
- _, err = o.Raw(sql, permissionIds).QueryRows(&ids)
- return
- }
|