Commit d7afc7a0 by chentian

调整

parent 523684ad
...@@ -35,7 +35,7 @@ public class TrackDataJob implements BaseJob { ...@@ -35,7 +35,7 @@ public class TrackDataJob implements BaseJob {
} }
public void execute(JobExecutionContext context) public void execute(JobExecutionContext context)
throws JobExecutionException { throws JobExecutionException {
_log.error("TrackData Job执行时间: " + new Date()); _log.error("TrackData Job执行时间: " + new Date());
JobKey key = context.getJobDetail().getKey();//获取JobDetail的标识信息 JobKey key = context.getJobDetail().getKey();//获取JobDetail的标识信息
...@@ -50,8 +50,33 @@ public class TrackDataJob implements BaseJob { ...@@ -50,8 +50,33 @@ public class TrackDataJob implements BaseJob {
//1.比对源执行dataimport,获取增量count,如果count等于null,或者等于"" 把它设为0,如果增量>0,则进入数据比对入库 //1.比对源执行dataimport,获取增量count,如果count等于null,或者等于"" 把它设为0,如果增量>0,则进入数据比对入库
Properties properties = propertiesUtil.propertiesUtil("solr.properties"); Properties properties = propertiesUtil.propertiesUtil("solr.properties");
String url= properties.getProperty("comparisonsolrdata"); 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"); 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"); String json = HttpClientUtil.doPost(url+core+"/dataimport?command=delta-import&clean=false&commit=true");
//根据第二次运行的结果才是准确的更新 //根据第二次运行的结果才是准确的更新
...@@ -64,21 +89,44 @@ public class TrackDataJob implements BaseJob { ...@@ -64,21 +89,44 @@ public class TrackDataJob implements BaseJob {
if(count==null || "".equals(count)){ if(count==null || "".equals(count)){
count="0"; 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为条件去比对源里查询增量数据。 //2.查询数据源里的ID,用fq:ID不等于 数据源里的ID为条件去比对源里查询增量数据。
if(Integer.parseInt(count)>0){ 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库 //25从比对源里查询出的增量 然后去数据源里查。如果存在。则这条不入oracle库
HttpSolrClient client = new HttpSolrClient(url); client = new HttpSolrClient(url);
SolrQuery params = new SolrQuery(); params = new SolrQuery();
//q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询 //q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询
params.set("q", "*:*"); params.set("q", "*:*");
// 排序 // 排序
params.addSort("DJSJ", SolrQuery.ORDER.desc);//按照djsj降序排序。然后取出增量数据 params.addSort("DJSJ", SolrQuery.ORDER.desc);//按照djsj降序排序。然后取出增量数据
params.setStart(0); params.setStart(0);
params.setRows(Integer.parseInt(count)); int rows=Integer.parseInt(count)*10;
params.setRows(rows);//放大十倍查询结果,为了不丢失数据
//执行搜索 //执行搜索
QueryResponse queryResponse = null; // QueryResponse queryResponse = null;
try { try {
queryResponse = client.query(core, params); queryResponse = client.query(core, params);
} catch (SolrServerException e) { } catch (SolrServerException e) {
...@@ -88,10 +136,9 @@ public class TrackDataJob implements BaseJob { ...@@ -88,10 +136,9 @@ public class TrackDataJob implements BaseJob {
} }
//搜索结果 //搜索结果
SolrDocumentList results = queryResponse.getResults(); SolrDocumentList results = queryResponse.getResults();
System.out.println("查询比对源条数:"+results.size()); System.out.println("3:查询比对源条数:"+results.size());
int savecount=0; int savecount=0;
for (SolrDocument solrDocument : results) { for (SolrDocument solrDocument : results) {
String sourceUrl= properties.getProperty("sourcesolrdata");
client = new HttpSolrClient(sourceUrl); client = new HttpSolrClient(sourceUrl);
params = new SolrQuery(); params = new SolrQuery();
//q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询 //q 查询字符串,如果查询所有*:* keywords:*15* 模糊查询
...@@ -113,9 +160,10 @@ public class TrackDataJob implements BaseJob { ...@@ -113,9 +160,10 @@ public class TrackDataJob implements BaseJob {
savecount++; savecount++;
} }
} }
System.out.println("保存条数:"+savecount); System.out.println("4:保存条数:"+savecount);
} }
}
} }
//保存基站信息 //保存基站信息
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment