es_comprehensive.go 38 KB

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