Browse Source

查研观向9.7

xingzai 2 years ago
parent
commit
27f36156ee
3 changed files with 74 additions and 13 deletions
  1. 1 0
      models/activity.go
  2. 23 12
      services/activity.go
  3. 50 1
      services/config.go

+ 1 - 0
models/activity.go

@@ -211,6 +211,7 @@ type ActivityListResp struct {
 
 type ActivityArticleResp struct {
 	ReportLink string `description:"报告链接"`
+	Title      string `description:"报告标题"`
 	ArticleId  int    `description:"报告id(报告链接跳转使用)"`
 }
 

+ 23 - 12
services/activity.go

@@ -604,20 +604,31 @@ func ActivityDetaailShow(activityInfo *models.ActivityListResp) (itemActivity *m
 	if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
 		activityInfo.SignupNum = activityInfo.LimitPeopleNum
 	}
+	//if activityInfo.ReportLink != "" {
+	//	artList := strings.Split(activityInfo.ReportLink, "{|}")
+	//	if len(artList) > 0 {
+	//		for _, v := range artList {
+	//			artitem := new(models.ActivityArticleResp)
+	//			artitem.ReportLink = v
+	//			artIdSlice := strings.Split(v, "/")
+	//			if len(artIdSlice) > 0 {
+	//				articleId, _ := strconv.Atoi(artIdSlice[len(artIdSlice)-1])
+	//				artitem.ArticleId = articleId
+	//			}
+	//			activityInfo.ArticleList = append(activityInfo.ArticleList, artitem)
+	//		}
+	//	}
+	//} else {
+	//	activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
+	//}
+
 	if activityInfo.ReportLink != "" {
-		artList := strings.Split(activityInfo.ReportLink, "{|}")
-		if len(artList) > 0 {
-			for _, v := range artList {
-				artitem := new(models.ActivityArticleResp)
-				artitem.ReportLink = v
-				artIdSlice := strings.Split(v, "/")
-				if len(artIdSlice) > 0 {
-					articleId, _ := strconv.Atoi(artIdSlice[len(artIdSlice)-1])
-					artitem.ArticleId = articleId
-				}
-				activityInfo.ArticleList = append(activityInfo.ArticleList, artitem)
-			}
+		artList, e := GetActivityReportLinkToArticleList(activityInfo)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = e
+			return
 		}
+		activityInfo.ArticleList = artList
 	} else {
 		activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
 	}

+ 50 - 1
services/config.go

@@ -1,11 +1,15 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"strings"
 )
 
-//是否展示限免标签
+// 是否展示限免标签
 func GetShowSustainable() (isShowSustainable bool) {
 	total, err := models.GetShowSustainable()
 	if err != nil {
@@ -29,3 +33,48 @@ func GetShowSustainableNew() (isShowSustainable bool, err error) {
 	}
 	return
 }
+
+// 解析活动填写的报告链接
+func GetActivityReportLinkToArticleList(item *models.ActivityListResp) (items []*models.ActivityArticleResp, err error) {
+	reportLink := item.ReportLink
+	//处理活动的
+	var articleIds []int
+	var articleList []string
+	if strings.Contains(reportLink, ";") {
+		articleList = strings.Split(reportLink, ";")
+	} else {
+		articleList = strings.Split(reportLink, ";")
+	}
+	for _, v := range articleList {
+		linkList := strings.Split(v, "/")
+		if linkList[len(linkList)-1] != "" {
+			linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
+			articleIds = append(articleIds, linkArticleId)
+		}
+	}
+
+	lenarticleIds := len(articleIds)
+	if lenarticleIds == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	pars = make([]interface{}, 0)
+	condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
+	pars = append(pars, articleIds)
+
+	listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
+	if e != nil {
+		err = errors.New("GetResourceDataList, Err: " + e.Error())
+		return
+	}
+	if len(listArticle) > 0 {
+		for _, v := range listArticle {
+			artItem := new(models.ActivityArticleResp)
+			artItem.ArticleId = v.ArticleId
+			artItem.Title = v.Title
+			items = append(items, artItem)
+		}
+	}
+	return
+}