up.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/mcn/model"
  6. "go-common/library/log"
  7. "github.com/pkg/errors"
  8. )
  9. // UpMcnUpStateCron .
  10. func (s *Service) UpMcnUpStateCron() {
  11. defer func() {
  12. if r := recover(); r != nil {
  13. r = errors.WithStack(r.(error))
  14. log.Error("recover panic error(%+v)", r)
  15. }
  16. }()
  17. var (
  18. err error
  19. page = 1
  20. limit = 100
  21. c = context.TODO()
  22. now = time.Now()
  23. nowDate = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
  24. mus []*model.MCNUPInfo
  25. )
  26. for {
  27. offset := int64((page - 1) * limit)
  28. if mus, err = s.dao.McnUps(c, offset, int64(limit)); err != nil {
  29. log.Error("s.dao.McnUps(%d,%d) error(%+v)", offset, limit, err)
  30. return
  31. }
  32. if len(mus) == 0 {
  33. log.Warn("mcn up data is empty!")
  34. return
  35. }
  36. for _, v := range mus {
  37. var state int8
  38. switch {
  39. case v.State.NotDealState():
  40. continue
  41. case v.BeginDate.Time().Unix() <= nowDate && nowDate <= v.EndDate.Time().Unix() && v.State != model.MCNUPStateOnSign && v.State == model.MCNUPStateOnPreOpen:
  42. state = int8(model.MCNUPStateOnSign)
  43. case nowDate > v.EndDate.Time().Unix() && v.State != model.MCNUPStateOnExpire:
  44. state = int8(model.MCNUPStateOnExpire)
  45. default:
  46. continue
  47. }
  48. if _, err = s.dao.UpMcnUpStateOP(c, v.SignUpID, state); err != nil {
  49. log.Error("s.dao.UpMcnUpStateOP(%d,%d) error(%+v)", v.SignUpID, state, err)
  50. continue
  51. }
  52. log.Info("signUpID(%d) change old state(%d) to new state(%d)", v.SignUpID, v.State, state)
  53. }
  54. page++
  55. }
  56. }