package services import ( "errors" "fmt" "hongze/hongze_web_mfyx/models" "hongze/hongze_web_mfyx/utils" "strconv" "strings" ) func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) { uid := user.UserId list, e := models.GetResourceDataList(condition, pars, startSize, pageSize) if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } mapItems := make(map[string]*models.CygxResourceDataNewResp) for _, v := range list { //预处理文章 item := new(models.CygxResourceDataNewResp) item.Id = v.Id item.SourceId = v.SourceId item.Source = v.Source //item.Title = v.Title //item.Annotation = v.Annotation //item.Abstract = v.Abstract item.PublishDate = utils.TimeRemoveHms2(v.PublishDate) mapItems[fmt.Sprint(v.Source, v.SourceId)] = item } var articleIds []int //报告 var activityIds []int //活动 var activityvideoIds []string // 活动视频 var activityvoiceIds []string //活动音频 var yanxuanSpecialIds []int // 研选专栏 var roadshowIds []string //微路演 var askserieVideoIds []string //问答系列视频 //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior for _, v := range list { if v.Source == "article" { articleIds = append(articleIds, v.SourceId) } else if v.Source == "activity" { activityIds = append(activityIds, v.SourceId) } else if v.Source == "activityvideo" { activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId)) } else if v.Source == "activityvoice" { activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId)) } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL { yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId) } } detail, e := models.GetConfigByCode("city_img_url") if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } detailChart, e := models.GetConfigByCode("chart_img_url") if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } addressList := strings.Split(detail.ConfigValue, "{|}") mapAddress := make(map[string]string) chartList := strings.Split(detailChart.ConfigValue, "{|}") mapChart := make(map[string]string) var cityName string var chartName string var imgUrl string var imgUrlChart string for _, v := range addressList { vslice := strings.Split(v, "_") cityName = vslice[0] imgUrl = vslice[len(vslice)-1] mapAddress[cityName] = imgUrl } for _, v := range chartList { vslice := strings.Split(v, "_") chartName = vslice[0] imgUrlChart = vslice[len(vslice)-1] mapChart[chartName] = imgUrlChart } var imgUrlResp string //处理文章 if len(articleIds) > 0 { pars = make([]interface{}, 0) condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)` pars = append(pars, articleIds) articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds)) if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } articleList, e = HandleArticleCategoryImg(articleList, user) if e != nil { err = errors.New("HandleArticleCategoryImg, Err: " + e.Error()) return } for _, v := range articleList { v.Body = "" mapItems[fmt.Sprint("article", v.ArticleId)].Article = v } } //处理活动 if len(activityIds) > 0 { //for _, vss := range activityIds { // imgUrlResp += strconv.Itoa(vss) + "," //} pars = make([]interface{}, 0) condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) ` pars = append(pars, activityIds) activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "") if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } var activityListRersp []*models.ActivityListResp //for _, v := range activityList { // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0))) //} activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0)) //处理不同的报名方式按钮回显 mapActivitySignup, e := GetActivitySignupResp(activityIds, user) if e != nil { err = errors.New("GetActivitySignupResp, Err: " + e.Error()) return } for _, v := range activityListRersp { if v == nil { continue } if v.ActivityType == 0 { if mapAddress[v.City] != "" { imgUrlResp = mapAddress[v.City] } else { imgUrlResp = mapAddress["其它"] } } else { if mapChart[v.ChartPermissionName] != "" { imgUrlResp = mapChart[v.ChartPermissionName] } } v.ImgUrl = imgUrlResp v.SourceType = mapActivitySignup[v.ActivityId] mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v } } //处理研选专栏 lenyanxuanSpecialIds := len(yanxuanSpecialIds) if lenyanxuanSpecialIds > 0 { pars = make([]interface{}, 0) condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) ` pars = append(pars, yanxuanSpecialIds) listyanxuanSpecial, e := models.GetYanxuanSpecialListHome(user.UserId, condition, pars, 0, 0) if e != nil { err = errors.New("GetYanxuanSpecialList, Err: " + e.Error()) return } yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds) // 专栏Pv for _, v := range listyanxuanSpecial { v.PublishTime = utils.TimeRemoveHms2(v.PublishTime) v.Annotation, _ = GetReportContentTextSubNew(v.Content) v.Content = "" v.Pv = yanxuanSpecialPv[v.Id] v.LabelKeywordImgLink = utils.LABEL_ICO_4 mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v } } if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 { audioIdstr := strings.Join(activityvoiceIds, ",") activityVideoIdsStr := strings.Join(activityvideoIds, ",") roadshowIdsStr := strings.Join(roadshowIds, ",") askserieVideoIdsStr := strings.Join(askserieVideoIds, ",") listv, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user) if e != nil { err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error()) return } // 用户权限 authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId) if e != nil { err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error()) return } // 获取默认图配置 audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig() if e != nil { err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error()) return } //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"` for i := range listv { // 权限 au := new(models.UserPermissionAuthInfo) au.SellerName = authInfo.SellerName au.SellerMobile = authInfo.SellerMobile au.HasPermission = authInfo.HasPermission au.OperationMode = authInfo.OperationMode if au.HasPermission == 1 { // 非宏观权限进一步判断是否有权限 if listv[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, listv[i].ChartPermissionName) { au.HasPermission = 2 } } // 无权限的弹框提示 if au.HasPermission != 1 { if au.OperationMode == UserPermissionOperationModeCall { if listv[i].Type == 1 { au.PopupMsg = UserPermissionPopupMsgCallActivity } else { au.PopupMsg = UserPermissionPopupMsgCallMicroVideo } } else { if listv[i].Type == 1 { au.PopupMsg = UserPermissionPopupMsgApplyActivity } else { au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo } } } listv[i].AuthInfo = au listv[i].PublishTime = utils.StrTimeToTime(listv[i].PublishTime).Format(utils.FormatDate) // 默认图 if listv[i].BackgroundImg == "" { if listv[i].Type == 1 { listv[i].BackgroundImg = audioMap[listv[i].ChartPermissionId] } else { listv[i].BackgroundImg = videoMap[listv[i].ChartPermissionId] } } // 分享图 if listv[i].ShareImg == "" { if listv[i].Type == 1 { listv[i].ShareImg = audioShareMap[listv[i].ChartPermissionId] } else { listv[i].ShareImg = videoShareMap[listv[i].ChartPermissionId] } } listv[i].LabelKeywordImgLink = utils.LABEL_ICO_10 } //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"` for _, item := range listv { if item.Type == 1 { mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item } else if item.Type == 2 { mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item } else if item.Type == 3 { mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item } else if item.Type == 4 { mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item } } } for _, vList := range list { for _, v := range mapItems { //如果这些类型都为空,那么就不合并 if v.Article == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.YanxuanSpecial == nil { continue } if v.SourceId == vList.SourceId && v.Source == vList.Source { items = append(items, v) } } } return }