tactics_time_line.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }