stat.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. CollectDate string `description:"收藏日期"`
  12. CollectNum int `description:"收藏的图表数量"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. }
  16. // 根据图表ID和日期获取图表收藏统计信息
  17. func GetChartCollectStatByChartInfoIdAndCollectDate(chartInfoId int, collectDate string) (stat *ChartCollectStat, err error) {
  18. o := orm.NewOrm()
  19. sql := "SELECT * FROM chart_collect_stat WHERE chart_info_id = ? AND collect_date = ?"
  20. err = o.Raw(sql, chartInfoId, collectDate).QueryRow(&stat)
  21. return
  22. }
  23. // 用户收藏图表每日汇总表
  24. type UserCollectChartStat struct {
  25. UserChartStatId int `orm:"column(user_chart_stat_id);pk"`
  26. UserId int `description:"用户ID"`
  27. BusinessCode string `description:"客户编码"`
  28. RealName string `description:"用户姓名"`
  29. CollectDate string `description:"收藏日期"`
  30. CollectNum int `description:"收藏的图表数量"`
  31. ChartSource int `description:"1:ETA图库;2:商品价格曲线;3:相关性图"`
  32. CreateTime time.Time `description:"创建时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. }
  35. // 根据用户ID和日期获取图表收藏统计信息
  36. func GetUserCollectChartStatByUserIdAndCollectDate(userId int, collectDate string) (stat *UserCollectChartStat, err error) {
  37. o := orm.NewOrm()
  38. sql := "SELECT * FROM chart_collect_stat WHERE user_id = ? AND collect_date = ?"
  39. err = o.Raw(sql, userId, collectDate).QueryRow(&stat)
  40. return
  41. }
  42. // 获取该用户数量
  43. func (u *UserCollectChartStat) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  44. o := orm.NewOrm()
  45. tmpSql := `SELECT s.* FROM user_collect_chart_stat AS s LEFT JOIN user AS u on s.user_id=u.user_id WHERE 1=1 `
  46. if condition != "" {
  47. tmpSql += condition
  48. }
  49. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  50. err = o.Raw(sql, pars).QueryRow(&count)
  51. return
  52. }
  53. // 获取该用户列表
  54. func (u *UserCollectChartStat) GetPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*UserCollectChartStatItem, err error) {
  55. o := orm.NewOrm()
  56. tmpSql := `SELECT s.*, u.last_collect_chart_time, u.business_code, u.real_name, u.eta_business_id FROM user_collect_chart_stat AS s LEFT JOIN user AS u on s.user_id=u.user_id WHERE 1=1 `
  57. if condition != "" {
  58. tmpSql += condition
  59. }
  60. if order != "" {
  61. tmpSql += ` ORDER BY ` + order + " s.chart_collect_stat_id DESC"
  62. } else {
  63. tmpSql += ` ORDER BY s.chart_collect_stat_id DESC`
  64. }
  65. tmpSql += ` Limit ?,?`
  66. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  67. return
  68. }
  69. type UserStatListResp struct {
  70. Paging *paging.PagingItem
  71. List []*UserCollectChartStatItem
  72. }
  73. type UserCollectChartStatItem struct {
  74. UserId int `description:"用户ID"`
  75. BusinessCode string `description:"客户编码"`
  76. RealName string `description:"用户姓名"`
  77. EtaBusinessId int
  78. BusinessName string
  79. CollectNum int `description:"收藏的图表数量"`
  80. CollectDate string
  81. LastCollectChartTime string
  82. }