email.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/growup/model"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _totalIncome = "SELECT id, av_id, mid, income, total_income, is_deleted FROM av_income WHERE date = ? AND id > ? ORDER BY id LIMIT ?"
  10. _getAV = "SELECT av_id, income, total_income FROM av_income WHERE date = ?"
  11. _tag = "SELECT id, tag, category_id, is_common FROM tag_info WHERE is_deleted = 0 AND start_at <= ? AND end_at >= ?"
  12. _ncMID = "SELECT mid FROM tag_up_info WHERE is_deleted = 0 AND tag_id = ?"
  13. _commonAV = "SELECT av_id, income, total_income, is_deleted FROM av_income WHERE tag_id = ? AND date = ?"
  14. _midAV = "SELECT av_id, income, total_income, is_deleted FROM av_income WHERE mid = ? AND date = ? AND tag_id = ?"
  15. )
  16. // TotalIncome get date totalincome,upcount, avcount
  17. func (d *Dao) TotalIncome(c context.Context, date time.Time, from, limit int64) (infos []*model.IncomeInfo, err error) {
  18. rows, err := d.db.Query(c, _totalIncome, date, from, limit)
  19. if err != nil {
  20. log.Error("growup-job dao.TotalIncome error(%v)", err)
  21. return
  22. }
  23. defer rows.Close()
  24. for rows.Next() {
  25. info := &model.IncomeInfo{}
  26. err = rows.Scan(&info.ID, &info.AVID, &info.MID, &info.Income, &info.TotalIncome, &info.IsDeleted)
  27. if err != nil {
  28. log.Error("growup-job dao.TotalIncome rows scan error(%v)", err)
  29. return
  30. }
  31. infos = append(infos, info)
  32. }
  33. err = rows.Err()
  34. return
  35. }
  36. // GetAV get av income.
  37. func (d *Dao) GetAV(c context.Context, date time.Time) (infos []*model.IncomeInfo, err error) {
  38. rows, err := d.db.Query(c, _getAV, date)
  39. if err != nil {
  40. log.Error("growup-job dao.GetAV error(%v)", err)
  41. return
  42. }
  43. defer rows.Close()
  44. for rows.Next() {
  45. info := &model.IncomeInfo{}
  46. err = rows.Scan(&info.AVID, &info.Income, &info.TotalIncome)
  47. if err != nil {
  48. log.Error("growup-job dao.GetAV rows scan error(%v)", err)
  49. return
  50. }
  51. infos = append(infos, info)
  52. }
  53. err = rows.Err()
  54. return
  55. }
  56. // GetTag get tag.
  57. func (d *Dao) GetTag(c context.Context, date time.Time) (infos []*model.TagInfo, err error) {
  58. infos = make([]*model.TagInfo, 0)
  59. rows, err := d.db.Query(c, _tag, date, date)
  60. if err != nil {
  61. log.Error("growup-job dao.GetTag error(%v),sql(%s)", err, _tag)
  62. return
  63. }
  64. defer rows.Close()
  65. for rows.Next() {
  66. info := &model.TagInfo{}
  67. err = rows.Scan(&info.ID, &info.Tag, &info.Category, &info.IsCommon)
  68. if err != nil {
  69. log.Error("growup-job dao.GetTag rows scan error(%v)", err)
  70. return
  71. }
  72. infos = append(infos, info)
  73. }
  74. err = rows.Err()
  75. return
  76. }
  77. // GetMID get tag mid.
  78. func (d *Dao) GetMID(c context.Context, TagID int64) (infos []*model.MIDInfo, err error) {
  79. infos = make([]*model.MIDInfo, 0)
  80. rows, err := d.db.Query(c, _ncMID, TagID)
  81. if err != nil {
  82. log.Error("growup-job dao.GetMID error(%v),sql(%s)", err, _ncMID)
  83. return
  84. }
  85. defer rows.Close()
  86. for rows.Next() {
  87. info := &model.MIDInfo{}
  88. err = rows.Scan(&info.MID)
  89. if err != nil {
  90. log.Error("growup-job dao.GetMID rows scan error(%v)", err)
  91. return
  92. }
  93. infos = append(infos, info)
  94. }
  95. err = rows.Err()
  96. return
  97. }
  98. // TagToAV common tag av.
  99. func (d *Dao) TagToAV(c context.Context, category int, date time.Time) (infos []*model.TagInfo, err error) {
  100. infos = make([]*model.TagInfo, 0)
  101. rows, err := d.db.Query(c, _commonAV, category, date)
  102. if err != nil {
  103. log.Error("growup-job dao.TagToAV error(%v),sql(%s)", err, _commonAV)
  104. return
  105. }
  106. defer rows.Close()
  107. for rows.Next() {
  108. info := &model.TagInfo{}
  109. err = rows.Scan(&info.AVID, &info.Income, &info.TotalIncome, &info.IsDeleted)
  110. if err != nil {
  111. log.Error("growup-job dao.TagToAV rows scan error(%v)", err)
  112. return
  113. }
  114. infos = append(infos, info)
  115. }
  116. err = rows.Err()
  117. return
  118. }
  119. // MIDToAV no common tag av.
  120. func (d *Dao) MIDToAV(c context.Context, mid int64, category int, date time.Time) (infos []*model.TagInfo, err error) {
  121. infos = make([]*model.TagInfo, 0)
  122. rows, err := d.db.Query(c, _midAV, mid, date, category)
  123. if err != nil {
  124. log.Error("growup-job dao.MIDToAV error(%v),sql(%s)", err, _midAV)
  125. return
  126. }
  127. defer rows.Close()
  128. for rows.Next() {
  129. info := &model.TagInfo{}
  130. err = rows.Scan(&info.AVID, &info.Income, &info.TotalIncome, &info.IsDeleted)
  131. if err != nil {
  132. log.Error("growup-job dao.MIDToAV rows scan error(%v)", err)
  133. return
  134. }
  135. infos = append(infos, info)
  136. }
  137. err = rows.Err()
  138. return
  139. }