es_comprehensive.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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. v.UpdateTime = v.PublishDate
  556. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  557. }
  558. }
  559. //产业资源包
  560. if len(industrialResourceIdsYx) > 0 {
  561. pars = make([]interface{}, 0)
  562. var industrialResourceIdstring []string
  563. for _, v := range industrialResourceIdsYx {
  564. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  565. }
  566. industrialId := strings.Join(industrialResourceIdstring, ",")
  567. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  568. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  569. if e != nil {
  570. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  571. return
  572. }
  573. fmt.Println(listIndustrialResourceIds)
  574. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  575. pars = append(pars, industrialResourceIdsYx)
  576. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  577. //合并产业关联的标的
  578. if e != nil {
  579. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  580. return
  581. }
  582. mapIndustrial := make(map[string]int)
  583. for _, v := range listSubjcet {
  584. for k2, v2 := range listIndustrialResourceIds {
  585. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  586. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  587. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  588. }
  589. }
  590. }
  591. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  592. for _, v := range listIndustrialResourceIds {
  593. v.Source = 2
  594. v.UpdateTime = v.PublishDate
  595. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  596. }
  597. }
  598. //处理图表
  599. if len(newchartIds) > 0 {
  600. pars = make([]interface{}, 0)
  601. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  602. pars = append(pars, newchartIds)
  603. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  604. if e != nil {
  605. err = errors.New("GetResourceDataList, Err: " + e.Error())
  606. return
  607. }
  608. for _, v := range chartDateList {
  609. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  610. }
  611. }
  612. //处理专项调研
  613. if len(activityspecialIds) > 0 {
  614. pars = make([]interface{}, 0)
  615. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  616. pars = append(pars, activityspecialIds)
  617. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  618. if e != nil {
  619. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  620. return
  621. }
  622. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  623. if e != nil {
  624. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  625. return
  626. }
  627. for _, v := range activitySpeciallist {
  628. if mapChart[v.ChartPermissionName] != "" {
  629. imgUrlResp = mapChart[v.ChartPermissionName]
  630. }
  631. if _, ok := UserMap[v.ActivityId]; ok {
  632. v.IsTrip = 1
  633. }
  634. if v.Days == 0 {
  635. v.TripStatus = 1
  636. v.TripImgLink = v.TripImgLink
  637. } else {
  638. v.TripStatus = 2
  639. v.TripImgLink = v.TripImgLinkFix
  640. v.ActivityTimeText = v.ActivityTimeTextByDay
  641. }
  642. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  643. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  644. if resultTimeStart.After(time.Now()) {
  645. v.ActiveState = "1"
  646. } else if time.Now().After(resultTimeEnd) {
  647. v.ActiveState = "3"
  648. } else {
  649. v.ActiveState = "2"
  650. }
  651. v.ImgUrl = imgUrlResp
  652. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  653. }
  654. }
  655. //处理路演 处理路活动视频 处理路活音频
  656. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  657. audioIdstr := strings.Join(activityvoiceIds, ",")
  658. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  659. roadshowIdsStr := strings.Join(roadshowIds, ",")
  660. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  661. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  662. if e != nil {
  663. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  664. return
  665. }
  666. // 用户权限
  667. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  668. if e != nil {
  669. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  670. return
  671. }
  672. // 获取默认图配置
  673. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  674. if e != nil {
  675. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  676. return
  677. }
  678. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  679. for i := range list {
  680. // 权限
  681. au := new(models.UserPermissionAuthInfo)
  682. au.SellerName = authInfo.SellerName
  683. au.SellerMobile = authInfo.SellerMobile
  684. au.HasPermission = authInfo.HasPermission
  685. au.OperationMode = authInfo.OperationMode
  686. if au.HasPermission == 1 {
  687. // 非宏观权限进一步判断是否有权限
  688. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  689. au.HasPermission = 2
  690. }
  691. }
  692. // 无权限的弹框提示
  693. if au.HasPermission != 1 {
  694. if au.OperationMode == UserPermissionOperationModeCall {
  695. if list[i].Type == 1 {
  696. au.PopupMsg = UserPermissionPopupMsgCallActivity
  697. } else {
  698. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  699. }
  700. } else {
  701. if list[i].Type == 1 {
  702. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  703. } else {
  704. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  705. }
  706. }
  707. }
  708. list[i].AuthInfo = au
  709. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  710. // 默认图
  711. if list[i].BackgroundImg == "" {
  712. if list[i].Type == 1 {
  713. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  714. } else {
  715. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  716. }
  717. }
  718. // 分享图
  719. if list[i].ShareImg == "" {
  720. if list[i].Type == 1 {
  721. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  722. } else {
  723. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  724. }
  725. }
  726. }
  727. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  728. for _, item := range list {
  729. if item.Type == 1 {
  730. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  731. } else if item.Type == 2 {
  732. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  733. } else if item.Type == 3 {
  734. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  735. } else if item.Type == 4 {
  736. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  737. }
  738. }
  739. }
  740. //处理研选专栏
  741. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  742. if lenyanxuanSpecialIds > 0 {
  743. pars = make([]interface{}, 0)
  744. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  745. pars = append(pars, yanxuanSpecialIds)
  746. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  747. if e != nil {
  748. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  749. return
  750. }
  751. for _, v := range listyanxuanSpecial {
  752. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  753. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  754. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  755. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  756. } else {
  757. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  758. }
  759. v.Annotation = "" //强制置空,兼容前端优先级
  760. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  761. }
  762. }
  763. for _, vList := range list {
  764. for _, v := range mapItems {
  765. //如果这些类型都为空,那么就不合并
  766. 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 {
  767. continue
  768. }
  769. //if v.Article != nil && v.SourceId == vList.SourceId {
  770. // v.Article.Title = vList.Title
  771. //}
  772. //if v.Newchart != nil && v.SourceId == vList.SourceId {
  773. // v.Newchart.Title = vList.Title
  774. //}
  775. //if v.Roadshow != nil && v.SourceId == vList.SourceId {
  776. // v.Roadshow.Title = vList.Title
  777. //}
  778. //if v.Activity != nil && v.SourceId == vList.SourceId {
  779. // v.Activity.ActivityName = vList.Title
  780. //}
  781. //if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  782. // v.Activityvideo.Title = vList.Title
  783. //}
  784. //if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  785. // v.Activityvoice.Title = vList.Title
  786. //}
  787. //
  788. //if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  789. // v.Activityspecial.ResearchTheme = vList.Title
  790. //}
  791. //if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  792. // v.Researchsummary.Title = vList.Title
  793. //}
  794. //if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  795. // v.Minutessummary.Title = vList.Title
  796. //}
  797. //if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  798. // v.ProductInterior.Title = vList.Title
  799. //}
  800. //if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
  801. // v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
  802. //}
  803. //if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
  804. // v.YanxuanSpecial.Title = vList.Title
  805. //}
  806. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  807. items = append(items, v)
  808. }
  809. }
  810. }
  811. for _, v := range items {
  812. if v.IndustrialResource != nil {
  813. v.Source = "industrialsource"
  814. }
  815. }
  816. return
  817. }
  818. func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
  819. keyWord = "%" + keyWord + "%"
  820. var conditionTitle string
  821. var parsTitle []interface{}
  822. conditionTitle = " AND search_title LIKE ? "
  823. parsTitle = append(parsTitle, keyWord)
  824. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  825. if e != nil {
  826. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  827. return
  828. }
  829. var conditionContent string
  830. var parsContent []interface{}
  831. conditionContent = " AND search_content LIKE ? AND search_title NOT LIKE ? "
  832. parsContent = append(parsContent, keyWord, keyWord)
  833. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  834. if e != nil {
  835. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  836. return
  837. }
  838. var searchTotal int
  839. searchTotal = (startSize/pageSize + 1) * pageSize
  840. var list []*models.CygxResourceData
  841. if totalTitle >= searchTotal {
  842. //全部都是标题搜索
  843. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  844. if e != nil && e.Error() != utils.ErrNoRow() {
  845. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  846. return
  847. }
  848. } else if totalTitle <= searchTotal-pageSize {
  849. //全部都是内容搜索
  850. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  851. if e != nil && e.Error() != utils.ErrNoRow() {
  852. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  853. return
  854. }
  855. } else {
  856. //一半标题搜索,一半内容搜索
  857. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  858. if e != nil && e.Error() != utils.ErrNoRow() {
  859. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  860. return
  861. }
  862. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  863. if e != nil && e.Error() != utils.ErrNoRow() {
  864. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  865. return
  866. }
  867. for _, v := range listContent {
  868. list = append(list, v)
  869. }
  870. }
  871. for _, v := range list {
  872. item := new(SearchComprehensiveItem)
  873. item.SourceId = v.SourceId
  874. item.Source = v.Source
  875. result = append(result, item)
  876. }
  877. total = totalTitle + totalContent
  878. return
  879. }
  880. // Es研选专栏
  881. func EsAddYanxuanSpecial(sourceId int) {
  882. var err error
  883. defer func() {
  884. if err != nil {
  885. fmt.Println("err:", err)
  886. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  887. }
  888. }()
  889. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  890. if e != nil {
  891. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  892. return
  893. }
  894. content := html.UnescapeString(detail.Content)
  895. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  896. if e != nil {
  897. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  898. return
  899. }
  900. bodyText := doc.Text()
  901. item := new(ElasticComprehensiveDetail)
  902. item.SourceId = detail.Id
  903. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  904. item.Title = detail.Title
  905. item.PublishDate = detail.PublishTime
  906. item.BodyText = bodyText
  907. item.Abstract = bodyText
  908. item.IndustryName = detail.IndustryTags
  909. item.SubjectNames = detail.CompanyTags + detail.Tags
  910. if detail.Status == 3 {
  911. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  912. } else {
  913. EsDeleteComprehensiveData(item) // 没有发布就删除
  914. }
  915. return
  916. }
  917. // 新增和修改数据
  918. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  919. indexName := utils.IndexNameComprehensive
  920. //return
  921. defer func() {
  922. if err != nil {
  923. fmt.Println(err, item.SourceId)
  924. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  925. }
  926. }()
  927. client := utils.Client
  928. mustMap := make([]interface{}, 0)
  929. mustMap = append(mustMap, map[string]interface{}{
  930. "term": map[string]interface{}{
  931. "SourceId": item.SourceId,
  932. },
  933. })
  934. mustMap = append(mustMap, map[string]interface{}{
  935. "term": map[string]interface{}{
  936. "Source": item.Source,
  937. },
  938. })
  939. queryMap := map[string]interface{}{
  940. "query": map[string]interface{}{
  941. "bool": map[string]interface{}{
  942. "must": mustMap,
  943. },
  944. },
  945. }
  946. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  947. total, e := requestTotalHits.Do(context.Background())
  948. if e != nil {
  949. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  950. return
  951. }
  952. //return
  953. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  954. if total == 0 {
  955. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  956. if e != nil {
  957. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  958. return
  959. }
  960. if resp.Status == 0 && resp.Result == "created" {
  961. //fmt.Println("新增成功")
  962. //err = nil
  963. return
  964. } else {
  965. //err = errors.New(fmt.Sprint(resp))
  966. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  967. return
  968. }
  969. } else {
  970. //拼接需要改动的前置条件
  971. bool_query := elastic.NewBoolQuery()
  972. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  973. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  974. //设置需要改动的内容
  975. var script string
  976. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  977. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  978. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  979. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  980. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  981. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  982. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  983. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  984. _, e = client.UpdateByQuery(indexName).
  985. Query(bool_query).
  986. Script(elastic.NewScriptInline(script)).
  987. Refresh("true").
  988. Do(context.Background())
  989. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  990. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  991. //fmt.Println("err", e.Error())
  992. ////err = e
  993. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  994. return
  995. }
  996. }
  997. return
  998. }
  999. // 删除数据
  1000. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  1001. defer func() {
  1002. if err != nil {
  1003. fmt.Println(err)
  1004. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  1005. }
  1006. }()
  1007. indexName := utils.IndexNameComprehensive
  1008. client := utils.Client
  1009. //拼接需要删除的前置条件
  1010. bool_query := elastic.NewBoolQuery()
  1011. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  1012. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  1013. _, e := client.DeleteByQuery(indexName).
  1014. Query(bool_query).
  1015. Do(context.Background())
  1016. if e != nil {
  1017. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  1018. return
  1019. }
  1020. return
  1021. }