|
@@ -8,30 +8,26 @@ import (
|
|
"html"
|
|
"html"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
//同步策略文章
|
|
//同步策略文章
|
|
-func SyncTacticsList() {
|
|
|
|
- var err error
|
|
|
|
|
|
+func SyncTacticsList() (err error) {
|
|
defer func() {
|
|
defer func() {
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("同步失败,Err:", err.Error())
|
|
fmt.Println("同步失败,Err:", err.Error())
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
- list, err := models.GetTacticsList()
|
|
|
|
|
|
+
|
|
|
|
+ indexName := "article_list"
|
|
|
|
+
|
|
|
|
+ endDate := time.Now().Format(utils.FormatDate)
|
|
|
|
+ list, err := models.GetTacticsList(endDate)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("GetTacticsList Err:", err.Error())
|
|
fmt.Println("GetTacticsList Err:", err.Error())
|
|
return
|
|
return
|
|
}
|
|
}
|
|
for k, v := range list {
|
|
for k, v := range list {
|
|
- fmt.Println(v.ArticleId)
|
|
|
|
- if v.ArticleId == 3439 {
|
|
|
|
- expertNumStr, expertContentStr, interviewDateStr := BodyAnalysis(v.Body)
|
|
|
|
- fmt.Println(k,expertNumStr, expertContentStr, interviewDateStr)
|
|
|
|
- }else{
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//判断是否已经存在
|
|
//判断是否已经存在
|
|
if v.ArticleId < 0 {
|
|
if v.ArticleId < 0 {
|
|
fmt.Println("参数错误")
|
|
fmt.Println("参数错误")
|
|
@@ -39,12 +35,12 @@ func SyncTacticsList() {
|
|
}
|
|
}
|
|
count, err := models.GetArticleCountById(v.ArticleId)
|
|
count, err := models.GetArticleCountById(v.ArticleId)
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
- return
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ expertNumStr, expertContentStr, interviewDateStr := BodyAnalysis(v.Body)
|
|
if count > 0 {
|
|
if count > 0 {
|
|
- fmt.Println("modify")
|
|
|
|
- expertNumStr, expertContentStr, interviewDateStr := BodyAnalysis(v.Body)
|
|
|
|
- bodyText,_:=GetReportContentTextSub(v.Body)
|
|
|
|
|
|
+ bodyText, _ := GetReportContentTextSub(v.Body)
|
|
updateParams := make(map[string]interface{})
|
|
updateParams := make(map[string]interface{})
|
|
updateParams["Title"] = v.Title
|
|
updateParams["Title"] = v.Title
|
|
updateParams["TitleEn"] = v.TitleEn
|
|
updateParams["TitleEn"] = v.TitleEn
|
|
@@ -65,19 +61,9 @@ func SyncTacticsList() {
|
|
whereParam := map[string]interface{}{"article_id": v.ArticleId}
|
|
whereParam := map[string]interface{}{"article_id": v.ArticleId}
|
|
go models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
|
|
go models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
|
|
} else {
|
|
} else {
|
|
|
|
+ fmt.Println(k, v.ArticleId, "add")
|
|
item := new(models.CygxArticle)
|
|
item := new(models.CygxArticle)
|
|
articleIdInt := v.ArticleId
|
|
articleIdInt := v.ArticleId
|
|
- //判断文章是否已经存在
|
|
|
|
- existItem, err := models.GetArticleDetailById(articleIdInt)
|
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
|
- fmt.Println("GetArticleDetailById Err:" + err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if existItem != nil && existItem.ArticleId > 0 {
|
|
|
|
- fmt.Println("exist", articleIdInt)
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- expertNumStr, expertContentStr, interviewDateStr := BodyAnalysis(v.Body)
|
|
|
|
item.ArticleId = articleIdInt
|
|
item.ArticleId = articleIdInt
|
|
item.Title = v.Title
|
|
item.Title = v.Title
|
|
item.TitleEn = v.TitleEn
|
|
item.TitleEn = v.TitleEn
|
|
@@ -98,14 +84,42 @@ func SyncTacticsList() {
|
|
_, err = models.AddCygxArticle(item)
|
|
_, err = models.AddCygxArticle(item)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("AddCygxArticle Err:", err.Error())
|
|
fmt.Println("AddCygxArticle Err:", err.Error())
|
|
- return
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ content := html.UnescapeString(v.Body)
|
|
|
|
+ doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("create doc err:", err.Error())
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ bodyText := doc.Text()
|
|
|
|
+ item := new(ElasticArticleDetail)
|
|
|
|
+ item.ArticleId = v.ArticleId
|
|
|
|
+ item.Title = v.Title
|
|
|
|
+ item.TitleEn = v.TitleEn
|
|
|
|
+ item.UpdateFrequency = v.UpdateFrequency
|
|
|
|
+ item.CreateDate = v.CreateDate
|
|
|
|
+ item.PublishDate = v.PublishDate
|
|
|
|
+ item.Abstract = v.Abstract
|
|
|
|
+ item.CategoryName = v.CategoryName
|
|
|
|
+ item.SubCategoryName = v.SubCategoryName
|
|
|
|
+ item.InterviewDate = interviewDateStr
|
|
|
|
+ item.ExpertBackground = expertContentStr
|
|
|
|
+ item.ExpertNumber = expertNumStr
|
|
|
|
+ item.Department = v.Department
|
|
|
|
+ item.ArticleIdMd5 = utils.MD5(strconv.Itoa(v.ArticleId))
|
|
|
|
+ item.BodyText = bodyText
|
|
|
|
+ EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
|
|
}
|
|
}
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//body 解析
|
|
//body 解析
|
|
func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr string) {
|
|
func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr string) {
|
|
|
|
+ body = html.UnescapeString(body)
|
|
|
|
+ utils.FileLog.Info("%s", body)
|
|
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
|
|
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("create doc err:", err.Error())
|
|
fmt.Println("create doc err:", err.Error())
|
|
@@ -117,7 +131,6 @@ func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr
|
|
var interviewDateArr []string
|
|
var interviewDateArr []string
|
|
|
|
|
|
doc.Find("p").Each(func(i int, s *goquery.Selection) {
|
|
doc.Find("p").Each(func(i int, s *goquery.Selection) {
|
|
- fmt.Println("get p")
|
|
|
|
contentTxt := s.Text()
|
|
contentTxt := s.Text()
|
|
if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
|
|
if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
|
|
interviewDate := s.Next().Text()
|
|
interviewDate := s.Next().Text()
|
|
@@ -149,11 +162,48 @@ func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+ if len(expertContentArr) == 0 {
|
|
|
|
+ doc.Find("pre").Each(func(i int, s *goquery.Selection) {
|
|
|
|
+ contentTxt := s.Text()
|
|
|
|
+ if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
|
|
|
|
+ interviewDate := s.Next().Text()
|
|
|
|
+ if interviewDate != "" {
|
|
|
|
+ interviewDateArr = append(interviewDateArr, interviewDate)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
|
|
|
|
+ expertContent := s.Next().Text()
|
|
|
|
+ if expertContent == "" {
|
|
|
|
+ expertContent = contentTxt
|
|
|
|
+ }
|
|
|
|
+ if expertContent != "" {
|
|
|
|
+ rightIndex := strings.Index(expertContent, ")")
|
|
|
|
+ if rightIndex == 0 {
|
|
|
|
+ rightIndex = strings.Index(expertContent, ")")
|
|
|
|
+ }
|
|
|
|
+ expertNum := expertContent[:rightIndex]
|
|
|
|
+ expertNum = strings.Replace(expertNum, "(", "", -1)
|
|
|
|
+ expertNum = strings.Replace(expertNum, "(", "", -1)
|
|
|
|
+ expertNum = strings.Replace(expertNum, "专家评价", "", -1)
|
|
|
|
+ if expertNum != "" {
|
|
|
|
+ expertNumArr = append(expertNumArr, expertNum)
|
|
|
|
+ rightIndex = rightIndex
|
|
|
|
+ expertContentStr := expertContent[rightIndex:]
|
|
|
|
+ expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
|
|
|
|
+ expertContentStr = strings.TrimLeft(expertContentStr, ":")
|
|
|
|
+ expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
|
|
|
|
+ if expertContentStr != "" {
|
|
|
|
+ expertContentArr = append(expertContentArr, expertContentStr)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
if len(expertNumArr) > 0 {
|
|
if len(expertNumArr) > 0 {
|
|
expertNumStr = expertNumArr[0]
|
|
expertNumStr = expertNumArr[0]
|
|
- if expertNumStr!="" {
|
|
|
|
|
|
+ if expertNumStr != "" {
|
|
expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
|
|
expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
|
|
expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
|
|
expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
|
|
expertNumStr = strings.Trim(expertNumStr, "")
|
|
expertNumStr = strings.Trim(expertNumStr, "")
|