tactics_time_line.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package cygx
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/cygx"
  5. "hongze/hz_crm_api/services/alarm_msg"
  6. "hongze/hz_crm_api/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. //func init() {
  11. // HandleTacticsTimeLinLink("https://web.hzinsights.com/charts/5577")
  12. //}
  13. // 处理传过来的链接,获取文章或者图表的ID详情
  14. func HandleTacticsTimeLinLink(link string) (articleId, chartId int) {
  15. sliceLink := strings.Split(link, "/")
  16. resourceId := sliceLink[len(sliceLink)-1]
  17. if strings.Contains(link, "info") {
  18. articleId, _ = strconv.Atoi(resourceId)
  19. } else if strings.Contains(link, "charts") {
  20. chartId, _ = strconv.Atoi(resourceId)
  21. }
  22. return
  23. }
  24. // 获取策略时间线的阅读数据
  25. func GetCygxTacticsTimeLineHistoryListMap(timeLineIds []int) (mapPv, mapUv map[int]int) {
  26. var err error
  27. defer func() {
  28. if err != nil {
  29. go alarm_msg.SendAlarmMsg("获取策略时间线的阅读数据,信息失败,Err:"+err.Error(), 3)
  30. }
  31. }()
  32. lentimeLineIds := len(timeLineIds)
  33. if lentimeLineIds == 0 {
  34. return
  35. }
  36. var condition string
  37. var pars []interface{}
  38. condition = ` AND time_line_id IN (` + utils.GetOrmInReplace(lentimeLineIds) + `)`
  39. pars = append(pars, timeLineIds)
  40. list, err := cygx.GetCygxTacticsTimeLineHistoryList(condition, pars)
  41. if err != nil {
  42. return
  43. }
  44. mapPv = make(map[int]int, 0)
  45. mapUv = make(map[int]int, 0)
  46. mapUvCount := make(map[string]int, 0)
  47. for _, v := range list {
  48. mapPv[v.TimeLineId]++
  49. if _, ok := mapUvCount[fmt.Sprint("UID_", v.UserId, "TimeLineId_", v.TimeLineId)]; !ok {
  50. mapUvCount[fmt.Sprint("UID_", v.UserId, "TimeLineId_", v.TimeLineId)] = v.TimeLineId
  51. mapUv[v.TimeLineId]++
  52. }
  53. }
  54. return
  55. }
  56. // GetArticleTitleMapByid 通过文章ID获取文章标题 map
  57. func GetArticleTitleMapByid(articleIds []int) (mapResp map[int]string) {
  58. var err error
  59. defer func() {
  60. if err != nil {
  61. go alarm_msg.SendAlarmMsg("通过文章ID获取文章标题 map,信息失败,Err:"+err.Error(), 3)
  62. }
  63. }()
  64. lenarticleIds := len(articleIds)
  65. if lenarticleIds == 0 {
  66. return
  67. }
  68. var condition string
  69. var pars []interface{}
  70. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) `
  71. pars = append(pars, articleIds)
  72. articleList, err := cygx.GetCygxArticleList(condition, pars, 0, lenarticleIds)
  73. if err != nil {
  74. return
  75. }
  76. mapResp = make(map[int]string, 0)
  77. for _, v := range articleList {
  78. mapResp[v.ArticleId] = v.Title
  79. }
  80. return
  81. }
  82. // 获取固收时间线的阅读数据
  83. func GetCygxGushouTimeLineHistoryListMap(timeLineIds []int) (mapPv, mapUv map[int]int) {
  84. var err error
  85. defer func() {
  86. if err != nil {
  87. go alarm_msg.SendAlarmMsg("获取固收时间线的阅读数据,信息失败,GetCygxGushouTimeLineHistoryListMap Err:"+err.Error(), 3)
  88. }
  89. }()
  90. lentimeLineIds := len(timeLineIds)
  91. if lentimeLineIds == 0 {
  92. return
  93. }
  94. var condition string
  95. var pars []interface{}
  96. condition = ` AND time_line_id IN (` + utils.GetOrmInReplace(lentimeLineIds) + `)`
  97. pars = append(pars, timeLineIds)
  98. list, err := cygx.GetCygxGushouTimeLineHistoryList(condition, pars)
  99. if err != nil {
  100. return
  101. }
  102. mapPv = make(map[int]int, 0)
  103. mapUv = make(map[int]int, 0)
  104. mapUvCount := make(map[string]int, 0)
  105. for _, v := range list {
  106. mapPv[v.TimeLineId]++
  107. if _, ok := mapUvCount[fmt.Sprint("UID_", v.UserId, "TimeLineId_", v.TimeLineId)]; !ok {
  108. mapUvCount[fmt.Sprint("UID_", v.UserId, "TimeLineId_", v.TimeLineId)] = v.TimeLineId
  109. mapUv[v.TimeLineId]++
  110. }
  111. }
  112. return
  113. }