Browse Source

no message

xingzai 1 year ago
parent
commit
0be40d6660

+ 1 - 1
controllers/morning_meeting.go

@@ -127,6 +127,7 @@ func (this *MorningMeetingController) GatherDetail() {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
 	}
+	resp.HasPermission = hasPermission
 	if hasPermission != 1 {
 		br.Ret = 200
 		br.Success = true
@@ -184,7 +185,6 @@ func (this *MorningMeetingController) GatherDetail() {
 	detailResp.PublishTime = utils.GetTimeDateRemoveYear(detail.PublishTime)
 	detailResp.Department = "弘则产品组"
 	resp.Detail = detailResp
-	resp.HasPermission = hasPermission
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 1 - 33
controllers/product_interior.go

@@ -1,13 +1,10 @@
 package controllers
 
 import (
-	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
-	"regexp"
-	"strings"
 )
 
 // 产品内测
@@ -124,36 +121,7 @@ func (this *ProductInteriorController) Detail() {
 	}
 	detail.PublishTime = utils.TimeRemoveHms2(detail.PublishTime)
 	resp.Detail = detail
-	body := detail.Body
-	var randStrStart = "start_cygx_{|}"
-	var randStr = "start_cygx_{|}_end_cygx"
-	urlMap := make(map[string]string)
-	var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
-	match := hrefRegexp.FindAllString(body, -1)
-	if match != nil {
-		for _, v := range match {
-			body = strings.Replace(body, fmt.Sprint("href=\"", v, "\""), "", -1)
-			body = strings.Replace(body, fmt.Sprint("<a >"), "", -1)
-			body = strings.Replace(body, fmt.Sprint("</a>"), "", -1)
-			body = strings.Replace(body, v, randStrStart+v+randStr, -1)
-			urlMap[v] = v
-		}
-	}
-	sliceBody := strings.Split(body, randStr)
-	var sliceBodyUrl []string
-	for _, v := range sliceBody {
-		sliceUrl := strings.Split(v, randStrStart)
-		for _, url := range sliceUrl {
-			if url == "" {
-				continue
-			}
-			sliceBodyUrl = append(sliceBodyUrl, url)
-		}
-	}
-	for _, v := range sliceBodyUrl {
-		detail.BodySlice = append(detail.BodySlice, services.GetProductInteriorUrl(v, urlMap))
-	}
-
+	detail.BodySlice = services.GetProductInteriorUrlBody(detail.Body)
 	go services.AddCygxProductInteriorHistory(user, productInteriorId)
 	br.Ret = 200
 	br.Success = true

+ 64 - 0
services/article.go

@@ -1843,6 +1843,70 @@ func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
 	return
 }
 
+// 处理核心观点的展示规则
+func AnnotationHtml(bodyText string) (annotation string) {
+
+	if bodyText == "" {
+		return
+	}
+	annotation = bodyText
+
+	annotation = html.UnescapeString(annotation)
+	doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
+	docText := doc.Text()
+	mapDoc := make(map[int]string)
+	var mapSort []int
+	p := doc.Find("p")
+	p.Each(func(tk int, pd *goquery.Selection) {
+		pdText := pd.Text()
+		pdText = strings.Replace(pdText, " ", "", -1)
+		if pdText != "" {
+			textLen := strings.Index(docText, pdText)
+			mapDoc[(strings.Index(docText, pdText))] = pdText
+			mapSort = append(mapSort, textLen)
+		}
+	})
+	li := doc.Find("li")
+	li.Each(func(tk int, li *goquery.Selection) {
+		liText := li.Text()
+		liText = strings.Replace(liText, " ", "", -1)
+		if liText != "" {
+			textLen := strings.Index(docText, liText)
+			mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
+			mapSort = append(mapSort, textLen)
+		}
+	})
+
+	ul := doc.Find("ul")
+	ul.Each(func(tk int, ul *goquery.Selection) {
+		ulText := ul.Text()
+		ulText = strings.Replace(ulText, " ", "", -1)
+		if ulText != "" {
+			textLen := strings.Index(docText, ulText)
+			mapDoc[(strings.Index(docText, ulText))] = ulText
+			mapSort = append(mapSort, textLen)
+		}
+	})
+	if len(mapSort) == 0 {
+		return
+	} else {
+		//排序
+		sort.Ints(mapSort)
+		var annotationHtml string
+		for _, vSort := range mapSort {
+			for k, v := range mapDoc {
+				if k == vSort && v != "" {
+					annotationHtml += v + "<br>"
+				}
+			}
+		}
+		annotationHtml = strings.TrimRight(annotationHtml, "<br>")
+		annotationHtml = "<p>" + annotationHtml + "</p>"
+		annotation = annotationHtml
+	}
+	return
+}
+
 // 解析研选内容中的核心观点
 func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
 	//如果不规范,就获取内容主体

+ 68 - 0
services/product_interior.go

@@ -1,8 +1,10 @@
 package services
 
 import (
+	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
@@ -38,6 +40,72 @@ func GetProductInteriorUrl(url string, urlMap map[string]string) (itemResp *mode
 	return
 }
 
+// GetProductInteriorUrl 处理产品内测中的连接并做跳转处理
+func GetProductInteriorUrlBody(body string) (itemResp []*models.ProductInteriorUrlResp) {
+	//2:文章详情  https://web.hzinsights.com/material/info/8436
+	//3:活动详情  https://web.hzinsights.com/activity/detail/2701
+	//4:产业详情  https://web.hzinsights.com/indepth/info/20/79
+	material := "material/info"
+	activity := "activity/detail"
+	indepth := "indepth/info"
+
+	var randStrStart = "start_cygx_{|}"
+	var randStr = "start_cygx_{|}_end_cygx"
+	urlMap := make(map[string]string)
+	var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
+	match := hrefRegexp.FindAllString(body, -1)
+	if match != nil {
+		for _, v := range match {
+			//过滤不相干的超链接
+			if !strings.Contains(v, material) && !strings.Contains(v, activity) && strings.Contains(v, indepth) {
+				continue
+			}
+			body = strings.Replace(body, fmt.Sprint("href=\"", v, "\""), "", -1)
+			body = strings.Replace(body, fmt.Sprint("<a >"), "", -1)
+			body = strings.Replace(body, fmt.Sprint("</a>"), "", -1)
+			body = strings.Replace(body, v, randStrStart+v+randStr, -1)
+			urlMap[v] = v
+		}
+	}
+	sliceBody := strings.Split(body, randStr)
+	var sliceBodyUrl []string
+	for _, v := range sliceBody {
+		sliceUrl := strings.Split(v, randStrStart)
+		for _, url := range sliceUrl {
+			if url == "" {
+				continue
+			}
+			sliceBodyUrl = append(sliceBodyUrl, url)
+		}
+	}
+
+	for _, url := range sliceBodyUrl {
+		item := new(models.ProductInteriorUrlResp)
+		item.Body = url
+		if urlMap[url] == "" {
+			item.Type = 1
+		} else {
+			urlSlice := strings.Split(url, "/")
+			lenurlSlice := len(urlSlice)
+			sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
+			item.SourceId = sourceId
+			if strings.Contains(url, material) {
+				item.Type = 2
+			} else if strings.Contains(url, activity) {
+				item.Type = 3
+			} else if strings.Contains(url, indepth) {
+				if lenurlSlice >= 2 {
+					chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
+					item.ChartPermissionId = chartPermissionId
+				}
+				item.Type = 4
+			}
+		}
+		itemResp = append(itemResp, item)
+	}
+	return
+}
+
 func AddCygxProductInteriorHistory(user *models.WxUserItem, articleId int) (err error) {
 	defer func() {
 		if err != nil {

+ 1 - 1
services/resource_data.go

@@ -104,7 +104,7 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 			return
 		}
 		for _, v := range listrMeet {
-			v.Content, _ = GetReportContentTextSub(v.Content)
+			v.Content = AnnotationHtml(v.Content)
 			v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
 			mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
 		}