user.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/spy/model"
  5. "go-common/library/log"
  6. )
  7. // UserInfo get UserInfo by mid , from cache or db or generate.
  8. func (s *Service) UserInfo(c context.Context, mid int64) (u *model.UserInfoDto, err error) {
  9. var (
  10. udb *model.UserInfo
  11. )
  12. if udb, err = s.spyDao.Info(c, mid); err != nil {
  13. log.Error("s.spyDao.Info(%d) error(%v)", mid, err)
  14. return
  15. }
  16. // init user score by rpc call
  17. if udb == nil {
  18. if _, err = s.spyDao.UserScore(c, mid); err != nil {
  19. log.Error("s.spyDao.UserScore(%d) error(%v)", mid, err)
  20. return
  21. }
  22. if udb, err = s.spyDao.Info(c, mid); err != nil {
  23. log.Error("s.spyDao.Info(%d) error(%v)", mid, err)
  24. return
  25. }
  26. }
  27. if udb == nil {
  28. log.Error("UserInfo init failed , still nil")
  29. return
  30. }
  31. u = &model.UserInfoDto{
  32. ID: udb.ID,
  33. Mid: udb.Mid,
  34. Score: udb.Score,
  35. BaseScore: udb.BaseScore,
  36. EventScore: udb.EventScore,
  37. State: udb.State,
  38. ReliveTimes: udb.ReliveTimes,
  39. Mtime: udb.Mtime.Unix(),
  40. }
  41. if m, err1 := s.spyDao.AccInfo(c, mid); err1 == nil && m != nil {
  42. u.Name = m.Name
  43. }
  44. return
  45. }
  46. // HisoryPage history page.
  47. func (s *Service) HisoryPage(c context.Context, h *model.HisParamReq) (page *model.HistoryPage, err error) {
  48. totalCount, err := s.spyDao.HistoryPageTotalC(c, h)
  49. if err != nil {
  50. log.Error("userDao HistoryPageTotalC(%v) error(%v)", h, err)
  51. return
  52. }
  53. page = &model.HistoryPage{}
  54. items, err := s.spyDao.HistoryPage(c, h)
  55. if err != nil {
  56. log.Error("spyDao.HistoryPage(%v) error(%v)", h, err)
  57. return
  58. }
  59. page.TotalCount = totalCount
  60. page.Items = items
  61. page.Pn = h.Pn
  62. page.Ps = h.Ps
  63. return
  64. }
  65. // ResetBase reset user base score.
  66. func (s *Service) ResetBase(c context.Context, mid int64, operator string) (err error) {
  67. if err = s.spyDao.ResetBase(c, mid, operator); err != nil {
  68. log.Error("s.spyDao.ResetBase(%d,%s) error(%v)", mid, operator, err)
  69. return
  70. }
  71. return
  72. }
  73. // Refresh reset user base score.
  74. func (s *Service) RefreshBase(c context.Context, mid int64, operator string) (err error) {
  75. if err = s.spyDao.RefreshBase(c, mid, operator); err != nil {
  76. log.Error("s.spyDao.RefreshBase(%d,%s) error(%v)", mid, operator, err)
  77. return
  78. }
  79. return
  80. }
  81. // ResetEvent reset user event score.
  82. func (s *Service) ResetEvent(c context.Context, mid int64, operator string) (err error) {
  83. if err = s.spyDao.ResetEvent(c, mid, operator); err != nil {
  84. log.Error("s.spyDao.ResetEvent(%d,%s) error(%v)", mid, operator, err)
  85. return
  86. }
  87. return
  88. }
  89. // ClearCount clear count.
  90. func (s *Service) ClearCount(c context.Context, mid int64, operator string) (err error) {
  91. if err = s.spyDao.ClearCount(c, mid, operator); err != nil {
  92. log.Error("s.spyDao.ClearCount(%d, %s) error(%v)", mid, operator, err)
  93. return
  94. }
  95. return
  96. }
  97. // ReportList report list.
  98. func (s *Service) ReportList(c context.Context, ps, pn int) (page *model.ReportPage, err error) {
  99. count, err := s.spyDao.ReportCount(c)
  100. if err != nil {
  101. log.Error("s.spyDao.ReportCount error(%v)", err)
  102. return
  103. }
  104. page = &model.ReportPage{}
  105. items, err := s.spyDao.ReportList(c, ps, pn)
  106. if err != nil {
  107. log.Error("s.spyDao.ReportPage(%d,%d) error(%v)", ps, pn, err)
  108. return
  109. }
  110. page.TotalCount = count
  111. page.Items = items
  112. page.Pn = pn
  113. page.Ps = ps
  114. return
  115. }