sync.go 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "bufio"
  4. "context"
  5. "io"
  6. "os"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "go-common/library/log"
  11. )
  12. func (s *Service) SyncUserVIP(ctx context.Context, file string) {
  13. log.Info("Start sync user VIP")
  14. f, err := os.OpenFile(file, os.O_RDONLY, os.ModePerm)
  15. if err != nil {
  16. log.Error("os.OpenFile(%s) , err [%s]", file, err)
  17. return
  18. }
  19. br := bufio.NewReader(f)
  20. var (
  21. str string
  22. mid int64
  23. count int
  24. )
  25. for {
  26. if str, err = br.ReadString('\n'); err != nil {
  27. if err == io.EOF {
  28. break
  29. }
  30. log.Error("br.ReadString error [%s]", err)
  31. return
  32. }
  33. if mid, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64); err != nil {
  34. log.Error("Parse midstr [%s] error [%s]", str, err)
  35. continue
  36. }
  37. if err = s.figureDao.UpdateVipStatus(ctx, mid, 1); err != nil {
  38. log.Error("s.figureDao.UpdateVipStatus(%d,1) err [%s]", mid, err)
  39. return
  40. }
  41. count++
  42. if count%10000 == 0 {
  43. time.Sleep(time.Second)
  44. }
  45. }
  46. log.Info("End sync user VIP count [%d]", count)
  47. }