crontab.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package ctrl_v1
  4. import (
  5. "gd_management_gateway/errors"
  6. "gd_management_gateway/params/param_base"
  7. "gd_management_gateway/params/param_v1_0"
  8. "gd_management_gateway/rpc_apis"
  9. "gd_management_gateway/rpc_apis/gd_crontab"
  10. "fmt"
  11. "time"
  12. "gd_management_gateway/common.in/httper"
  13. "gd_management_gateway/common.in/task"
  14. "gd_management_gateway/common.in/utils"
  15. "github.com/astaxie/beego"
  16. "go.uber.org/zap"
  17. )
  18. // Operations about access log api
  19. type CrontabController struct {
  20. metadata interface{} // 中继元数据
  21. beego.Controller
  22. LogID string
  23. }
  24. // @Title 手动生成日报
  25. // @Description 手动生成日报
  26. // @Param token header string true "token"
  27. // @Param uid header int64 true "admin id"
  28. // @Param merchant_id query int64 false "商户id"
  29. // @Param api_id query int64 false "基础api id"
  30. // @Param provider_api_id query int64 false "数据源api id"
  31. // @Param dates query string false "导出日期以分号分隔,默认为前一天"
  32. // @Param api_report query bool false "是否统计商户日报"
  33. // @Param provider_report query bool false "是否统计数据源日报"
  34. // @Param business_report query bool false "是否统计商务日报"
  35. // @Param is_insert query bool false "统计的数据是否插入日报表中"
  36. // @Param only_mail query bool false "是否仅发送邮件,不统计"
  37. // @Param only_report query bool false "是否仅统计, 不发送邮件"
  38. // @Param file_name query string false "指定文件名"
  39. // @Success 200 {object} params.param_v1_0.LogGenerateReportResp "响应信息"
  40. // @Failure 500 服务器错误
  41. // @router /report [get]
  42. func (u *CrontabController) LogGenerateReport() {
  43. u.LogID = fmt.Sprintf("LogQueryAccessLog[%d]", time.Now().UnixNano())
  44. req := &param_v1_0.LogGenerateReportReq{}
  45. getParamsTask := func() error {
  46. httper.FillRequireParams(u.Ctx, req, u.LogID)
  47. return nil
  48. }
  49. handleDataTask := func() error {
  50. mreq := gd_crontab.LogGenerateReportReq{}
  51. mreq.ApiId = req.ApiId
  52. mreq.MerchantId = req.MerchantId
  53. mreq.ProviderApiId = req.ProviderApiId
  54. mreq.IsInsert = req.IsInsert
  55. mreq.OnlyMail = req.OnlyMail
  56. mreq.OnlyReport = req.OnlyReport
  57. mreq.Dates = req.Dates
  58. mreq.ApiReport = req.ApiReport
  59. mreq.ProviderReport = req.ProviderReport
  60. mreq.FileName = req.FileName
  61. mreq.BusinessReport = req.BusinessReport
  62. mreq.ApiWeekStart = req.ApiWeekStart
  63. mreq.ApiMonthStart = req.ApiMonthStart
  64. mreq.ProviderMonthStart = req.ProviderMonthStart
  65. mreq.ProviderWeekStart = req.ProviderWeekStart
  66. mreq.BusinessWeekStart = req.BusinessWeekStart
  67. mreq.BusinessMonthStart = req.BusinessMonthStart
  68. _, err := rpc_apis.Crontab.LogGenerateReport(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  69. if err != nil {
  70. l.Error("rpc",
  71. zap.String("call", "LogGenerateReport"),
  72. zap.String("args", utils.MarshalJsonString(req)),
  73. zap.String("error", err.Error()))
  74. return errors.ErrorTransform(err)
  75. }
  76. resp := param_v1_0.LogGenerateReportResp{
  77. SimpleResp: param_base.SimpleResp{
  78. Code: 0,
  79. Msg: "SUCCESS",
  80. },
  81. }
  82. httper.JSON(u.Ctx, resp, u.LogID)
  83. return nil
  84. }
  85. // 执行以上定义的任务
  86. task.Do(&task.PanicRecover{
  87. Ctx: u.Ctx,
  88. LogID: u.LogID}, u.Ctx,
  89. getParamsTask, handleDataTask,
  90. )
  91. }