service.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/growup/conf"
  5. "go-common/app/admin/main/growup/dao"
  6. "go-common/app/admin/main/growup/dao/message"
  7. "go-common/app/admin/main/growup/dao/resource"
  8. "go-common/app/admin/main/growup/dao/shell"
  9. "go-common/app/admin/main/growup/model/offlineactivity"
  10. "go-common/library/net/http/blademaster"
  11. )
  12. // Service struct
  13. type Service struct {
  14. conf *conf.Config
  15. dao *dao.Dao
  16. msg *message.Dao
  17. chanCheckDb chan int
  18. chanCheckShellOrder chan *offlineactivity.OfflineActivityResult
  19. chanCheckActivity chan int64 // it's result id in this channel
  20. shellClient *shell.Client
  21. }
  22. // New fn
  23. func New(c *conf.Config) (s *Service) {
  24. s = &Service{
  25. conf: c,
  26. dao: dao.New(c),
  27. msg: message.New(c),
  28. chanCheckDb: make(chan int, 1),
  29. chanCheckShellOrder: make(chan *offlineactivity.OfflineActivityResult, 10240),
  30. chanCheckActivity: make(chan int64, 1000),
  31. shellClient: shell.New(c.ShellConf, blademaster.NewClient(c.HTTPClient)),
  32. }
  33. resource.Init(c)
  34. if c.OtherConf.OfflineOrderConsume {
  35. go s.offlineactivityCheckSendDbProc()
  36. }
  37. go s.offlineactivityCheckShellOrderProc()
  38. return s
  39. }
  40. // Ping fn
  41. func (s *Service) Ping(c context.Context) (err error) {
  42. return s.dao.Ping(c)
  43. }
  44. // Close dao
  45. func (s *Service) Close() {
  46. s.dao.Close()
  47. }