123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- package services
- import (
- "context"
- "encoding/json"
- "fmt"
- "github.com/PuerkitoBio/goquery"
- "github.com/olivere/elastic/v7"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/utils"
- "strconv"
-
- "errors"
- "html"
- "strings"
- )
- type SearchComprehensiveItem struct {
- SourceId int `description:"资源ID"`
- IsSummary int `description:"是否是纪要"`
- Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior"`
- Title string `description:"标题"`
- BodyText string `description:"内容"`
- PublishDate string `description:"发布时间"`
- Abstract string `description:"摘要"`
- Annotation string `description:"核心观点"`
- IndustryName string `description:"产业名称"`
- SubjectNames string `description:"标的名称"`
- Body []string
- }
- type ElasticComprehensiveDetail struct {
- 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:"内容"`
- PublishDate string `description:"发布时间"`
- Abstract string `description:"摘要"`
- Annotation string `description:"核心观点"`
- IndustryName string `description:"产业名称"`
- SubjectNames string `description:"标的名称"`
- }
- func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
- indexName := utils.IndexNameComprehensive
- client := utils.Client
- keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
- keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
- keyWordLen := len(keyWordArr)
- if keyWordLen <= 0 {
- keyWordArr = append(keyWordArr, keyWord)
- keyWordLen = len(keyWordArr)
- }
-
-
- mustMap := make([]interface{}, 0)
- shouldMap := make(map[string]interface{}, 0)
- shouldMapquery := make([]interface{}, 0)
- mustNotMap := make([]interface{}, 0)
- shouldNotMap := make(map[string]interface{}, 0)
- shouldNotMapquery := make([]interface{}, 0)
-
-
- var boost int
-
- for k, v := range keyWordArr {
- if k > 0 {
- continue
- }
- if k == 0 {
- boost = 2 * 1000
- } else {
- boost = 1
- }
- if v != "" {
- shouldMapquery = append(shouldMapquery, map[string]interface{}{
- "function_score": map[string]interface{}{
- "query": map[string]interface{}{
- "multi_match": map[string]interface{}{
-
- "boost": boost,
- "fields": []interface{}{"Title"},
- "query": v,
- },
- },
- },
- })
- shouldMapquery = append(shouldMapquery, map[string]interface{}{
- "function_score": map[string]interface{}{
- "query": map[string]interface{}{
- "multi_match": map[string]interface{}{
- "boost": boost,
- "fields": []interface{}{"Abstract"},
- "query": v,
- },
- },
- },
- })
- shouldMapquery = append(shouldMapquery, map[string]interface{}{
- "function_score": map[string]interface{}{
- "query": map[string]interface{}{
- "multi_match": map[string]interface{}{
- "boost": boost,
- "fields": []interface{}{"Annotation"},
- "query": v,
- },
- },
- },
- })
-
-
-
-
-
-
-
-
-
-
-
-
- shouldMapquery = append(shouldMapquery, map[string]interface{}{
- "function_score": map[string]interface{}{
- "query": map[string]interface{}{
- "multi_match": map[string]interface{}{
-
- "boost": boost,
- "fields": []interface{}{"IndustryName"},
- "query": v,
- },
- },
- },
- })
- shouldMapquery = append(shouldMapquery, map[string]interface{}{
- "function_score": map[string]interface{}{
- "query": map[string]interface{}{
- "multi_match": map[string]interface{}{
-
- "boost": boost,
- "fields": []interface{}{"SubjectNames"},
- "query": v,
- },
- },
- },
- })
- }
- }
- shouldMap = map[string]interface{}{
- "should": shouldMapquery,
- }
- shouldNotMap = map[string]interface{}{
- "should": shouldNotMapquery,
- }
-
- sortMap := make([]interface{}, 0)
-
- sortMap = append(sortMap, map[string]interface{}{
- "PublishDate": map[string]interface{}{
- "order": "desc",
- },
- })
-
-
-
-
-
-
- highlightMap := make(map[string]interface{}, 0)
- highlightMap = map[string]interface{}{
- "fields": map[string]interface{}{
-
- "Title": map[string]interface{}{},
- "Abstract": map[string]interface{}{},
- "Annotation": map[string]interface{}{},
- },
-
- "post_tags": []interface{}{"</font>"},
- "pre_tags": []interface{}{"<font color='red'>"},
- "fragment_size": 50,
- }
- mustMap = append(mustMap, map[string]interface{}{
- "bool": shouldMap,
- })
- mustNotMap = append(mustNotMap, map[string]interface{}{
- "bool": shouldNotMap,
- })
- queryMap := map[string]interface{}{
- "query": map[string]interface{}{
- "bool": map[string]interface{}{
- "must": mustMap,
- },
- },
- }
- queryMap["sort"] = sortMap
- queryMap["from"] = startSize
- queryMap["size"] = pageSize
- queryMap["highlight"] = highlightMap
-
-
-
- request := client.Search(indexName).Source(queryMap)
- searchByMatch, err := request.Do(context.Background())
- if searchByMatch != nil {
- if searchByMatch.Hits != nil {
- for _, v := range searchByMatch.Hits.Hits {
- var isAppend bool
- articleJson, err := v.Source.MarshalJSON()
- if err != nil {
- return nil, 0, err
- }
- article := new(ElasticComprehensiveDetail)
- err = json.Unmarshal(articleJson, &article)
- if err != nil {
- return nil, 0, err
- }
-
- searchItem := new(SearchComprehensiveItem)
- searchItem.SourceId = article.SourceId
- if len(v.Highlight["Annotation"]) > 0 {
- for _, vText := range v.Highlight["Annotation"] {
- searchItem.Body = append(searchItem.Body, vText)
- }
- }
- if len(v.Highlight["Abstract"]) > 0 {
- for _, vText := range v.Highlight["Abstract"] {
- searchItem.Body = append(searchItem.Body, vText)
- }
- }
- if len(v.Highlight["BodyText"]) > 0 {
- for _, vText := range v.Highlight["BodyText"] {
- searchItem.Body = append(searchItem.Body, vText)
- }
- }
-
-
-
-
-
-
-
-
-
-
- var title string
- if len(v.Highlight["Title"]) > 0 {
- title = v.Highlight["Title"][0]
- } else {
- title = article.Title
- }
- searchItem.Title = title
- searchItem.Source = article.Source
- searchItem.PublishDate = article.PublishDate
- if !isAppend {
- result = append(result, searchItem)
- }
- }
- }
- total = searchByMatch.Hits.TotalHits.Value
- }
- return
- }
- func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
- var condition string
- var pars []interface{}
- uid := user.UserId
- titleHighlight := make(map[int]string)
- bodyHighlight := make(map[int][]string)
- yanXuanbodyHighlight := make(map[int][]string)
- mapItems := make(map[string]*models.CygxResourceDataNewResp)
- for _, v := range list {
-
- item := new(models.CygxResourceDataNewResp)
- item.SourceId = v.SourceId
- item.Source = v.Source
- item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- item.BodyHighlight = v.Body
- item.TitleHighlight = v.Title
- titleHighlight[v.SourceId] = v.Title
- bodyHighlight[v.SourceId] = v.Body
- mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
- }
- var articleIds []int
- var activityIds []int
- var yanxuanSpecialIds []int
- var yanxuanspecialauthorIds []int
- var activityvideoIds []string
- var activityvoiceIds []string
- var roadshowIds []string
- var askserieVideoIds []string
-
- for _, v := range list {
- if v.Source == "article" {
- articleIds = append(articleIds, v.SourceId)
- } else if v.Source == "activity" {
- activityIds = append(activityIds, v.SourceId)
- } else if v.Source == "activityvideo" {
- activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
- } else if v.Source == "activityvoice" {
- activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
- } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
- yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
- } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL_AUTHOR {
- yanxuanspecialauthorIds = append(yanxuanspecialauthorIds, v.SourceId)
- }
- }
- detail, e := models.GetConfigByCode("city_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- detailChart, e := models.GetConfigByCode("chart_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- addressList := strings.Split(detail.ConfigValue, "{|}")
- mapAddress := make(map[string]string)
- chartList := strings.Split(detailChart.ConfigValue, "{|}")
- mapChart := make(map[string]string)
- var cityName string
- var chartName string
- var imgUrl string
- var imgUrlChart string
- for _, v := range addressList {
- vslice := strings.Split(v, "_")
- cityName = vslice[0]
- imgUrl = vslice[len(vslice)-1]
- mapAddress[cityName] = imgUrl
- }
- for _, v := range chartList {
- vslice := strings.Split(v, "_")
- chartName = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapChart[chartName] = imgUrlChart
- }
- var imgUrlResp string
-
- if len(articleIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- pars = append(pars, articleIds)
- articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- articleList, e = HandleArticleCategoryImg(articleList, user)
- if e != nil {
- err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
- return
- }
- for _, v := range articleList {
- v.Body = ""
- if titleHighlight[v.ArticleId] != "" {
- v.Title = titleHighlight[v.ArticleId]
- }
- if len(bodyHighlight[v.ArticleId]) > 0 {
- v.Abstract = ""
- v.Annotation = ""
- v.BodyHighlight = bodyHighlight[v.ArticleId]
- } else {
- v.BodyHighlight = make([]string, 0)
- }
- mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
- }
- }
-
- if len(activityIds) > 0 {
- for _, vss := range activityIds {
- imgUrlResp += strconv.Itoa(vss) + ","
- }
- pars = make([]interface{}, 0)
- condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
- pars = append(pars, activityIds)
- activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- var activityListRersp []*models.ActivityListResp
-
-
-
-
- activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
-
- mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
- if e != nil {
- err = errors.New("GetActivitySignupResp, Err: " + e.Error())
- return
- }
- for _, v := range activityListRersp {
- if v == nil {
- continue
- }
- if v.ActivityType == 0 {
- if mapAddress[v.City] != "" {
- imgUrlResp = mapAddress[v.City]
- } else {
- imgUrlResp = mapAddress["其它"]
- }
- } else {
- if mapChart[v.ChartPermissionName] != "" {
- imgUrlResp = mapChart[v.ChartPermissionName]
- }
- }
- v.ImgUrl = imgUrlResp
- v.SourceType = mapActivitySignup[v.ActivityId]
- mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
- }
- }
-
- 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, 0, 0)
- if e != nil {
- err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
- return
- }
- yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds)
- for _, v := range listyanxuanSpecial {
- v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
- v.Annotation, _ = GetReportContentTextSubNew(v.Content)
- v.Pv = yanxuanSpecialPv[v.Id]
- if len(yanXuanbodyHighlight[v.Id]) > 0 {
- v.BodyHighlight = yanXuanbodyHighlight[v.Id]
- } else {
- v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
- }
- v.Annotation = ""
- v.LabelKeywordImgLink = utils.LABEL_ICO_4
- mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
- }
- }
-
- lenyanxuanspecialauthorIds := len(yanxuanspecialauthorIds)
- if lenyanxuanspecialauthorIds > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanspecialauthorIds) + `) `
- condition += ` ORDER BY latest_publish_time DESC `
- pars = append(pars, yanxuanspecialauthorIds)
- listAuthor, e := models.GetYanxuanSpecialAuthorList("", condition, pars, 0, lenyanxuanspecialauthorIds)
- if e != nil {
- err = errors.New("GetYanxuanSpecialAuthorList, Err: " + e.Error())
- return
- }
- for _, v := range listAuthor {
- v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate)
- v.LabelKeywordImgLink = utils.LABEL_ICO_9
- mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL_AUTHOR, v.Id)].YanxuanSpecialAuthor = v
- }
- }
- if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
- audioIdstr := strings.Join(activityvoiceIds, ",")
- activityVideoIdsStr := strings.Join(activityvideoIds, ",")
- roadshowIdsStr := strings.Join(roadshowIds, ",")
- askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
- listv, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
- if e != nil {
- err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
- return
- }
-
- authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
- return
- }
-
- audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
- return
- }
-
- for i := range listv {
-
- au := new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
-
- if listv[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, listv[i].ChartPermissionName) {
- au.HasPermission = 2
- }
- }
-
- if au.HasPermission != 1 {
- if au.OperationMode == UserPermissionOperationModeCall {
- if listv[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgCallActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
- }
- } else {
- if listv[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgApplyActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
- }
- }
- }
- listv[i].AuthInfo = au
- listv[i].PublishTime = utils.StrTimeToTime(listv[i].PublishTime).Format(utils.FormatDate)
-
- if listv[i].BackgroundImg == "" {
- if listv[i].Type == 1 {
- listv[i].BackgroundImg = audioMap[listv[i].ChartPermissionId]
- } else {
- listv[i].BackgroundImg = videoMap[listv[i].ChartPermissionId]
- }
- }
-
- if listv[i].ShareImg == "" {
- if listv[i].Type == 1 {
- listv[i].ShareImg = audioShareMap[listv[i].ChartPermissionId]
- } else {
- listv[i].ShareImg = videoShareMap[listv[i].ChartPermissionId]
- }
- }
- listv[i].LabelKeywordImgLink = utils.LABEL_ICO_10
- }
-
- for _, item := range listv {
- if item.Type == 1 {
- mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
- } else if item.Type == 2 {
- mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
- } else if item.Type == 3 {
- mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
- } else if item.Type == 4 {
- mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
- }
- }
- }
- 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.YanxuanSpecial == nil && v.AskserieVideo == nil && v.YanxuanSpecialAuthor == nil {
- continue
- }
- if v.SourceId == vList.SourceId && v.Source == vList.Source {
- items = append(items, v)
- }
- }
- }
- return
- }
- func SqlComprehensiveSearch(user *models.WxUserItem, keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
- yanxuanActivityIds := GetYanxuanActivityIds(user, "")
- yanxuanArticleIds := GetYanxuanArticleIds()
- yanxuanArticleIds = append(yanxuanArticleIds, 0)
- yanxuanActivityIds = append(yanxuanActivityIds, 0)
- var yanxuanArticleIdsStr []string
- var yanxuanActivityIdsStr []string
- for _, v := range yanxuanArticleIds {
- yanxuanArticleIdsStr = append(yanxuanArticleIdsStr, strconv.Itoa(v))
- }
- for _, v := range yanxuanActivityIds {
- yanxuanActivityIdsStr = append(yanxuanActivityIdsStr, strconv.Itoa(v))
- }
-
- condition := " AND source IN ('article','activity','yanxuanspecial','activityvoice','activityvideo') AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id = 31 ,1=1 ) "
- condition += ` AND IF ( source = 'article' , source_id IN (` + strings.Join(yanxuanArticleIdsStr, ",") + `) ,1=1 ) `
-
- condition += ` AND IF ( source = 'activity' , source_id IN (` + strings.Join(yanxuanActivityIdsStr, ",") + `) ,1=1 ) `
-
- keyWord = "%" + keyWord + "%"
- var conditionTitle string
- var parsTitle []interface{}
- conditionTitle = " AND search_title LIKE ? " + condition
- parsTitle = append(parsTitle, keyWord)
- var conditionContentYxAuthor string
- var parsContentYxAuthor []interface{}
- conditionContentYxAuthor = " AND (special_name LIKE ? OR nick_name LIKE ? ) "
- parsContentYxAuthor = append(parsContentYxAuthor, keyWord, keyWord)
- totalTitle, e := models.GetResourceDataAndYanxuanSpecialAuthorCount(conditionTitle, parsTitle, conditionContentYxAuthor, parsContentYxAuthor)
-
- if e != nil {
- err = errors.New("GetResourceDataAndYanxuanSpecialAuthorCount, Err: " + e.Error())
- return
- }
- var conditionContent string
- var parsContent []interface{}
- conditionContent = " AND search_content LIKE ? AND search_title NOT LIKE ? " + condition
- parsContent = append(parsContent, keyWord, keyWord)
- totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
- if e != nil {
- err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
- return
- }
- var searchTotal int
- searchTotal = (startSize/pageSize + 1) * pageSize
- var list []*models.CygxResourceData
- if totalTitle >= searchTotal {
-
- list, e = models.GetResourceDataAndYanxuanSpecialAuthorListCondition(conditionTitle, parsTitle, conditionContentYxAuthor, parsContentYxAuthor, startSize, pageSize)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
- return
- }
- } else if totalTitle <= searchTotal-pageSize {
-
- startSize = startSize - totalTitle
- list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
- return
- }
- } else {
-
-
- list, e = models.GetResourceDataAndYanxuanSpecialAuthorListCondition(conditionTitle, parsTitle, conditionContentYxAuthor, parsContentYxAuthor, startSize, pageSize)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetResourceDataAndYanxuanSpecialAuthorListCondition, Err: " + e.Error())
- return
- }
- listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
- return
- }
- for _, v := range listContent {
- list = append(list, v)
- }
- }
- for _, v := range list {
- item := new(SearchComprehensiveItem)
- item.SourceId = v.SourceId
- item.Source = v.Source
- result = append(result, item)
- }
- total = totalTitle + totalContent
- return
- }
- 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
- item.Abstract = bodyText
- item.IndustryName = detail.IndustryTags
- item.SubjectNames = detail.CompanyTags + detail.Tags
- if detail.Status == 3 {
- EsAddOrEditComprehensiveData(item)
- } else {
- EsDeleteComprehensiveData(item)
- }
- return
- }
- func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
- indexName := utils.IndexNameComprehensive
-
- defer func() {
- if err != nil {
- fmt.Println(err, item.SourceId)
-
- }
- }()
- 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
- }
-
-
- 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" {
-
-
- return
- } else {
-
- 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]" {
-
-
-
-
- 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
- }
|