service.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/openplatform/open-sug/conf"
  5. "go-common/app/job/openplatform/open-sug/dao"
  6. "go-common/library/queue/databus"
  7. "sync"
  8. "time"
  9. )
  10. // Service struct
  11. type Service struct {
  12. c *conf.Config
  13. dao *dao.Dao
  14. pgcSub *databus.Databus
  15. pgcMsgCnt int64
  16. wg *sync.WaitGroup
  17. seasonMsgCnt int64
  18. }
  19. // New init
  20. func New(c *conf.Config) (s *Service) {
  21. s = &Service{
  22. c: c,
  23. dao: dao.New(c),
  24. wg: new(sync.WaitGroup),
  25. pgcSub: databus.New(c.PgcSub),
  26. pgcMsgCnt: 0,
  27. seasonMsgCnt: 0,
  28. }
  29. s.existsOrCreate(c.ElasticSearch.Season)
  30. go s.pgcConsumePROC()
  31. go s.fetchData()
  32. return s
  33. }
  34. // Ping Service
  35. func (s *Service) Ping(c context.Context) (err error) {
  36. return s.dao.Ping(c)
  37. }
  38. // Close Service
  39. func (s *Service) Close() {
  40. s.dao.Close()
  41. }
  42. func (s *Service) fetchData() {
  43. for {
  44. s.buildData()
  45. s.Refresh()
  46. s.Filter()
  47. time.Sleep(time.Hour * 24)
  48. }
  49. }
  50. // Refresh ...
  51. func (s *Service) Refresh() {
  52. s.dao.ItemSalesMin = make(map[string]int)
  53. s.dao.ItemSalesMax = make(map[string]int)
  54. s.dao.ItemWishMax = make(map[string]int)
  55. s.dao.ItemWishMin = make(map[string]int)
  56. s.dao.ItemCommentMax = make(map[string]int)
  57. s.dao.ItemCommentMin = make(map[string]int)
  58. }