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
8b056187
Commit
8b056187
authored
Dec 14, 2023
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改年月日调用量查询
parent
f870502a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
2 deletions
+53
-2
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
+53
-2
No files found.
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
View file @
8b056187
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.date.DateUtil
;
import
co.elastic.clients.elasticsearch.ElasticsearchClient
;
import
co.elastic.clients.elasticsearch.core.BulkRequest
;
import
co.elastic.clients.elasticsearch.core.BulkResponse
;
import
co.elastic.clients.elasticsearch.core.DeleteByQueryResponse
;
import
co.elastic.clients.elasticsearch.core.GetResponse
;
import
co.elastic.clients.elasticsearch.indices.DeleteIndexResponse
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord3
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord3Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord4Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.
HashMap
;
import
java.util.
Map
;
import
java.util.
*
;
import
java.util.
stream.Collectors
;
/**
* @author Hmb
...
...
@@ -29,6 +40,15 @@ public class ElasticSearchService{
private
static
final
Map
<
Character
,
String
>
SPECIAL_CHARACTERS_MAP
=
new
HashMap
<>();
private
static
String
lastIndexTime
=
"2023-11-30 00:00:00"
;
@Resource
private
AppAbilityRecordAllMapper
recordAllMapper
;
@Resource
private
AppAbilityRecord4Mapper
record4Mapper
;
@Resource
private
AppAbilityRecord3Mapper
record3Mapper
;
static
{
SPECIAL_CHARACTERS_MAP
.
put
(
'['
,
"\\["
);
SPECIAL_CHARACTERS_MAP
.
put
(
']'
,
"\\]"
);
...
...
@@ -75,4 +95,35 @@ public class ElasticSearchService{
DeleteByQueryResponse
deleteByQueryResponse
=
client
.
deleteByQuery
(
s
->
s
.
index
(
index
).
query
(
q
->
q
.
matchAll
(
m
->
m
)));
log
.
info
(
"删除索引文档操作结果:{}"
,
deleteByQueryResponse
.
deleted
());
}
@Scheduled
(
fixedDelayString
=
"10000"
)
private
void
dataImport
()
{
String
startTime
=
lastIndexTime
;
String
endTime
=
""
;
while
(!
DateUtil
.
parse
(
startTime
,
"yyyy-MM-dd HH:mm:ss"
).
after
(
new
Date
()))
{
endTime
=
DateUtil
.
offsetHour
(
DateUtil
.
parse
(
startTime
,
"yyyy-MM-dd HH:mm:ss"
),
4
).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
// List<AppAbilityRecordAll> documentList = recordAllMapper.selectList(Wrappers.lambdaQuery(AppAbilityRecordAll.class).between(AppAbilityRecordAll::getCallTime, startTime, endTime));
List
<
AppAbilityRecord3
>
documentList
=
record3Mapper
.
selectList
(
Wrappers
.
lambdaQuery
(
AppAbilityRecord3
.
class
).
between
(
AppAbilityRecord3:
:
getCallTime
,
startTime
,
endTime
));
documentList
=
documentList
.
stream
().
sorted
(
Comparator
.
comparing
(
AppAbilityRecord3:
:
getCallTime
)).
collect
(
Collectors
.
toList
());
if
(
CollUtil
.
isNotEmpty
(
documentList
))
{
BulkRequest
.
Builder
br
=
new
BulkRequest
.
Builder
();
documentList
.
forEach
(
document
->
br
.
operations
(
bo
->
bo
.
index
(
io
->
io
.
index
(
"app_ability_record"
).
id
(
String
.
valueOf
(
document
.
getId
())).
document
(
document
))));
BulkResponse
response
=
null
;
try
{
response
=
client
.
bulk
(
br
.
build
());
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
log
.
info
(
"是否发生错误:{}"
,
response
.
errors
());
log
.
info
(
"调用记录增量数据条数:{}"
,
documentList
.
size
());
}
startTime
=
endTime
;
}
lastIndexTime
=
DateUtil
.
formatDateTime
(
new
Date
());
log
.
info
(
"app_ability_record索引最后更新时间:{}"
,
lastIndexTime
);
}
}
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