stat.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package chart_collect
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // 图表收藏每日汇总统计表
  8. type ChartCollectStat struct {
  9. ChartCollectStatId int `orm:"column(chart_collect_stat_id);pk"`
  10. ChartInfoId int `description:"图表ID"`
  11. ChartSource int `description:"1:ETA图库;2:商品价格曲线;3:相关性图"`
  12. ChartName string `description:"图表名称"`
  13. LastCollectTime time.Time `description:"最后被收藏的时间"`
  14. CollectDate string `description:"收藏日期"`
  15. CollectNum int `description:"收藏的图表数量"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. }
  19. // 根据图表ID和日期获取图表收藏统计信息
  20. func GetChartCollectStatByChartInfoIdAndCollectDate(chartInfoId int, collectDate string) (stat *ChartCollectStat, err error) {
  21. o := orm.NewOrm()
  22. sql := "SELECT * FROM chart_collect_stat WHERE chart_info_id = ? AND collect_date = ?"
  23. err = o.Raw(sql, chartInfoId, collectDate).QueryRow(&stat)
  24. return
  25. }
  26. // 用户收藏图表每日汇总表
  27. type UserCollectChartStat struct {
  28. UserChartStatId int `orm:"column(user_chart_stat_id);pk"`
  29. UserId int `description:"用户ID"`
  30. BusinessCode string `description:"客户编码"`
  31. EtaBusinessId int
  32. RealName string `description:"用户姓名"`
  33. CollectDate string `description:"收藏日期"`
  34. CollectNum int `description:"收藏的图表数量"`
  35. LastCollectChartTime time.Time `description:"最近收藏图表时间"`
  36. CreateTime time.Time `description:"创建时间"`
  37. ModifyTime time.Time `description:"修改时间"`
  38. }
  39. // 获取该用户数量
  40. func (u *UserCollectChartStat) GetGroupUserCountByCondition(condition string, pars []interface{}) (count int, err error) {
  41. o := orm.NewOrm()
  42. tmpSql := `SELECT * FROM user_collect_chart_stat WHERE 1=1 `
  43. if condition != "" {
  44. tmpSql += condition
  45. }
  46. tmpSql += ` group by user_id `
  47. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  48. err = o.Raw(sql, pars).QueryRow(&count)
  49. return
  50. }
  51. // 获取该用户列表
  52. func (u *UserCollectChartStat) GetGroupUserPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*UserCollectChartStatItem, err error) {
  53. o := orm.NewOrm()
  54. tmpSql := `SELECT sum(collect_num) as collect_num, max(last_collect_chart_time) as last_collect_chart_time, user_id, real_name, eta_business_id, business_code FROM user_collect_chart_stat WHERE 1=1 `
  55. if condition != "" {
  56. tmpSql += condition
  57. }
  58. tmpSql += ` group by user_id `
  59. if order != "" {
  60. tmpSql += ` ORDER BY ` + order + ", user_chart_stat_id DESC"
  61. } else {
  62. tmpSql += ` ORDER BY user_chart_stat_id DESC`
  63. }
  64. tmpSql += ` Limit ?,?`
  65. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  66. return
  67. }
  68. type UserStatListResp struct {
  69. Paging *paging.PagingItem
  70. List []*UserCollectChartStatItem
  71. }
  72. type UserCollectChartStatItem struct {
  73. UserId int `description:"用户ID"`
  74. BusinessCode string `description:"客户编码"`
  75. RealName string `description:"用户姓名"`
  76. EtaBusinessId int
  77. BusinessName string
  78. CollectNum int `description:"收藏的图表数量"`
  79. LastCollectChartTime string
  80. }
  81. type ChartCollectChartStatItem struct {
  82. ChartInfoId int `description:"图表ID"`
  83. ChartName string `description:"图表名称"`
  84. LastCollectTime string `description:"最后被收藏的时间"`
  85. CollectNum int `description:"收藏的图表数量"`
  86. }
  87. type ChartStatListResp struct {
  88. List []*ChartCollectChartStatItem
  89. }
  90. // 获取该用户列表
  91. func (u *ChartCollectStat) GetChartInfoStatusNum() (items []*ChartCollectChartStatItem, err error) {
  92. o := orm.NewOrm()
  93. tmpSql := `SELECT sum(collect_num) as collect_num, max(last_collect_time) as last_collect_time, chart_info_id, chart_name FROM chart_collect_stat group by chart_info_id ORDER BY sum(collect_num) DESC limit 0, 20`
  94. _, err = o.Raw(tmpSql).QueryRows(&items)
  95. return
  96. }