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. var ficcreporrtIds []string //FICC研报
  297. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  298. for _, v := range list {
  299. if v.Source == "article" {
  300. articleIds = append(articleIds, v.SourceId)
  301. } else if v.Source == "newchart" {
  302. newchartIds = append(newchartIds, v.SourceId)
  303. } else if v.Source == "roadshow" {
  304. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  305. } else if v.Source == "activity" {
  306. activityIds = append(activityIds, v.SourceId)
  307. } else if v.Source == "activityvideo" {
  308. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  309. } else if v.Source == "activityvoice" {
  310. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  311. } else if v.Source == "activityspecial" {
  312. activityspecialIds = append(activityspecialIds, v.SourceId)
  313. } else if v.Source == "researchsummary" {
  314. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  315. } else if v.Source == "minutessummary" {
  316. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  317. } else if v.Source == "meetingreviewchapt" {
  318. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  319. } else if v.Source == "productinterior" {
  320. productinteriorIds = append(productinteriorIds, v.SourceId)
  321. } else if v.Source == "industrialsourceHz" {
  322. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  323. } else if v.Source == "industrialsourceYx" {
  324. industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
  325. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  326. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  327. yanXuanbodyHighlight[v.SourceId] = v.Body
  328. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  329. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  330. } else if v.Source == "reportselection" {
  331. reportselectionIds = append(reportselectionIds, v.SourceId)
  332. } else if v.Source == utils.CYGX_OBJ_FICC_REPORT {
  333. ficcreporrtIds = append(ficcreporrtIds, strconv.Itoa(v.SourceId))
  334. }
  335. }
  336. detail, e := models.GetConfigByCode("city_img_url")
  337. if e != nil {
  338. err = errors.New("GetResourceDataList, Err: " + e.Error())
  339. return
  340. }
  341. detailChart, e := models.GetConfigByCode("chart_img_url")
  342. if e != nil {
  343. err = errors.New("GetResourceDataList, Err: " + e.Error())
  344. return
  345. }
  346. addressList := strings.Split(detail.ConfigValue, "{|}")
  347. mapAddress := make(map[string]string)
  348. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  349. mapChart := make(map[string]string)
  350. var cityName string
  351. var chartName string
  352. var imgUrl string
  353. var imgUrlChart string
  354. for _, v := range addressList {
  355. vslice := strings.Split(v, "_")
  356. cityName = vslice[0]
  357. imgUrl = vslice[len(vslice)-1]
  358. mapAddress[cityName] = imgUrl
  359. }
  360. for _, v := range chartList {
  361. vslice := strings.Split(v, "_")
  362. chartName = vslice[0]
  363. imgUrlChart = vslice[len(vslice)-1]
  364. mapChart[chartName] = imgUrlChart
  365. }
  366. var imgUrlResp string
  367. //处理文章
  368. if len(articleIds) > 0 {
  369. pars = make([]interface{}, 0)
  370. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  371. pars = append(pars, articleIds)
  372. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  373. if e != nil {
  374. err = errors.New("GetResourceDataList, Err: " + e.Error())
  375. return
  376. }
  377. articleList, e = HandleArticleCategoryImg(articleList, user)
  378. if e != nil {
  379. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  380. return
  381. }
  382. for _, v := range articleList {
  383. v.Body = ""
  384. if titleHighlight[v.ArticleId] != "" {
  385. v.Title = titleHighlight[v.ArticleId]
  386. }
  387. if len(bodyHighlight[v.ArticleId]) > 0 {
  388. v.Abstract = ""
  389. v.Annotation = ""
  390. v.BodyHighlight = bodyHighlight[v.ArticleId]
  391. } else {
  392. v.BodyHighlight = make([]string, 0)
  393. }
  394. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  395. }
  396. }
  397. //处理晨会精华
  398. if len(meetingreviewchaptIds) > 0 {
  399. //pars = make([]interface{}, 0)
  400. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  401. //pars = append(pars, meetingreviewchaptIds)
  402. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  403. if e != nil {
  404. err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
  405. return
  406. }
  407. for _, v := range listrMeet {
  408. v.Content = AnnotationHtml(v.Content)
  409. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  410. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  411. }
  412. }
  413. //处理上周纪要汇总
  414. if len(minutessummaryIds) > 0 {
  415. pars = make([]interface{}, 0)
  416. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  417. pars = append(pars, minutessummaryIds)
  418. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  419. if e != nil {
  420. err = errors.New("GetResourceDataList, Err: " + e.Error())
  421. return
  422. }
  423. for _, v := range listresearchsummary {
  424. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  425. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  426. }
  427. }
  428. //处理本周纪要汇总
  429. if len(researchsummaryIds) > 0 {
  430. pars = make([]interface{}, 0)
  431. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  432. pars = append(pars, researchsummaryIds)
  433. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  434. if e != nil {
  435. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  436. return
  437. }
  438. for _, v := range listresearchsummary {
  439. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  440. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  441. }
  442. }
  443. //处理产品内测
  444. if len(productinteriorIds) > 0 {
  445. pars = make([]interface{}, 0)
  446. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  447. pars = append(pars, productinteriorIds)
  448. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  449. if e != nil {
  450. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  451. return
  452. }
  453. for _, v := range listProductInterior {
  454. v.Body = ProductInteriorHtml(v.Body)
  455. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  456. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  457. }
  458. }
  459. //处理报告精选
  460. lenreportselectionIds := len(reportselectionIds)
  461. if lenreportselectionIds > 0 {
  462. pars = make([]interface{}, 0)
  463. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  464. pars = append(pars, reportselectionIds)
  465. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  466. if e != nil {
  467. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  468. return
  469. }
  470. mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
  471. for _, v := range listreportselection {
  472. v.Title += "(第" + v.Periods + "期)"
  473. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  474. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  475. v.Pv = mapPv[v.ArticleId]
  476. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  477. }
  478. }
  479. //处理活动
  480. if len(activityIds) > 0 {
  481. for _, vss := range activityIds {
  482. imgUrlResp += strconv.Itoa(vss) + ","
  483. }
  484. pars = make([]interface{}, 0)
  485. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  486. pars = append(pars, activityIds)
  487. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  488. if e != nil {
  489. err = errors.New("GetResourceDataList, Err: " + e.Error())
  490. return
  491. }
  492. var activityListRersp []*models.ActivityListResp
  493. //for _, v := range activityList {
  494. // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  495. //}
  496. //var pArr []string
  497. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  498. //处理不同的报名方式按钮回显
  499. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  500. if e != nil {
  501. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  502. return
  503. }
  504. for _, v := range activityListRersp {
  505. if v == nil {
  506. continue
  507. }
  508. if v.ActivityType == 0 {
  509. if mapAddress[v.City] != "" {
  510. imgUrlResp = mapAddress[v.City]
  511. } else {
  512. imgUrlResp = mapAddress["其它"]
  513. }
  514. } else {
  515. if mapChart[v.ChartPermissionName] != "" {
  516. imgUrlResp = mapChart[v.ChartPermissionName]
  517. }
  518. }
  519. v.ImgUrl = imgUrlResp
  520. v.SourceType = mapActivitySignup[v.ActivityId]
  521. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  522. }
  523. }
  524. //产业资源包
  525. if len(industrialResourceIdsHz) > 0 {
  526. pars = make([]interface{}, 0)
  527. var industrialResourceIdstring []string
  528. for _, v := range industrialResourceIdsHz {
  529. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  530. }
  531. industrialId := strings.Join(industrialResourceIdstring, ",")
  532. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  533. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  534. if e != nil {
  535. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  536. return
  537. }
  538. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsHz)) + `)`
  539. pars = append(pars, industrialResourceIdsHz)
  540. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  541. //合并产业关联的标的
  542. if e != nil {
  543. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  544. return
  545. }
  546. mapIndustrial := make(map[string]int)
  547. for _, v := range listSubjcet {
  548. for k2, v2 := range listIndustrialResourceIds {
  549. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  550. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  551. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  552. }
  553. }
  554. }
  555. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Hz")
  556. for _, v := range listIndustrialResourceIds {
  557. if v.TimeLineData == "" {
  558. v.ListTimeLine = make([]models.TimeLineReportResp, 0)
  559. } else {
  560. if err = json.Unmarshal([]byte(v.TimeLineData), &v.ListTimeLine); err != nil {
  561. e = errors.New("Unmarshal, Err: " + e.Error())
  562. return
  563. }
  564. }
  565. v.Source = 1
  566. v.UpdateTime = v.PublishDate
  567. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  568. }
  569. }
  570. //产业资源包
  571. if len(industrialResourceIdsYx) > 0 {
  572. pars = make([]interface{}, 0)
  573. var industrialResourceIdstring []string
  574. for _, v := range industrialResourceIdsYx {
  575. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  576. }
  577. industrialId := strings.Join(industrialResourceIdstring, ",")
  578. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  579. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  580. if e != nil {
  581. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  582. return
  583. }
  584. fmt.Println(listIndustrialResourceIds)
  585. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  586. pars = append(pars, industrialResourceIdsYx)
  587. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  588. //合并产业关联的标的
  589. if e != nil {
  590. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  591. return
  592. }
  593. mapIndustrial := make(map[string]int)
  594. for _, v := range listSubjcet {
  595. for k2, v2 := range listIndustrialResourceIds {
  596. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  597. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  598. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  599. }
  600. }
  601. }
  602. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  603. for _, v := range listIndustrialResourceIds {
  604. v.Source = 2
  605. v.UpdateTime = v.PublishDate
  606. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  607. }
  608. }
  609. //处理图表
  610. if len(newchartIds) > 0 {
  611. pars = make([]interface{}, 0)
  612. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  613. pars = append(pars, newchartIds)
  614. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  615. if e != nil {
  616. err = errors.New("GetResourceDataList, Err: " + e.Error())
  617. return
  618. }
  619. for _, v := range chartDateList {
  620. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  621. }
  622. }
  623. //处理专项调研
  624. if len(activityspecialIds) > 0 {
  625. pars = make([]interface{}, 0)
  626. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  627. pars = append(pars, activityspecialIds)
  628. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  629. if e != nil {
  630. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  631. return
  632. }
  633. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  634. if e != nil {
  635. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  636. return
  637. }
  638. for _, v := range activitySpeciallist {
  639. if mapChart[v.ChartPermissionName] != "" {
  640. imgUrlResp = mapChart[v.ChartPermissionName]
  641. }
  642. if _, ok := UserMap[v.ActivityId]; ok {
  643. v.IsTrip = 1
  644. }
  645. if v.Days == 0 {
  646. v.TripStatus = 1
  647. v.TripImgLink = v.TripImgLink
  648. } else {
  649. v.TripStatus = 2
  650. v.TripImgLink = v.TripImgLinkFix
  651. v.ActivityTimeText = v.ActivityTimeTextByDay
  652. }
  653. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  654. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  655. if resultTimeStart.After(time.Now()) {
  656. v.ActiveState = "1"
  657. } else if time.Now().After(resultTimeEnd) {
  658. v.ActiveState = "3"
  659. } else {
  660. v.ActiveState = "2"
  661. }
  662. v.ImgUrl = imgUrlResp
  663. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  664. }
  665. }
  666. //处理路演 处理路活动视频 处理路活音频
  667. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  668. audioIdstr := strings.Join(activityvoiceIds, ",")
  669. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  670. roadshowIdsStr := strings.Join(roadshowIds, ",")
  671. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  672. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  673. if e != nil {
  674. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  675. return
  676. }
  677. // 用户权限
  678. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  679. if e != nil {
  680. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  681. return
  682. }
  683. // 获取默认图配置
  684. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  685. if e != nil {
  686. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  687. return
  688. }
  689. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  690. for i := range list {
  691. // 权限
  692. au := new(models.UserPermissionAuthInfo)
  693. au.SellerName = authInfo.SellerName
  694. au.SellerMobile = authInfo.SellerMobile
  695. au.HasPermission = authInfo.HasPermission
  696. au.OperationMode = authInfo.OperationMode
  697. if au.HasPermission == 1 {
  698. // 非宏观权限进一步判断是否有权限
  699. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  700. au.HasPermission = 2
  701. }
  702. }
  703. // 无权限的弹框提示
  704. if au.HasPermission != 1 {
  705. if au.OperationMode == UserPermissionOperationModeCall {
  706. if list[i].Type == 1 {
  707. au.PopupMsg = UserPermissionPopupMsgCallActivity
  708. } else {
  709. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  710. }
  711. } else {
  712. if list[i].Type == 1 {
  713. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  714. } else {
  715. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  716. }
  717. }
  718. }
  719. list[i].AuthInfo = au
  720. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  721. // 默认图
  722. if list[i].BackgroundImg == "" {
  723. if list[i].Type == 1 {
  724. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  725. } else {
  726. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  727. }
  728. }
  729. // 分享图
  730. if list[i].ShareImg == "" {
  731. if list[i].Type == 1 {
  732. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  733. } else {
  734. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  735. }
  736. }
  737. }
  738. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  739. for _, item := range list {
  740. if item.Type == 1 {
  741. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  742. } else if item.Type == 2 {
  743. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  744. } else if item.Type == 3 {
  745. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  746. } else if item.Type == 4 {
  747. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  748. }
  749. }
  750. }
  751. //处理研选专栏
  752. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  753. if lenyanxuanSpecialIds > 0 {
  754. pars = make([]interface{}, 0)
  755. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  756. pars = append(pars, yanxuanSpecialIds)
  757. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  758. if e != nil {
  759. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  760. return
  761. }
  762. for _, v := range listyanxuanSpecial {
  763. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  764. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  765. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  766. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  767. } else {
  768. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  769. }
  770. v.Annotation = "" //强制置空,兼容前端优先级
  771. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  772. }
  773. }
  774. //处理FICC研报
  775. if len(ficcreporrtIds) > 0 {
  776. pars = make([]interface{}, 0)
  777. condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
  778. pars = append(pars, ficcreporrtIds)
  779. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(ficcreporrtIds))
  780. if e != nil {
  781. err = errors.New("GetHomeListPublic, Err: " + e.Error())
  782. return
  783. }
  784. articleList, e = HandleArticleCategoryImg(articleList, user)
  785. if e != nil {
  786. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  787. return
  788. }
  789. for _, v := range articleList {
  790. v.Body = ""
  791. mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
  792. }
  793. }
  794. for _, vList := range list {
  795. for _, v := range mapItems {
  796. //如果这些类型都为空,那么就不合并
  797. 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 && v.FiccReport == nil {
  798. continue
  799. }
  800. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  801. items = append(items, v)
  802. }
  803. }
  804. }
  805. for _, v := range items {
  806. if v.IndustrialResource != nil {
  807. v.Source = "industrialsource"
  808. }
  809. }
  810. return
  811. }
  812. func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
  813. keyWord = "%" + keyWord + "%"
  814. var conditionTitle string
  815. var parsTitle []interface{}
  816. conditionTitle = " AND is_hide = 0 AND search_title LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) "
  817. parsTitle = append(parsTitle, keyWord)
  818. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  819. if e != nil {
  820. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  821. return
  822. }
  823. var conditionContent string
  824. var parsContent []interface{}
  825. conditionContent = " AND is_hide = 0 AND search_content LIKE ? AND search_title NOT LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) "
  826. parsContent = append(parsContent, keyWord, keyWord)
  827. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  828. if e != nil {
  829. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  830. return
  831. }
  832. var searchTotal int
  833. searchTotal = (startSize/pageSize + 1) * pageSize
  834. var list []*models.CygxResourceData
  835. if totalTitle >= searchTotal {
  836. //全部都是标题搜索
  837. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  838. if e != nil && e.Error() != utils.ErrNoRow() {
  839. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  840. return
  841. }
  842. } else if totalTitle <= searchTotal-pageSize {
  843. //全部都是内容搜索
  844. startSize = startSize - totalTitle
  845. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  846. if e != nil && e.Error() != utils.ErrNoRow() {
  847. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  848. return
  849. }
  850. } else {
  851. //一半标题搜索,一半内容搜索
  852. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  853. if e != nil && e.Error() != utils.ErrNoRow() {
  854. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  855. return
  856. }
  857. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  858. if e != nil && e.Error() != utils.ErrNoRow() {
  859. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  860. return
  861. }
  862. for _, v := range listContent {
  863. list = append(list, v)
  864. }
  865. }
  866. for _, v := range list {
  867. item := new(SearchComprehensiveItem)
  868. item.SourceId = v.SourceId
  869. item.Source = v.Source
  870. result = append(result, item)
  871. }
  872. total = totalTitle + totalContent
  873. return
  874. }
  875. // Es研选专栏
  876. func EsAddYanxuanSpecial(sourceId int) {
  877. var err error
  878. defer func() {
  879. if err != nil {
  880. fmt.Println("err:", err)
  881. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  882. }
  883. }()
  884. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  885. if e != nil {
  886. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  887. return
  888. }
  889. content := html.UnescapeString(detail.Content)
  890. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  891. if e != nil {
  892. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  893. return
  894. }
  895. bodyText := doc.Text()
  896. item := new(ElasticComprehensiveDetail)
  897. item.SourceId = detail.Id
  898. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  899. item.Title = detail.Title
  900. item.PublishDate = detail.PublishTime
  901. item.BodyText = bodyText
  902. item.Abstract = bodyText
  903. item.IndustryName = detail.IndustryTags
  904. item.SubjectNames = detail.CompanyTags + detail.Tags
  905. if detail.Status == 3 {
  906. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  907. } else {
  908. EsDeleteComprehensiveData(item) // 没有发布就删除
  909. }
  910. return
  911. }
  912. // 新增和修改数据
  913. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  914. indexName := utils.IndexNameComprehensive
  915. //return
  916. defer func() {
  917. if err != nil {
  918. fmt.Println(err, item.SourceId)
  919. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  920. }
  921. }()
  922. client := utils.Client
  923. mustMap := make([]interface{}, 0)
  924. mustMap = append(mustMap, map[string]interface{}{
  925. "term": map[string]interface{}{
  926. "SourceId": item.SourceId,
  927. },
  928. })
  929. mustMap = append(mustMap, map[string]interface{}{
  930. "term": map[string]interface{}{
  931. "Source": item.Source,
  932. },
  933. })
  934. queryMap := map[string]interface{}{
  935. "query": map[string]interface{}{
  936. "bool": map[string]interface{}{
  937. "must": mustMap,
  938. },
  939. },
  940. }
  941. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  942. total, e := requestTotalHits.Do(context.Background())
  943. if e != nil {
  944. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  945. return
  946. }
  947. //return
  948. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  949. if total == 0 {
  950. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  951. if e != nil {
  952. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  953. return
  954. }
  955. if resp.Status == 0 && resp.Result == "created" {
  956. //fmt.Println("新增成功")
  957. //err = nil
  958. return
  959. } else {
  960. //err = errors.New(fmt.Sprint(resp))
  961. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  962. return
  963. }
  964. } else {
  965. //拼接需要改动的前置条件
  966. bool_query := elastic.NewBoolQuery()
  967. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  968. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  969. //设置需要改动的内容
  970. var script string
  971. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  972. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  973. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  974. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  975. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  976. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  977. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  978. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  979. _, e = client.UpdateByQuery(indexName).
  980. Query(bool_query).
  981. Script(elastic.NewScriptInline(script)).
  982. Refresh("true").
  983. Do(context.Background())
  984. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  985. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  986. //fmt.Println("err", e.Error())
  987. ////err = e
  988. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  989. return
  990. }
  991. }
  992. return
  993. }
  994. // 删除数据
  995. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  996. defer func() {
  997. if err != nil {
  998. fmt.Println(err)
  999. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  1000. }
  1001. }()
  1002. indexName := utils.IndexNameComprehensive
  1003. client := utils.Client
  1004. //拼接需要删除的前置条件
  1005. bool_query := elastic.NewBoolQuery()
  1006. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  1007. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  1008. _, e := client.DeleteByQuery(indexName).
  1009. Query(bool_query).
  1010. Do(context.Background())
  1011. if e != nil {
  1012. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  1013. return
  1014. }
  1015. return
  1016. }