|
@@ -0,0 +1,206 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_clpt/models"
|
|
|
+ "hongze/hongze_clpt/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataResp, 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[int]*models.CygxResourceDataResp)
|
|
|
+ for _, v := range list {
|
|
|
+ //预处理文章
|
|
|
+ item := new(models.CygxResourceDataResp)
|
|
|
+ item.Id = v.Id
|
|
|
+ item.SourceId = v.SourceId
|
|
|
+ item.Source = v.Source
|
|
|
+ item.Title = v.Title
|
|
|
+ item.Annotation = v.Annotation
|
|
|
+ item.Abstract = v.Abstract
|
|
|
+ mapItems[v.SourceId] = item
|
|
|
+ }
|
|
|
+ var articleIds []int
|
|
|
+ var newchartIds []int
|
|
|
+ var roadshowIds []int
|
|
|
+ var activityIds []int
|
|
|
+ var activityvideoIds []int
|
|
|
+ var activityvoiceIds []int
|
|
|
+ var activityspecialIds []int
|
|
|
+ //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
|
|
|
+ for _, v := range list {
|
|
|
+ if v.Source == "article" {
|
|
|
+ articleIds = append(articleIds, v.SourceId)
|
|
|
+ } else if v.Source == "newchart" {
|
|
|
+ newchartIds = append(newchartIds, v.SourceId)
|
|
|
+ } else if v.Source == "roadshow" {
|
|
|
+ roadshowIds = append(roadshowIds, v.SourceId)
|
|
|
+ } else if v.Source == "activity" {
|
|
|
+ activityIds = append(activityIds, v.SourceId)
|
|
|
+ } else if v.Source == "activityvideo" {
|
|
|
+ activityvideoIds = append(activityvideoIds, v.SourceId)
|
|
|
+ } else if v.Source == "activityvoice" {
|
|
|
+ activityvoiceIds = append(activityvoiceIds, v.SourceId)
|
|
|
+ } else if v.Source == "activityspecial" {
|
|
|
+ activityspecialIds = append(activityspecialIds, 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(activityIds) > 0 {
|
|
|
+ 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, startSize, 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))
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range activityListRersp {
|
|
|
+ if v.ActivityType == 0 {
|
|
|
+ if mapAddress[v.City] != "" {
|
|
|
+ imgUrlResp = mapAddress[v.City]
|
|
|
+ } else {
|
|
|
+ imgUrlResp = mapAddress["其它"]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if mapChart[v.ChartPermissionName] != "" {
|
|
|
+ imgUrlResp = mapChart[v.ChartPermissionName]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapItems[v.ActivityId].Title = v.ActivityName
|
|
|
+ mapItems[v.ActivityId].City = v.City
|
|
|
+ mapItems[v.ActivityId].IsSignup = v.IsSignup
|
|
|
+ mapItems[v.ActivityId].IsCancelMeetingReminder = v.IsCancelMeetingReminder
|
|
|
+ mapItems[v.ActivityId].IsAppointment = v.IsAppointment
|
|
|
+ mapItems[v.ActivityId].ActiveState = v.ActiveState
|
|
|
+ mapItems[v.ActivityId].ImgUrlText = v.ImgUrlText
|
|
|
+ mapItems[v.ActivityId].ActivityType = v.ActivityType
|
|
|
+ mapItems[v.ActivityId].IsShowOutboundCall = v.IsShowOutboundCall
|
|
|
+ mapItems[v.ActivityId].IsShowMeetingReminder = v.IsShowMeetingReminder
|
|
|
+ mapItems[v.ActivityId].IsShowHelpSsk = v.IsShowHelpSsk
|
|
|
+ mapItems[v.ActivityId].IsShowSignup = v.IsShowSignup
|
|
|
+ mapItems[v.ActivityId].IsShowAppointment = v.IsShowAppointment
|
|
|
+ mapItems[v.ActivityId].IsShowDetails = v.IsShowDetails
|
|
|
+ mapItems[v.ActivityId].ActivityTimeText = v.ActivityTimeText
|
|
|
+ mapItems[v.ActivityId].ImgUrl = imgUrlResp
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理图表
|
|
|
+ if len(newchartIds) > 0 {
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
|
|
|
+ pars = append(pars, newchartIds)
|
|
|
+ chartDateList, e := models.GetChartListCollection(condition, pars, uid, startSize, len(newchartIds))
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetResourceDataList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range chartDateList {
|
|
|
+ mapItems[v.ChartId].Title = v.Title
|
|
|
+ mapItems[v.ChartId].ImgUrl = v.BodyHtml
|
|
|
+ mapItems[v.ChartId].IsTop = v.IsTop
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理专项调研
|
|
|
+ if len(activityspecialIds) > 0 {
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
|
|
|
+ pars = append(pars, activityspecialIds)
|
|
|
+ activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, len(activityspecialIds))
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range activitySpeciallist {
|
|
|
+ if mapChart[v.ChartPermissionName] != "" {
|
|
|
+ imgUrlResp = mapChart[v.ChartPermissionName]
|
|
|
+ }
|
|
|
+ if _, ok := UserMap[v.ActivityId]; ok {
|
|
|
+ mapItems[v.ActivityId].IsTrip = 1
|
|
|
+ }
|
|
|
+ if v.Days == 0 {
|
|
|
+ mapItems[v.ActivityId].TripStatus = 1
|
|
|
+ } else {
|
|
|
+ mapItems[v.ActivityId].TripStatus = 2
|
|
|
+ }
|
|
|
+ resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
|
|
|
+ resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
|
|
|
+ if resultTimeStart.After(time.Now()) {
|
|
|
+ mapItems[v.ActivityId].ActiveState = strconv.Itoa(1)
|
|
|
+ } else if time.Now().After(resultTimeEnd) {
|
|
|
+ mapItems[v.ActivityId].ActiveState = strconv.Itoa(3)
|
|
|
+ } else {
|
|
|
+ mapItems[v.ActivityId].ActiveState = strconv.Itoa(2)
|
|
|
+ }
|
|
|
+ mapItems[v.ActivityId].Title = v.ResearchTheme
|
|
|
+ mapItems[v.ActivityId].ActivityType = v.SpecialType
|
|
|
+ mapItems[v.ActivityId].City = v.City
|
|
|
+ mapItems[v.ActivityId].ActivityTimeText = v.ActivityTimeText
|
|
|
+ mapItems[v.ActivityId].TripImgLink = v.TripImgLink
|
|
|
+ mapItems[v.ActivityId].IsSignup = v.IsSignup
|
|
|
+ mapItems[v.ActivityId].ImgUrl = imgUrlResp
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range mapItems {
|
|
|
+ fmt.Println(v)
|
|
|
+ items = append(items, v)
|
|
|
+ }
|
|
|
+ fmt.Println(activityIds)
|
|
|
+ return
|
|
|
+}
|