es_comprehensive.go 38 KB

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