service.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/dm/conf"
  6. "go-common/app/interface/main/dm/dao"
  7. "go-common/app/interface/main/dm/model"
  8. dmCli "go-common/app/interface/main/dm2/rpc/client"
  9. accoutCli "go-common/app/service/main/account/api"
  10. arcCli "go-common/app/service/main/archive/api/gorpc"
  11. assCli "go-common/app/service/main/assist/rpc/client"
  12. )
  13. // Service define Service struct
  14. type Service struct {
  15. c *conf.Config
  16. // dao
  17. dao *dao.Dao
  18. // rpc
  19. acvSvc *arcCli.Service2
  20. accountSvc accoutCli.AccountClient
  21. astSvc *assCli.Service
  22. dmRPC *dmCli.Service
  23. //proc
  24. delDMReportChan chan *model.Report
  25. hideDMReportChan chan *model.Report
  26. }
  27. // New new a Service and return.cdfg
  28. func New(c *conf.Config) *Service {
  29. s := &Service{
  30. c: c,
  31. // dmDao
  32. dao: dao.New(c),
  33. // archive rpc service
  34. acvSvc: arcCli.New2(c.ArchiveRPC),
  35. astSvc: assCli.New(c.AssistRPC),
  36. dmRPC: dmCli.New(c.DMRPC),
  37. //proc
  38. delDMReportChan: make(chan *model.Report, 1024),
  39. hideDMReportChan: make(chan *model.Report, 1024),
  40. }
  41. accountSvc, err := accoutCli.NewClient(c.AccountRPC)
  42. if err != nil {
  43. panic(err)
  44. }
  45. s.accountSvc = accountSvc
  46. go s.dmReportProc()
  47. go s.cronproc()
  48. return s
  49. }
  50. // Ping check server ok
  51. func (s *Service) Ping(c context.Context) (err error) {
  52. return s.dao.Ping(c)
  53. }
  54. // cronproc 一分钟执行一次
  55. func (s *Service) cronproc() {
  56. for {
  57. <-time.After(time.Minute)
  58. go s.sendProtectNotifyToUp(context.Background())
  59. go s.sendProtectNotifyToUser(context.Background())
  60. }
  61. }