package base_api import ( "context" "gd_management/apis" "gd_management/errors" "github.com/astaxie/beego/orm" //"strings" ) type ProviderGroupApiItem struct { GroupNo int `json:"group_no"` GroupName string `json:"group_name"` apis.BaseApiProviderItem } func ManagementGetBaseApiProviderList(ctx context.Context, req *apis.ManagementGetBaseApiProviderListReq, reply *apis.ManagementGetBaseApiProviderListReply) (err error) { if req.ApiId == 0 { return errors.ArgsError } var list = []ProviderGroupApiItem{} sql := `select provider_api_id, group_no, group_name, priority,thirdpart_api_name, thirdpart_api_router,platform_name from (t_gd_api_provider_relation as t1 left join t_gd_provider_api as t2 on t1.provider_api_id = t2.id) left join t_gd_provider as t3 on t2.provider_id=t3.id where t1.api_id=? order by group_no, priority` _, err = orm.NewOrm().Raw(sql, req.ApiId).QueryRows(&list) if err != nil && err != orm.ErrNoRows { return errors.DataBaseError } m := map[int][]apis.BaseApiProviderItem{} nameMap := map[int]string{} groupNoArray := []int{} for _, v := range list { if _, ok := m[v.GroupNo]; ok == false { groupNoArray = append(groupNoArray, v.GroupNo) } nameMap[v.GroupNo] = v.GroupName m[v.GroupNo] = append(m[v.GroupNo], v.BaseApiProviderItem) } for _, v := range groupNoArray { item := apis.BaseApiProviderGroupItem{} item.GroupNo = v item.GroupName, _ = nameMap[v] item.ProviderApiList, _ = m[v] reply.ProviderGroupList = append(reply.ProviderGroupList, item) } return nil //l.Debug(utils.MarshalJsonString(req, reply)) }