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
18eafb0e
Commit
18eafb0e
authored
Jun 07, 2022
by
吴星煌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据统计
parent
0ee90bd8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
245 additions
and
1 deletions
+245
-1
client/src/main/java/com/wecloud/imserver/client/api/ImOverview.java
+9
-0
client/src/main/java/com/wecloud/imserver/client/model/vo/LineChart.java
+14
-0
client/src/main/java/com/wecloud/imserver/client/model/vo/StatisticsVo.java
+25
-0
core/src/main/java/com/wecloud/im/appmanager/ImOverviewImpl.java
+102
-1
core/src/main/java/com/wecloud/im/appmanager/ImStatisticsImpl.java
+30
-0
core/src/main/java/com/wecloud/im/entity/ImStatistics.java
+43
-0
core/src/main/java/com/wecloud/im/mapper/ImStatisticsMapper.java
+9
-0
core/src/main/java/com/wecloud/im/service/ImStatisticsService.java
+13
-0
No files found.
client/src/main/java/com/wecloud/imserver/client/api/ImOverview.java
View file @
18eafb0e
package
com
.
wecloud
.
imserver
.
client
.
api
;
package
com
.
wecloud
.
imserver
.
client
.
api
;
import
com.wecloud.imserver.client.model.vo.LineChart
;
import
com.wecloud.imserver.client.model.vo.StatisticsVo
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
public
interface
ImOverview
{
public
interface
ImOverview
{
HashMap
<
String
,
Integer
>
overview
(
Long
appId
);
HashMap
<
String
,
Integer
>
overview
(
Long
appId
);
StatisticsVo
groupStatistics
(
Long
appId
,
LocalDateTime
start
,
LocalDateTime
end
);
List
<
LineChart
>
activeUser
(
Long
appId
,
LocalDateTime
start
,
LocalDateTime
end
);
}
}
client/src/main/java/com/wecloud/imserver/client/model/vo/LineChart.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
imserver
.
client
.
model
.
vo
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
@Data
public
class
LineChart
{
private
Integer
count
;
private
LocalDateTime
date
;
}
client/src/main/java/com/wecloud/imserver/client/model/vo/StatisticsVo.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
imserver
.
client
.
model
.
vo
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
StatisticsVo
{
//活跃群组
private
Integer
activeGroup
;
//新增群组
private
Integer
newGroup
;
//解散群组
private
Integer
dismissGroup
;
//活跃群组平均成员数
private
Integer
avgActiveGroup
;
//曲线图数据
private
List
<
LineChart
>
activeGroupLine
;
private
List
<
LineChart
>
newGroupLine
;
private
List
<
LineChart
>
dismissGroupLine
;
private
List
<
LineChart
>
avgActiveGroupLine
;
}
core/src/main/java/com/wecloud/im/appmanager/ImOverviewImpl.java
View file @
18eafb0e
...
@@ -4,11 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...
@@ -4,11 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImStatistics
;
import
com.wecloud.im.sdk.enums.ChatTypeEnum
;
import
com.wecloud.im.sdk.enums.ChatTypeEnum
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.service.ImStatisticsService
;
import
com.wecloud.imserver.client.api.ImOverview
;
import
com.wecloud.imserver.client.api.ImOverview
;
import
com.wecloud.imserver.client.model.vo.LineChart
;
import
com.wecloud.imserver.client.model.vo.StatisticsVo
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -17,6 +21,8 @@ import org.springframework.stereotype.Service;
...
@@ -17,6 +21,8 @@ import org.springframework.stereotype.Service;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.LocalTime
;
import
java.time.temporal.ChronoUnit
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -32,12 +38,13 @@ public class ImOverviewImpl implements ImOverview {
...
@@ -32,12 +38,13 @@ public class ImOverviewImpl implements ImOverview {
private
ImClientService
imClientService
;
private
ImClientService
imClientService
;
@Autowired
@Autowired
private
ImConversationService
imConversationService
;
private
ImConversationService
imConversationService
;
@Autowired
private
ImStatisticsService
imStatisticsService
;
@Override
@Override
public
HashMap
<
String
,
Integer
>
overview
(
Long
appId
)
{
public
HashMap
<
String
,
Integer
>
overview
(
Long
appId
)
{
HashMap
<
String
,
Integer
>
count
=
new
HashMap
<>();
HashMap
<
String
,
Integer
>
count
=
new
HashMap
<>();
//今日活跃用户
//今日活跃用户
List
<
Long
>
userIds
=
imMessageService
.
list
(
new
LambdaQueryWrapper
<
ImMessage
>()
List
<
Long
>
userIds
=
imMessageService
.
list
(
new
LambdaQueryWrapper
<
ImMessage
>()
.
eq
(
ImMessage:
:
getFkAppid
,
appId
)
.
eq
(
ImMessage:
:
getFkAppid
,
appId
)
...
@@ -78,4 +85,98 @@ public class ImOverviewImpl implements ImOverview {
...
@@ -78,4 +85,98 @@ public class ImOverviewImpl implements ImOverview {
return
count
;
return
count
;
}
}
@Override
public
StatisticsVo
groupStatistics
(
Long
appId
,
LocalDateTime
start
,
LocalDateTime
end
)
{
if
(
start
==
null
&&
end
==
null
){
start
=
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
.
minusHours
(
24
*
8
));
end
=
start
.
plusDays
(
7
);
}
StatisticsVo
statisticsVo
=
new
StatisticsVo
();
//活跃群组数(前1天)
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
)))
);
Integer
activeGroup
=
statistics
.
getData
();
statisticsVo
.
setActiveGroup
(
activeGroup
);
//新增群组数(前1天)
Integer
newGroup
=
imConversationService
.
count
(
new
LambdaQueryWrapper
<
ImConversation
>()
.
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
)))
);
statisticsVo
.
setNewGroup
(
newGroup
);
//todo 解散群组数,暂时未能查询
statisticsVo
.
setDismissGroup
(
0
);
//活跃群组平均成员数
Integer
avgMember
=
statistics
.
getGroupMember
()/
statistics
.
getData
();
statisticsVo
.
setAvgActiveGroup
(
avgMember
);
//活跃群组折线图
List
<
ImStatistics
>
imStatistics
=
imStatisticsService
.
activeUserOrGroup
(
appId
,
2
,
start
,
end
);
List
<
LineChart
>
activeGroupLine
=
new
ArrayList
<>();
for
(
ImStatistics
imStatistic
:
imStatistics
)
{
LineChart
lineChart
=
new
LineChart
();
lineChart
.
setCount
(
imStatistic
.
getData
());
lineChart
.
setDate
(
imStatistic
.
getTime
());
activeGroupLine
.
add
(
lineChart
);
}
statisticsVo
.
setActiveGroupLine
(
activeGroupLine
);
//新增群组折线图
Long
days
=
ChronoUnit
.
DAYS
.
between
(
start
,
end
);
List
<
LineChart
>
newGroupLine
=
new
ArrayList
<>();
for
(
int
i
=
days
.
intValue
();
i
>
0
;
i
--){
LineChart
lineChart
=
new
LineChart
();
Integer
count
=
imConversationService
.
count
(
new
LambdaQueryWrapper
<
ImConversation
>()
.
eq
(
ImConversation:
:
getFkAppid
,
appId
)
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
NORMAL_GROUP
.
getCode
())
.
eq
(
ImConversation:
:
getChatType
,
ChatTypeEnum
.
THOUSAND_GROUP
.
getCode
())
.
between
(
ImConversation:
:
getCreateTime
,
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
i
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
i
-
1
))
);
lineChart
.
setDate
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
MIN
).
minusDays
(
i
));
lineChart
.
setCount
(
count
);
newGroupLine
.
add
(
lineChart
);
}
statisticsVo
.
setNewGroupLine
(
newGroupLine
);
//todo 解散群组折线图
List
<
LineChart
>
dismissGroupLine
=
new
ArrayList
<>();
statisticsVo
.
setDismissGroupLine
(
dismissGroupLine
);
//活跃群组平均成员数
List
<
LineChart
>
avgActiveGroupLine
=
new
ArrayList
<>();
for
(
ImStatistics
imStatistic
:
imStatistics
)
{
LineChart
lineChart
=
new
LineChart
();
lineChart
.
setCount
(
imStatistic
.
getGroupMember
()/
imStatistic
.
getData
());
lineChart
.
setDate
(
imStatistic
.
getTime
());
avgActiveGroupLine
.
add
(
lineChart
);
}
statisticsVo
.
setAvgActiveGroupLine
(
avgActiveGroupLine
);
return
statisticsVo
;
}
@Override
public
List
<
LineChart
>
activeUser
(
Long
appId
,
LocalDateTime
start
,
LocalDateTime
end
)
{
//活跃用户数
List
<
ImStatistics
>
imStatistics
=
imStatisticsService
.
activeUserOrGroup
(
appId
,
1
,
start
,
end
);
List
<
LineChart
>
activeUser
=
new
ArrayList
<>();
for
(
ImStatistics
imStatistic
:
imStatistics
)
{
LineChart
lineChart
=
new
LineChart
();
lineChart
.
setCount
(
imStatistic
.
getData
());
lineChart
.
setDate
(
imStatistic
.
getTime
());
activeUser
.
add
(
lineChart
);
}
return
activeUser
;
}
}
}
core/src/main/java/com/wecloud/im/appmanager/ImStatisticsImpl.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
im
.
appmanager
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.wecloud.im.entity.ImStatistics
;
import
com.wecloud.im.mapper.ImStatisticsMapper
;
import
com.wecloud.im.service.ImStatisticsService
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
import
java.util.List
;
@Slf4j
@Service
public
class
ImStatisticsImpl
extends
BaseServiceImpl
<
ImStatisticsMapper
,
ImStatistics
>
implements
ImStatisticsService
{
@Override
public
List
<
ImStatistics
>
activeUserOrGroup
(
Long
appId
,
Integer
type
,
LocalDateTime
start
,
LocalDateTime
end
)
{
return
this
.
list
(
new
LambdaQueryWrapper
<
ImStatistics
>()
.
eq
(
ImStatistics:
:
getFkAppid
,
appId
)
.
eq
(
ImStatistics:
:
getType
,
type
)
.
ge
(
start
!=
null
,
ImStatistics:
:
getTime
,
start
)
.
le
(
end
!=
null
,
ImStatistics:
:
getTime
,
end
)
.
orderByAsc
(
ImStatistics:
:
getTime
)
);
}
}
core/src/main/java/com/wecloud/im/entity/ImStatistics.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
im
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
io.geekidea.springbootplus.framework.common.entity.BaseEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotNull
;
import
java.time.LocalDateTime
;
@Data
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"ImStatistics每日活跃用户/群组统计"
)
public
class
ImStatistics
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
@NotNull
(
message
=
"id不能为空"
)
@ApiModelProperty
(
"id"
)
@TableId
(
value
=
"id"
,
type
=
IdType
.
INPUT
)
private
Long
id
;
@NotNull
(
message
=
"应用appid不能为空"
)
@ApiModelProperty
(
"应用appid"
)
private
Long
fkAppid
;
@ApiModelProperty
(
"统计类型 1用户 2群组"
)
private
Integer
type
;
@ApiModelProperty
(
"数据"
)
private
Integer
data
;
@ApiModelProperty
(
"统计的日期"
)
private
LocalDateTime
time
;
@ApiModelProperty
(
"总成员数"
)
private
Integer
groupMember
;
}
core/src/main/java/com/wecloud/im/mapper/ImStatisticsMapper.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
im
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.wecloud.im.entity.ImStatistics
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
ImStatisticsMapper
extends
BaseMapper
<
ImStatistics
>
{
}
core/src/main/java/com/wecloud/im/service/ImStatisticsService.java
0 → 100644
View file @
18eafb0e
package
com
.
wecloud
.
im
.
service
;
import
com.wecloud.im.entity.ImStatistics
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
java.time.LocalDateTime
;
import
java.util.List
;
public
interface
ImStatisticsService
extends
BaseService
<
ImStatistics
>
{
List
<
ImStatistics
>
activeUserOrGroup
(
Long
appId
,
Integer
type
,
LocalDateTime
start
,
LocalDateTime
end
);
}
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