123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package dao
- import (
- "context"
- "fmt"
- "go-common/app/admin/main/up-rating/model"
- "go-common/library/log"
- )
- const (
- _totalType int64 = iota
- _creativeType
- _influenceType
- _creditType
- )
- const (
- // select
- _ratingStatisticsSQL = "SELECT ups,section,tips,total_score,creativity_score,influence_score,credit_score,fans,avs,coin,play,tag_id,ctype,cdate FROM up_rating_statistics WHERE cdate = '%s' AND ctype = ? AND tag_id IN (%s)"
- _trendAscCountSQL = "SELECT count(*) FROM up_rating_trend_asc WHERE date='%s' %s"
- _trendDescCountSQL = "SELECT count(*) FROM up_rating_trend_desc WHERE date='%s' %s"
- _trendAscSQL = "SELECT mid,magnetic_score,creativity_score,influence_score,credit_score,%s_diff FROM up_rating_trend_asc WHERE date='%s' %s"
- _trendDescSQL = "SELECT mid,magnetic_score,creativity_score,influence_score,credit_score,%s_diff FROM up_rating_trend_desc WHERE date='%s' %s"
- )
- // GetRatingStatis get rating statistics
- func (d *Dao) GetRatingStatis(c context.Context, ctype int64, date, tags string) (statis []*model.RatingStatis, err error) {
- statis = make([]*model.RatingStatis, 0)
- rows, err := d.db.Query(c, fmt.Sprintf(_ratingStatisticsSQL, date, tags), ctype)
- if err != nil {
- log.Error("d.db.Query error(%v)", err)
- return
- }
- defer rows.Close()
- for rows.Next() {
- s := &model.RatingStatis{}
- err = rows.Scan(
- &s.Ups, &s.Section, &s.Tips, &s.TotalScore, &s.CreativityScore, &s.InfluenceScore, &s.CreditScore, &s.Fans, &s.Avs, &s.Coin, &s.Play, &s.TagID, &s.CType, &s.CDate)
- if err != nil {
- log.Error("rows.Scan error(%v)", err)
- return
- }
- switch ctype {
- case _totalType:
- s.Score = s.TotalScore
- case _creativeType:
- s.Score = s.CreativityScore
- case _influenceType:
- s.Score = s.InfluenceScore
- case _creditType:
- s.Score = s.CreditScore
- }
- statis = append(statis, s)
- }
- err = rows.Err()
- return
- }
- // AscTrendCount asc trend count
- func (d *Dao) AscTrendCount(c context.Context, date string, query string) (count int, err error) {
- row := d.db.QueryRow(c, fmt.Sprintf(_trendAscCountSQL, date, query))
- if err = row.Scan(&count); err != nil {
- log.Error("d.db.Query error(%v)", err)
- }
- return
- }
- // DescTrendCount desc trend count
- func (d *Dao) DescTrendCount(c context.Context, date string, query string) (count int, err error) {
- row := d.db.QueryRow(c, fmt.Sprintf(_trendDescCountSQL, date, query))
- if err = row.Scan(&count); err != nil {
- log.Error("d.db.Query error(%v)", err)
- }
- return
- }
- // GetTrendAsc get asc trend
- func (d *Dao) GetTrendAsc(c context.Context, ctype string, date string, query string) (ts []*model.Trend, err error) {
- rows, err := d.db.Query(c, fmt.Sprintf(_trendAscSQL, ctype, date, query))
- if err != nil {
- return
- }
- ts = make([]*model.Trend, 0)
- defer rows.Close()
- for rows.Next() {
- t := &model.Trend{}
- err = rows.Scan(&t.MID, &t.MagneticScore, &t.CreativityScore, &t.InfluenceScore, &t.CreditScore, &t.DValue)
- if err != nil {
- log.Error("rows.Scan error(%v)", err)
- return
- }
- ts = append(ts, t)
- }
- return
- }
- // GetTrendDesc get desc trend
- func (d *Dao) GetTrendDesc(c context.Context, ctype string, date string, query string) (ts []*model.Trend, err error) {
- rows, err := d.db.Query(c, fmt.Sprintf(_trendDescSQL, ctype, date, query))
- if err != nil {
- return
- }
- ts = make([]*model.Trend, 0)
- defer rows.Close()
- for rows.Next() {
- t := &model.Trend{}
- err = rows.Scan(&t.MID, &t.MagneticScore, &t.CreativityScore, &t.InfluenceScore, &t.CreditScore, &t.DValue)
- if err != nil {
- log.Error("rows.Scan error(%v)", err)
- return
- }
- ts = append(ts, t)
- }
- return
- }
|