You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: contact_way_group.go
    path of file: ./repos/api-server/app/services
    
    the code of the file until where you have to start completion: package services

import (
	"github.com/jinzhu/copier"
	"github.com/pkg/errors"
	"openscrm/app/models"
	"openscrm/app/requests"
	"openscrm/app/responses"
	"openscrm/common/app"
	"openscrm/common/id_generator"
)

type ContactWayGroup struct {
	model models.ContactWayGroup
}

func NewContactWayGroup() *ContactWayGroup {
	return &ContactWayGroup{model: models.ContactWayGroup{}}
}

func (o *ContactWayGroup) Query(req requests.QueryContactWayGroupReq, extCorpID string, sorter *app.Sorter, pager *app.Pager) (items []responses.ContactWayGroup, total int64, err erro
    
func (o *ContactWayGroup) Query(req requests.QueryContactWayGroupReq, extCorpID string, sorter *app.Sorter, pager *app.Pager) (items []responses.ContactWayGroup, total int64, err error) {
	param := models.ContactWayGroup{}
	err = copier.Copy(&param, req)
	if err != nil {
		err = errors.Wrap(err, "copier.Copy failed")
		return
	}

	var contactWayGroups []models.ContactWayGroup
	contactWayGroups, total, err = o.model.Query(param, extCorpID, sorter, pager)
	if err != nil {
		err = errors.Wrap(err, "o.model.Query failed")
		return
	}

	counts := make([]struct {
		GroupID string
		Total   int64
	}, 0)

	err = models.DB.Model(&models.ContactWay{}).Where("ext_corp_id = ?", extCorpID).Group("group_id").Select("count(*) as total,group_id").Scan(&counts).Error
	if err != nil {
		err = errors.Wrap(err, "count ContactWay failed")
		return
	}

	countMap := make(map[string]int64, 0)
	for _, count := range counts {
		countMap[count.GroupID] = count.Total
	}

	for _, contactWayGroup := range contactWayGroups {
		item := responses.ContactWayGroup{
			ContactWayGroup: contactWayGroup,
			Count:           countMap[contactWayGroup.ID],
		}
		items = append(items, item)
	}

	return
}