Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SolrDataComparison
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
常超
SolrDataComparison
Commits
d7afc7a0
Commit
d7afc7a0
authored
Mar 29, 2019
by
chentian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整
parent
523684ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
10 deletions
+58
-10
src/main/java/com/cc/solr/job/TrackDataJob.java
+58
-10
No files found.
src/main/java/com/cc/solr/job/TrackDataJob.java
View file @
d7afc7a0
...
...
@@ -35,7 +35,7 @@ public class TrackDataJob implements BaseJob {
}
public
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
throws
JobExecutionException
{
_log
.
error
(
"TrackData Job执行时间: "
+
new
Date
());
JobKey
key
=
context
.
getJobDetail
().
getKey
();
//获取JobDetail的标识信息
...
...
@@ -50,8 +50,33 @@ public class TrackDataJob implements BaseJob {
//1.比对源执行dataimport,获取增量count,如果count等于null,或者等于"" 把它设为0,如果增量>0,则进入数据比对入库
Properties
properties
=
propertiesUtil
.
propertiesUtil
(
"solr.properties"
);
String
url
=
properties
.
getProperty
(
"comparisonsolrdata"
);
String
sourceUrl
=
properties
.
getProperty
(
"sourcesolrdata"
);
System
.
out
.
println
(
"开始执行。。。。。。。。。。。"
);
//查询参数
Map
<
String
,
String
>
param
=
new
HashMap
<>();
//28查询比对源总数 begin
HttpSolrClient
client
=
new
HttpSolrClient
(
url
);
SolrQuery
params
=
new
SolrQuery
();
//q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询
params
.
set
(
"q"
,
"*:*"
);
//执行搜索
QueryResponse
queryResponse
=
null
;
long
compareTotal
=
0
;
//执行增量前比对源数据总数
long
compareAfterTotal
=
0
;
//执行增量后比对源数据总数
try
{
queryResponse
=
client
.
query
(
core
,
params
);
SolrDocumentList
results
=
queryResponse
.
getResults
();
// 数量,分页用
compareTotal
=
results
.
getNumFound
();
}
catch
(
SolrServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//28查询比对源总数 end
System
.
out
.
println
(
"更新实例地址============="
+
url
+
core
+
"/dataimport?command=delta-import&clean=false&commit=true"
);
String
json
=
HttpClientUtil
.
doPost
(
url
+
core
+
"/dataimport?command=delta-import&clean=false&commit=true"
);
//根据第二次运行的结果才是准确的更新
...
...
@@ -64,21 +89,44 @@ public class TrackDataJob implements BaseJob {
if
(
count
==
null
||
""
.
equals
(
count
)){
count
=
"0"
;
}
System
.
out
.
println
(
"更新条数:"
+
count
);
System
.
out
.
println
(
"1:更新条数:"
+
count
);
//28 执行完增量之后,再查询一次比对源数据总量
try
{
queryResponse
=
client
.
query
(
core
,
params
);
SolrDocumentList
results
=
queryResponse
.
getResults
();
// 数量,分页用
compareAfterTotal
=
results
.
getNumFound
();
}
catch
(
SolrServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//28 执行完增量之后,再查询一次比对源数据总量
//2.查询数据源里的ID,用fq:ID不等于 数据源里的ID为条件去比对源里查询增量数据。
if
(
Integer
.
parseInt
(
count
)>
0
){
//28用增量结束后的总数减去增量前的总数 和 获取到的count比较,如果大于0小于等于count 则进入: begin
int
total
=(
int
)
compareAfterTotal
-(
int
)
compareTotal
;
System
.
out
.
println
(
"2:比对源相减结果:"
+
total
);
if
((
total
>
0
&&
total
<=
Integer
.
parseInt
(
count
))){
//28用增量结束后的总数减去增量前的总数 和 获取到的count比较,如果大于0小于等于count 则进入: end
//25从比对源里查询出的增量 然后去数据源里查。如果存在。则这条不入oracle库
HttpSolrClient
client
=
new
HttpSolrClient
(
url
);
SolrQuery
params
=
new
SolrQuery
();
client
=
new
HttpSolrClient
(
url
);
params
=
new
SolrQuery
();
//q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询
params
.
set
(
"q"
,
"*:*"
);
// 排序
params
.
addSort
(
"DJSJ"
,
SolrQuery
.
ORDER
.
desc
);
//按照djsj降序排序。然后取出增量数据
params
.
setStart
(
0
);
params
.
setRows
(
Integer
.
parseInt
(
count
));
int
rows
=
Integer
.
parseInt
(
count
)*
10
;
params
.
setRows
(
rows
);
//放大十倍查询结果,为了不丢失数据
//执行搜索
QueryResponse
queryResponse
=
null
;
//
QueryResponse queryResponse = null;
try
{
queryResponse
=
client
.
query
(
core
,
params
);
}
catch
(
SolrServerException
e
)
{
...
...
@@ -88,10 +136,9 @@ public class TrackDataJob implements BaseJob {
}
//搜索结果
SolrDocumentList
results
=
queryResponse
.
getResults
();
System
.
out
.
println
(
"查询比对源条数:"
+
results
.
size
());
System
.
out
.
println
(
"
3:
查询比对源条数:"
+
results
.
size
());
int
savecount
=
0
;
for
(
SolrDocument
solrDocument
:
results
)
{
String
sourceUrl
=
properties
.
getProperty
(
"sourcesolrdata"
);
client
=
new
HttpSolrClient
(
sourceUrl
);
params
=
new
SolrQuery
();
//q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询
...
...
@@ -113,9 +160,10 @@ public class TrackDataJob implements BaseJob {
savecount
++;
}
}
System
.
out
.
println
(
"保存条数:"
+
savecount
);
System
.
out
.
println
(
"
4:
保存条数:"
+
savecount
);
}
}
}
//保存基站信息
...
...
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