Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
28fd870d
Commit
28fd870d
authored
Apr 23, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
房间列表排序
parent
b6951346
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
1 deletion
+84
-1
redisPrefix.go
_const/redis_key/redisPrefix.go
+7
-0
country.go
domain/cache/res_c/country.go
+29
-0
country.go
domain/model/res_m/country.go
+17
-1
group_list.go
route/group_r/group_list.go
+31
-0
No files found.
_const/redis_key/redisPrefix.go
View file @
28fd870d
...
@@ -261,6 +261,9 @@ const groupPowerDiamond = "group_diamond_{period}"
...
@@ -261,6 +261,9 @@ const groupPowerDiamond = "group_diamond_{period}"
// 国家Icon
// 国家Icon
const
countryIcon
=
"contry_icon"
const
countryIcon
=
"contry_icon"
// 国家Area
const
countryArea
=
"contry:area"
// 群贡献前三
// 群贡献前三
const
groupTop3Consume
=
"group_top3_consume_{period}_{groupId}"
const
groupTop3Consume
=
"group_top3_consume_{period}_{groupId}"
...
@@ -778,6 +781,10 @@ func GetCountryIconKey() string {
...
@@ -778,6 +781,10 @@ func GetCountryIconKey() string {
return
countryIcon
return
countryIcon
}
}
func
GetCountryAreaKey
()
string
{
return
countryArea
}
func
GetGroupTop3ConsumeKey
(
period
string
,
groupId
string
)
string
{
func
GetGroupTop3ConsumeKey
(
period
string
,
groupId
string
)
string
{
return
strings
.
Replace
(
strings
.
Replace
(
groupTop3Consume
,
"{period}"
,
period
,
-
1
),
"groupId"
,
groupId
,
-
1
)
return
strings
.
Replace
(
strings
.
Replace
(
groupTop3Consume
,
"{period}"
,
period
,
-
1
),
"groupId"
,
groupId
,
-
1
)
}
}
...
...
domain/cache/res_c/country.go
View file @
28fd870d
...
@@ -36,3 +36,32 @@ func SaveAllCountryIcon(model *domain.Model, icons map[string]string) (int64, er
...
@@ -36,3 +36,32 @@ func SaveAllCountryIcon(model *domain.Model, icons map[string]string) (int64, er
}
}
return
ret
,
err
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
}
domain/model/res_m/country.go
View file @
28fd870d
...
@@ -23,6 +23,7 @@ type ResCountry struct {
...
@@ -23,6 +23,7 @@ type ResCountry struct {
StandardShortName
mysql
.
Str
StandardShortName
mysql
.
Str
AreaCode
mysql
.
Str
AreaCode
mysql
.
Str
AreaCodeName
mysql
.
Str
AreaCodeName
mysql
.
Str
Area
mysql
.
Str
}
}
type
ResLanguage
struct
{
type
ResLanguage
struct
{
...
@@ -81,6 +82,22 @@ func GetAllCountries(model *domain.Model) (map[string]string, error) {
...
@@ -81,6 +82,22 @@ func GetAllCountries(model *domain.Model) (map[string]string, error) {
return
result
,
nil
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
)
{
func
GetAllCountryByFilter
(
model
*
domain
.
Model
,
shortNames
[]
string
)
([]
ResCountry
,
error
)
{
var
countrys
[]
ResCountry
var
countrys
[]
ResCountry
if
err
:=
model
.
Db
.
Model
(
&
ResCountry
{})
.
Where
(
&
ResCountry
{
if
err
:=
model
.
Db
.
Model
(
&
ResCountry
{})
.
Where
(
&
ResCountry
{
...
@@ -196,4 +213,3 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
...
@@ -196,4 +213,3 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
return
""
,
myerr
.
WrapErr
(
err
)
return
""
,
myerr
.
WrapErr
(
err
)
}
}
}
}
route/group_r/group_list.go
View file @
28fd870d
package
group_r
package
group_r
import
(
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
...
@@ -155,6 +156,20 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -155,6 +156,20 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
//}
//}
//logstr += " |"
//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
)
countryScore
:=
make
(
map
[
string
]
int
)
if
len
(
myCountry
)
>
0
{
if
len
(
myCountry
)
>
0
{
for
_
,
i
:=
range
sortedGroupIds
{
for
_
,
i
:=
range
sortedGroupIds
{
...
@@ -163,6 +178,13 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -163,6 +178,13 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
}
else
{
}
else
{
countryScore
[
i
]
=
0
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
))
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) {
...
@@ -192,6 +214,15 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
}
else
if
countryScore
[
gi
]
<
countryScore
[
gj
]
{
}
else
if
countryScore
[
gi
]
<
countryScore
[
gj
]
{
return
false
return
false
}
}
// 不是我的国家,按区域排序
if
countryScore
[
gi
]
==
0
{
if
areaScore
[
gi
]
>
areaScore
[
gj
]
{
return
true
}
else
if
areaScore
[
gi
]
<
areaScore
[
gj
]
{
return
false
}
}
// 2、按麦上人数多少排序
// 2、按麦上人数多少排序
if
micGroupNum
[
gi
]
>
micGroupNum
[
gj
]
{
if
micGroupNum
[
gi
]
>
micGroupNum
[
gj
]
{
return
true
return
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment