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