123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package services
- import (
- "eta/eta_mini_crm_ht/models"
- "eta/eta_mini_crm_ht/utils"
- "strings"
- )
- func GetUserSourceClickFlowListCountByUserId(userId int, condition string, pars []interface{}, permissionIds []int, product models.SourceType) (total int, conditionNew string, parsNew []interface{}, err error) {
- if len(permissionIds) == 0 {
- total, err = models.GetUserSourceClickFlowListCountByUserId(userId, condition, pars)
- conditionNew = condition
- parsNew = pars
- return
- }
- if product == models.AudioSourceType || product == models.VideoSourceType {
- mediaType := transMediaType(product)
- videoIds, queryErr := GetMediaIdsByPermissionIds(permissionIds, mediaType)
- if queryErr != nil || len(videoIds) == 0 {
- return
- }
- condition = condition + " and source_id in (" + utils.GetOrmReplaceHolder(len(videoIds)) + ") "
- pars = append(pars, videoIds)
- } else if product == models.ReportSourceType {
- reportIds, queryErr := GetReportIdsByPermissionIds(permissionIds)
- if queryErr != nil || len(reportIds) == 0 {
- return
- }
- condition = condition + " and source_id in (" + utils.GetOrmReplaceHolder(len(reportIds)) + ") "
- pars = append(pars, reportIds)
- } else {
- reportIds, reportErr := GetReportIdsByPermissionIds(permissionIds)
- addReport := false
- addVideo := false
- addAudio := false
- var permissionCondition string
- var permissionPars []interface{}
- if reportErr == nil && len(reportIds) > 0 {
- permissionCondition = permissionCondition + " (source_id in (" + utils.GetOrmReplaceHolder(len(reportIds)) + ") and source_type=?)"
- permissionPars = append(permissionPars, reportIds)
- permissionPars = append(permissionPars, models.ReportSourceType)
- addReport = true
- }
- videoIds, videoErr := GetMediaIdsByPermissionIds(permissionIds, models.Video)
- if videoErr == nil && len(videoIds) > 0 {
- if addReport {
- permissionCondition = permissionCondition + "or (source_id in (" + utils.GetOrmReplaceHolder(len(videoIds)) + ") and source_type=?)"
- } else {
- permissionCondition = permissionCondition + " (source_id in (" + utils.GetOrmReplaceHolder(len(videoIds)) + ") and source_type=?)"
- }
- permissionPars = append(permissionPars, videoIds)
- permissionPars = append(permissionPars, models.VideoSourceType)
- addVideo = true
- }
- audioIds, audioErr := GetMediaIdsByPermissionIds(permissionIds, models.Audio)
- if audioErr == nil && len(audioIds) > 0 {
- if addReport || addVideo {
- permissionCondition = permissionCondition + "or (source_id in (" + utils.GetOrmReplaceHolder(len(audioIds)) + ") and source_type=?)"
- } else {
- permissionCondition = permissionCondition + " (source_id in (" + utils.GetOrmReplaceHolder(len(audioIds)) + ") and source_type=?)"
- }
- permissionPars = append(permissionPars, audioIds)
- permissionPars = append(permissionPars, models.AudioSourceType)
- addAudio = true
- }
- if addReport || addVideo || addAudio {
- condition = condition + " and ( " + permissionCondition + " ) "
- pars = append(pars, permissionPars...)
- }
- }
- if condition == "" {
- utils.FileLog.Warn("没有符合要求的阅读记录")
- return
- }
- total, err = models.GetUserSourceClickFlowListCountByUserId(userId, condition, pars)
- conditionNew = condition
- parsNew = pars
- return
- }
- func GetUserSourceClickFlowListByUserId(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []models.UserSourceClickFlowView, err error) {
- list, err := models.GetUserSourceClickFlowListByUserId(userId, condition, pars, startSize, pageSize)
- if err != nil {
- return
- }
- for _, item := range list {
- viewItem := item.ToView()
- switch item.SourceType {
- case models.ReportSourceType:
- viewItem.PermissionNames = getReportPermissionNames(item.SourceId)
- case models.AudioSourceType, models.VideoSourceType:
- mediaType := transMediaType(item.SourceType)
- viewItem.PermissionNames = getMediaPermissionNames(item.SourceId, mediaType)
- }
- items = append(items, viewItem)
- }
- return
- }
- func transMediaType(sourceType models.SourceType) models.MediaType {
- switch sourceType {
- case models.AudioSourceType:
- return models.Audio
- case models.VideoSourceType:
- return models.Video
- default:
- return ""
- }
- }
- func getReportPermissionNames(reportId int) (permissionNames string) {
- report, err := models.GetReportById(reportId)
- if err != nil {
- return
- }
- if report.Source == models.SourceETA {
- permissionIds, queryErr := models.GetByPermissionIdsByClassifyId(report.ClassifyId)
- if queryErr != nil {
- return
- }
- permissionNameList, nameErr := models.GetPermissionNames(permissionIds)
- if nameErr != nil {
- utils.FileLog.Error("获取品种名称列表失败", err.Error())
- return
- }
- if len(permissionNameList) > 0 {
- permissionNames = strings.Join(permissionNameList, ",")
- }
- return
- }
- if report.Source == models.SourceHT {
- return report.PlateName
- }
- return
- }
- func getMediaPermissionNames(mediaId int, mediaType models.MediaType) (permissionNames string) {
- media, err := models.GetMediaById(mediaType, mediaId)
- if err != nil {
- utils.FileLog.Error("获取媒体失败,Err:" + err.Error())
- return
- }
- permissionIds, queryErr := models.GetPermissionIdsByMediaId(media.MediaType, media.Id)
- if queryErr != nil {
- utils.FileLog.Error("获取媒体权限失败,Err:" + queryErr.Error())
- return
- }
- permissionNameList, nameErr := models.GetPermissionNames(permissionIds)
- if nameErr != nil {
- utils.FileLog.Error("获取品种名称列表信息失败", nameErr.Error())
- return
- }
- permissionNames = strings.Join(permissionNameList, ",")
- return
- }
|