es_comprehensive.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "github.com/olivere/elastic/v7"
  8. "hongze/hongze_clpt/models"
  9. "hongze/hongze_clpt/utils"
  10. "strconv"
  11. //"strconv"
  12. "errors"
  13. "html"
  14. "strings"
  15. "time"
  16. )
  17. type SearchComprehensiveItem struct {
  18. SourceId int `description:"资源ID"`
  19. IsSummary int `description:"是否是纪要"`
  20. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior"`
  21. Title string `description:"标题"`
  22. BodyText string `description:"内容"`
  23. PublishDate string `description:"发布时间"`
  24. Abstract string `description:"摘要"`
  25. Annotation string `description:"核心观点"`
  26. IndustryName string `description:"产业名称"`
  27. SubjectNames string `description:"标的名称"`
  28. Body []string
  29. }
  30. type ElasticComprehensiveDetail struct {
  31. SourceId int `description:"资源ID"`
  32. IsSummary int `description:"是否是纪要"`
  33. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior 、 产业资源包:industrialsource"`
  34. Title string `description:"标题"`
  35. BodyText string `description:"内容"`
  36. PublishDate string `description:"发布时间"`
  37. Abstract string `description:"摘要"`
  38. Annotation string `description:"核心观点"`
  39. IndustryName string `description:"产业名称"`
  40. SubjectNames string `description:"标的名称"`
  41. }
  42. func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  43. indexName := utils.IndexNameComprehensive
  44. client := utils.Client
  45. keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
  46. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  47. keyWordLen := len(keyWordArr)
  48. if keyWordLen <= 0 {
  49. keyWordArr = append(keyWordArr, keyWord)
  50. keyWordLen = len(keyWordArr)
  51. }
  52. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  53. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  54. mustMap := make([]interface{}, 0)
  55. shouldMap := make(map[string]interface{}, 0)
  56. shouldMapquery := make([]interface{}, 0)
  57. mustNotMap := make([]interface{}, 0)
  58. shouldNotMap := make(map[string]interface{}, 0)
  59. shouldNotMapquery := make([]interface{}, 0)
  60. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  61. //keyWordWeight := GetWeight(keyWordLen)
  62. var boost int
  63. //lenkeyWordArr := len(keyWordArr)
  64. for k, v := range keyWordArr {
  65. if k > 0 {
  66. continue
  67. }
  68. if k == 0 {
  69. boost = 2 * 1000
  70. } else {
  71. boost = 1
  72. }
  73. if v != "" {
  74. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  75. "function_score": map[string]interface{}{
  76. "query": map[string]interface{}{
  77. "multi_match": map[string]interface{}{
  78. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  79. "boost": boost, //给查询的值赋予权重
  80. "fields": []interface{}{"Title"},
  81. "query": v,
  82. },
  83. },
  84. },
  85. })
  86. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  87. "function_score": map[string]interface{}{
  88. "query": map[string]interface{}{
  89. "multi_match": map[string]interface{}{
  90. "boost": boost, //给查询的值赋予权重
  91. "fields": []interface{}{"Abstract"},
  92. "query": v,
  93. },
  94. },
  95. },
  96. })
  97. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  98. "function_score": map[string]interface{}{
  99. "query": map[string]interface{}{
  100. "multi_match": map[string]interface{}{
  101. "boost": boost, //给查询的值赋予权重
  102. "fields": []interface{}{"Annotation"},
  103. "query": v,
  104. },
  105. },
  106. },
  107. })
  108. //shouldMapquery = append(shouldMapquery, map[string]interface{}{
  109. // "function_score": map[string]interface{}{
  110. // "query": map[string]interface{}{
  111. // "multi_match": map[string]interface{}{
  112. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  113. // "boost": boost, //给查询的值赋予权重
  114. // "fields": []interface{}{"BodyText"},
  115. // "query": v,
  116. // },
  117. // },
  118. // },
  119. //})
  120. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  121. "function_score": map[string]interface{}{
  122. "query": map[string]interface{}{
  123. "multi_match": map[string]interface{}{
  124. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  125. "boost": boost, //给查询的值赋予权重
  126. "fields": []interface{}{"IndustryName"},
  127. "query": v,
  128. },
  129. },
  130. },
  131. })
  132. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  133. "function_score": map[string]interface{}{
  134. "query": map[string]interface{}{
  135. "multi_match": map[string]interface{}{
  136. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  137. "boost": boost, //给查询的值赋予权重
  138. "fields": []interface{}{"SubjectNames"},
  139. "query": v,
  140. },
  141. },
  142. },
  143. })
  144. }
  145. }
  146. shouldMap = map[string]interface{}{
  147. "should": shouldMapquery,
  148. }
  149. shouldNotMap = map[string]interface{}{
  150. "should": shouldNotMapquery,
  151. }
  152. //排序
  153. sortMap := make([]interface{}, 0)
  154. //时间
  155. sortMap = append(sortMap, map[string]interface{}{
  156. "PublishDate": map[string]interface{}{
  157. "order": "desc",
  158. },
  159. })
  160. //sortMap = append(sortMap, map[string]interface{}{
  161. // "_score": map[string]interface{}{
  162. // "order": "desc",
  163. // },
  164. //})
  165. //高亮
  166. highlightMap := make(map[string]interface{}, 0)
  167. highlightMap = map[string]interface{}{
  168. "fields": map[string]interface{}{
  169. //"BodyText": map[string]interface{}{},
  170. "Title": map[string]interface{}{},
  171. "Abstract": map[string]interface{}{},
  172. "Annotation": map[string]interface{}{},
  173. },
  174. //样式 红色
  175. "post_tags": []interface{}{"</font>"},
  176. "pre_tags": []interface{}{"<font color='red'>"},
  177. "fragment_size": 50,
  178. }
  179. mustMap = append(mustMap, map[string]interface{}{
  180. "bool": shouldMap,
  181. })
  182. mustNotMap = append(mustNotMap, map[string]interface{}{
  183. "bool": shouldNotMap,
  184. })
  185. queryMap := map[string]interface{}{
  186. "query": map[string]interface{}{
  187. "bool": map[string]interface{}{
  188. "must": mustMap,
  189. },
  190. },
  191. }
  192. queryMap["sort"] = sortMap
  193. queryMap["from"] = startSize
  194. queryMap["size"] = pageSize
  195. queryMap["highlight"] = highlightMap
  196. //jsonBytes, _ := json.Marshal(queryMap)
  197. //fmt.Println(string(jsonBytes))
  198. //utils.FileLog.Info(string(jsonBytes))
  199. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  200. searchByMatch, err := request.Do(context.Background())
  201. if searchByMatch != nil {
  202. if searchByMatch.Hits != nil {
  203. for _, v := range searchByMatch.Hits.Hits {
  204. var isAppend bool
  205. articleJson, err := v.Source.MarshalJSON()
  206. if err != nil {
  207. return nil, 0, err
  208. }
  209. article := new(ElasticComprehensiveDetail)
  210. err = json.Unmarshal(articleJson, &article)
  211. if err != nil {
  212. return nil, 0, err
  213. }
  214. //fmt.Println(article.SourceId, article.Title, article.Source)
  215. searchItem := new(SearchComprehensiveItem)
  216. searchItem.SourceId = article.SourceId
  217. if len(v.Highlight["Annotation"]) > 0 {
  218. for _, vText := range v.Highlight["Annotation"] {
  219. searchItem.Body = append(searchItem.Body, vText)
  220. }
  221. }
  222. if len(v.Highlight["Abstract"]) > 0 {
  223. for _, vText := range v.Highlight["Abstract"] {
  224. searchItem.Body = append(searchItem.Body, vText)
  225. }
  226. }
  227. if len(v.Highlight["BodyText"]) > 0 {
  228. for _, vText := range v.Highlight["BodyText"] {
  229. searchItem.Body = append(searchItem.Body, vText)
  230. }
  231. }
  232. //searchItem.IsSummary = article.IsSummary
  233. //if len(searchItem.Body) == 0 {
  234. // bodyRune := []rune(article.BodyText)
  235. // bodyRuneLen := len(bodyRune)
  236. // if bodyRuneLen > 100 {
  237. // bodyRuneLen = 100
  238. // }
  239. // body := string(bodyRune[:bodyRuneLen])
  240. // searchItem.Body = []string{body}
  241. //}
  242. var title string
  243. if len(v.Highlight["Title"]) > 0 {
  244. title = v.Highlight["Title"][0]
  245. } else {
  246. title = article.Title
  247. }
  248. searchItem.Title = title
  249. searchItem.Source = article.Source
  250. searchItem.PublishDate = article.PublishDate
  251. if !isAppend {
  252. result = append(result, searchItem)
  253. }
  254. }
  255. }
  256. total = searchByMatch.Hits.TotalHits.Value
  257. }
  258. return
  259. }
  260. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  261. var condition string
  262. var pars []interface{}
  263. uid := user.UserId
  264. titleHighlight := make(map[int]string)
  265. bodyHighlight := make(map[int][]string)
  266. yanXuanbodyHighlight := make(map[int][]string)
  267. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  268. for _, v := range list {
  269. //预处理文章
  270. item := new(models.CygxResourceDataNewResp)
  271. item.SourceId = v.SourceId
  272. item.Source = v.Source
  273. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  274. item.BodyHighlight = v.Body
  275. item.TitleHighlight = v.Title
  276. titleHighlight[v.SourceId] = v.Title
  277. bodyHighlight[v.SourceId] = v.Body
  278. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  279. }
  280. var articleIds []int //报告
  281. var newchartIds []int //图表
  282. var roadshowIds []string //微路演
  283. var activityIds []int //活动
  284. var activityvideoIds []string // 活动视频
  285. var activityvoiceIds []string //活动音频
  286. var activityspecialIds []int //专项调研活动
  287. var researchsummaryIds []int //本周研究汇总
  288. var minutessummaryIds []int //上周纪要汇总
  289. var meetingreviewchaptIds []int //晨会精华
  290. var productinteriorIds []int //产品内测
  291. var industrialResourceIdsHz []int // 弘则产业资源包
  292. var industrialResourceIdsYx []int // 研选产业资源包
  293. var yanxuanSpecialIds []int // 研选专栏
  294. var askserieVideoIds []string //问答系列视频
  295. var reportselectionIds []int //报告精选
  296. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  297. for _, v := range list {
  298. if v.Source == "article" {
  299. articleIds = append(articleIds, v.SourceId)
  300. } else if v.Source == "newchart" {
  301. newchartIds = append(newchartIds, v.SourceId)
  302. } else if v.Source == "roadshow" {
  303. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  304. } else if v.Source == "activity" {
  305. activityIds = append(activityIds, v.SourceId)
  306. } else if v.Source == "activityvideo" {
  307. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  308. } else if v.Source == "activityvoice" {
  309. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  310. } else if v.Source == "activityspecial" {
  311. activityspecialIds = append(activityspecialIds, v.SourceId)
  312. } else if v.Source == "researchsummary" {
  313. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  314. } else if v.Source == "minutessummary" {
  315. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  316. } else if v.Source == "meetingreviewchapt" {
  317. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  318. } else if v.Source == "productinterior" {
  319. productinteriorIds = append(productinteriorIds, v.SourceId)
  320. } else if v.Source == "industrialsourceHz" {
  321. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  322. } else if v.Source == "industrialsourceYx" {
  323. industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
  324. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  325. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  326. yanXuanbodyHighlight[v.SourceId] = v.Body
  327. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  328. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  329. } else if v.Source == "reportselection" {
  330. reportselectionIds = append(reportselectionIds, v.SourceId)
  331. }
  332. }
  333. detail, e := models.GetConfigByCode("city_img_url")
  334. if e != nil {
  335. err = errors.New("GetResourceDataList, Err: " + e.Error())
  336. return
  337. }
  338. detailChart, e := models.GetConfigByCode("chart_img_url")
  339. if e != nil {
  340. err = errors.New("GetResourceDataList, Err: " + e.Error())
  341. return
  342. }
  343. addressList := strings.Split(detail.ConfigValue, "{|}")
  344. mapAddress := make(map[string]string)
  345. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  346. mapChart := make(map[string]string)
  347. var cityName string
  348. var chartName string
  349. var imgUrl string
  350. var imgUrlChart string
  351. for _, v := range addressList {
  352. vslice := strings.Split(v, "_")
  353. cityName = vslice[0]
  354. imgUrl = vslice[len(vslice)-1]
  355. mapAddress[cityName] = imgUrl
  356. }
  357. for _, v := range chartList {
  358. vslice := strings.Split(v, "_")
  359. chartName = vslice[0]
  360. imgUrlChart = vslice[len(vslice)-1]
  361. mapChart[chartName] = imgUrlChart
  362. }
  363. var imgUrlResp string
  364. //处理文章
  365. if len(articleIds) > 0 {
  366. pars = make([]interface{}, 0)
  367. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  368. pars = append(pars, articleIds)
  369. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  370. if e != nil {
  371. err = errors.New("GetResourceDataList, Err: " + e.Error())
  372. return
  373. }
  374. articleList, e = HandleArticleCategoryImg(articleList, user)
  375. if e != nil {
  376. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  377. return
  378. }
  379. for _, v := range articleList {
  380. v.Body = ""
  381. if titleHighlight[v.ArticleId] != "" {
  382. v.Title = titleHighlight[v.ArticleId]
  383. }
  384. if len(bodyHighlight[v.ArticleId]) > 0 {
  385. v.Abstract = ""
  386. v.Annotation = ""
  387. v.BodyHighlight = bodyHighlight[v.ArticleId]
  388. } else {
  389. v.BodyHighlight = make([]string, 0)
  390. }
  391. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  392. }
  393. }
  394. //处理晨会精华
  395. if len(meetingreviewchaptIds) > 0 {
  396. //pars = make([]interface{}, 0)
  397. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  398. //pars = append(pars, meetingreviewchaptIds)
  399. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  400. if e != nil {
  401. err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
  402. return
  403. }
  404. for _, v := range listrMeet {
  405. v.Content = AnnotationHtml(v.Content)
  406. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  407. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  408. }
  409. }
  410. //处理上周纪要汇总
  411. if len(minutessummaryIds) > 0 {
  412. pars = make([]interface{}, 0)
  413. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  414. pars = append(pars, minutessummaryIds)
  415. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  416. if e != nil {
  417. err = errors.New("GetResourceDataList, Err: " + e.Error())
  418. return
  419. }
  420. for _, v := range listresearchsummary {
  421. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  422. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  423. }
  424. }
  425. //处理本周纪要汇总
  426. if len(researchsummaryIds) > 0 {
  427. pars = make([]interface{}, 0)
  428. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  429. pars = append(pars, researchsummaryIds)
  430. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  431. if e != nil {
  432. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  433. return
  434. }
  435. for _, v := range listresearchsummary {
  436. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  437. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  438. }
  439. }
  440. //处理产品内测
  441. if len(productinteriorIds) > 0 {
  442. pars = make([]interface{}, 0)
  443. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  444. pars = append(pars, productinteriorIds)
  445. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  446. if e != nil {
  447. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  448. return
  449. }
  450. for _, v := range listProductInterior {
  451. v.Body = ProductInteriorHtml(v.Body)
  452. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  453. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  454. }
  455. }
  456. //处理报告精选
  457. lenreportselectionIds := len(reportselectionIds)
  458. if lenreportselectionIds > 0 {
  459. pars = make([]interface{}, 0)
  460. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  461. pars = append(pars, reportselectionIds)
  462. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  463. if e != nil {
  464. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  465. return
  466. }
  467. mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
  468. for _, v := range listreportselection {
  469. v.Title += "(第" + v.Periods + "期)"
  470. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  471. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  472. v.Pv = mapPv[v.ArticleId]
  473. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  474. }
  475. }
  476. //处理活动
  477. if len(activityIds) > 0 {
  478. for _, vss := range activityIds {
  479. imgUrlResp += strconv.Itoa(vss) + ","
  480. }
  481. pars = make([]interface{}, 0)
  482. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  483. pars = append(pars, activityIds)
  484. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  485. if e != nil {
  486. err = errors.New("GetResourceDataList, Err: " + e.Error())
  487. return
  488. }
  489. var activityListRersp []*models.ActivityListResp
  490. //for _, v := range activityList {
  491. // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  492. //}
  493. //var pArr []string
  494. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  495. //处理不同的报名方式按钮回显
  496. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  497. if e != nil {
  498. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  499. return
  500. }
  501. for _, v := range activityListRersp {
  502. if v == nil {
  503. continue
  504. }
  505. if v.ActivityType == 0 {
  506. if mapAddress[v.City] != "" {
  507. imgUrlResp = mapAddress[v.City]
  508. } else {
  509. imgUrlResp = mapAddress["其它"]
  510. }
  511. } else {
  512. if mapChart[v.ChartPermissionName] != "" {
  513. imgUrlResp = mapChart[v.ChartPermissionName]
  514. }
  515. }
  516. v.ImgUrl = imgUrlResp
  517. v.SourceType = mapActivitySignup[v.ActivityId]
  518. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  519. }
  520. }
  521. //产业资源包
  522. if len(industrialResourceIdsHz) > 0 {
  523. pars = make([]interface{}, 0)
  524. var industrialResourceIdstring []string
  525. for _, v := range industrialResourceIdsHz {
  526. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  527. }
  528. industrialId := strings.Join(industrialResourceIdstring, ",")
  529. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  530. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  531. if e != nil {
  532. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  533. return
  534. }
  535. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsHz)) + `)`
  536. pars = append(pars, industrialResourceIdsHz)
  537. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  538. //合并产业关联的标的
  539. if e != nil {
  540. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  541. return
  542. }
  543. mapIndustrial := make(map[string]int)
  544. for _, v := range listSubjcet {
  545. for k2, v2 := range listIndustrialResourceIds {
  546. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  547. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  548. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  549. }
  550. }
  551. }
  552. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Hz")
  553. for _, v := range listIndustrialResourceIds {
  554. v.Source = 1
  555. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  556. }
  557. }
  558. //产业资源包
  559. if len(industrialResourceIdsYx) > 0 {
  560. pars = make([]interface{}, 0)
  561. var industrialResourceIdstring []string
  562. for _, v := range industrialResourceIdsYx {
  563. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  564. }
  565. industrialId := strings.Join(industrialResourceIdstring, ",")
  566. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  567. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  568. if e != nil {
  569. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  570. return
  571. }
  572. fmt.Println(listIndustrialResourceIds)
  573. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  574. pars = append(pars, industrialResourceIdsYx)
  575. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  576. //合并产业关联的标的
  577. if e != nil {
  578. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  579. return
  580. }
  581. mapIndustrial := make(map[string]int)
  582. for _, v := range listSubjcet {
  583. for k2, v2 := range listIndustrialResourceIds {
  584. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  585. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  586. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  587. }
  588. }
  589. }
  590. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  591. for _, v := range listIndustrialResourceIds {
  592. v.Source = 2
  593. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  594. }
  595. }
  596. //处理图表
  597. if len(newchartIds) > 0 {
  598. pars = make([]interface{}, 0)
  599. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  600. pars = append(pars, newchartIds)
  601. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  602. if e != nil {
  603. err = errors.New("GetResourceDataList, Err: " + e.Error())
  604. return
  605. }
  606. for _, v := range chartDateList {
  607. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  608. }
  609. }
  610. //处理专项调研
  611. if len(activityspecialIds) > 0 {
  612. pars = make([]interface{}, 0)
  613. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  614. pars = append(pars, activityspecialIds)
  615. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  616. if e != nil {
  617. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  618. return
  619. }
  620. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  621. if e != nil {
  622. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  623. return
  624. }
  625. for _, v := range activitySpeciallist {
  626. if mapChart[v.ChartPermissionName] != "" {
  627. imgUrlResp = mapChart[v.ChartPermissionName]
  628. }
  629. if _, ok := UserMap[v.ActivityId]; ok {
  630. v.IsTrip = 1
  631. }
  632. if v.Days == 0 {
  633. v.TripStatus = 1
  634. v.TripImgLink = v.TripImgLink
  635. } else {
  636. v.TripStatus = 2
  637. v.TripImgLink = v.TripImgLinkFix
  638. v.ActivityTimeText = v.ActivityTimeTextByDay
  639. }
  640. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  641. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  642. if resultTimeStart.After(time.Now()) {
  643. v.ActiveState = "1"
  644. } else if time.Now().After(resultTimeEnd) {
  645. v.ActiveState = "3"
  646. } else {
  647. v.ActiveState = "2"
  648. }
  649. v.ImgUrl = imgUrlResp
  650. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  651. }
  652. }
  653. //处理路演 处理路活动视频 处理路活音频
  654. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  655. audioIdstr := strings.Join(activityvoiceIds, ",")
  656. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  657. roadshowIdsStr := strings.Join(roadshowIds, ",")
  658. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  659. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  660. if e != nil {
  661. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  662. return
  663. }
  664. // 用户权限
  665. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  666. if e != nil {
  667. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  668. return
  669. }
  670. // 获取默认图配置
  671. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  672. if e != nil {
  673. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  674. return
  675. }
  676. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  677. for i := range list {
  678. // 权限
  679. au := new(models.UserPermissionAuthInfo)
  680. au.SellerName = authInfo.SellerName
  681. au.SellerMobile = authInfo.SellerMobile
  682. au.HasPermission = authInfo.HasPermission
  683. au.OperationMode = authInfo.OperationMode
  684. if au.HasPermission == 1 {
  685. // 非宏观权限进一步判断是否有权限
  686. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  687. au.HasPermission = 2
  688. }
  689. }
  690. // 无权限的弹框提示
  691. if au.HasPermission != 1 {
  692. if au.OperationMode == UserPermissionOperationModeCall {
  693. if list[i].Type == 1 {
  694. au.PopupMsg = UserPermissionPopupMsgCallActivity
  695. } else {
  696. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  697. }
  698. } else {
  699. if list[i].Type == 1 {
  700. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  701. } else {
  702. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  703. }
  704. }
  705. }
  706. list[i].AuthInfo = au
  707. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  708. // 默认图
  709. if list[i].BackgroundImg == "" {
  710. if list[i].Type == 1 {
  711. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  712. } else {
  713. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  714. }
  715. }
  716. // 分享图
  717. if list[i].ShareImg == "" {
  718. if list[i].Type == 1 {
  719. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  720. } else {
  721. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  722. }
  723. }
  724. }
  725. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  726. for _, item := range list {
  727. if item.Type == 1 {
  728. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  729. } else if item.Type == 2 {
  730. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  731. } else if item.Type == 3 {
  732. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  733. } else if item.Type == 4 {
  734. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  735. }
  736. }
  737. }
  738. //处理研选专栏
  739. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  740. if lenyanxuanSpecialIds > 0 {
  741. pars = make([]interface{}, 0)
  742. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  743. pars = append(pars, yanxuanSpecialIds)
  744. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  745. if e != nil {
  746. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  747. return
  748. }
  749. for _, v := range listyanxuanSpecial {
  750. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  751. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  752. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  753. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  754. } else {
  755. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  756. }
  757. v.Annotation = "" //强制置空,兼容前端优先级
  758. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  759. }
  760. }
  761. for _, vList := range list {
  762. for _, v := range mapItems {
  763. //如果这些类型都为空,那么就不合并
  764. 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 && v.AskserieVideo == nil && v.ReportSelection == nil {
  765. continue
  766. }
  767. //if v.Article != nil && v.SourceId == vList.SourceId {
  768. // v.Article.Title = vList.Title
  769. //}
  770. //if v.Newchart != nil && v.SourceId == vList.SourceId {
  771. // v.Newchart.Title = vList.Title
  772. //}
  773. //if v.Roadshow != nil && v.SourceId == vList.SourceId {
  774. // v.Roadshow.Title = vList.Title
  775. //}
  776. //if v.Activity != nil && v.SourceId == vList.SourceId {
  777. // v.Activity.ActivityName = vList.Title
  778. //}
  779. //if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  780. // v.Activityvideo.Title = vList.Title
  781. //}
  782. //if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  783. // v.Activityvoice.Title = vList.Title
  784. //}
  785. //
  786. //if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  787. // v.Activityspecial.ResearchTheme = vList.Title
  788. //}
  789. //if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  790. // v.Researchsummary.Title = vList.Title
  791. //}
  792. //if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  793. // v.Minutessummary.Title = vList.Title
  794. //}
  795. //if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  796. // v.ProductInterior.Title = vList.Title
  797. //}
  798. //if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
  799. // v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
  800. //}
  801. //if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
  802. // v.YanxuanSpecial.Title = vList.Title
  803. //}
  804. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  805. items = append(items, v)
  806. }
  807. }
  808. }
  809. for _, v := range items {
  810. if v.IndustrialResource != nil {
  811. v.Source = "industrialsource"
  812. }
  813. }
  814. return
  815. }
  816. func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
  817. keyWord = "%" + keyWord + "%"
  818. var conditionTitle string
  819. var parsTitle []interface{}
  820. conditionTitle = " AND search_title LIKE ? "
  821. parsTitle = append(parsTitle, keyWord)
  822. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  823. if e != nil {
  824. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  825. return
  826. }
  827. var conditionContent string
  828. var parsContent []interface{}
  829. conditionContent = " AND search_content LIKE ? AND search_title NOT LIKE ? "
  830. parsContent = append(parsContent, keyWord, keyWord)
  831. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  832. if e != nil {
  833. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  834. return
  835. }
  836. var searchTotal int
  837. searchTotal = (startSize/pageSize + 1) * pageSize
  838. var list []*models.CygxResourceData
  839. if totalTitle >= searchTotal {
  840. //全部都是标题搜索
  841. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  842. if e != nil && e.Error() != utils.ErrNoRow() {
  843. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  844. return
  845. }
  846. } else if totalTitle <= searchTotal-pageSize {
  847. //全部都是内容搜索
  848. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  849. if e != nil && e.Error() != utils.ErrNoRow() {
  850. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  851. return
  852. }
  853. } else {
  854. //一半标题搜索,一半内容搜索
  855. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  856. if e != nil && e.Error() != utils.ErrNoRow() {
  857. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  858. return
  859. }
  860. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  861. if e != nil && e.Error() != utils.ErrNoRow() {
  862. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  863. return
  864. }
  865. for _, v := range listContent {
  866. list = append(list, v)
  867. }
  868. }
  869. for _, v := range list {
  870. item := new(SearchComprehensiveItem)
  871. item.SourceId = v.SourceId
  872. item.Source = v.Source
  873. result = append(result, item)
  874. }
  875. total = totalTitle + totalContent
  876. return
  877. }
  878. // Es研选专栏
  879. func EsAddYanxuanSpecial(sourceId int) {
  880. var err error
  881. defer func() {
  882. if err != nil {
  883. fmt.Println("err:", err)
  884. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  885. }
  886. }()
  887. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  888. if e != nil {
  889. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  890. return
  891. }
  892. content := html.UnescapeString(detail.Content)
  893. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  894. if e != nil {
  895. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  896. return
  897. }
  898. bodyText := doc.Text()
  899. item := new(ElasticComprehensiveDetail)
  900. item.SourceId = detail.Id
  901. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  902. item.Title = detail.Title
  903. item.PublishDate = detail.PublishTime
  904. item.BodyText = bodyText
  905. item.Abstract = bodyText
  906. item.IndustryName = detail.IndustryTags
  907. item.SubjectNames = detail.CompanyTags + detail.Tags
  908. if detail.Status == 3 {
  909. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  910. } else {
  911. EsDeleteComprehensiveData(item) // 没有发布就删除
  912. }
  913. return
  914. }
  915. // 新增和修改数据
  916. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  917. indexName := utils.IndexNameComprehensive
  918. //return
  919. defer func() {
  920. if err != nil {
  921. fmt.Println(err, item.SourceId)
  922. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  923. }
  924. }()
  925. client := utils.Client
  926. mustMap := make([]interface{}, 0)
  927. mustMap = append(mustMap, map[string]interface{}{
  928. "term": map[string]interface{}{
  929. "SourceId": item.SourceId,
  930. },
  931. })
  932. mustMap = append(mustMap, map[string]interface{}{
  933. "term": map[string]interface{}{
  934. "Source": item.Source,
  935. },
  936. })
  937. queryMap := map[string]interface{}{
  938. "query": map[string]interface{}{
  939. "bool": map[string]interface{}{
  940. "must": mustMap,
  941. },
  942. },
  943. }
  944. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  945. total, e := requestTotalHits.Do(context.Background())
  946. if e != nil {
  947. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  948. return
  949. }
  950. //return
  951. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  952. if total == 0 {
  953. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  954. if e != nil {
  955. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  956. return
  957. }
  958. if resp.Status == 0 && resp.Result == "created" {
  959. //fmt.Println("新增成功")
  960. //err = nil
  961. return
  962. } else {
  963. //err = errors.New(fmt.Sprint(resp))
  964. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  965. return
  966. }
  967. } else {
  968. //拼接需要改动的前置条件
  969. bool_query := elastic.NewBoolQuery()
  970. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  971. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  972. //设置需要改动的内容
  973. var script string
  974. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  975. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  976. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  977. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  978. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  979. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  980. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  981. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  982. _, e = client.UpdateByQuery(indexName).
  983. Query(bool_query).
  984. Script(elastic.NewScriptInline(script)).
  985. Refresh("true").
  986. Do(context.Background())
  987. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  988. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  989. //fmt.Println("err", e.Error())
  990. ////err = e
  991. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  992. return
  993. }
  994. }
  995. return
  996. }
  997. // 删除数据
  998. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  999. defer func() {
  1000. if err != nil {
  1001. fmt.Println(err)
  1002. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  1003. }
  1004. }()
  1005. indexName := utils.IndexNameComprehensive
  1006. client := utils.Client
  1007. //拼接需要删除的前置条件
  1008. bool_query := elastic.NewBoolQuery()
  1009. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  1010. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  1011. _, e := client.DeleteByQuery(indexName).
  1012. Query(bool_query).
  1013. Do(context.Background())
  1014. if e != nil {
  1015. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  1016. return
  1017. }
  1018. return
  1019. }