package eta_trial

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type EtaTrialRecord struct {
	RecordId   int    `orm:"column(record_id);pk" description:"eta试用客户id"`
	UserName   string `description:"客户名称"`
	Mobile     string `description:"手机号"`
	Part       string `description:"感兴趣板块"`
	ActiveTime int    `description:"累计活跃时长"`
	CreateTime time.Time
}

func GetEtaTrialRecordParts(mobiles string) (items []*EtaTrialRecord, err error) {
	sql := `
SELECT
	a.mobile,
	COUNT( part ) AS count,
	SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT part ORDER BY count DESC SEPARATOR ',' ), ',', 3 ) AS part 
FROM
	( SELECT *, COUNT( part ) AS count FROM eta_trial_active_record GROUP BY mobile, part ORDER BY mobile, count DESC ) AS a 
WHERE
	a.mobile IN (` + mobiles + `)
GROUP BY
	a.mobile `

	o := orm.NewOrm()
	_, err = o.Raw(sql).QueryRows(&items)
	return
}