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
698d4f79
Commit
698d4f79
authored
Mar 22, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
房间列表按热度排序
parent
be119516
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
12 deletions
+88
-12
group.go
cv/group_cv/group.go
+8
-4
groupInfo.go
domain/model/group_m/groupInfo.go
+39
-8
room.go
domain/model/group_m/room.go
+41
-0
No files found.
cv/group_cv/group.go
View file @
698d4f79
...
...
@@ -481,12 +481,16 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
model
.
Log
.
Infof
(
"BuildPopularGroupInfo, roomEnterTime: %v"
,
roomEnterTime
)
// 排序优先级V8.0版本
//sort.Slice(groupIds, func(i, j int) bool {
// gi := groupIds[i]
// gj := groupIds[j]
// return roomEnterTime[gi] > roomEnterTime[gj] ||
// roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] > visitCount[gj] ||
// roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] == visitCount[gj] && i >= j
//})
sort
.
Slice
(
groupIds
,
func
(
i
,
j
int
)
bool
{
gi
:=
groupIds
[
i
]
gj
:=
groupIds
[
j
]
return
roomEnterTime
[
gi
]
>
roomEnterTime
[
gj
]
||
roomEnterTime
[
gi
]
==
roomEnterTime
[
gj
]
&&
visitCount
[
gj
]
>
visitCount
[
gj
]
||
roomEnterTime
[
gi
]
==
roomEnterTime
[
gj
]
&&
visitCount
[
gj
]
==
visitCount
[
gj
]
&&
i
>=
j
return
visitCount
[
gj
]
>
visitCount
[
gj
]
})
result
:=
make
([]
*
PopularGroupInfo
,
0
)
...
...
domain/model/group_m/groupInfo.go
View file @
698d4f79
...
...
@@ -8,10 +8,10 @@ import (
"github.com/bluele/gcache"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/common"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
"math/rand"
"sort"
"time"
)
...
...
@@ -45,6 +45,7 @@ type GroupInfo struct {
MemberFee
uint64
// 加入会员需要黄钻数
CreatedTime
time
.
Time
`gorm:"->"`
UpdatedTime
time
.
Time
`gorm:"->"`
VisitCount
int64
`gorm:"-"`
// 热度
}
func
GenerateGroupCode
(
n
uint16
)
string
{
...
...
@@ -516,18 +517,48 @@ func GetLatestGroupInfos(model *domain.Model, limit, lastId int, groupIds []stri
return
}
func
GetFamilyRooms
(
model
*
domain
.
Model
,
familyId
uint64
,
pageSize
,
pageIndex
int
)
([]
*
GroupInfo
,
int
,
bool
,
error
)
{
rows
:=
make
([]
*
GroupInfo
,
0
)
db
:=
model
.
Db
.
Model
(
GroupInfo
{})
.
Where
(
"owner in (select user_id from group_power_user where group_power_id=? order by field(`role`, 2, 3, 1))"
,
familyId
)
func
GetFamilyRooms
(
model
*
domain
.
Model
,
familyId
uint64
,
pageSize
,
pageIndex
int
)
(
res
[]
*
GroupInfo
,
nextIdx
int
,
hasNext
bool
,
err
error
)
{
allImGroupIds
:=
make
([]
string
,
0
)
var
count
int64
err
:=
db
.
Count
(
&
count
)
.
Error
err
=
model
.
Db
.
Model
(
GroupInfo
{})
.
Select
(
"im_group_id"
)
.
Where
(
"owner in (select user_id from group_power_user where group_power_id=?)"
,
familyId
)
.
Pluck
(
"im_group_id"
,
&
allImGroupIds
)
.
Count
(
&
count
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
false
,
err
}
err
=
db
.
Limit
(
pageSize
)
.
Offset
(
pageIndex
)
.
Find
(
&
rows
)
.
Error
// 房间热度排序
visitCountMap
,
visitCountList
,
err
:=
BatchGetRoomVisitCountList
(
model
.
Log
,
allImGroupIds
)
if
err
!=
nil
{
return
nil
,
0
,
false
,
err
}
nextIdx
,
hasNext
:=
common
.
PageNext
(
count
,
pageIndex
,
pageSize
)
return
rows
,
nextIdx
,
hasNext
,
nil
roomNum
:=
len
(
visitCountList
)
if
roomNum
>
pageIndex
{
endIndex
:=
pageIndex
+
pageSize
if
roomNum
>=
endIndex
{
visitCountList
=
visitCountList
[
pageIndex
:
pageIndex
+
pageSize
]
if
roomNum
>
endIndex
{
nextIdx
=
endIndex
hasNext
=
true
}
}
else
{
visitCountList
=
visitCountList
[
pageIndex
:
]
}
}
else
{
return
nil
,
0
,
false
,
err
}
res
=
make
([]
*
GroupInfo
,
0
)
err
=
model
.
Db
.
Model
(
GroupInfo
{})
.
Where
(
"im_group_id in ?"
,
allImGroupIds
)
.
Find
(
&
res
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
false
,
err
}
for
i
,
v
:=
range
res
{
if
c
,
ok
:=
visitCountMap
[
v
.
ImGroupId
];
ok
{
res
[
i
]
.
VisitCount
=
c
}
}
sort
.
Slice
(
res
,
func
(
i
,
j
int
)
bool
{
return
res
[
i
]
.
VisitCount
>
res
[
j
]
.
VisitCount
})
return
res
,
nextIdx
,
hasNext
,
nil
}
domain/model/group_m/room.go
View file @
698d4f79
...
...
@@ -451,6 +451,47 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i
return
visitCount
,
nil
}
type
RoomVisit
struct
{
ImGroupId
string
Count
int64
}
// 批量查询房间最近N天的访问人数。使用二级缓存
func
BatchGetRoomVisitCountList
(
logE
*
logrus
.
Entry
,
groupIds
[]
string
)
(
map
[
string
]
int64
,
[]
*
RoomVisit
,
error
)
{
//roomVisitCount, err := redis.GetAllRoomVisitCount()
roomVisitCount
,
err
:=
room_c
.
MGetRoomVisitCount
(
groupIds
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
logE
.
Infof
(
"MGetRoomVisitCount:%v"
,
roomVisitCount
)
res
:=
make
([]
*
RoomVisit
,
0
,
len
(
groupIds
))
visitCount
:=
make
(
map
[
string
]
int64
)
for
_
,
groupId
:=
range
groupIds
{
// 先从二级缓存中找
if
c
,
ok
:=
roomVisitCount
[
groupId
];
ok
{
if
vc
,
err
:=
strconv
.
ParseInt
(
c
,
10
,
64
);
err
==
nil
&&
vc
>
0
{
logE
.
Debugf
(
"GetRoomVisitCount, from roomVisitCount %s - %d"
,
groupId
,
vc
)
visitCount
[
groupId
]
=
vc
res
=
append
(
res
,
&
RoomVisit
{
ImGroupId
:
groupId
,
Count
:
vc
})
}
}
else
{
// 如果没有,就从roomVisit中取
if
vc
,
err
:=
room_c
.
GetSetRoomVisitCount
(
groupId
);
err
==
nil
&&
vc
>
0
{
logE
.
Infof
(
"GetRoomVisitCount, from roomVisit %s - %d"
,
groupId
,
vc
)
visitCount
[
groupId
]
=
vc
res
=
append
(
res
,
&
RoomVisit
{
ImGroupId
:
groupId
,
Count
:
vc
})
}
}
}
sort
.
Slice
(
res
,
func
(
i
,
j
int
)
bool
{
return
res
[
i
]
.
Count
>=
res
[
j
]
.
Count
})
return
visitCount
,
res
,
nil
}
type
UserEnterRoom
struct
{
UserId
uint64
GroupId
string
...
...
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