summary.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/log"
  6. xtime "go-common/library/time"
  7. "go-common/library/xstr"
  8. "github.com/pkg/errors"
  9. )
  10. // UpMcnDataSummaryCron .
  11. func (s *Service) UpMcnDataSummaryCron() {
  12. defer func() {
  13. if r := recover(); r != nil {
  14. r = errors.WithStack(r.(error))
  15. log.Error("recover panic error(%+v)", r)
  16. }
  17. }()
  18. var (
  19. err error
  20. sids []int64
  21. msid map[int64]int64
  22. mmc map[int64]int64
  23. mup map[int64][]int64
  24. c = context.TODO()
  25. )
  26. if msid, sids, err = s.dao.McnSignMids(c); err != nil {
  27. log.Error("s.dao.McnSignMids error(%+v)", err)
  28. return
  29. }
  30. if len(sids) == 0 {
  31. log.Warn("mcn sign data summary empty!")
  32. return
  33. }
  34. if mmc, err = s.dao.McnUPCount(c, sids); err != nil {
  35. log.Error("s.dao.McnUPCount(%s) error(%+v)", xstr.JoinInts(sids), err)
  36. return
  37. }
  38. if mup, err = s.dao.McnUPMids(c, sids); err != nil {
  39. log.Error("s.dao.McnUPMids(%s) error(%+v)", xstr.JoinInts(sids), err)
  40. return
  41. }
  42. for sid, smid := range msid {
  43. var (
  44. upOK, upMidOK bool
  45. upNums int64
  46. upMids []int64
  47. totalFans int64
  48. now = time.Now()
  49. gDate = time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local)
  50. )
  51. if upNums, upOK = mmc[sid]; !upOK {
  52. upNums = 0
  53. }
  54. if upMids, upMidOK = mup[sid]; upMidOK {
  55. if len(upMids) == 0 {
  56. totalFans = 0
  57. } else {
  58. if totalFans, err = s.dao.CrmUpMidsSum(c, upMids); err != nil {
  59. log.Error("s.dao.CrmUpMidsSum(%s) error(%+v)", xstr.JoinInts(upMids), err)
  60. err = nil
  61. totalFans = 0
  62. }
  63. }
  64. } else {
  65. totalFans = 0
  66. }
  67. if err = s.dao.AddMcnDataSummary(c, smid, sid, upNums, totalFans, xtime.Time(gDate.Unix())); err != nil {
  68. log.Error("s.dao.UpMcnUpStateOP(%d,%d,%d,%d,%+v) error(%+v)", smid, sid, upNums, totalFans, xtime.Time(gDate.Unix()), err)
  69. continue
  70. }
  71. log.Info("mcnMid(%d) signID(%d) upNum(%d) totalFans(%d) date(%+v) add data summary table", smid, sid, upNums, totalFans, xtime.Time(gDate.Unix()))
  72. }
  73. }