service_order.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package ctrl_v1
  2. import (
  3. "gd_management_gateway/errors"
  4. "gd_management_gateway/params/param_base"
  5. "gd_management_gateway/params/param_v1_0"
  6. "gd_management_gateway/rpc_apis"
  7. "gd_management_gateway/rpc_apis/gd_management"
  8. "gd_management_gateway/rpc_apis/gd_service"
  9. "fmt"
  10. "time"
  11. "gd_management_gateway/common.in/httper"
  12. "gd_management_gateway/common.in/task"
  13. "gd_management_gateway/common.in/utils"
  14. "go.uber.org/zap"
  15. "github.com/astaxie/beego"
  16. )
  17. // Operations about base api
  18. type ServiceOrderController struct {
  19. metadata interface{} // 中继元数据
  20. beego.Controller
  21. LogID string
  22. }
  23. // @Title get service order list
  24. // @Description 获取服务订单
  25. // @Param token header string true "token"
  26. // @Param uid header string true "uid"
  27. // @Param page_number query string false ""
  28. // @Param order_status query int false "0 获取所有状态订单 1 待支付,2 进行中 3已完成 4 已取消"
  29. // @Param order_type query int false "0 所有服务类型 311上线年审,312 免检年审,314免检年审在线办理, 315 上线年审自行预约"
  30. // @Param start_time query string false "uid"
  31. // @Param end_time query string false "uid"
  32. // @Success 200 {object} params.param_v1_0.ServiceManagementOrderListResp "响应信息"
  33. // @Failure 500 服务器错误
  34. // @router /service_order_list [get]
  35. func (u *ServiceOrderController) ServiceManagementOrderList() {
  36. u.LogID = fmt.Sprintf("ServiceManagementOrderList[%d]", time.Now().UnixNano())
  37. req := &param_v1_0.ServiceManagementOrderListReq{}
  38. getParamsTask := func() error {
  39. httper.FillRequireParams(u.Ctx, req, u.LogID)
  40. return nil
  41. }
  42. handleDataTask := func() error {
  43. sreq := gd_service.ServiceManagementOrderListReq{}
  44. sreq.PageNumber = req.PageNumber
  45. sreq.StartTime = req.StartTime
  46. sreq.EndTime = req.EndTime
  47. sreq.OrderType = req.OrderType
  48. sreq.OrderStatus = req.OrderStatus
  49. reply, err := rpc_apis.Service.ServiceManagementOrderList(utils.NewContextFromBeegoCtx(u.Ctx), &sreq)
  50. if err != nil {
  51. l.Error("rpc",
  52. zap.String("call", "ServiceManagementOrderList"),
  53. zap.String("args", utils.MarshalJsonString(req)),
  54. zap.String("error", err.Error()))
  55. return errors.ErrorTransform(err)
  56. }
  57. appKeys := []string{}
  58. for _, v := range reply.Infos {
  59. appKeys = append(appKeys, v.AppKey)
  60. }
  61. mreq := gd_management.ManagementGetUserMerchantNameReq{}
  62. mreq.AppKeys = appKeys
  63. mreply, err := rpc_apis.Management.ManagementGetUserMerchantName(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  64. if err != nil {
  65. return errors.ErrorTransform(err)
  66. }
  67. appKeyMap := map[string]gd_management.ManagementGetUserMerchantNameItem{}
  68. for _, v := range mreply.Infos {
  69. appKeyMap[v.AppKey] = v
  70. }
  71. for k, _ := range reply.Infos {
  72. reply.Infos[k].MerchantName = appKeyMap[reply.Infos[k].AppKey].MerchantName
  73. reply.Infos[k].UserName = appKeyMap[reply.Infos[k].AppKey].UserName
  74. }
  75. resp := param_v1_0.ServiceManagementOrderListResp{
  76. SimpleResp: param_base.SimpleResp{
  77. Code: 0,
  78. Msg: "SUCCESS",
  79. },
  80. }
  81. resp.Infos = reply.Infos
  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. }