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
4ebf3eae
Commit
4ebf3eae
authored
May 05, 2022
by
wangsong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add max hour data
parent
0c1a6c5b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
7 deletions
+88
-7
StatisticsController.java
...den/authcenter/agent/controller/StatisticsController.java
+13
-4
AuthLogDao.java
...va/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
+54
-3
AuthLogHourCount.java
...hineseall/eden/authcenter/log/model/AuthLogHourCount.java
+12
-0
AuthLogService.java
...hineseall/eden/authcenter/log/service/AuthLogService.java
+3
-0
AuthLogServiceImpl.java
.../eden/authcenter/log/service/impl/AuthLogServiceImpl.java
+6
-0
No files found.
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/StatisticsController.java
View file @
4ebf3eae
...
...
@@ -10,6 +10,7 @@ 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.model.AuthLogHourCount
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
...
...
@@ -304,10 +305,10 @@ public class StatisticsController {
public
MapMessage
authPickTimes
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
)
{
Map
<
String
,
Object
>
p
aram
=
new
HashMap
<>();
p
aram
.
put
(
"loginSuccessFlag"
,
true
);
Map
<
String
,
Object
>
commonP
aram
=
new
HashMap
<>();
commonP
aram
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
p
aram
.
put
(
"clientId"
,
clientId
);
commonP
aram
.
put
(
"clientId"
,
clientId
);
}
Date
startDate
=
getStartDay
(
latestDays
);
...
...
@@ -315,6 +316,8 @@ public class StatisticsController {
List
<
Integer
>
hourList
=
new
ArrayList
<>();
List
<
Long
>
hourCountList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
putAll
(
commonParam
);
for
(
int
i
=
0
;
i
<
24
;
i
++){
param
.
put
(
"hour"
,
i
);
long
count
=
authLogService
.
count
(
param
,
startDate
);
...
...
@@ -322,7 +325,13 @@ public class StatisticsController {
hourCountList
.
add
(
Double
.
valueOf
(
MathUtils
.
doubleDivide
(
count
,
latestDays
,
0
)).
longValue
());
}
return
MapMessage
.
successMessage
().
add
(
"hourList"
,
hourList
).
add
(
"dataList"
,
hourCountList
);
List
<
AuthLogHourCount
>
hourTopList
=
authLogService
.
hourMaxCount
(
commonParam
,
startDate
,
1
);
AuthLogHourCount
max
=
null
;
if
(
CollectionUtils
.
isNotEmpty
(
hourTopList
)){
max
=
hourTopList
.
get
(
0
);
}
return
MapMessage
.
successMessage
().
add
(
"hourList"
,
hourList
).
add
(
"dataList"
,
hourCountList
).
add
(
"maxHour"
,
max
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
View file @
4ebf3eae
...
...
@@ -5,14 +5,25 @@ import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domai
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
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.hql.MongoCriteriaTranslator
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
com.mongodb.MongoClient
;
import
com.mongodb.client.AggregateIterable
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.MongoDatabase
;
import
com.mongodb.client.model.*
;
import
org.bson.BsonDocument
;
import
org.bson.Document
;
import
org.bson.conversions.Bson
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
@Component
public
class
AuthLogDao
extends
StaticCacheDimensionDocumentMongoDao
<
AuthLog
,
String
>
{
...
...
@@ -134,4 +145,44 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
Pageable
pageable
=
new
PageRequest
(
pageNo
-
1
,
pageSize
,
sort
);
return
query
(
query
.
with
(
pageable
));
}
public
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
){
DocumentDatabase
documentDatabase
=
(
DocumentDatabase
)
this
.
getDocumentClass
().
getAnnotation
(
DocumentDatabase
.
class
);
DocumentCollection
documentCollection
=
(
DocumentCollection
)
this
.
getDocumentClass
().
getAnnotation
(
DocumentCollection
.
class
);
MongoClient
mongoClient
=
super
.
getMongoClient
();
MongoDatabase
database
=
mongoClient
.
getDatabase
(
documentDatabase
.
database
());
MongoCollection
<
BsonDocument
>
collection
=
database
.
getCollection
(
documentCollection
.
collection
(),
BsonDocument
.
class
);
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
matchParams
&&
matchParams
.
size
()
>
0
){
matchParams
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
criteria
.
and
(
"createTime"
).
gte
(
beginTime
);
}
List
<
Bson
>
aggregateList
=
new
ArrayList
<>();
BsonDocument
matchDocument
=
MongoCriteriaTranslator
.
INSTANCE
.
translate
(
criteria
);
aggregateList
.
add
(
Aggregates
.
match
(
matchDocument
));
Document
groupBy
=
new
Document
().
append
(
"yearMonthDay"
,
"$yearMonthDay"
).
append
(
"hour"
,
"$hour"
);
aggregateList
.
add
(
Aggregates
.
group
(
groupBy
,
Accumulators
.
sum
(
"count"
,
1
)));
Document
project
=
new
Document
().
append
(
"_id"
,
0
).
append
(
"yearMonthDay"
,
"$_id.yearMonthDay"
).
append
(
"hour"
,
"$_id.hour"
).
append
(
"count"
,
"$count"
);
aggregateList
.
add
(
Aggregates
.
project
(
project
));
aggregateList
.
add
(
Aggregates
.
sort
(
Sorts
.
descending
(
"count"
)));
aggregateList
.
add
(
Aggregates
.
limit
(
topN
));
AggregateIterable
<
AuthLogHourCount
>
iterable
=
collection
.
aggregate
(
aggregateList
,
AuthLogHourCount
.
class
);
List
<
AuthLogHourCount
>
dataList
=
new
ArrayList
<>();
for
(
AuthLogHourCount
item
:
iterable
){
dataList
.
add
(
item
);
}
return
dataList
;
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/model/AuthLogHourCount.java
0 → 100644
View file @
4ebf3eae
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
model
;
import
java.io.Serializable
;
public
class
AuthLogHourCount
implements
Serializable
{
private
String
yearMonthDay
;
private
Integer
hour
;
private
Long
count
;
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/AuthLogService.java
View file @
4ebf3eae
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
service
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -28,4 +29,6 @@ public interface AuthLogService {
void
replace
(
AuthLog
authLog
);
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
);
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
);
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/impl/AuthLogServiceImpl.java
View file @
4ebf3eae
...
...
@@ -3,6 +3,7 @@ package com.chineseall.eden.authcenter.log.service.impl;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
com.chineseall.eden.authcenter.log.dao.AuthLogDao
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -96,4 +97,9 @@ public class AuthLogServiceImpl implements AuthLogService {
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
return
authLogDao
.
listLogWithPage
(
pageNo
,
pageSize
,
prams
);
}
@Override
public
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
)
{
return
authLogDao
.
hourMaxCount
(
matchParams
,
beginTime
,
topN
);
}
}
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