report.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/spy/conf"
  6. "go-common/app/job/main/spy/model"
  7. "go-common/library/log"
  8. )
  9. // AddReport add daill report.
  10. func (s *Service) AddReport(c context.Context) {
  11. var (
  12. scount int64
  13. pcount int64
  14. dateVersion string
  15. err error
  16. )
  17. year, month, day := time.Now().Date()
  18. stoday := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  19. etoday := time.Date(year, month, day, 23, 59, 59, 999, time.Local)
  20. syesday := stoday.AddDate(0, 0, -1)
  21. eyesday := etoday.AddDate(0, 0, -1)
  22. dateVersion = syesday.Format("20060102")
  23. if pcount, err = s.dao.PunishmentCount(c, syesday, eyesday); err != nil {
  24. log.Error("s.dao.PunishmentCount(%s, %s), err(%v)", syesday, eyesday, err)
  25. return
  26. }
  27. s.dao.AddReport(c, &model.Report{
  28. Name: model.BlockCount,
  29. DateVersion: dateVersion,
  30. Val: pcount,
  31. Ctime: time.Now(),
  32. })
  33. for i := int64(0); i < conf.Conf.Property.HistoryShard; i++ {
  34. var count int64
  35. if count, err = s.dao.SecurityLoginCount(c, i, "导入二次验证,恢复行为得分", syesday, eyesday); err != nil {
  36. log.Error("s.dao.SecurityLoginCount(%s, %s), err(%v)", syesday, eyesday, err)
  37. return
  38. }
  39. scount = scount + count
  40. time.Sleep(s.blockTick)
  41. }
  42. s.dao.AddReport(c, &model.Report{
  43. Name: model.SecurityLoginCount,
  44. DateVersion: dateVersion,
  45. Val: scount,
  46. Ctime: time.Now(),
  47. })
  48. }