package data_api import ( "context" "gd_management/apis" "gd_management/common.in/utils" "gd_management/errors" "fmt" "github.com/astaxie/beego/orm" "go.uber.org/zap" ) func DataApiGetApiInfo(ctx context.Context, req *apis.ManagementDataApiGetApiInfoReq, reply *apis.ManagementDataApiGetApiInfoReply) error { if req.DataApiId == 0 { return errors.ArgsError } o := orm.NewOrm() rows, err := o.QueryTable("t_gd_data_api_query_type").Filter("data_api_id", req.DataApiId).All(&reply.QueryTypes) if err != err { if err == orm.ErrNoRows { return nil } else { return errors.DataBaseError } } else if rows == 0 { return nil } pChan := make(chan int, rows) for index, _ := range reply.QueryTypes { fmt.Println("index ", index) go func(index int) { dReq := apis.ManagementDataApiGetQueryTypeReq{QueryTypeId: reply.QueryTypes[index].Id} dReply := apis.ManagementDataApiGetQueryTypeReply{} err := DataApiGetQueryType(ctx, &dReq, &dReply) if err != nil { l.Error("func", zap.String("call", "DataApiGetQueryType"), zap.String("args", utils.MarshalJsonString(dReq)), zap.String("error", err.Error())) } else { reply.QueryTypes[index].FreeDataCombos = dReply.QueryTypeInfo.FreeDataCombos reply.QueryTypes[index].TotalDataCombos = dReply.QueryTypeInfo.TotalDataCombos reply.QueryTypes[index].DayDataCombos = dReply.QueryTypeInfo.DayDataCombos reply.QueryTypes[index].DataApiBaseApis = dReply.QueryTypeInfo.DataApiBaseApis } pChan <- 1 }(index) } for { if rows == 0 { close(pChan) break } select { case _, ok := <-pChan: if ok { rows-- } } } return nil } func GetApiInfo(ctx context.Context, req *apis.GetApiInfoReq, reply *apis.GetApiInfoReply) error { if req.Id <= 0 { return errors.ArgsError } p := apis.DataApi{} err := orm.NewOrm().Raw("SELECT * FROM t_gd_data_api WHERE id = ?", req.Id).QueryRow(&p) if err != nil { l.Error("mysql", zap.String("sql", "select t_gd_data_api"), zap.String("fields", utils.MarshalJsonString(req)), zap.String("error", err.Error())) return errors.DataBaseError } reply.DataApiName = p.DataApiName reply.DataApiDesc = p.DataApiDesc reply.DataApiType = p.DataApiType reply.IsRelease = p.IsRelease reply.Version = p.Version return nil }