Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sh-ds
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李良停
sh-ds
Commits
a783e533
Commit
a783e533
authored
May 03, 2022
by
wangsong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add statistics api
parent
f05b7b0a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
231 additions
and
0 deletions
+231
-0
StatisticsController.java
...den/authcenter/agent/controller/StatisticsController.java
+175
-0
AuthLogDao.java
...va/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
+32
-0
AuthLogService.java
...hineseall/eden/authcenter/log/service/AuthLogService.java
+4
-0
AuthLogServiceImpl.java
.../eden/authcenter/log/service/impl/AuthLogServiceImpl.java
+20
-0
No files found.
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/StatisticsController.java
0 → 100644
View file @
a783e533
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.api.MapMessage
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
com.chineseall.eden.authcenter.agent.client.ClientItem
;
import
com.chineseall.eden.authcenter.agent.vo.StatItem
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.service.AuthClientService
;
import
com.chineseall.eden.authcenter.config.service.AuthSourceService
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Controller
@RequestMapping
(
"statistics"
)
public
class
StatisticsController
{
@Autowired
private
AuthClientService
authClientService
;
@Autowired
private
AuthSourceService
authSourceService
;
@Autowired
private
AuthLogService
authLogService
;
/**
* 接入的应用列表
*
* @return
*/
@RequestMapping
(
"auth_apps"
)
@ResponseBody
public
MapMessage
authApps
()
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AuthClient
>
clientList
=
authClientService
.
listAll
();
if
(
CollectionUtils
.
isNotEmpty
(
clientList
)){
clientList
.
forEach
(
item
->
{
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"code"
,
item
.
getKey
());
data
.
put
(
"name"
,
item
.
getName
());
result
.
add
(
data
);
});
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
private
Date
getStartDay
(
Integer
latestDays
){
Date
now
=
new
Date
();
return
DateUtils
.
calculateDateDay
(
now
,
-
latestDays
);
}
/**
* APP使用情况统计
*
* @param latestDays 最近多少天的统计
* @param topN topN
* @return 指定app的认证数
*/
@RequestMapping
(
"app"
)
@ResponseBody
public
MapMessage
applications
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
required
=
false
)
Integer
latestDays
,
@RequestParam
(
value
=
"topN"
,
required
=
false
)
Integer
topN
)
{
List
<
StatItem
>
dataList
=
new
ArrayList
<>();
List
<
AuthClient
>
clientList
=
authClientService
.
listAll
();
if
(
StringUtils
.
isNoneBlank
(
clientId
)){
clientList
=
clientList
.
stream
().
filter
(
p
->
Objects
.
equals
(
p
.
getKey
(),
clientId
)).
collect
(
Collectors
.
toList
());
}
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
Date
startDate
=
getStartDay
(
latestDays
);
clientList
.
forEach
(
item
->
{
StatItem
statItem
=
new
StatItem
();
statItem
.
setCode
(
item
.
getKey
());
statItem
.
setName
(
item
.
getName
());
param
.
put
(
"clientId"
,
item
.
getKey
());
long
count
=
authLogService
.
count
(
param
,
startDate
);
statItem
.
setCount
(
count
);
dataList
.
add
(
statItem
);
});
dataList
.
sort
((
o1
,
o2
)
->
Long
.
valueOf
(
o2
.
getCount
()
-
o1
.
getCount
()).
intValue
());
List
<
StatItem
>
result
=
dataList
;
if
(
topN
!=
null
&&
topN
>
0
){
if
(
topN
<
result
.
size
()){
result
=
result
.
subList
(
0
,
topN
);
}
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
/**
* 来源环境情况统计
*
* @param latestDays 最近多少天
* @return
*/
@RequestMapping
(
"environment"
)
@ResponseBody
public
MapMessage
environments
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
required
=
false
)
Integer
latestDays
)
{
Map
<
String
,
List
<
StatItem
>>
result
=
new
HashMap
<>();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
param
.
put
(
"clientId"
,
clientId
);
}
Date
startDate
=
getStartDay
(
latestDays
);
long
all_auth
=
authLogService
.
count
(
param
,
startDate
);
List
<
StatItem
>
browserResult
=
new
ArrayList
<>();
List
<
String
>
browserList
=
authLogService
.
distinct
(
"browser"
,
param
,
startDate
);
long
unknownBrowser
=
all_auth
;
if
(
CollectionUtils
.
isNotEmpty
(
browserList
)){
for
(
String
item
:
browserList
)
{
param
.
put
(
"browser"
,
item
);
long
count
=
authLogService
.
count
(
param
,
startDate
);
StatItem
statItem
=
new
StatItem
();
statItem
.
setName
(
item
);
statItem
.
setCount
(
count
);
unknownBrowser
=
unknownBrowser
-
count
;
browserResult
.
add
(
statItem
);
}
}
if
(
unknownBrowser
>
0
){
StatItem
statItem
=
new
StatItem
();
statItem
.
setName
(
"unknown"
);
statItem
.
setCount
(
unknownBrowser
);
browserResult
.
add
(
statItem
);
}
result
.
put
(
"browser"
,
browserResult
);
List
<
StatItem
>
osResult
=
new
ArrayList
<>();
param
.
remove
(
"browser"
);
List
<
String
>
osList
=
authLogService
.
distinct
(
"os"
,
param
,
startDate
);
long
unknownOs
=
all_auth
;
if
(
CollectionUtils
.
isNotEmpty
(
osList
)){
for
(
String
item
:
osList
)
{
param
.
put
(
"os"
,
item
);
long
count
=
authLogService
.
count
(
param
,
startDate
);
StatItem
statItem
=
new
StatItem
();
statItem
.
setName
(
item
);
statItem
.
setCount
(
count
);
osResult
.
add
(
statItem
);
unknownOs
=
unknownOs
-
count
;
}
}
if
(
unknownOs
>
0
){
StatItem
statItem
=
new
StatItem
();
statItem
.
setName
(
"unknown"
);
statItem
.
setCount
(
unknownOs
);
osResult
.
add
(
statItem
);
}
result
.
put
(
"os"
,
osResult
);
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
View file @
a783e533
...
@@ -3,6 +3,7 @@ package com.chineseall.eden.authcenter.log.dao;
...
@@ -3,6 +3,7 @@ package com.chineseall.eden.authcenter.log.dao;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
...
@@ -39,6 +40,9 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -39,6 +40,9 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
if
(
params
.
get
(
"endTime"
)!=
null
){
if
(
params
.
get
(
"endTime"
)!=
null
){
criteria
.
lte
((
Date
)
params
.
get
(
"endTime"
));
criteria
.
lte
((
Date
)
params
.
get
(
"endTime"
));
}
}
if
(
params
.
get
(
"clientId"
)
!=
null
){
criteria
.
and
(
"clientId"
).
is
(
params
.
get
(
"clientId"
).
toString
());
}
Query
query
=
Query
.
query
(
criteria
);
Query
query
=
Query
.
query
(
criteria
);
return
count
(
query
);
return
count
(
query
);
}
}
...
@@ -60,6 +64,20 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -60,6 +64,20 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
}
}
public
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
params
,
Date
beginTime
){
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
params
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
criteria
.
and
(
"createTime"
).
gte
(
beginTime
);
}
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
}
public
long
count
(
Map
<
String
,
Object
>
params
){
public
long
count
(
Map
<
String
,
Object
>
params
){
Criteria
criteria
=
new
Criteria
();
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
if
(
null
!=
params
&&
params
.
size
()
>
0
){
...
@@ -71,6 +89,20 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -71,6 +89,20 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return
count
(
query
);
return
count
(
query
);
}
}
public
long
count
(
Map
<
String
,
Object
>
params
,
Date
beginTime
){
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
params
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
criteria
.
and
(
"createTime"
).
gte
(
beginTime
);
}
Query
query
=
Query
.
query
(
criteria
);
return
count
(
query
);
}
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
Criteria
criteria
=
new
Criteria
();
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
prams
&&
prams
.
size
()
>
0
){
if
(
null
!=
prams
&&
prams
.
size
()
>
0
){
...
...
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/AuthLogService.java
View file @
a783e533
...
@@ -2,6 +2,7 @@ package com.chineseall.eden.authcenter.log.service;
...
@@ -2,6 +2,7 @@ package com.chineseall.eden.authcenter.log.service;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -17,7 +18,10 @@ public interface AuthLogService {
...
@@ -17,7 +18,10 @@ public interface AuthLogService {
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
);
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
);
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
,
Date
beginTime
);
long
count
(
Map
<
String
,
Object
>
prams
);
long
count
(
Map
<
String
,
Object
>
prams
);
long
count
(
Map
<
String
,
Object
>
prams
,
Date
beginTime
);
void
replace
(
AuthLog
authLog
);
void
replace
(
AuthLog
authLog
);
...
...
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/impl/AuthLogServiceImpl.java
View file @
a783e533
...
@@ -57,11 +57,31 @@ public class AuthLogServiceImpl implements AuthLogService {
...
@@ -57,11 +57,31 @@ public class AuthLogServiceImpl implements AuthLogService {
return
result
;
return
result
;
}
}
@Override
public
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
,
Date
beginTime
)
{
List
<
String
>
stringList
=
authLogDao
.
distinct
(
key
,
prams
,
beginTime
);
List
<
String
>
result
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
stringList
)){
stringList
.
forEach
(
item
->
{
if
(
null
!=
item
){
result
.
add
(
item
);
}
});
}
return
result
;
}
@Override
@Override
public
long
count
(
Map
<
String
,
Object
>
prams
)
{
public
long
count
(
Map
<
String
,
Object
>
prams
)
{
return
authLogDao
.
count
(
prams
);
return
authLogDao
.
count
(
prams
);
}
}
@Override
public
long
count
(
Map
<
String
,
Object
>
prams
,
Date
beginTime
)
{
return
authLogDao
.
count
(
prams
,
beginTime
);
}
@Override
@Override
public
void
replace
(
AuthLog
authLog
)
{
public
void
replace
(
AuthLog
authLog
)
{
authLogDao
.
replace
(
authLog
);
authLogDao
.
replace
(
authLog
);
...
...
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