es_comprehensive.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package elastic
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "github.com/olivere/elastic/v7"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/services/alarm_msg"
  10. cygxService "hongze/hz_crm_api/services/cygx"
  11. "hongze/hz_crm_api/utils"
  12. "html"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type ElasticComprehensiveDetail 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 、 产业资源包:industrialsource"`
  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. }
  29. // 新增和修改数据
  30. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  31. indexName := utils.IndexNameComprehensive // 避免调用错别的项目的索引 ,这里写死
  32. //return
  33. defer func() {
  34. if err != nil {
  35. go alarm_msg.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  36. }
  37. }()
  38. client, err := NewClient()
  39. if err != nil {
  40. fmt.Println(err, "err1")
  41. return
  42. }
  43. mustMap := make([]interface{}, 0)
  44. mustMap = append(mustMap, map[string]interface{}{
  45. "term": map[string]interface{}{
  46. "SourceId": item.SourceId,
  47. },
  48. })
  49. mustMap = append(mustMap, map[string]interface{}{
  50. "term": map[string]interface{}{
  51. "Source": item.Source,
  52. },
  53. })
  54. //fmt.Println(item.SourceId)
  55. queryMap := map[string]interface{}{
  56. "query": map[string]interface{}{
  57. "bool": map[string]interface{}{
  58. "must": mustMap,
  59. },
  60. },
  61. }
  62. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  63. total, e := requestTotalHits.Do(context.Background())
  64. if e != nil {
  65. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  66. return
  67. }
  68. //return
  69. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  70. if total == 0 {
  71. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  72. if e != nil {
  73. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  74. return
  75. }
  76. if resp.Status == 0 && resp.Result == "created" {
  77. //fmt.Println("新增成功")
  78. //err = nil
  79. return
  80. } else {
  81. err = errors.New(fmt.Sprint(resp))
  82. return
  83. }
  84. } else {
  85. //拼接需要改动的前置条件
  86. bool_query := elastic.NewBoolQuery()
  87. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  88. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  89. //设置需要改动的内容
  90. var script string
  91. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  92. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  93. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  94. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  95. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  96. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  97. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  98. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  99. _, e := client.UpdateByQuery(indexName).
  100. Query(bool_query).
  101. Script(elastic.NewScriptInline(script)).
  102. Refresh("true").
  103. Do(context.Background())
  104. if e != nil {
  105. err = errors.New(" client.UpdateByQuery(indexName), Err: " + e.Error())
  106. return
  107. }
  108. }
  109. return
  110. }
  111. // 更新产业资源包
  112. func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
  113. var err error
  114. defer func() {
  115. if err != nil {
  116. go alarm_msg.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
  117. }
  118. }()
  119. sourceId := itemSource.SourceId
  120. var source = itemSource.Source
  121. //判断是否存在,如果不存在就新增,存在就更新
  122. totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  123. if e != nil {
  124. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  125. return
  126. }
  127. item := new(cygx.CygxResourceData)
  128. item.SourceId = sourceId
  129. item.Source = source
  130. item.PublishDate = itemSource.PublishDate
  131. item.CreateTime = time.Now()
  132. item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
  133. item.SearchContent = ""
  134. item.SearchOrderTime = itemSource.PublishDate
  135. if totalData == 0 {
  136. _, e = cygx.AddCygxResourceData(item)
  137. if e != nil {
  138. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  139. return
  140. }
  141. } else {
  142. e = cygx.UpdateResourceDataByItem(item)
  143. if e != nil {
  144. err = errors.New("UpdateResourceData, Err: " + e.Error())
  145. return
  146. }
  147. }
  148. return
  149. }
  150. // 删除数据
  151. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  152. indexName := utils.IndexNameComprehensive // 避免调用错别的项目的索引 ,这里写死
  153. defer func() {
  154. if err != nil {
  155. fmt.Println(err)
  156. go alarm_msg.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  157. }
  158. }()
  159. fmt.Println("删除", item.SourceId)
  160. client, err := NewClient()
  161. //拼接需要删除的前置条件
  162. bool_query := elastic.NewBoolQuery()
  163. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  164. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  165. _, e := client.DeleteByQuery(indexName).
  166. Query(bool_query).
  167. Do(context.Background())
  168. if e != nil {
  169. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  170. return
  171. }
  172. return
  173. }
  174. // ES添加文章:报告、纪要
  175. func AddComprehensiveArticle(sourceId int) {
  176. time.Sleep(3 * time.Second) // 延迟三秒处理
  177. var err error
  178. defer func() {
  179. if err != nil {
  180. fmt.Println("err:", err)
  181. go alarm_msg.SendAlarmMsg("AddComprehensiveArticle,Err:"+err.Error(), 3)
  182. }
  183. }()
  184. v, e := cygx.GetArticleInfoOtherByArticleId(sourceId)
  185. if e != nil {
  186. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  187. return
  188. }
  189. content := html.UnescapeString(v.Body)
  190. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  191. if e != nil {
  192. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  193. return
  194. }
  195. bodyText := doc.Text()
  196. item := new(ElasticComprehensiveDetail)
  197. item.SourceId = v.ArticleId
  198. item.IsSummary = v.IsSummary
  199. item.Source = utils.CYGX_OBJ_ARTICLE
  200. item.Title = v.Title
  201. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  202. item.BodyText = bodyText
  203. item.Annotation = html.UnescapeString(v.Annotation)
  204. item.Abstract = html.UnescapeString(v.Abstract)
  205. if v.PublishStatus == 1 {
  206. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  207. } else {
  208. EsDeleteComprehensiveData(item) // 没有发布就删除
  209. }
  210. return
  211. }
  212. // Es添加活动
  213. func AddComprehensiveActivity(sourceId int) {
  214. time.Sleep(3 * time.Second) // 延迟三秒处理
  215. var err error
  216. defer func() {
  217. if err != nil {
  218. fmt.Println("err:", err)
  219. go alarm_msg.SendAlarmMsg("AddComprehensiveActivity,Err:"+err.Error(), 3)
  220. }
  221. }()
  222. activityId := sourceId
  223. detail, e := cygx.GetAddActivityInfoById(sourceId)
  224. if e != nil {
  225. err = errors.New("GetAddActivityInfoById" + e.Error())
  226. return
  227. }
  228. mapActivityIndustrialManagement := make(map[int][]string)
  229. mapActivitySubject := make(map[int][]string)
  230. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  231. if e != nil && e.Error() != utils.ErrNoRow() {
  232. err = errors.New("GetIndustrialActivityGroupManagementList" + e.Error())
  233. return
  234. }
  235. if len(industrialList) > 0 {
  236. for _, v := range industrialList {
  237. mapActivityIndustrialManagement[activityId] = append(mapActivityIndustrialManagement[activityId], v.IndustryName)
  238. }
  239. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  240. if e != nil && e.Error() != utils.ErrNoRow() {
  241. err = errors.New("GetSubjectActivityGroupManagementList" + e.Error())
  242. return
  243. }
  244. if len(subjectList) > 0 {
  245. for _, v := range subjectList {
  246. mapActivitySubject[activityId] = append(mapActivitySubject[activityId], v.SubjectName)
  247. }
  248. }
  249. }
  250. item := new(ElasticComprehensiveDetail)
  251. item.SourceId = detail.ActivityId
  252. item.Source = utils.CYGX_OBJ_ACTIVITY
  253. item.SubjectNames = strings.Join(mapActivitySubject[detail.ActivityId], ",")
  254. item.IndustryName = strings.Join(mapActivityIndustrialManagement[detail.ActivityId], ",")
  255. item.Title = detail.ActivityName
  256. item.PublishDate = detail.ActivityTime
  257. if detail.PublishStatus == 1 {
  258. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  259. } else {
  260. EsDeleteComprehensiveData(item) // 没有发布就删除
  261. }
  262. return
  263. }
  264. // Es添加专项调研活动
  265. func AddComprehensiveActivitySpecial(sourceId int) {
  266. time.Sleep(3 * time.Second) // 延迟三秒处理
  267. var err error
  268. defer func() {
  269. if err != nil {
  270. fmt.Println("err:", err)
  271. go alarm_msg.SendAlarmMsg("AddComprehensiveActivitySpecial,Err:"+err.Error(), 3)
  272. }
  273. }()
  274. activityId := sourceId
  275. detail, e := cygx.GetAddActivityInfoSpecialById(sourceId)
  276. if e != nil {
  277. err = errors.New("GetAddActivityInfoSpecialById" + e.Error())
  278. return
  279. }
  280. mapActivityIndustrialManagement := make(map[int][]string)
  281. mapActivitySubject := make(map[int][]string)
  282. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 2)
  283. if e != nil && e.Error() != utils.ErrNoRow() {
  284. err = errors.New("GetIndustrialActivityGroupManagementList" + e.Error())
  285. return
  286. }
  287. if len(industrialList) > 0 {
  288. for _, v := range industrialList {
  289. mapActivityIndustrialManagement[activityId] = append(mapActivityIndustrialManagement[activityId], v.IndustryName)
  290. }
  291. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 2)
  292. if e != nil && e.Error() != utils.ErrNoRow() {
  293. err = errors.New("GetSubjectActivityGroupManagementList" + e.Error())
  294. return
  295. }
  296. if len(subjectList) > 0 {
  297. for _, v := range subjectList {
  298. mapActivitySubject[activityId] = append(mapActivitySubject[activityId], v.SubjectName)
  299. }
  300. }
  301. }
  302. item := new(ElasticComprehensiveDetail)
  303. item.SourceId = detail.ActivityId
  304. item.Source = utils.CYGX_OBJ_ACTIVITYSPECIAL
  305. item.SubjectNames = strings.Join(mapActivitySubject[detail.ActivityId], ",")
  306. item.IndustryName = strings.Join(mapActivityIndustrialManagement[detail.ActivityId], ",")
  307. item.Title = detail.ResearchTheme
  308. if detail.ActivityTime == utils.EmptyDateTimeStr {
  309. item.PublishDate = detail.LastUpdatedTime.Format(utils.FormatDateTime)
  310. } else {
  311. item.PublishDate = detail.ActivityTime
  312. }
  313. if detail.PublishStatus == 1 {
  314. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  315. } else {
  316. EsDeleteComprehensiveData(item) // 没有发布就删除
  317. }
  318. return
  319. }
  320. // Es添加活动视频
  321. func AddComprehensiveActivityVideo(activityId int) {
  322. time.Sleep(3 * time.Second) // 延迟三秒处理
  323. var err error
  324. defer func() {
  325. if err != nil {
  326. fmt.Println("err:", err)
  327. go alarm_msg.SendAlarmMsg("AddComprehensiveActivityVideo,Err:"+err.Error(), 3)
  328. }
  329. }()
  330. detailactivity, e := cygx.GetAddActivityInfoById(activityId)
  331. if e != nil {
  332. err = errors.New("GetAddActivityInfoById" + e.Error())
  333. return
  334. }
  335. detail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
  336. if e != nil {
  337. err = errors.New("GetAddActivityInfoById" + e.Error())
  338. return
  339. }
  340. item := new(ElasticComprehensiveDetail)
  341. item.SourceId = detail.VideoId
  342. item.Source = utils.CYGX_OBJ_ACTIVITYVIDEO
  343. if detail == nil {
  344. EsDeleteComprehensiveData(item) //如果活动视频不存在 没有发布就删除
  345. }
  346. mapActivityIndustrialManagement := make(map[int][]string)
  347. mapActivitySubject := make(map[int][]string)
  348. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  349. if e != nil && e.Error() != utils.ErrNoRow() {
  350. err = errors.New("GetIndustrialActivityGroupManagementList" + e.Error())
  351. return
  352. }
  353. if len(industrialList) > 0 {
  354. for _, v := range industrialList {
  355. mapActivityIndustrialManagement[activityId] = append(mapActivityIndustrialManagement[activityId], v.IndustryName)
  356. }
  357. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  358. if e != nil && e.Error() != utils.ErrNoRow() {
  359. err = errors.New("GetSubjectActivityGroupManagementList" + e.Error())
  360. return
  361. }
  362. if len(subjectList) > 0 {
  363. for _, v := range subjectList {
  364. mapActivitySubject[activityId] = append(mapActivitySubject[activityId], v.SubjectName)
  365. }
  366. }
  367. }
  368. item.SubjectNames = strings.Join(mapActivitySubject[detail.ActivityId], ",")
  369. item.IndustryName = strings.Join(mapActivityIndustrialManagement[detail.ActivityId], ",")
  370. item.Title = detail.VideoName
  371. item.BodyText = detailactivity.ActivityName
  372. item.PublishDate = detailactivity.ActivityTime
  373. EsAddOrEditComprehensiveData(item) //新增或者修改
  374. return
  375. }
  376. // Es添加活动音频
  377. func AddComprehensiveActivityVoice(activityId int) {
  378. time.Sleep(3 * time.Second) // 延迟三秒处理
  379. var err error
  380. defer func() {
  381. if err != nil {
  382. fmt.Println("err:", err)
  383. go alarm_msg.SendAlarmMsg("AddComprehensiveActivityVoice,Err:"+err.Error(), 3)
  384. }
  385. }()
  386. detailactivity, e := cygx.GetAddActivityInfoById(activityId)
  387. if e != nil {
  388. err = errors.New("GetAddActivityInfoById" + e.Error())
  389. return
  390. }
  391. detail, e := cygx.GetCygxActivityVoiceReqDetail(activityId)
  392. if e != nil {
  393. err = errors.New("GetAddActivityInfoById" + e.Error())
  394. return
  395. }
  396. item := new(ElasticComprehensiveDetail)
  397. item.SourceId = detail.ActivityVoiceId
  398. item.Source = utils.CYGX_OBJ_ACTIVITYVOICE
  399. if detail == nil {
  400. EsDeleteComprehensiveData(item) //如果不存在就先删除
  401. }
  402. mapActivityIndustrialManagement := make(map[int][]string)
  403. mapActivitySubject := make(map[int][]string)
  404. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  405. if e != nil && e.Error() != utils.ErrNoRow() {
  406. err = errors.New("GetIndustrialActivityGroupManagementList" + e.Error())
  407. return
  408. }
  409. if len(industrialList) > 0 {
  410. for _, v := range industrialList {
  411. mapActivityIndustrialManagement[activityId] = append(mapActivityIndustrialManagement[activityId], v.IndustryName)
  412. }
  413. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  414. if e != nil && e.Error() != utils.ErrNoRow() {
  415. err = errors.New("GetSubjectActivityGroupManagementList" + e.Error())
  416. return
  417. }
  418. if len(subjectList) > 0 {
  419. for _, v := range subjectList {
  420. mapActivitySubject[activityId] = append(mapActivitySubject[activityId], v.SubjectName)
  421. }
  422. }
  423. }
  424. item.SubjectNames = strings.Join(mapActivitySubject[detail.ActivityId], ",")
  425. item.IndustryName = strings.Join(mapActivityIndustrialManagement[detail.ActivityId], ",")
  426. item.Title = detail.VoiceName
  427. item.BodyText = detailactivity.ActivityName
  428. item.PublishDate = detailactivity.ActivityTime
  429. EsAddOrEditComprehensiveData(item) //新增或者修改
  430. return
  431. }
  432. // Es添加微路演
  433. func AddComprehensiveRoadshow(sourceId int) {
  434. time.Sleep(3 * time.Second) // 延迟三秒处理
  435. var err error
  436. defer func() {
  437. if err != nil {
  438. fmt.Println("err:", err)
  439. go alarm_msg.SendAlarmMsg("AddComprehensiveActivityVoice,Err:"+err.Error(), 3)
  440. }
  441. }()
  442. v, e := cygx.GetMicroRoadshowVideoByVideoId(sourceId)
  443. if e != nil {
  444. err = errors.New("GetMicroRoadshowVideoByVideoId" + e.Error())
  445. return
  446. }
  447. item := new(ElasticComprehensiveDetail)
  448. item.SourceId = v.VideoId
  449. item.Source = utils.CYGX_OBJ_ROADSHOW
  450. item.IndustryName = v.IndustryName
  451. item.Title = v.VideoName
  452. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  453. if v.PublishStatus == 1 {
  454. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  455. } else {
  456. EsDeleteComprehensiveData(item) // 没有发布就删除
  457. }
  458. return
  459. }
  460. // Es添加晨会精华
  461. func AddComprehensiveMeetingreviewchapt(sourceId int) {
  462. time.Sleep(3 * time.Second) // 延迟三秒处理
  463. var err error
  464. defer func() {
  465. if err != nil {
  466. fmt.Println("err:", err)
  467. go alarm_msg.SendAlarmMsg("AddComprehensiveMeetingreviewchapt,Err:"+err.Error(), 3)
  468. }
  469. }()
  470. v, e := cygx.GetCygxMorningMeetingReviewChapterDetail(sourceId)
  471. if e != nil {
  472. err = errors.New("GetCygxMorningMeetingReviewChapterDetail" + e.Error())
  473. return
  474. }
  475. content := html.UnescapeString(v.Content)
  476. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  477. if e != nil {
  478. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  479. return
  480. }
  481. bodyText := doc.Text()
  482. item := new(ElasticComprehensiveDetail)
  483. item.SourceId = sourceId
  484. item.Source = utils.CYGX_OBJ_MEETINGREVIEWCHAPT
  485. item.IndustryName = v.IndustryName
  486. item.PublishDate = v.MeetingTime.Format(utils.FormatDateTime)
  487. item.Abstract = bodyText
  488. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  489. return
  490. }
  491. // Es删除晨会精华
  492. func DeleteComprehensiveMeetingreviewchapt(sourceId int) {
  493. time.Sleep(3 * time.Second) // 延迟三秒处理
  494. var err error
  495. defer func() {
  496. if err != nil {
  497. fmt.Println("err:", err)
  498. go alarm_msg.SendAlarmMsg("AddComprehensiveMeetingreviewchapt,Err:"+err.Error(), 3)
  499. }
  500. }()
  501. item := new(ElasticComprehensiveDetail)
  502. item.SourceId = sourceId
  503. item.Source = utils.CYGX_OBJ_MEETINGREVIEWCHAPT
  504. EsDeleteComprehensiveData(item) //删除
  505. return
  506. }
  507. // 添加产业资源包
  508. func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
  509. time.Sleep(3 * time.Second) // 延迟三秒处理
  510. var err error
  511. defer func() {
  512. if err != nil {
  513. fmt.Println(err)
  514. go alarm_msg.SendAlarmMsg("AddComprehensiveIndustrialSource"+err.Error(), 2)
  515. }
  516. }()
  517. var condition string
  518. var pars []interface{}
  519. mapActivitySubject := make(map[int][]string, 0)
  520. listsubject, e := cygx.GetCygxIndustrialSubjectListCondition(condition, pars)
  521. if e != nil {
  522. err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error())
  523. return
  524. }
  525. for _, v := range listsubject {
  526. mapActivitySubject[v.IndustrialManagementId] = append(mapActivitySubject[v.IndustrialManagementId], v.SubjectName)
  527. }
  528. var industrialsource string
  529. if sourceType == "Hz" {
  530. condition = " AND a.article_type_id = 0 " // 弘则资源包
  531. industrialsource = "industrialsourceHz"
  532. } else {
  533. condition = " AND a.article_type_id > 0 " //研选资源包
  534. industrialsource = "industrialsourceYx"
  535. }
  536. if articleId > 0 {
  537. condition += " AND a.article_id = " + strconv.Itoa(articleId)
  538. }
  539. list, err := cygx.GetSearchResourceList(0, condition, 0, 0)
  540. if err != nil {
  541. fmt.Println(err)
  542. return
  543. }
  544. if len(list) == 0 {
  545. return
  546. }
  547. for _, v := range list {
  548. item := new(ElasticComprehensiveDetail)
  549. item.SourceId = v.IndustrialManagementId
  550. item.Source = industrialsource
  551. item.IndustryName = v.IndustryName
  552. item.SubjectNames = strings.Join(mapActivitySubject[v.IndustrialManagementId], ",")
  553. item.PublishDate = v.PublishDate + " 00:00:00"
  554. EsAddOrEditComprehensiveData(item)
  555. UpdateComprehensiveIndustrialResourceData(item)
  556. }
  557. }
  558. // Es研选专栏
  559. func EsAddYanxuanSpecial(sourceId int) {
  560. var err error
  561. defer func() {
  562. if err != nil {
  563. fmt.Println("err:", err)
  564. go alarm_msg.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, err.Error()), 2)
  565. }
  566. }()
  567. detail, e := cygx.GetYanxuanSpecialItemById(sourceId)
  568. if e != nil {
  569. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  570. return
  571. }
  572. content := html.UnescapeString(detail.Content)
  573. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  574. if e != nil {
  575. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  576. return
  577. }
  578. bodyText := doc.Text()
  579. item := new(ElasticComprehensiveDetail)
  580. item.SourceId = detail.Id
  581. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  582. item.Title = detail.Title
  583. item.PublishDate = detail.PublishTime
  584. item.BodyText = bodyText
  585. if detail.Status == 3 {
  586. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  587. } else {
  588. EsDeleteComprehensiveData(item) // 没有发布就删除
  589. }
  590. return
  591. }
  592. //func init() {
  593. // EsAddAskserieVideo(74)
  594. //}
  595. // Es问答系列视频
  596. func EsAddAskserieVideo(sourceId int) {
  597. var err error
  598. defer func() {
  599. if err != nil {
  600. fmt.Println("err:", err)
  601. go alarm_msg.SendAlarmMsg(fmt.Sprint("Es更新问答系列视频AddAskserieVideo失败sourceId: ", sourceId, err.Error()), 2)
  602. }
  603. }()
  604. detail, e := cygx.GetCygxAskserieVideoDetail(sourceId)
  605. if e != nil {
  606. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  607. return
  608. }
  609. content := html.UnescapeString(detail.VideoName)
  610. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  611. if e != nil {
  612. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  613. return
  614. }
  615. bodyText := doc.Text()
  616. item := new(ElasticComprehensiveDetail)
  617. item.SourceId = detail.AskserieVideoId
  618. item.Source = utils.CYGX_OBJ_ASKSERIEVIDEO
  619. item.Title = detail.VideoName
  620. item.PublishDate = detail.PublishDate
  621. item.BodyText = bodyText
  622. mapLabel := cygxService.GetCygxAskserieVideoLabelMap([]int{sourceId}) // 标签
  623. item.IndustryName = mapLabel[sourceId]
  624. if detail.PublishStatus == 1 {
  625. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  626. } else {
  627. EsDeleteComprehensiveData(item) // 没有发布就删除
  628. }
  629. return
  630. }