stat.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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) GetCountByCondition(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. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  47. err = o.Raw(sql, pars).QueryRow(&count)
  48. return
  49. }
  50. // 获取该用户列表
  51. func (u *UserCollectChartStat) GetPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*UserCollectChartStatItem, err error) {
  52. o := orm.NewOrm()
  53. tmpSql := `SELECT * FROM user_collect_chart_stat WHERE 1=1 `
  54. if condition != "" {
  55. tmpSql += condition
  56. }
  57. if order != "" {
  58. tmpSql += ` ORDER BY ` + order + ", user_chart_stat_id DESC"
  59. } else {
  60. tmpSql += ` ORDER BY user_chart_stat_id DESC`
  61. }
  62. tmpSql += ` Limit ?,?`
  63. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  64. return
  65. }
  66. type UserStatListResp struct {
  67. Paging *paging.PagingItem
  68. List []*UserCollectChartStatItem
  69. }
  70. type UserCollectChartStatItem struct {
  71. UserId int `description:"用户ID"`
  72. BusinessCode string `description:"客户编码"`
  73. RealName string `description:"用户姓名"`
  74. EtaBusinessId int
  75. BusinessName string
  76. CollectNum int `description:"收藏的图表数量"`
  77. CollectDate string
  78. LastCollectChartTime string
  79. }
  80. type ChartCollectChartStatItem struct {
  81. ChartInfoId int `description:"图表ID"`
  82. ChartName string `description:"图表名称"`
  83. LastCollectTime string `description:"最后被收藏的时间"`
  84. CollectNum int `description:"收藏的图表数量"`
  85. }
  86. type ChartStatListResp struct {
  87. List []*ChartCollectChartStatItem
  88. }
  89. // 获取该用户列表
  90. func (u *ChartCollectStat) GetChartInfoStatusNum() (items []*ChartCollectChartStatItem, err error) {
  91. o := orm.NewOrm()
  92. 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`
  93. _, err = o.Raw(tmpSql).QueryRows(&items)
  94. return
  95. }