up_base_Info.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package up
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/mcn/model"
  6. xsql "go-common/library/database/sql"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. _selUpBaseInfoMapSQL = "SELECT mid,fans_count,active_tid,article_count_accumulate FROM up_base_info WHERE mid IN (%s) AND business_type = 1"
  11. _selUpPlayInfoMapSQL = "SELECT mid,play_count_accumulate,article_count FROM up_play_info WHERE mid IN (%s) AND business_type = 1"
  12. )
  13. // UpBaseInfoMap .
  14. func (d *Dao) UpBaseInfoMap(c context.Context, mids []int64) (mbi map[int64]*model.UpBaseInfo, err error) {
  15. var rows *xsql.Rows
  16. if rows, err = d.db.Query(c, fmt.Sprintf(_selUpBaseInfoMapSQL, xstr.JoinInts(mids))); err != nil {
  17. return
  18. }
  19. defer rows.Close()
  20. mbi = make(map[int64]*model.UpBaseInfo, len(mids))
  21. for rows.Next() {
  22. bi := new(model.UpBaseInfo)
  23. if err = rows.Scan(&bi.Mid, &bi.FansCount, &bi.ActiveTid, &bi.ArticleCountAccumulate); err != nil {
  24. return
  25. }
  26. mbi[bi.Mid] = bi
  27. }
  28. err = rows.Err()
  29. return
  30. }
  31. // UpPlayInfoMap .
  32. func (d *Dao) UpPlayInfoMap(c context.Context, mids []int64) (mpi map[int64]*model.UpPlayInfo, err error) {
  33. var rows *xsql.Rows
  34. if rows, err = d.db.Query(c, fmt.Sprintf(_selUpPlayInfoMapSQL, xstr.JoinInts(mids))); err != nil {
  35. return
  36. }
  37. defer rows.Close()
  38. mpi = make(map[int64]*model.UpPlayInfo, len(mids))
  39. for rows.Next() {
  40. pi := new(model.UpPlayInfo)
  41. if err = rows.Scan(&pi.Mid, &pi.PlayCountAccumulate, &pi.ArticleCount); err != nil {
  42. return
  43. }
  44. if pi.ArticleCount != 0 {
  45. pi.PlayCountAverage = pi.PlayCountAccumulate / pi.ArticleCount
  46. }
  47. mpi[pi.Mid] = pi
  48. }
  49. err = rows.Err()
  50. return
  51. }