es_comprehensive.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. listListNoEnd, e := models.GetActivityIdListNoEnd()
  814. var activityIds []string
  815. for _, v := range listListNoEnd {
  816. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  817. }
  818. activityIds = append(activityIds, "0")
  819. conditionActivity := " AND IF ( source IN('activity') , source_id IN (" + strings.Join(activityIds, ",") + ") != 31 ,1=1 )"
  820. keyWord = "%" + keyWord + "%"
  821. var conditionTitle string
  822. var parsTitle []interface{}
  823. conditionTitle = " AND is_hide = 0 AND search_title LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) " + conditionActivity
  824. parsTitle = append(parsTitle, keyWord)
  825. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  826. if e != nil {
  827. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  828. return
  829. }
  830. var conditionContent string
  831. var parsContent []interface{}
  832. 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 ) " + conditionActivity
  833. parsContent = append(parsContent, keyWord, keyWord)
  834. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  835. if e != nil {
  836. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  837. return
  838. }
  839. var searchTotal int
  840. searchTotal = (startSize/pageSize + 1) * pageSize
  841. var list []*models.CygxResourceData
  842. if totalTitle >= searchTotal {
  843. //全部都是标题搜索
  844. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  845. if e != nil && e.Error() != utils.ErrNoRow() {
  846. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  847. return
  848. }
  849. } else if totalTitle <= searchTotal-pageSize {
  850. //全部都是内容搜索
  851. startSize = startSize - totalTitle
  852. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  853. if e != nil && e.Error() != utils.ErrNoRow() {
  854. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  855. return
  856. }
  857. } else {
  858. //一半标题搜索,一半内容搜索
  859. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  860. if e != nil && e.Error() != utils.ErrNoRow() {
  861. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  862. return
  863. }
  864. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  865. if e != nil && e.Error() != utils.ErrNoRow() {
  866. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  867. return
  868. }
  869. for _, v := range listContent {
  870. list = append(list, v)
  871. }
  872. }
  873. for _, v := range list {
  874. item := new(SearchComprehensiveItem)
  875. item.SourceId = v.SourceId
  876. item.Source = v.Source
  877. result = append(result, item)
  878. }
  879. total = totalTitle + totalContent
  880. return
  881. }
  882. // Es研选专栏
  883. func EsAddYanxuanSpecial(sourceId int) {
  884. var err error
  885. defer func() {
  886. if err != nil {
  887. fmt.Println("err:", err)
  888. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  889. }
  890. }()
  891. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  892. if e != nil {
  893. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  894. return
  895. }
  896. content := html.UnescapeString(detail.Content)
  897. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  898. if e != nil {
  899. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  900. return
  901. }
  902. bodyText := doc.Text()
  903. item := new(ElasticComprehensiveDetail)
  904. item.SourceId = detail.Id
  905. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  906. item.Title = detail.Title
  907. item.PublishDate = detail.PublishTime
  908. item.BodyText = bodyText
  909. item.Abstract = bodyText
  910. item.IndustryName = detail.IndustryTags
  911. item.SubjectNames = detail.CompanyTags + detail.Tags
  912. if detail.Status == 3 {
  913. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  914. } else {
  915. EsDeleteComprehensiveData(item) // 没有发布就删除
  916. }
  917. return
  918. }
  919. // 新增和修改数据
  920. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  921. indexName := utils.IndexNameComprehensive
  922. //return
  923. defer func() {
  924. if err != nil {
  925. fmt.Println(err, item.SourceId)
  926. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  927. }
  928. }()
  929. client := utils.Client
  930. mustMap := make([]interface{}, 0)
  931. mustMap = append(mustMap, map[string]interface{}{
  932. "term": map[string]interface{}{
  933. "SourceId": item.SourceId,
  934. },
  935. })
  936. mustMap = append(mustMap, map[string]interface{}{
  937. "term": map[string]interface{}{
  938. "Source": item.Source,
  939. },
  940. })
  941. queryMap := map[string]interface{}{
  942. "query": map[string]interface{}{
  943. "bool": map[string]interface{}{
  944. "must": mustMap,
  945. },
  946. },
  947. }
  948. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  949. total, e := requestTotalHits.Do(context.Background())
  950. if e != nil {
  951. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  952. return
  953. }
  954. //return
  955. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  956. if total == 0 {
  957. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  958. if e != nil {
  959. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  960. return
  961. }
  962. if resp.Status == 0 && resp.Result == "created" {
  963. //fmt.Println("新增成功")
  964. //err = nil
  965. return
  966. } else {
  967. //err = errors.New(fmt.Sprint(resp))
  968. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  969. return
  970. }
  971. } else {
  972. //拼接需要改动的前置条件
  973. bool_query := elastic.NewBoolQuery()
  974. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  975. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  976. //设置需要改动的内容
  977. var script string
  978. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  979. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  980. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  981. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  982. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  983. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  984. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  985. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  986. _, e = client.UpdateByQuery(indexName).
  987. Query(bool_query).
  988. Script(elastic.NewScriptInline(script)).
  989. Refresh("true").
  990. Do(context.Background())
  991. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  992. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  993. //fmt.Println("err", e.Error())
  994. ////err = e
  995. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  996. return
  997. }
  998. }
  999. return
  1000. }
  1001. // 删除数据
  1002. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  1003. defer func() {
  1004. if err != nil {
  1005. fmt.Println(err)
  1006. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  1007. }
  1008. }()
  1009. indexName := utils.IndexNameComprehensive
  1010. client := utils.Client
  1011. //拼接需要删除的前置条件
  1012. bool_query := elastic.NewBoolQuery()
  1013. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  1014. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  1015. _, e := client.DeleteByQuery(indexName).
  1016. Query(bool_query).
  1017. Do(context.Background())
  1018. if e != nil {
  1019. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  1020. return
  1021. }
  1022. return
  1023. }