data_api_get_data_combo.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package data_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "encoding/json"
  7. "fmt"
  8. "gd_management/common.in/jsonrpc2"
  9. "gd_management/common.in/utils"
  10. "github.com/astaxie/beego/orm"
  11. "go.uber.org/zap"
  12. )
  13. func DataApiGetDataCombo(ctx context.Context, req *apis.ManagementDataApiGetDataComboReq, reply *apis.ManagementDataApiGetDataComboReply) (err error) {
  14. // 捕获各个task中的异常并返回给调用者
  15. defer func() {
  16. if r := recover(); r != nil {
  17. err = fmt.Errorf("%+v", r)
  18. e := &jsonrpc2.Error{}
  19. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  20. l.Error("err",
  21. zap.String("system_err", err.Error()),
  22. zap.Stack("stacktrace"))
  23. }
  24. }
  25. }()
  26. if req.ComboId <= 0 {
  27. l.Error("argument",
  28. zap.String("call", "check"),
  29. zap.String("fields", utils.MarshalJsonString(req)))
  30. return errors.ArgsError
  31. }
  32. sql := "SELECT a.`count`, a.price, a.type, a.total_day, b.query_type_name FROM t_gd_data_api_combo a LEFT JOIN t_gd_data_api_query_type b ON a.query_type_id = b.id WHERE a.id = ?"
  33. err = orm.NewOrm().Raw(sql, req.ComboId).QueryRow(&reply)
  34. if err != nil {
  35. if err == orm.ErrNoRows {
  36. return errors.ComboNotExist
  37. }
  38. l.Error("mysql",
  39. zap.String("sql", sql),
  40. zap.String("fields", utils.MarshalJsonString(req)),
  41. zap.String("error", err.Error()))
  42. return errors.DataBaseError
  43. }
  44. return nil
  45. }