data_api_get_api_info.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package data_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/common.in/utils"
  6. "gd_management/errors"
  7. "fmt"
  8. "github.com/astaxie/beego/orm"
  9. "go.uber.org/zap"
  10. )
  11. func DataApiGetApiInfo(ctx context.Context, req *apis.ManagementDataApiGetApiInfoReq, reply *apis.ManagementDataApiGetApiInfoReply) error {
  12. if req.DataApiId == 0 {
  13. return errors.ArgsError
  14. }
  15. o := orm.NewOrm()
  16. rows, err := o.QueryTable("t_gd_data_api_query_type").Filter("data_api_id", req.DataApiId).All(&reply.QueryTypes)
  17. if err != err {
  18. if err == orm.ErrNoRows {
  19. return nil
  20. } else {
  21. return errors.DataBaseError
  22. }
  23. } else if rows == 0 {
  24. return nil
  25. }
  26. pChan := make(chan int, rows)
  27. for index, _ := range reply.QueryTypes {
  28. fmt.Println("index ", index)
  29. go func(index int) {
  30. dReq := apis.ManagementDataApiGetQueryTypeReq{QueryTypeId: reply.QueryTypes[index].Id}
  31. dReply := apis.ManagementDataApiGetQueryTypeReply{}
  32. err := DataApiGetQueryType(ctx, &dReq, &dReply)
  33. if err != nil {
  34. l.Error("func",
  35. zap.String("call", "DataApiGetQueryType"),
  36. zap.String("args", utils.MarshalJsonString(dReq)),
  37. zap.String("error", err.Error()))
  38. } else {
  39. reply.QueryTypes[index].FreeDataCombos = dReply.QueryTypeInfo.FreeDataCombos
  40. reply.QueryTypes[index].TotalDataCombos = dReply.QueryTypeInfo.TotalDataCombos
  41. reply.QueryTypes[index].DayDataCombos = dReply.QueryTypeInfo.DayDataCombos
  42. reply.QueryTypes[index].DataApiBaseApis = dReply.QueryTypeInfo.DataApiBaseApis
  43. }
  44. pChan <- 1
  45. }(index)
  46. }
  47. for {
  48. if rows == 0 {
  49. close(pChan)
  50. break
  51. }
  52. select {
  53. case _, ok := <-pChan:
  54. if ok {
  55. rows--
  56. }
  57. }
  58. }
  59. return nil
  60. }
  61. func GetApiInfo(ctx context.Context, req *apis.GetApiInfoReq, reply *apis.GetApiInfoReply) error {
  62. if req.Id <= 0 {
  63. return errors.ArgsError
  64. }
  65. p := apis.DataApi{}
  66. err := orm.NewOrm().Raw("SELECT * FROM t_gd_data_api WHERE id = ?", req.Id).QueryRow(&p)
  67. if err != nil {
  68. l.Error("mysql",
  69. zap.String("sql", "select t_gd_data_api"),
  70. zap.String("fields", utils.MarshalJsonString(req)),
  71. zap.String("error", err.Error()))
  72. return errors.DataBaseError
  73. }
  74. reply.DataApiName = p.DataApiName
  75. reply.DataApiDesc = p.DataApiDesc
  76. reply.DataApiType = p.DataApiType
  77. reply.IsRelease = p.IsRelease
  78. reply.Version = p.Version
  79. return nil
  80. }