Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
ocrCloudPlatForm
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
ocr-cloud-platform
ocrCloudPlatForm
Commits
ec76952a
Commit
ec76952a
authored
Apr 19, 2024
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改/stat/getBrokenLineData接口参数
parent
6f7d1c5b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
6 deletions
+124
-6
src/main/java/com/gxmailu/ocrCloudPlatform/controller/StatController.java
+5
-3
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/StatService.java
+119
-3
No files found.
src/main/java/com/gxmailu/ocrCloudPlatform/controller/StatController.java
View file @
ec76952a
...
...
@@ -32,13 +32,15 @@ public class StatController {
@ApiOperation
(
value
=
"获取调用信息数据"
)
@ApiImplicitParams
(
value
=
{
@ApiImplicitParam
(
name
=
"interval"
,
value
=
"时间间隔,可选值[year|month|day|hour|minute|second]"
,
dataType
=
"String"
,
required
=
false
),
@ApiImplicitParam
(
name
=
"startDate"
,
value
=
"开始日期范围,非必填,为空则默认当日"
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"endDate"
,
value
=
"结束日期范围,非必填"
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"displayType"
,
value
=
"展示类型,总体量或各法院使用量可选值[detailed|full]"
,
dataType
=
"String"
,
required
=
false
),
})
@GetMapping
(
"/getBrokenLineData"
)
public
Result
getBrokenLineData
(
@RequestParam
(
value
=
"interval"
,
defaultValue
=
"minute"
)
String
interval
,
public
Result
getBrokenLineData
(
@RequestParam
(
value
=
"startDate"
,
required
=
false
)
String
startDate
,
@RequestParam
(
value
=
"endDate"
,
required
=
false
)
String
endDate
,
@RequestParam
(
value
=
"displayType"
,
defaultValue
=
"full"
)
String
displayType
)
{
return
statService
.
getBrokenLineData
(
interval
,
displayType
);
return
statService
.
getBrokenLineData
(
startDate
,
endDate
,
"interval"
,
displayType
);
}
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/StatService.java
View file @
ec76952a
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.StrUtil
;
...
...
@@ -46,11 +47,11 @@ public class StatService {
private
static
final
String
APP_ABILITY_RECORD_INDEX
=
"app_ability_record"
;
public
Result
getBrokenLineData
(
String
interval
,
String
displayType
)
{
public
Result
getBrokenLineData
(
String
startDate
,
String
endDate
,
String
interval
,
String
displayType
)
{
try
{
List
<
BrokenLineData
>
brokenLineData
=
new
ArrayList
<>();
if
(
displayType
.
equals
(
"full"
))
{
return
Result
.
success
(
"获取折线数据成功"
,
getLineData
(
interval
,
null
));
return
Result
.
success
(
"获取折线数据成功"
,
getLineData
(
startDate
,
endDate
,
interval
,
null
));
}
else
{
List
<
Court
>
courtList
=
courtService
.
getCourtList
()
...
...
@@ -59,7 +60,7 @@ public class StatService {
.
collect
(
Collectors
.
toList
());
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Court
court
:
courtList
)
{
List
<
BrokenLineData
>
lineData
=
getLineData
(
interval
,
court
);
List
<
BrokenLineData
>
lineData
=
getLineData
(
startDate
,
endDate
,
interval
,
court
);
map
.
put
(
court
.
getForSort
(),
lineData
);
}
...
...
@@ -73,6 +74,121 @@ public class StatService {
}
}
public
List
<
BrokenLineData
>
getLineData
(
String
startDate
,
String
endDate
,
String
interval
,
Court
court
)
{
List
<
BrokenLineData
>
resultList
=
new
ArrayList
<>();
// String startTime = DateUtil.beginOfDay(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// String endTime = DateUtil.beginOfDay(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
String
startTime
=
DateUtil
.
beginOfDay
(
DateUtil
.
parseDate
(
"2024-01-23"
)).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
String
endTime
=
DateUtil
.
endOfDay
(
DateUtil
.
parseDate
(
"2024-01-23"
)).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
CalendarInterval
defaultInterval
=
CalendarInterval
.
Minute
;
// switch (interval) {
// case "year":
// startTime = DateUtil.beginOfYear(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// endTime = DateUtil.endOfYear(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// defaultInterval = CalendarInterval.Month;
// break;
// case "month":
// // startTime = DateUtil.beginOfMonth(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// // endTime = DateUtil.endOfMonth(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// startTime = DateUtil.beginOfMonth(DateUtil.parseDate("2024-01-23")).toString("yyyy-MM-dd HH:mm:ss");
// endTime = DateUtil.endOfMonth(DateUtil.parseDate("2024-01-23")).toString("yyyy-MM-dd HH:mm:ss");
// defaultInterval = CalendarInterval.Day;
// break;
// case "day":
// defaultInterval = CalendarInterval.Hour;
// break;
// case "hour":
// break;
// case "minute":
// break;
// case "second":
// defaultInterval = CalendarInterval.Second;
// break;
// }
String
newEndDate
=
""
;
if
(
StrUtil
.
isNotBlank
(
startDate
))
{
int
count
=
startDate
.
split
(
"-"
).
length
;
switch
(
count
)
{
case
1
:
DateTime
year
=
DateUtil
.
parse
(
startDate
,
"yyyy"
);
startDate
=
DateUtil
.
beginOfYear
(
year
).
toString
();
newEndDate
=
DateUtil
.
endOfYear
(
year
).
toString
();
defaultInterval
=
CalendarInterval
.
Month
;
break
;
case
2
:
DateTime
yearMonth
=
DateUtil
.
parse
(
startDate
,
"yyyy-MM"
);
startDate
=
DateUtil
.
beginOfMonth
(
yearMonth
).
toString
();
newEndDate
=
DateUtil
.
endOfMonth
(
yearMonth
).
toString
();
defaultInterval
=
CalendarInterval
.
Day
;
break
;
case
3
:
DateTime
yearMonthDayDateTime
=
DateUtil
.
parse
(
startDate
,
"yyyy-MM-dd"
);
startDate
=
DateUtil
.
beginOfDay
(
yearMonthDayDateTime
).
toString
();
newEndDate
=
DateUtil
.
endOfDay
(
yearMonthDayDateTime
).
toString
();
defaultInterval
=
CalendarInterval
.
Hour
;
break
;
}
}
else
{
// startTime = DateUtil.beginOfDay(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
// newEndDate = DateUtil.beginOfDay(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
startDate
=
DateUtil
.
beginOfDay
(
DateUtil
.
parseDate
(
"2024-01-23"
)).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
newEndDate
=
DateUtil
.
endOfDay
(
DateUtil
.
parseDate
(
"2024-01-23"
)).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
defaultInterval
=
CalendarInterval
.
Minute
;
}
endDate
=
StrUtil
.
isBlank
(
endDate
)
?
newEndDate
:
endDate
;
try
{
String
finalStartTime
=
startDate
;
String
finalEndTime
=
endDate
;
CalendarInterval
finalDefaultInterval
=
defaultInterval
;
SearchResponse
<
Void
>
search
=
client
.
search
(
srBuilder
->
srBuilder
.
index
(
APP_ABILITY_RECORD_INDEX
).
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
// 日期范围查询
boolQuery
.
must
(
q
->
q
.
range
(
rangeQueryBuilder
->
rangeQueryBuilder
.
field
(
"callTime"
)
.
gte
(
JsonData
.
of
(
finalStartTime
))
.
lte
(
JsonData
.
of
(
finalEndTime
))
));
boolQuery
.
must
(
mustQuery
->
mustQuery
.
bool
(
bq
->
{
if
(
ObjUtil
.
isNotNull
(
court
))
{
List
<
String
>
ipScopes
=
StrUtil
.
splitTrim
(
court
.
getIpScope
(),
"-"
);
try
{
List
<
String
>
ipRange
=
ipScopes
.
size
()
!=
2
?
Arrays
.
asList
(
"255.255.255.255"
,
"255.255.255.255"
)
:
IpUtils
.
getIPRange
(
ipScopes
.
get
(
0
),
ipScopes
.
get
(
1
),
3
);
ipRange
.
forEach
(
ip
->
bq
.
should
(
q
->
q
.
prefix
(
pq
->
pq
.
field
(
"ip.keyword"
).
value
(
ip
))));
}
catch
(
Exception
e
)
{
log
.
error
(
"IP段解析错误"
,
e
);
}
}
return
bq
;
}));
return
boolQuery
;
// 聚合查询,按每一分钟为间隔查询每分钟的调用量
})).
aggregations
(
"record"
,
agg
->
agg
.
dateHistogram
(
DateHistogramAggregation
.
of
(
s
->
s
.
field
(
"callTime"
).
calendarInterval
(
finalDefaultInterval
)))
.
aggregations
(
"fileCount"
,
fileCountAgg
->
fileCountAgg
.
sum
(
SumAggregation
.
of
(
s
->
s
.
field
(
"fileCount"
)))))
.
trackTotalHits
(
tb
->
tb
.
enabled
(
true
)),
Void
.
class
);
List
<
DateHistogramBucket
>
recordBcketList
=
search
.
aggregations
().
get
(
"record"
).
dateHistogram
().
buckets
().
array
();
recordBcketList
.
forEach
(
recordBucket
->
{
BrokenLineData
brokenLineData
=
new
BrokenLineData
();
String
time
=
StrUtil
.
isBlank
(
recordBucket
.
keyAsString
())
?
""
:
recordBucket
.
keyAsString
();
brokenLineData
.
setTime
(
time
);
long
value
=
(
long
)
recordBucket
.
aggregations
().
get
(
"fileCount"
).
sum
().
value
();
brokenLineData
.
setValue
(
value
);
resultList
.
add
(
brokenLineData
);
});
return
resultList
;
}
catch
(
IOException
e
)
{
log
.
error
(
"获取折线图数据失败"
,
e
);
return
resultList
;
}
}
public
List
<
BrokenLineData
>
getLineData
(
String
interval
,
Court
court
)
{
List
<
BrokenLineData
>
resultList
=
new
ArrayList
<>();
...
...
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