Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
86c95259
Commit
86c95259
authored
Jun 08, 2022
by
吴星煌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
保存活跃用户活跃群组的定时任务
parent
c80affc9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
4 deletions
+99
-4
core/src/main/java/com/wecloud/im/appmanager/ImOverviewImpl.java
+6
-4
scheduled/src/main/java/io/geekidea/springbootplus/scheduled/OverviewScheduled.java
+93
-0
No files found.
core/src/main/java/com/wecloud/im/appmanager/ImOverviewImpl.java
View file @
86c95259
...
...
@@ -95,8 +95,9 @@ public class ImOverviewImpl implements ImOverview {
ImStatistics
statistics
=
imStatisticsService
.
getOne
(
new
LambdaQueryWrapper
<
ImStatistics
>()
.
eq
(
ImStatistics:
:
getFkAppid
,
appId
)
.
eq
(
ImStatistics:
:
getType
,
2
)
.
ge
(
ImStatistics:
:
getTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
.
minusHours
(
24
)))
.
le
(
ImStatistics:
:
getTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
.
minusHours
(
24
)))
.
between
(
ImStatistics:
:
getTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
1
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
).
minusDays
(
1
))
);
Integer
activeGroup
=
statistics
==
null
?
0
:
statistics
.
getData
();
statisticsVo
.
setActiveGroup
(
activeGroup
);
...
...
@@ -106,8 +107,9 @@ public class ImOverviewImpl implements ImOverview {
.
eq
(
ImConversation:
:
getFkAppid
,
appId
)
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
NORMAL_GROUP
.
getCode
())
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
THOUSAND_GROUP
.
getCode
())
.
ge
(
ImConversation:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
.
minusHours
(
24
)))
.
le
(
ImConversation:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
.
minusHours
(
24
)))
.
between
(
ImConversation:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
1
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
).
minusDays
(
1
))
);
statisticsVo
.
setNewGroup
(
newGroup
);
...
...
scheduled/src/main/java/io/geekidea/springbootplus/scheduled/OverviewScheduled.java
0 → 100644
View file @
86c95259
package
io
.
geekidea
.
springbootplus
.
scheduled
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImStatistics
;
import
com.wecloud.im.sdk.enums.ChatTypeEnum
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.service.ImStatisticsService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Slf4j
@Component
public
class
OverviewScheduled
{
@Autowired
private
ImStatisticsService
imStatisticsService
;
@Autowired
private
ImApplicationService
imApplicationService
;
@Autowired
private
ImMessageService
imMessageService
;
@Autowired
private
ImConversationService
imConversationService
;
//统计数据统计中的数据并存入im_statistics表
@Scheduled
(
cron
=
"0 0 1 1-31 1-12 ? "
)
public
void
statisticsData
(){
log
.
info
(
"正在记录前一天的数据统计"
);
List
<
ImApplication
>
imApplicationList
=
imApplicationService
.
list
();
for
(
ImApplication
imApplication
:
imApplicationList
)
{
Long
appId
=
imApplication
.
getId
();
//统计活跃用户数量并保存
Integer
activeUser
=
imMessageService
.
count
(
new
LambdaQueryWrapper
<
ImMessage
>()
.
eq
(
ImMessage:
:
getFkAppid
,
appId
)
.
between
(
ImMessage:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
1
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
).
minusDays
(
1
))
.
groupBy
(
ImMessage:
:
getSender
)
.
select
(
ImMessage:
:
getSender
)
);
ImStatistics
userStatistics
=
new
ImStatistics
();
userStatistics
.
setData
(
activeUser
);
userStatistics
.
setFkAppid
(
appId
);
userStatistics
.
setTime
(
LocalDateTime
.
now
().
minusDays
(
1
));
userStatistics
.
setType
(
1
);
imStatisticsService
.
save
(
userStatistics
);
//统计活跃群组数量并保存
List
<
Long
>
ids
=
imMessageService
.
list
(
new
LambdaQueryWrapper
<
ImMessage
>()
.
between
(
ImMessage:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
1
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MAX
).
minusDays
(
1
))
.
groupBy
(
ImMessage:
:
getFkConversationId
)
.
select
(
ImMessage:
:
getFkConversationId
)
).
stream
().
map
(
ImMessage:
:
getFkConversationId
).
collect
(
Collectors
.
toList
());
List
<
ImConversation
>
groupList
=
imConversationService
.
list
(
new
LambdaQueryWrapper
<
ImConversation
>()
.
eq
(
ImConversation:
:
getFkAppid
,
appId
)
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
NORMAL_GROUP
.
getCode
())
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
THOUSAND_GROUP
.
getCode
())
.
in
(
ImConversation:
:
getId
,
ids
)
);
Integer
activeGroup
=
groupList
.
size
();
//活跃群的成员总数
Integer
groupMember
=
0
;
for
(
ImConversation
imConversation
:
groupList
)
{
groupMember
+=
imConversation
.
getMemberCount
();
}
ImStatistics
groupStatistics
=
new
ImStatistics
();
groupStatistics
.
setData
(
activeGroup
);
groupStatistics
.
setFkAppid
(
appId
);
groupStatistics
.
setTime
(
LocalDateTime
.
now
().
minusDays
(
1
));
groupStatistics
.
setType
(
2
);
groupStatistics
.
setGroupMember
(
groupMember
);
imStatisticsService
.
save
(
groupStatistics
);
}
}
}
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