DB.Select("MAX(id) id").Where(" visitor_id in (? )",visitorIds).Group("visitor_id").Find(&ids)
iflen(ids)<=0{
returnmessages
}
varidStr=make([]string,0,0)
for_,mes:=rangeids{
idStr=append(idStr,fmt.Sprintf("%d",mes.ID))
}
DB.Select("visitor_id,id,content").Where(" id in (? )",idStr).Find(&messages)
//subQuery := DB.
// Table("message").
// Where(" visitor_id in (? )", visitorIds).
// Order("id desc").
// Limit(1024).
// SubQuery()
//DB.Raw("SELECT ANY_VALUE(visitor_id) visitor_id,ANY_VALUE(id) id,ANY_VALUE(content) content FROM ? message_alia GROUP BY visitor_id", subQuery).Scan(&messages)
DB.Table("message").Where(query,args...).Select("message.*,visitor.avator visitor_avator,visitor.name visitor_name,user.avator kefu_avator,user.nickname kefu_name").Joins("left join user on message.kefu_id=user.name").Joins("left join visitor on visitor.visitor_id=message.visitor_id").Order("message.id asc").Find(&messages)