excitation.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/videoup-report/dao/data"
  5. "go-common/app/job/main/videoup-report/model/archive"
  6. "go-common/app/job/main/videoup-report/model/manager"
  7. "go-common/library/log"
  8. "time"
  9. )
  10. // hdlExcitation 激励回查逻辑
  11. func (s *Service) hdlExcitation(nw, old *archive.Archive) (err error) {
  12. defer func() {
  13. if pErr := recover(); pErr != nil {
  14. log.Error("s.hdlExcitation(%v,%v) panic(%v)", nw, old, pErr)
  15. }
  16. }()
  17. var (
  18. c = context.TODO()
  19. state int8
  20. archives []*archive.Archive
  21. addits map[int64]*archive.Addit
  22. now = time.Now()
  23. aids []int64
  24. isIgn bool
  25. aCount = 20 //自制投稿阀值
  26. )
  27. log.Info("hdlExcitation() begin new archive(%v) old archive(%v)", nw, old)
  28. if old != nil { //只有新投稿才需要继续
  29. return
  30. }
  31. //检查UP主是否在白名单中
  32. if isIgn, err = s.isIgnMidExcitation(c, nw.Mid); err != nil {
  33. log.Error("s.hdlExcitation() new(%v) old(%v) s.isIgnMidExcitation() error(%v)", nw, old, err)
  34. go s.hdlExcitationRetry(nw, old)
  35. return
  36. } else if isIgn {
  37. log.Error("s.hdlExcitation() new(%v) old(%v) ignore white mid(%d)", nw, old, nw.Mid)
  38. return
  39. }
  40. if state, err = s.dataDao.UpProfitState(c, nw.Mid); err != nil {
  41. log.Error("hdlExcitation() s.dataDao.UpProfitState(%d) error(%v)", nw.Mid, err)
  42. go s.hdlExcitationRetry(nw, old)
  43. return
  44. }
  45. if state != data.UpProfitStateSigned {
  46. log.Info("hdlExcitation() ignore 非签约UP主(%d) state(%d)", nw.Mid, state)
  47. return
  48. }
  49. //查询7天内自制、过审、定时过审稿件
  50. st := now.Add(-168 * time.Hour)
  51. if archives, err = s.arc.ExcitationArchivesByTime(c, nw.Mid, st, now); err != nil {
  52. log.Error("hdlExcitation() s.arc.ExcitationAidsByTime(%d,%v,%v) error(%v)", nw.Mid, st, now, err)
  53. go s.hdlExcitationRetry(nw, old)
  54. return
  55. }
  56. if len(archives) == 0 {
  57. log.Info("hdlExcitation() ignore UP主(%d) 在 %v 到 %v 时间内没有自制、非特殊分区、非私单、非商单稿件。", nw.Mid, st, now)
  58. return
  59. }
  60. for _, a := range archives {
  61. if s.isAuditType(a.TypeID) || a.AttrVal(archive.AttrBitIsPOrder) == archive.AttrYes {
  62. log.Info("hdlExcitation() 忽略特殊分区、私单 archive(%v)", a)
  63. continue
  64. }
  65. aids = append(aids, a.ID)
  66. }
  67. if addits, err = s.arc.Addits(c, aids); err != nil {
  68. log.Error("hdlExcitation() aid(%d) s.arc.Addits(%v) error(%v)", nw.ID, aids, err)
  69. go s.hdlExcitationRetry(nw, old)
  70. return
  71. }
  72. for i := 0; i < len(aids); i++ {
  73. if _, ok := addits[aids[i]]; ok && addits[aids[i]].OrderID > 0 {
  74. log.Info("hdlExcitation() 忽略商单 addit(%v)", addits[aids[i]])
  75. aids = append(aids[:i], aids[i+1:]...)
  76. i--
  77. continue
  78. }
  79. }
  80. if len(aids) < aCount {
  81. log.Info("hdlExcitation() ignore UP主(%d) 在 %v 到 %v 时间内只有 %d 个自制、非特殊分区、非私单、非商单稿件没有达到 %d 个。aids:%v", nw.Mid, st, now, len(aids), aCount, aids)
  82. return
  83. }
  84. log.Info("hdlExcitation() 符合激励回查的UP主(%d) 正在插入激励回查aids(%v)", nw.Mid, aids)
  85. if err = s.arc.AddRecheckAids(c, archive.TypeExcitationRecheck, aids, true); err != nil {
  86. log.Error("s.hdlExcitation() s.arc.AddRecheckAids error(%v)", err)
  87. go s.hdlExcitationRetry(nw, old)
  88. return
  89. }
  90. return
  91. }
  92. // isIgnMidExcitation 检查UP主是否在白名单中
  93. func (s *Service) isIgnMidExcitation(c context.Context, mid int64) (is bool, err error) {
  94. groups, err := s.dataDao.MidGroups(c, mid)
  95. if err != nil {
  96. log.Error("s.isIgnMidExcitation(%d) error(%v)", mid, err)
  97. return
  98. }
  99. if _, ok := groups[manager.UpTypeExcitationWhite]; ok {
  100. is = true
  101. return
  102. }
  103. return
  104. }
  105. // ignoreUpsExcitation 将UP主的未回查的稿件从激励回查去除
  106. func (s *Service) ignoreUpsExcitation(c context.Context, mid int64) (err error) {
  107. log.Info("s.ignoreUpsExcitation(%d)", mid)
  108. if err = s.arc.UpdateMidRecheckState(c, archive.TypeExcitationRecheck, mid, archive.RecheckStateIgnore); err != nil {
  109. log.Error("s.ignoreUpsExcitation(%d) error(%v)", mid, err)
  110. return
  111. }
  112. return
  113. }
  114. // hdlExcitationRetry 激励回查重试
  115. func (s *Service) hdlExcitationRetry(nw, old *archive.Archive) (err error) {
  116. mTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nw.MTime, time.Local)
  117. if time.Now().Unix()-mTime.Unix() > 3600 {
  118. log.Error("s.hdlExcitationRetry() new(%v) old(%v) the retry handler finish. (over 60 mins)", nw, old)
  119. return
  120. }
  121. log.Error("s.hdlExcitationRetry() new(%v) old(%v) the handler will retry in 10 seconds", nw, old)
  122. time.Sleep(10 * time.Second)
  123. err = s.hdlExcitation(nw, old)
  124. return
  125. }