rcvr.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. // package impl implement all interfaces of micro service in gd_crontab
  4. package impl
  5. import (
  6. "context"
  7. "gd_crontab/apis"
  8. "gd_crontab/impl/accounting"
  9. "gd_crontab/impl/crontab"
  10. "gd_crontab/impl/warning"
  11. "fmt"
  12. "github.com/robfig/cron"
  13. "gd_crontab/common.in/config"
  14. "gd_crontab/common.in/task"
  15. "github.com/astaxie/beego/orm"
  16. )
  17. // 具体实现
  18. type Rcvr struct {
  19. }
  20. // TODO delete
  21. func (c *Rcvr) WarningApiCount(ctx context.Context, req *apis.WarningApiCountReq, reply *apis.WarningApiCountReply) error {
  22. t1 := func() error {
  23. return warning.WarningApiCount(ctx, req, reply)
  24. }
  25. return task.Do(ctx, t1)
  26. }
  27. // TODO delete
  28. func (c *Rcvr) WarningProviderCount(ctx context.Context, req *apis.WarningProviderCountReq, reply *apis.WarningProviderCountReply) error {
  29. t1 := func() error {
  30. return warning.WarningProviderCount(ctx, req, reply)
  31. }
  32. return task.Do(ctx, t1)
  33. }
  34. func (c *Rcvr) LogGenerateReport(ctx context.Context, req *apis.LogGenerateReportReq, reply *apis.LogGenerateReportReply) error {
  35. t1 := func() error {
  36. return crontab.LogGenerateReport(ctx, req, reply)
  37. }
  38. return task.Do(ctx, t1)
  39. }
  40. func (c *Rcvr) LogQueryProviderCountExport(ctx context.Context, req *apis.LogQueryProviderCountExportReq, reply *apis.LogQueryProviderCountExportReply) error {
  41. t1 := func() error {
  42. return crontab.LogQueryProviderCountExport(ctx, req, reply)
  43. }
  44. return task.Do(ctx, t1)
  45. }
  46. func (c *Rcvr) ExportProviderDay(ctx context.Context, req *apis.LogQueryProviderCountExportReq, reply *apis.LogQueryProviderCountExportReply) error {
  47. t1 := func() error {
  48. return crontab.ExportProviderDay(ctx, req, reply)
  49. }
  50. return task.Do(ctx, t1)
  51. }
  52. func (c *Rcvr) ReciveAccessLog(ctx context.Context, req *apis.ReciveAccessLogReq, reply *apis.ReciveAccessLogReply) error {
  53. t1 := func() error {
  54. return warning.ReciveAccessLog(ctx, req, reply)
  55. }
  56. return task.Do(ctx, t1)
  57. }
  58. func (c *Rcvr) ReciveThirdPartLog(ctx context.Context, req *apis.ReciveThirdPartLogReq, reply *apis.ReciveThirdPartLogReply) error {
  59. t1 := func() error {
  60. return warning.ReciveThirdPartLog(ctx, req, reply)
  61. }
  62. return task.Do(ctx, t1)
  63. }
  64. func RegisterOrmModel() {
  65. //orm.RegisterModel(new(apis.AccessLog))
  66. //orm.RegisterModel(new(apis.TGdAccessLogHistory))
  67. //orm.RegisterModel(new(apis.ThirdpartLog))
  68. //orm.RegisterModel(new(apis.TGdThirdpartAccessLogHistory))
  69. orm.RegisterModel(new(crontab.TGdReport))
  70. orm.RegisterModel(new(crontab.TGdBusinessReport))
  71. orm.RegisterModel(new(crontab.TGdProviderReport))
  72. orm.RegisterModel(new(crontab.TGdReportHour))
  73. orm.RegisterModel(new(crontab.TGdProviderReportHour))
  74. orm.RegisterModel(new(crontab.TGdProviderCodeHour))
  75. orm.RegisterModel(new(crontab.TGdApiCodeHour))
  76. orm.RegisterModel(new(apis.AccessLogDay))
  77. orm.RegisterModel(new(apis.ThirdpartLogDay))
  78. orm.RegisterModel(new(apis.TGdAccessLogMonth1))
  79. orm.RegisterModel(new(apis.TGdAccessLogMonth2))
  80. orm.RegisterModel(new(apis.TGdAccessLogMonth3))
  81. orm.RegisterModel(new(apis.TGdAccessLogMonth4))
  82. orm.RegisterModel(new(apis.TGdAccessLogMonth5))
  83. orm.RegisterModel(new(apis.TGdAccessLogMonth6))
  84. orm.RegisterModel(new(apis.TGdAccessLogMonth7))
  85. orm.RegisterModel(new(apis.TGdAccessLogMonth8))
  86. orm.RegisterModel(new(apis.TGdAccessLogMonth9))
  87. orm.RegisterModel(new(apis.TGdAccessLogMonth10))
  88. orm.RegisterModel(new(apis.TGdAccessLogMonth11))
  89. orm.RegisterModel(new(apis.TGdAccessLogMonth12))
  90. orm.RegisterModel(new(apis.TGdThirdpartLogMonth1))
  91. orm.RegisterModel(new(apis.TGdThirdpartLogMonth2))
  92. orm.RegisterModel(new(apis.TGdThirdpartLogMonth3))
  93. orm.RegisterModel(new(apis.TGdThirdpartLogMonth4))
  94. orm.RegisterModel(new(apis.TGdThirdpartLogMonth5))
  95. orm.RegisterModel(new(apis.TGdThirdpartLogMonth6))
  96. orm.RegisterModel(new(apis.TGdThirdpartLogMonth7))
  97. orm.RegisterModel(new(apis.TGdThirdpartLogMonth8))
  98. orm.RegisterModel(new(apis.TGdThirdpartLogMonth9))
  99. orm.RegisterModel(new(apis.TGdThirdpartLogMonth10))
  100. orm.RegisterModel(new(apis.TGdThirdpartLogMonth11))
  101. orm.RegisterModel(new(apis.TGdThirdpartLogMonth12))
  102. }
  103. // 按计划执行定时任务
  104. // 秒,分钟,小时,日,月,星期几,执行的func。
  105. func TaskInit() {
  106. //conf := parser.Conf.Rpc.Cron
  107. fmt.Println("bill cron :",config.Conf.BillCreateCron)
  108. c := cron.New()
  109. //config.Conf.BillCreateCron
  110. // 定时每日凌晨启动车辆查询
  111. _ = c.AddFunc(config.Conf.BillCreateCron, func() {
  112. accounting.GenerateBill()
  113. })
  114. _ = c.AddFunc(config.Conf.BillNotifyCron, func() {
  115. accounting.BillNotify()
  116. })
  117. _ = c.AddFunc("0 */1 * * * ?", func() {
  118. warning.CheckLog()
  119. })
  120. c.Start()
  121. }