Browse Source

Revert "fix: 无权限分段"

This reverts commit 0a247cb8478255a0d9b25ceaf670af6f713b1201.
hsun 2 years ago
parent
commit
05b2fade8e
3 changed files with 7 additions and 45 deletions
  1. 4 2
      go.mod
  2. 1 35
      services/report/report.go
  3. 2 8
      services/report/report_chapter.go

+ 4 - 2
go.mod

@@ -3,8 +3,8 @@ module hongze/hongze_yb
 go 1.15
 
 require (
-	github.com/PuerkitoBio/goquery v1.8.0
 	github.com/aliyun/aliyun-oss-go-sdk v1.9.8
+	github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220111164937-1b144fa7b40f // indirect
 	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
 	github.com/fsnotify/fsnotify v1.5.1
 	github.com/gin-gonic/gin v1.7.4
@@ -21,13 +21,15 @@ require (
 	github.com/olivere/elastic/v7 v7.0.31
 	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
 	github.com/satori/go.uuid v1.2.0 // indirect
+	github.com/shopspring/decimal v1.2.0
 	github.com/silenceper/wechat/v2 v2.0.9
 	github.com/spf13/viper v1.9.0
 	github.com/swaggo/gin-swagger v1.3.3
 	github.com/swaggo/swag v1.7.4
+	github.com/yidane/formula v0.0.0-20210902154546-0782e1736717
 	golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
 	golang.org/x/image v0.0.0-20190802002840-cff245a6509b
-	golang.org/x/sys v0.0.0-20211107104306-e0b2ad06fe42 // indirect
+	golang.org/x/sys v0.0.0-20211107104306-e0b2ad06fe42
 	golang.org/x/text v0.3.7 // indirect
 	gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df

+ 1 - 35
services/report/report.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"github.com/PuerkitoBio/goquery"
 	report_chapter_type_cache "hongze/hongze_yb/cache/report_chapter_type"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
@@ -419,7 +418,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
 	reportItem.Stage = reportInfo.Stage
 	reportItem.Abstract = reportInfo.Abstract
-	//reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
+	reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
 	reportItem.Frequency = reportInfo.Frequency
 	reportItem.VideoName = reportInfo.VideoName
 	if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
@@ -448,14 +447,6 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 		task.Task(AddViewRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
 		reportItem.Content = html.UnescapeString(reportInfo.Content)
 		reportItem.VideoUrl = reportInfo.VideoUrl
-	} else {
-		contents := html.UnescapeString(reportInfo.Content)
-		contentSub, tmpErr := SlicingReportContentSub(contents)
-		if tmpErr != nil {
-			err = errors.New("报告分段有误")
-			return
-		}
-		reportItem.ContentSub = contentSub
 	}
 	//新增用户访问日志
 	task.Task(AddUserAccessRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0, authOk)
@@ -1109,28 +1100,3 @@ func addAliasToKeyword(keyword string) string {
 	keyword = strings.Join(keywordArr, ",")
 	return keyword
 }
-
-func SlicingReportContentSub(content string) (contentSub string, err error) {
-	content = html.UnescapeString(content)
-	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
-	if err != nil {
-		fmt.Println("create doc err:", err.Error())
-		return
-	}
-	n := 0
-	doc.Find("p").Each(func(i int, s *goquery.Selection) {
-		if n >= 10 {
-			return
-		}
-		n++
-		phtml, err := s.Html()
-		if err != nil {
-			fmt.Println("get html err", err.Error())
-			return
-		}
-		if s.Text() != "" || strings.Contains(phtml, "src") {
-			contentSub = contentSub + "<p>" + phtml + "</p>"
-		}
-	})
-	return
-}

+ 2 - 8
services/report/report_chapter.go

@@ -264,14 +264,8 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		}
 
 		task.Task(AddViewRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
-	} else {
-		contents := html.UnescapeString(reportInfo.Content)
-		contentSub, tmpErr := SlicingReportContentSub(contents)
-		if tmpErr != nil {
-			err = errors.New("报告分段有误")
-			return
-		}
-		reportChapterItem.ContentSub = contentSub
+	}else{
+		reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
 	}
 	task.Task(AddUserAccessRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
 	reportChapterDetail = new(response.ReportChapterDetail)