es_comprehensive.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "github.com/olivere/elastic/v7"
  8. "hongze/hongze_clpt/models"
  9. "hongze/hongze_clpt/utils"
  10. "strconv"
  11. //"strconv"
  12. "errors"
  13. "html"
  14. "strings"
  15. "time"
  16. )
  17. type SearchComprehensiveItem struct {
  18. SourceId int `description:"资源ID"`
  19. IsSummary int `description:"是否是纪要"`
  20. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior"`
  21. Title string `description:"标题"`
  22. BodyText string `description:"内容"`
  23. PublishDate string `description:"发布时间"`
  24. Abstract string `description:"摘要"`
  25. Annotation string `description:"核心观点"`
  26. IndustryName string `description:"产业名称"`
  27. SubjectNames string `description:"标的名称"`
  28. Body []string
  29. }
  30. type ElasticComprehensiveDetail struct {
  31. SourceId int `description:"资源ID"`
  32. IsSummary int `description:"是否是纪要"`
  33. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior 、 产业资源包:industrialsource"`
  34. Title string `description:"标题"`
  35. BodyText string `description:"内容"`
  36. PublishDate string `description:"发布时间"`
  37. Abstract string `description:"摘要"`
  38. Annotation string `description:"核心观点"`
  39. IndustryName string `description:"产业名称"`
  40. SubjectNames string `description:"标的名称"`
  41. }
  42. func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  43. indexName := utils.IndexNameComprehensive
  44. client := utils.Client
  45. keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
  46. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  47. keyWordLen := len(keyWordArr)
  48. if keyWordLen <= 0 {
  49. keyWordArr = append(keyWordArr, keyWord)
  50. keyWordLen = len(keyWordArr)
  51. }
  52. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  53. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  54. mustMap := make([]interface{}, 0)
  55. shouldMap := make(map[string]interface{}, 0)
  56. shouldMapquery := make([]interface{}, 0)
  57. mustNotMap := make([]interface{}, 0)
  58. shouldNotMap := make(map[string]interface{}, 0)
  59. shouldNotMapquery := make([]interface{}, 0)
  60. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  61. //keyWordWeight := GetWeight(keyWordLen)
  62. var boost int
  63. //lenkeyWordArr := len(keyWordArr)
  64. for k, v := range keyWordArr {
  65. if k > 0 {
  66. continue
  67. }
  68. if k == 0 {
  69. boost = 2 * 1000
  70. } else {
  71. boost = 1
  72. }
  73. if v != "" {
  74. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  75. "function_score": map[string]interface{}{
  76. "query": map[string]interface{}{
  77. "multi_match": map[string]interface{}{
  78. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  79. "boost": boost, //给查询的值赋予权重
  80. "fields": []interface{}{"Title"},
  81. "query": v,
  82. },
  83. },
  84. },
  85. })
  86. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  87. "function_score": map[string]interface{}{
  88. "query": map[string]interface{}{
  89. "multi_match": map[string]interface{}{
  90. "boost": boost, //给查询的值赋予权重
  91. "fields": []interface{}{"Abstract"},
  92. "query": v,
  93. },
  94. },
  95. },
  96. })
  97. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  98. "function_score": map[string]interface{}{
  99. "query": map[string]interface{}{
  100. "multi_match": map[string]interface{}{
  101. "boost": boost, //给查询的值赋予权重
  102. "fields": []interface{}{"Annotation"},
  103. "query": v,
  104. },
  105. },
  106. },
  107. })
  108. //shouldMapquery = append(shouldMapquery, map[string]interface{}{
  109. // "function_score": map[string]interface{}{
  110. // "query": map[string]interface{}{
  111. // "multi_match": map[string]interface{}{
  112. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  113. // "boost": boost, //给查询的值赋予权重
  114. // "fields": []interface{}{"BodyText"},
  115. // "query": v,
  116. // },
  117. // },
  118. // },
  119. //})
  120. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  121. "function_score": map[string]interface{}{
  122. "query": map[string]interface{}{
  123. "multi_match": map[string]interface{}{
  124. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  125. "boost": boost, //给查询的值赋予权重
  126. "fields": []interface{}{"IndustryName"},
  127. "query": v,
  128. },
  129. },
  130. },
  131. })
  132. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  133. "function_score": map[string]interface{}{
  134. "query": map[string]interface{}{
  135. "multi_match": map[string]interface{}{
  136. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  137. "boost": boost, //给查询的值赋予权重
  138. "fields": []interface{}{"SubjectNames"},
  139. "query": v,
  140. },
  141. },
  142. },
  143. })
  144. }
  145. }
  146. shouldMap = map[string]interface{}{
  147. "should": shouldMapquery,
  148. }
  149. shouldNotMap = map[string]interface{}{
  150. "should": shouldNotMapquery,
  151. }
  152. //排序
  153. sortMap := make([]interface{}, 0)
  154. //时间
  155. sortMap = append(sortMap, map[string]interface{}{
  156. "PublishDate": map[string]interface{}{
  157. "order": "desc",
  158. },
  159. })
  160. //sortMap = append(sortMap, map[string]interface{}{
  161. // "_score": map[string]interface{}{
  162. // "order": "desc",
  163. // },
  164. //})
  165. //高亮
  166. highlightMap := make(map[string]interface{}, 0)
  167. highlightMap = map[string]interface{}{
  168. "fields": map[string]interface{}{
  169. //"BodyText": map[string]interface{}{},
  170. "Title": map[string]interface{}{},
  171. "Abstract": map[string]interface{}{},
  172. "Annotation": map[string]interface{}{},
  173. },
  174. //样式 红色
  175. "post_tags": []interface{}{"</font>"},
  176. "pre_tags": []interface{}{"<font color='red'>"},
  177. "fragment_size": 50,
  178. }
  179. mustMap = append(mustMap, map[string]interface{}{
  180. "bool": shouldMap,
  181. })
  182. mustNotMap = append(mustNotMap, map[string]interface{}{
  183. "bool": shouldNotMap,
  184. })
  185. queryMap := map[string]interface{}{
  186. "query": map[string]interface{}{
  187. "bool": map[string]interface{}{
  188. "must": mustMap,
  189. },
  190. },
  191. }
  192. queryMap["sort"] = sortMap
  193. queryMap["from"] = startSize
  194. queryMap["size"] = pageSize
  195. queryMap["highlight"] = highlightMap
  196. //jsonBytes, _ := json.Marshal(queryMap)
  197. //fmt.Println(string(jsonBytes))
  198. //utils.FileLog.Info(string(jsonBytes))
  199. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  200. searchByMatch, err := request.Do(context.Background())
  201. if searchByMatch != nil {
  202. if searchByMatch.Hits != nil {
  203. for _, v := range searchByMatch.Hits.Hits {
  204. var isAppend bool
  205. articleJson, err := v.Source.MarshalJSON()
  206. if err != nil {
  207. return nil, 0, err
  208. }
  209. article := new(ElasticComprehensiveDetail)
  210. err = json.Unmarshal(articleJson, &article)
  211. if err != nil {
  212. return nil, 0, err
  213. }
  214. //fmt.Println(article.SourceId, article.Title, article.Source)
  215. searchItem := new(SearchComprehensiveItem)
  216. searchItem.SourceId = article.SourceId
  217. if len(v.Highlight["Annotation"]) > 0 {
  218. for _, vText := range v.Highlight["Annotation"] {
  219. searchItem.Body = append(searchItem.Body, vText)
  220. }
  221. }
  222. if len(v.Highlight["Abstract"]) > 0 {
  223. for _, vText := range v.Highlight["Abstract"] {
  224. searchItem.Body = append(searchItem.Body, vText)
  225. }
  226. }
  227. if len(v.Highlight["BodyText"]) > 0 {
  228. for _, vText := range v.Highlight["BodyText"] {
  229. searchItem.Body = append(searchItem.Body, vText)
  230. }
  231. }
  232. //searchItem.IsSummary = article.IsSummary
  233. //if len(searchItem.Body) == 0 {
  234. // bodyRune := []rune(article.BodyText)
  235. // bodyRuneLen := len(bodyRune)
  236. // if bodyRuneLen > 100 {
  237. // bodyRuneLen = 100
  238. // }
  239. // body := string(bodyRune[:bodyRuneLen])
  240. // searchItem.Body = []string{body}
  241. //}
  242. var title string
  243. if len(v.Highlight["Title"]) > 0 {
  244. title = v.Highlight["Title"][0]
  245. } else {
  246. title = article.Title
  247. }
  248. searchItem.Title = title
  249. searchItem.Source = article.Source
  250. searchItem.PublishDate = article.PublishDate
  251. if !isAppend {
  252. result = append(result, searchItem)
  253. }
  254. }
  255. }
  256. total = searchByMatch.Hits.TotalHits.Value
  257. }
  258. return
  259. }
  260. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  261. var condition string
  262. var pars []interface{}
  263. uid := user.UserId
  264. titleHighlight := make(map[int]string)
  265. bodyHighlight := make(map[int][]string)
  266. yanXuanbodyHighlight := make(map[int][]string)
  267. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  268. for _, v := range list {
  269. //预处理文章
  270. item := new(models.CygxResourceDataNewResp)
  271. item.SourceId = v.SourceId
  272. item.Source = v.Source
  273. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  274. item.BodyHighlight = v.Body
  275. item.TitleHighlight = v.Title
  276. titleHighlight[v.SourceId] = v.Title
  277. bodyHighlight[v.SourceId] = v.Body
  278. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  279. }
  280. var articleIds []int //报告
  281. var newchartIds []int //图表
  282. var roadshowIds []string //微路演
  283. var activityIds []int //活动
  284. var activityvideoIds []string // 活动视频
  285. var activityvoiceIds []string //活动音频
  286. var activityspecialIds []int //专项调研活动
  287. var researchsummaryIds []int //本周研究汇总
  288. var minutessummaryIds []int //上周纪要汇总
  289. var meetingreviewchaptIds []int //晨会精华
  290. var productinteriorIds []int //产品内测
  291. var industrialResourceIdsHz []int // 弘则产业资源包
  292. var industrialResourceIdsYx []int // 研选产业资源包
  293. var yanxuanSpecialIds []int // 研选专栏
  294. var askserieVideoIds []string //问答系列视频
  295. var reportselectionIds []int //报告精选
  296. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  297. for _, v := range list {
  298. if v.Source == "article" {
  299. articleIds = append(articleIds, v.SourceId)
  300. } else if v.Source == "newchart" {
  301. newchartIds = append(newchartIds, v.SourceId)
  302. } else if v.Source == "roadshow" {
  303. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  304. } else if v.Source == "activity" {
  305. activityIds = append(activityIds, v.SourceId)
  306. } else if v.Source == "activityvideo" {
  307. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  308. } else if v.Source == "activityvoice" {
  309. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  310. } else if v.Source == "activityspecial" {
  311. activityspecialIds = append(activityspecialIds, v.SourceId)
  312. } else if v.Source == "researchsummary" {
  313. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  314. } else if v.Source == "minutessummary" {
  315. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  316. } else if v.Source == "meetingreviewchapt" {
  317. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  318. } else if v.Source == "productinterior" {
  319. productinteriorIds = append(productinteriorIds, v.SourceId)
  320. } else if v.Source == "industrialsourceHz" {
  321. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  322. } else if v.Source == "industrialsourceYx" {
  323. industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
  324. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  325. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  326. yanXuanbodyHighlight[v.SourceId] = v.Body
  327. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  328. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  329. } else if v.Source == "reportselection" {
  330. reportselectionIds = append(reportselectionIds, v.SourceId)
  331. }
  332. }
  333. detail, e := models.GetConfigByCode("city_img_url")
  334. if e != nil {
  335. err = errors.New("GetResourceDataList, Err: " + e.Error())
  336. return
  337. }
  338. detailChart, e := models.GetConfigByCode("chart_img_url")
  339. if e != nil {
  340. err = errors.New("GetResourceDataList, Err: " + e.Error())
  341. return
  342. }
  343. addressList := strings.Split(detail.ConfigValue, "{|}")
  344. mapAddress := make(map[string]string)
  345. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  346. mapChart := make(map[string]string)
  347. var cityName string
  348. var chartName string
  349. var imgUrl string
  350. var imgUrlChart string
  351. for _, v := range addressList {
  352. vslice := strings.Split(v, "_")
  353. cityName = vslice[0]
  354. imgUrl = vslice[len(vslice)-1]
  355. mapAddress[cityName] = imgUrl
  356. }
  357. for _, v := range chartList {
  358. vslice := strings.Split(v, "_")
  359. chartName = vslice[0]
  360. imgUrlChart = vslice[len(vslice)-1]
  361. mapChart[chartName] = imgUrlChart
  362. }
  363. var imgUrlResp string
  364. //处理文章
  365. if len(articleIds) > 0 {
  366. pars = make([]interface{}, 0)
  367. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  368. pars = append(pars, articleIds)
  369. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  370. if e != nil {
  371. err = errors.New("GetResourceDataList, Err: " + e.Error())
  372. return
  373. }
  374. articleList, e = HandleArticleCategoryImg(articleList, user)
  375. if e != nil {
  376. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  377. return
  378. }
  379. for _, v := range articleList {
  380. v.Body = ""
  381. if titleHighlight[v.ArticleId] != "" {
  382. v.Title = titleHighlight[v.ArticleId]
  383. }
  384. if len(bodyHighlight[v.ArticleId]) > 0 {
  385. v.Abstract = ""
  386. v.Annotation = ""
  387. v.BodyHighlight = bodyHighlight[v.ArticleId]
  388. } else {
  389. v.BodyHighlight = make([]string, 0)
  390. }
  391. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  392. }
  393. }
  394. //处理晨会精华
  395. if len(meetingreviewchaptIds) > 0 {
  396. //pars = make([]interface{}, 0)
  397. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  398. //pars = append(pars, meetingreviewchaptIds)
  399. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  400. if e != nil {
  401. err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
  402. return
  403. }
  404. for _, v := range listrMeet {
  405. v.Content = AnnotationHtml(v.Content)
  406. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  407. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  408. }
  409. }
  410. //处理上周纪要汇总
  411. if len(minutessummaryIds) > 0 {
  412. pars = make([]interface{}, 0)
  413. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  414. pars = append(pars, minutessummaryIds)
  415. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  416. if e != nil {
  417. err = errors.New("GetResourceDataList, Err: " + e.Error())
  418. return
  419. }
  420. for _, v := range listresearchsummary {
  421. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  422. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  423. }
  424. }
  425. //处理本周纪要汇总
  426. if len(researchsummaryIds) > 0 {
  427. pars = make([]interface{}, 0)
  428. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  429. pars = append(pars, researchsummaryIds)
  430. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  431. if e != nil {
  432. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  433. return
  434. }
  435. for _, v := range listresearchsummary {
  436. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  437. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  438. }
  439. }
  440. //处理产品内测
  441. if len(productinteriorIds) > 0 {
  442. pars = make([]interface{}, 0)
  443. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  444. pars = append(pars, productinteriorIds)
  445. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  446. if e != nil {
  447. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  448. return
  449. }
  450. for _, v := range listProductInterior {
  451. v.Body = ProductInteriorHtml(v.Body)
  452. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  453. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  454. }
  455. }
  456. //处理报告精选
  457. lenreportselectionIds := len(reportselectionIds)
  458. if lenreportselectionIds > 0 {
  459. pars = make([]interface{}, 0)
  460. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  461. pars = append(pars, reportselectionIds)
  462. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  463. if e != nil {
  464. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  465. return
  466. }
  467. mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
  468. for _, v := range listreportselection {
  469. v.Title += "(第" + v.Periods + "期)"
  470. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  471. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  472. v.Pv = mapPv[v.ArticleId]
  473. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  474. }
  475. }
  476. //处理活动
  477. if len(activityIds) > 0 {
  478. for _, vss := range activityIds {
  479. imgUrlResp += strconv.Itoa(vss) + ","
  480. }
  481. pars = make([]interface{}, 0)
  482. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  483. pars = append(pars, activityIds)
  484. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  485. if e != nil {
  486. err = errors.New("GetResourceDataList, Err: " + e.Error())
  487. return
  488. }
  489. var activityListRersp []*models.ActivityListResp
  490. //for _, v := range activityList {
  491. // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  492. //}
  493. //var pArr []string
  494. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  495. //处理不同的报名方式按钮回显
  496. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  497. if e != nil {
  498. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  499. return
  500. }
  501. for _, v := range activityListRersp {
  502. if v == nil {
  503. continue
  504. }
  505. if v.ActivityType == 0 {
  506. if mapAddress[v.City] != "" {
  507. imgUrlResp = mapAddress[v.City]
  508. } else {
  509. imgUrlResp = mapAddress["其它"]
  510. }
  511. } else {
  512. if mapChart[v.ChartPermissionName] != "" {
  513. imgUrlResp = mapChart[v.ChartPermissionName]
  514. }
  515. }
  516. v.ImgUrl = imgUrlResp
  517. v.SourceType = mapActivitySignup[v.ActivityId]
  518. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  519. }
  520. }
  521. //产业资源包
  522. if len(industrialResourceIdsHz) > 0 {
  523. pars = make([]interface{}, 0)
  524. var industrialResourceIdstring []string
  525. for _, v := range industrialResourceIdsHz {
  526. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  527. }
  528. industrialId := strings.Join(industrialResourceIdstring, ",")
  529. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  530. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  531. if e != nil {
  532. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  533. return
  534. }
  535. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsHz)) + `)`
  536. pars = append(pars, industrialResourceIdsHz)
  537. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  538. //合并产业关联的标的
  539. if e != nil {
  540. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  541. return
  542. }
  543. mapIndustrial := make(map[string]int)
  544. for _, v := range listSubjcet {
  545. for k2, v2 := range listIndustrialResourceIds {
  546. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  547. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  548. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  549. }
  550. }
  551. }
  552. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Hz")
  553. for _, v := range listIndustrialResourceIds {
  554. v.Source = 1
  555. v.UpdateTime = v.PublishDate
  556. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  557. }
  558. }
  559. //产业资源包
  560. if len(industrialResourceIdsYx) > 0 {
  561. pars = make([]interface{}, 0)
  562. var industrialResourceIdstring []string
  563. for _, v := range industrialResourceIdsYx {
  564. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  565. }
  566. industrialId := strings.Join(industrialResourceIdstring, ",")
  567. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  568. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  569. if e != nil {
  570. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  571. return
  572. }
  573. fmt.Println(listIndustrialResourceIds)
  574. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  575. pars = append(pars, industrialResourceIdsYx)
  576. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  577. //合并产业关联的标的
  578. if e != nil {
  579. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  580. return
  581. }
  582. mapIndustrial := make(map[string]int)
  583. for _, v := range listSubjcet {
  584. for k2, v2 := range listIndustrialResourceIds {
  585. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  586. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  587. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  588. }
  589. }
  590. }
  591. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  592. for _, v := range listIndustrialResourceIds {
  593. v.Source = 2
  594. v.UpdateTime = v.PublishDate
  595. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  596. }
  597. }
  598. //处理图表
  599. if len(newchartIds) > 0 {
  600. pars = make([]interface{}, 0)
  601. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  602. pars = append(pars, newchartIds)
  603. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  604. if e != nil {
  605. err = errors.New("GetResourceDataList, Err: " + e.Error())
  606. return
  607. }
  608. for _, v := range chartDateList {
  609. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  610. }
  611. }
  612. //处理专项调研
  613. if len(activityspecialIds) > 0 {
  614. pars = make([]interface{}, 0)
  615. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  616. pars = append(pars, activityspecialIds)
  617. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  618. if e != nil {
  619. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  620. return
  621. }
  622. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  623. if e != nil {
  624. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  625. return
  626. }
  627. for _, v := range activitySpeciallist {
  628. if mapChart[v.ChartPermissionName] != "" {
  629. imgUrlResp = mapChart[v.ChartPermissionName]
  630. }
  631. if _, ok := UserMap[v.ActivityId]; ok {
  632. v.IsTrip = 1
  633. }
  634. if v.Days == 0 {
  635. v.TripStatus = 1
  636. v.TripImgLink = v.TripImgLink
  637. } else {
  638. v.TripStatus = 2
  639. v.TripImgLink = v.TripImgLinkFix
  640. v.ActivityTimeText = v.ActivityTimeTextByDay
  641. }
  642. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  643. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  644. if resultTimeStart.After(time.Now()) {
  645. v.ActiveState = "1"
  646. } else if time.Now().After(resultTimeEnd) {
  647. v.ActiveState = "3"
  648. } else {
  649. v.ActiveState = "2"
  650. }
  651. v.ImgUrl = imgUrlResp
  652. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  653. }
  654. }
  655. //处理路演 处理路活动视频 处理路活音频
  656. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  657. audioIdstr := strings.Join(activityvoiceIds, ",")
  658. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  659. roadshowIdsStr := strings.Join(roadshowIds, ",")
  660. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  661. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  662. if e != nil {
  663. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  664. return
  665. }
  666. // 用户权限
  667. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  668. if e != nil {
  669. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  670. return
  671. }
  672. // 获取默认图配置
  673. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  674. if e != nil {
  675. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  676. return
  677. }
  678. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  679. for i := range list {
  680. // 权限
  681. au := new(models.UserPermissionAuthInfo)
  682. au.SellerName = authInfo.SellerName
  683. au.SellerMobile = authInfo.SellerMobile
  684. au.HasPermission = authInfo.HasPermission
  685. au.OperationMode = authInfo.OperationMode
  686. if au.HasPermission == 1 {
  687. // 非宏观权限进一步判断是否有权限
  688. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  689. au.HasPermission = 2
  690. }
  691. }
  692. // 无权限的弹框提示
  693. if au.HasPermission != 1 {
  694. if au.OperationMode == UserPermissionOperationModeCall {
  695. if list[i].Type == 1 {
  696. au.PopupMsg = UserPermissionPopupMsgCallActivity
  697. } else {
  698. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  699. }
  700. } else {
  701. if list[i].Type == 1 {
  702. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  703. } else {
  704. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  705. }
  706. }
  707. }
  708. list[i].AuthInfo = au
  709. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  710. // 默认图
  711. if list[i].BackgroundImg == "" {
  712. if list[i].Type == 1 {
  713. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  714. } else {
  715. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  716. }
  717. }
  718. // 分享图
  719. if list[i].ShareImg == "" {
  720. if list[i].Type == 1 {
  721. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  722. } else {
  723. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  724. }
  725. }
  726. }
  727. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  728. for _, item := range list {
  729. if item.Type == 1 {
  730. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  731. } else if item.Type == 2 {
  732. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  733. } else if item.Type == 3 {
  734. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  735. } else if item.Type == 4 {
  736. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  737. }
  738. }
  739. }
  740. //处理研选专栏
  741. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  742. if lenyanxuanSpecialIds > 0 {
  743. pars = make([]interface{}, 0)
  744. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  745. pars = append(pars, yanxuanSpecialIds)
  746. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  747. if e != nil {
  748. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  749. return
  750. }
  751. for _, v := range listyanxuanSpecial {
  752. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  753. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  754. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  755. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  756. } else {
  757. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  758. }
  759. v.Annotation = "" //强制置空,兼容前端优先级
  760. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  761. }
  762. }
  763. for _, vList := range list {
  764. for _, v := range mapItems {
  765. //如果这些类型都为空,那么就不合并
  766. if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil && v.ReportSelection == nil {
  767. continue
  768. }
  769. //if v.Article != nil && v.SourceId == vList.SourceId {
  770. // v.Article.Title = vList.Title
  771. //}
  772. //if v.Newchart != nil && v.SourceId == vList.SourceId {
  773. // v.Newchart.Title = vList.Title
  774. //}
  775. //if v.Roadshow != nil && v.SourceId == vList.SourceId {
  776. // v.Roadshow.Title = vList.Title
  777. //}
  778. //if v.Activity != nil && v.SourceId == vList.SourceId {
  779. // v.Activity.ActivityName = vList.Title
  780. //}
  781. //if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  782. // v.Activityvideo.Title = vList.Title
  783. //}
  784. //if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  785. // v.Activityvoice.Title = vList.Title
  786. //}
  787. //
  788. //if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  789. // v.Activityspecial.ResearchTheme = vList.Title
  790. //}
  791. //if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  792. // v.Researchsummary.Title = vList.Title
  793. //}
  794. //if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  795. // v.Minutessummary.Title = vList.Title
  796. //}
  797. //if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  798. // v.ProductInterior.Title = vList.Title
  799. //}
  800. //if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
  801. // v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
  802. //}
  803. //if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
  804. // v.YanxuanSpecial.Title = vList.Title
  805. //}
  806. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  807. items = append(items, v)
  808. }
  809. }
  810. }
  811. for _, v := range items {
  812. if v.IndustrialResource != nil {
  813. v.Source = "industrialsource"
  814. }
  815. }
  816. return
  817. }
  818. func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
  819. keyWord = "%" + keyWord + "%"
  820. var conditionTitle string
  821. var parsTitle []interface{}
  822. conditionTitle = " AND is_hide = 0 AND search_title LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) "
  823. parsTitle = append(parsTitle, keyWord)
  824. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  825. if e != nil {
  826. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  827. return
  828. }
  829. var conditionContent string
  830. var parsContent []interface{}
  831. conditionContent = " AND is_hide = 0 AND search_content LIKE ? AND search_title NOT LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) "
  832. parsContent = append(parsContent, keyWord, keyWord)
  833. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  834. if e != nil {
  835. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  836. return
  837. }
  838. var searchTotal int
  839. searchTotal = (startSize/pageSize + 1) * pageSize
  840. var list []*models.CygxResourceData
  841. if totalTitle >= searchTotal {
  842. //全部都是标题搜索
  843. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  844. if e != nil && e.Error() != utils.ErrNoRow() {
  845. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  846. return
  847. }
  848. } else if totalTitle <= searchTotal-pageSize {
  849. //全部都是内容搜索
  850. startSize = startSize - totalTitle
  851. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  852. if e != nil && e.Error() != utils.ErrNoRow() {
  853. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  854. return
  855. }
  856. } else {
  857. //一半标题搜索,一半内容搜索
  858. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  859. if e != nil && e.Error() != utils.ErrNoRow() {
  860. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  861. return
  862. }
  863. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  864. if e != nil && e.Error() != utils.ErrNoRow() {
  865. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  866. return
  867. }
  868. for _, v := range listContent {
  869. list = append(list, v)
  870. }
  871. }
  872. for _, v := range list {
  873. item := new(SearchComprehensiveItem)
  874. item.SourceId = v.SourceId
  875. item.Source = v.Source
  876. result = append(result, item)
  877. }
  878. total = totalTitle + totalContent
  879. return
  880. }
  881. // Es研选专栏
  882. func EsAddYanxuanSpecial(sourceId int) {
  883. var err error
  884. defer func() {
  885. if err != nil {
  886. fmt.Println("err:", err)
  887. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  888. }
  889. }()
  890. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  891. if e != nil {
  892. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  893. return
  894. }
  895. content := html.UnescapeString(detail.Content)
  896. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  897. if e != nil {
  898. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  899. return
  900. }
  901. bodyText := doc.Text()
  902. item := new(ElasticComprehensiveDetail)
  903. item.SourceId = detail.Id
  904. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  905. item.Title = detail.Title
  906. item.PublishDate = detail.PublishTime
  907. item.BodyText = bodyText
  908. item.Abstract = bodyText
  909. item.IndustryName = detail.IndustryTags
  910. item.SubjectNames = detail.CompanyTags + detail.Tags
  911. if detail.Status == 3 {
  912. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  913. } else {
  914. EsDeleteComprehensiveData(item) // 没有发布就删除
  915. }
  916. return
  917. }
  918. // 新增和修改数据
  919. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  920. indexName := utils.IndexNameComprehensive
  921. //return
  922. defer func() {
  923. if err != nil {
  924. fmt.Println(err, item.SourceId)
  925. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  926. }
  927. }()
  928. client := utils.Client
  929. mustMap := make([]interface{}, 0)
  930. mustMap = append(mustMap, map[string]interface{}{
  931. "term": map[string]interface{}{
  932. "SourceId": item.SourceId,
  933. },
  934. })
  935. mustMap = append(mustMap, map[string]interface{}{
  936. "term": map[string]interface{}{
  937. "Source": item.Source,
  938. },
  939. })
  940. queryMap := map[string]interface{}{
  941. "query": map[string]interface{}{
  942. "bool": map[string]interface{}{
  943. "must": mustMap,
  944. },
  945. },
  946. }
  947. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  948. total, e := requestTotalHits.Do(context.Background())
  949. if e != nil {
  950. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  951. return
  952. }
  953. //return
  954. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  955. if total == 0 {
  956. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  957. if e != nil {
  958. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  959. return
  960. }
  961. if resp.Status == 0 && resp.Result == "created" {
  962. //fmt.Println("新增成功")
  963. //err = nil
  964. return
  965. } else {
  966. //err = errors.New(fmt.Sprint(resp))
  967. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  968. return
  969. }
  970. } else {
  971. //拼接需要改动的前置条件
  972. bool_query := elastic.NewBoolQuery()
  973. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  974. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  975. //设置需要改动的内容
  976. var script string
  977. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  978. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  979. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  980. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  981. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  982. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  983. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  984. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  985. _, e = client.UpdateByQuery(indexName).
  986. Query(bool_query).
  987. Script(elastic.NewScriptInline(script)).
  988. Refresh("true").
  989. Do(context.Background())
  990. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  991. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  992. //fmt.Println("err", e.Error())
  993. ////err = e
  994. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  995. return
  996. }
  997. }
  998. return
  999. }
  1000. // 删除数据
  1001. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  1002. defer func() {
  1003. if err != nil {
  1004. fmt.Println(err)
  1005. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  1006. }
  1007. }()
  1008. indexName := utils.IndexNameComprehensive
  1009. client := utils.Client
  1010. //拼接需要删除的前置条件
  1011. bool_query := elastic.NewBoolQuery()
  1012. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  1013. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  1014. _, e := client.DeleteByQuery(indexName).
  1015. Query(bool_query).
  1016. Do(context.Background())
  1017. if e != nil {
  1018. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  1019. return
  1020. }
  1021. return
  1022. }