Commit 28fd870d authored by chenweijian's avatar chenweijian

房间列表排序

parent b6951346
......@@ -261,6 +261,9 @@ const groupPowerDiamond = "group_diamond_{period}"
// 国家Icon
const countryIcon = "contry_icon"
// 国家Area
const countryArea = "contry:area"
// 群贡献前三
const groupTop3Consume = "group_top3_consume_{period}_{groupId}"
......@@ -778,6 +781,10 @@ func GetCountryIconKey() string {
return countryIcon
}
func GetCountryAreaKey() string {
return countryArea
}
func GetGroupTop3ConsumeKey(period string, groupId string) string {
return strings.Replace(strings.Replace(groupTop3Consume, "{period}", period, -1), "groupId", groupId, -1)
}
......
......@@ -36,3 +36,32 @@ func SaveAllCountryIcon(model *domain.Model, icons map[string]string) (int64, er
}
return ret, err
}
func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
m, err := GetAllCountryArea(model)
if err != nil || len(m) <= 0 {
m, err = res_m.GetAllCountriesArea(model)
if err != nil {
return nil, err
}
if len(m) <= 0 {
return map[string]string{}, nil
}
SaveAllCountryArea(model, m)
}
return m, nil
}
func GetAllCountryArea(model *domain.Model) (map[string]string, error) {
key := redis_key.GetCountryAreaKey()
return model.Redis.HGetAll(context.Background(), key).Result()
}
func SaveAllCountryArea(model *domain.Model, data map[string]string) (int64, error) {
key := redis_key.GetCountryAreaKey()
ret, err := model.Redis.HSet(context.Background(), key, data).Result()
if err == nil {
model.Redis.Expire(context.Background(), key, time.Minute*10)
}
return ret, err
}
......@@ -23,6 +23,7 @@ type ResCountry struct {
StandardShortName mysql.Str
AreaCode mysql.Str
AreaCodeName mysql.Str
Area mysql.Str
}
type ResLanguage struct {
......@@ -81,6 +82,22 @@ func GetAllCountries(model *domain.Model) (map[string]string, error) {
return result, nil
}
// 获取所有国家的Area信息
func GetAllCountriesArea(model *domain.Model) (map[string]string, error) {
var countrys []ResCountry
if err := model.Db.Model(&ResCountry{}).Where(&ResCountry{
Status: mysql.USER,
}).Find(&countrys).Error; err != nil {
return nil, myerr.WrapErr(err)
}
result := make(map[string]string, 0)
for _, i := range countrys {
result[i.Name] = i.Area
}
return result, nil
}
func GetAllCountryByFilter(model *domain.Model, shortNames []string) ([]ResCountry, error) {
var countrys []ResCountry
if err := model.Db.Model(&ResCountry{}).Where(&ResCountry{
......@@ -196,4 +213,3 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
return "", myerr.WrapErr(err)
}
}
package group_r
import (
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
......@@ -155,6 +156,20 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
//}
//logstr += " |"
// 获取国家信息
_, area, err := user_m.GetUserCountryArea(model, myUserId)
if err != nil {
model.Log.Errorf("GetUserCountryArea 获取国家资源错误 userId:%d, err:%v", myUserId, err)
return myContext, err
}
myArea := fmt.Sprintf("%d", area)
// 国家区域信息
resAreaMap, err := res_c.GetCountryAreaMap(model)
if err != nil {
return myContext, err
}
areaScore := make(map[string]int)
countryScore := make(map[string]int)
if len(myCountry) > 0 {
for _, i := range sortedGroupIds {
......@@ -163,6 +178,13 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
} else {
countryScore[i] = 0
}
if cArea, ok := resAreaMap[groups[i].Country]; ok {
if myArea == cArea {
areaScore[i] = 1
} else {
areaScore[i] = 0
}
}
}
}
model.Log.Infof("GetPopularGroups, countryScore[*]: %v,cost:%v", countryScore, time.Now().Sub(start))
......@@ -192,6 +214,15 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
} else if countryScore[gi] < countryScore[gj] {
return false
}
// 不是我的国家,按区域排序
if countryScore[gi] == 0 {
if areaScore[gi] > areaScore[gj] {
return true
} else if areaScore[gi] < areaScore[gj] {
return false
}
}
// 2、按麦上人数多少排序
if micGroupNum[gi] > micGroupNum[gj] {
return true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment