|
@@ -4,11 +4,14 @@ import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/PuerkitoBio/goquery"
|
|
|
+ "github.com/olivere/elastic/v7"
|
|
|
"hongze/hongze_clpt/models"
|
|
|
"hongze/hongze_clpt/utils"
|
|
|
"strconv"
|
|
|
//"strconv"
|
|
|
"errors"
|
|
|
+ "html"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -28,8 +31,8 @@ type SearchComprehensiveItem struct {
|
|
|
}
|
|
|
|
|
|
type ElasticComprehensiveDetail struct {
|
|
|
- SourceId int `description:"资源ID"`
|
|
|
- //IsSummary int `description:"是否是纪要"`
|
|
|
+ SourceId int `description:"资源ID"`
|
|
|
+ IsSummary int `description:"是否是纪要"`
|
|
|
Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior 、 产业资源包:industrialsource"`
|
|
|
Title string `description:"标题"`
|
|
|
BodyText string `description:"内容"`
|
|
@@ -304,6 +307,7 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
|
|
|
var productinteriorIds []int //产品内测
|
|
|
var industrialResourceIdsHz []int // 弘则产业资源包
|
|
|
var industrialResourceIdsYx []int // 研选产业资源包
|
|
|
+ var yanxuanSpecialIds []int // 研选专栏
|
|
|
//Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
|
|
|
for _, v := range list {
|
|
|
if v.Source == "article" {
|
|
@@ -332,6 +336,8 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
|
|
|
industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
|
|
|
} else if v.Source == "industrialsourceYx" {
|
|
|
industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
|
|
|
+ } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
|
|
|
+ yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
|
|
|
}
|
|
|
}
|
|
|
detail, e := models.GetConfigByCode("city_img_url")
|
|
@@ -771,10 +777,29 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //处理研选专栏
|
|
|
+ lenyanxuanSpecialIds := len(yanxuanSpecialIds)
|
|
|
+ if lenyanxuanSpecialIds > 0 {
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
|
|
|
+ pars = append(pars, yanxuanSpecialIds)
|
|
|
+ listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range listyanxuanSpecial {
|
|
|
+ v.Annotation, _ = GetReportContentTextSubNew(v.Content)
|
|
|
+ mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for _, vList := range list {
|
|
|
for _, v := range mapItems {
|
|
|
//如果这些类型都为空,那么就不合并
|
|
|
- if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil {
|
|
|
+ if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.YanxuanSpecial == nil {
|
|
|
continue
|
|
|
}
|
|
|
if v.Article != nil && v.SourceId == vList.SourceId {
|
|
@@ -823,3 +848,147 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// Es研选专栏
|
|
|
+func EsAddYanxuanSpecial(sourceId int) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err:", err)
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ detail, e := models.GetYanxuanSpecialItemById(sourceId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ content := html.UnescapeString(detail.Content)
|
|
|
+ doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("goquery.NewDocumentFromReader" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ bodyText := doc.Text()
|
|
|
+ item := new(ElasticComprehensiveDetail)
|
|
|
+ item.SourceId = detail.Id
|
|
|
+ item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
|
|
|
+ item.Title = detail.Title
|
|
|
+ item.PublishDate = detail.PublishTime
|
|
|
+ item.BodyText = bodyText
|
|
|
+ if detail.Status == 3 {
|
|
|
+ EsAddOrEditComprehensiveData(item) //如果发布了就新增
|
|
|
+ } else {
|
|
|
+ EsDeleteComprehensiveData(item) // 没有发布就删除
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 新增和修改数据
|
|
|
+func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
|
|
|
+ indexName := utils.IndexNameComprehensive
|
|
|
+ //return
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err, item.SourceId)
|
|
|
+ //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ client := utils.Client
|
|
|
+ mustMap := make([]interface{}, 0)
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "term": map[string]interface{}{
|
|
|
+ "SourceId": item.SourceId,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "term": map[string]interface{}{
|
|
|
+ "Source": item.Source,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "query": map[string]interface{}{
|
|
|
+ "bool": map[string]interface{}{
|
|
|
+ "must": mustMap,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ requestTotalHits := client.Count(indexName).BodyJson(queryMap)
|
|
|
+ total, e := requestTotalHits.Do(context.Background())
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //return
|
|
|
+ //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
|
|
|
+ if total == 0 {
|
|
|
+ resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if resp.Status == 0 && resp.Result == "created" {
|
|
|
+ //fmt.Println("新增成功")
|
|
|
+ //err = nil
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ //err = errors.New(fmt.Sprint(resp))
|
|
|
+ err = errors.New(fmt.Sprint("articleId", item.SourceId))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //拼接需要改动的前置条件
|
|
|
+ bool_query := elastic.NewBoolQuery()
|
|
|
+ bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
|
|
|
+ bool_query.Must(elastic.NewTermQuery("Source", item.Source))
|
|
|
+ //设置需要改动的内容
|
|
|
+ var script string
|
|
|
+ script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
|
|
|
+ script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
|
|
|
+ script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
|
|
|
+
|
|
|
+ _, e = client.UpdateByQuery(indexName).
|
|
|
+ Query(bool_query).
|
|
|
+ Script(elastic.NewScriptInline(script)).
|
|
|
+ Refresh("true").
|
|
|
+ Do(context.Background())
|
|
|
+
|
|
|
+ if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
|
|
|
+ //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
|
|
|
+ //fmt.Println("err", e.Error())
|
|
|
+ ////err = e
|
|
|
+ //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 删除数据
|
|
|
+func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ indexName := utils.IndexNameComprehensive
|
|
|
+ client := utils.Client
|
|
|
+ //拼接需要删除的前置条件
|
|
|
+ bool_query := elastic.NewBoolQuery()
|
|
|
+ bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
|
|
|
+ bool_query.Must(elastic.NewTermQuery("Source", item.Source))
|
|
|
+ _, e := client.DeleteByQuery(indexName).
|
|
|
+ Query(bool_query).
|
|
|
+ Do(context.Background())
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|