123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package chart_collect
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // 图表收藏每日汇总统计表
- type ChartCollectStat struct {
- ChartCollectStatId int `orm:"column(chart_collect_stat_id);pk"`
- ChartInfoId int `description:"图表ID"`
- ChartSource int `description:"1:ETA图库;2:商品价格曲线;3:相关性图"`
- ChartName string `description:"图表名称"`
- LastCollectTime time.Time `description:"最后被收藏的时间"`
- CollectDate string `description:"收藏日期"`
- CollectNum int `description:"收藏的图表数量"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // 根据图表ID和日期获取图表收藏统计信息
- func GetChartCollectStatByChartInfoIdAndCollectDate(chartInfoId int, collectDate string) (stat *ChartCollectStat, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM chart_collect_stat WHERE chart_info_id = ? AND collect_date = ?"
- err = o.Raw(sql, chartInfoId, collectDate).QueryRow(&stat)
- return
- }
- // 用户收藏图表每日汇总表
- type UserCollectChartStat struct {
- UserChartStatId int `orm:"column(user_chart_stat_id);pk"`
- UserId int `description:"用户ID"`
- BusinessCode string `description:"客户编码"`
- EtaBusinessId int
- RealName string `description:"用户姓名"`
- CollectDate string `description:"收藏日期"`
- CollectNum int `description:"收藏的图表数量"`
- LastCollectChartTime time.Time `description:"最近收藏图表时间"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // 获取该用户数量
- func (u *UserCollectChartStat) GetGroupUserCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- tmpSql := `SELECT * FROM user_collect_chart_stat WHERE 1=1 `
- if condition != "" {
- tmpSql += condition
- }
- tmpSql += ` group by user_id `
- sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- // 获取该用户列表
- func (u *UserCollectChartStat) GetGroupUserPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*UserCollectChartStatItem, err error) {
- o := orm.NewOrm()
- 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 `
- if condition != "" {
- tmpSql += condition
- }
- tmpSql += ` group by user_id `
- if order != "" {
- tmpSql += ` ORDER BY ` + order + ", user_chart_stat_id DESC"
- } else {
- tmpSql += ` ORDER BY user_chart_stat_id DESC`
- }
- tmpSql += ` Limit ?,?`
- _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- type UserStatListResp struct {
- Paging *paging.PagingItem
- List []*UserCollectChartStatItem
- }
- type UserCollectChartStatItem struct {
- UserId int `description:"用户ID"`
- BusinessCode string `description:"客户编码"`
- RealName string `description:"用户姓名"`
- EtaBusinessId int
- BusinessName string
- CollectNum int `description:"收藏的图表数量"`
- LastCollectChartTime string
- }
- type ChartCollectChartStatItem struct {
- ChartInfoId int `description:"图表ID"`
- ChartName string `description:"图表名称"`
- LastCollectTime string `description:"最后被收藏的时间"`
- CollectNum int `description:"收藏的图表数量"`
- }
- type ChartStatListResp struct {
- List []*ChartCollectChartStatItem
- }
- // 获取该用户列表
- func (u *ChartCollectStat) GetChartInfoStatusNum() (items []*ChartCollectChartStatItem, err error) {
- o := orm.NewOrm()
- 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`
- _, err = o.Raw(tmpSql).QueryRows(&items)
- return
- }
|