stat.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/spy/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // UpdateStatData update spy stat data.
  10. func (s *Service) UpdateStatData(c context.Context, m *model.SpyStatMessage) (err error) {
  11. //TODO check event resaon
  12. if s.allEventName[m.EventName] == 0 {
  13. log.Error("event name not found %+v", err)
  14. err = ecode.SpyEventNotExist
  15. return
  16. }
  17. stat := &model.Statistics{
  18. TargetMid: m.TargetMid,
  19. TargetID: m.TargetID,
  20. EventID: s.allEventName[m.EventName],
  21. State: model.WaiteCheck,
  22. Quantity: m.Quantity,
  23. Ctime: time.Now(),
  24. }
  25. if stat.TargetID != 0 {
  26. _, ok := s.activityEvents[m.EventName]
  27. if ok {
  28. stat.Type = model.ActivityType
  29. } else {
  30. stat.Type = model.ArchiveType
  31. }
  32. }
  33. // add stat
  34. if model.ResetStat == m.Type {
  35. if _, err = s.dao.AddStatistics(c, stat); err != nil {
  36. log.Error("%+v", err)
  37. return
  38. }
  39. } else {
  40. if _, err = s.dao.AddIncrStatistics(c, stat); err != nil {
  41. log.Error("%+v", err)
  42. return
  43. }
  44. }
  45. return
  46. }