salary_data.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/vip/model"
  6. "go-common/library/log"
  7. "github.com/pkg/errors"
  8. )
  9. //ScanSalaryLog scan salary log.
  10. func (s *Service) ScanSalaryLog(c context.Context) (err error) {
  11. var (
  12. dv = time.Now().Format("2006_01")
  13. olds []*model.OldSalaryLog
  14. size = 1000
  15. endID = 0
  16. )
  17. if endID, err = s.dao.SalaryLogMaxID(context.TODO(), dv); err != nil {
  18. err = errors.WithStack(err)
  19. return
  20. }
  21. page := endID / size
  22. if endID%size != 0 {
  23. page++
  24. }
  25. for i := 0; i < page; {
  26. startID := i * size
  27. eID := (i + 1) * size
  28. if olds, err = s.dao.SelOldSalaryList(context.TODO(), startID, eID, dv); err != nil {
  29. err = errors.WithStack(err)
  30. return
  31. }
  32. i++
  33. for _, v := range olds {
  34. l := &model.VideoCouponSalaryLog{
  35. Mid: v.Mid,
  36. CouponCount: v.CouponCount,
  37. State: v.State,
  38. Type: v.Type,
  39. CouponType: model.SalaryCouponType,
  40. }
  41. if err = s.dao.AddSalaryLog(context.TODO(), l, dv); err != nil {
  42. err = errors.WithStack(err)
  43. log.Error("+%v", err)
  44. continue
  45. }
  46. }
  47. }
  48. return
  49. }