report_history_record.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package services
  2. import (
  3. "hongze/hongze_cygx/models"
  4. "hongze/hongze_cygx/utils"
  5. "strconv"
  6. )
  7. // 添加历史信息
  8. func AddCygxReportHistoryRecord(item *models.CygxReportHistoryRecord) (err error) {
  9. //defer func() {
  10. // if err != nil {
  11. // go utils.SendAlarmMsg("产品内测用户浏览信息记录失败"+err.Error(), 2)
  12. // }
  13. //}()
  14. if item.StopTime >= 5 {
  15. _, err = models.AddCygxReportHistoryRecord(item)
  16. if err != nil {
  17. go utils.SendAlarmMsg("报告精选用户浏览信息记录失败"+err.Error()+"报告类型"+item.ReportType+"报告ID:"+strconv.Itoa(item.ArticleId), 2)
  18. }
  19. }
  20. historyRecordLog := new(models.CygxReportHistoryRecordLog)
  21. historyRecordLog.UserId = item.UserId
  22. historyRecordLog.ArticleId = historyRecordLog.ArticleId
  23. historyRecordLog.CreateTime = historyRecordLog.CreateTime
  24. historyRecordLog.Mobile = historyRecordLog.Mobile
  25. historyRecordLog.Email = historyRecordLog.Email
  26. historyRecordLog.CompanyId = historyRecordLog.CompanyId
  27. historyRecordLog.CompanyName = historyRecordLog.CompanyName
  28. historyRecordLog.StopTime = historyRecordLog.StopTime
  29. historyRecordLog.OutType = historyRecordLog.OutType
  30. historyRecordLog.ReportType = historyRecordLog.ReportType
  31. historyRecordLog.RegisterPlatform = historyRecordLog.RegisterPlatform
  32. _, err = models.AddCygxReportHistoryRecordLog(historyRecordLog)
  33. if err != nil {
  34. go utils.SendAlarmMsg("报告精选用户浏览信息日志记录失败"+err.Error()+"报告类型"+item.ReportType+"报告ID:"+strconv.Itoa(item.ArticleId), 2)
  35. }
  36. return
  37. }
  38. // 获取 报告精选,本周研究汇总、上周纪要汇总Pv 阅读数据
  39. func GetCygxReportHistoryRecordListMap(articleIds []int, reportType string) (mapPv map[int]int) {
  40. var err error
  41. defer func() {
  42. if err != nil {
  43. go utils.SendAlarmMsg("获取产品内测的阅读数据,信息失败,Err:"+err.Error(), 3)
  44. }
  45. }()
  46. lenArr := len(articleIds)
  47. if lenArr == 0 {
  48. return
  49. }
  50. var condition string
  51. var pars []interface{}
  52. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND report_type = ?`
  53. pars = append(pars, articleIds, reportType)
  54. list, e := models.GetCygxReportHistoryRecordListPv(condition, pars)
  55. if e != nil && e.Error() != utils.ErrNoRow() {
  56. return
  57. }
  58. mapPv = make(map[int]int, 0)
  59. for _, v := range list {
  60. mapPv[v.ArticleId] = v.Pv
  61. }
  62. return
  63. }