拉取优化

version1
admin 2 years ago
parent e305c02888
commit 7ff5fb9056

@ -108,9 +108,9 @@ public class IdcServiceImpl implements IdcService {
if(map==null) if(map==null)
ResultVOUtils.error(9000, "下载任务不存在"); ResultVOUtils.error(9000, "下载任务不存在");
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString()); String json = FileUtils.readFileAll(map.get("cacheFilePath").toString());
logger.info("download-->"+json);
JSONObject object = JSON.parseObject(json); JSONObject object = JSON.parseObject(json);
if(object!=null&&object.getInteger("code")!=null&&object.getInteger("code")==20000) { if(object!=null&&object.getInteger("code")!=null) {
BaseResponse response = JSON.parseObject(json,BaseResponse.class); BaseResponse response = JSON.parseObject(json,BaseResponse.class);
return response; return response;
} }
@ -157,7 +157,7 @@ public class IdcServiceImpl implements IdcService {
logger.info("fetch from ip:"+host); logger.info("fetch from ip:"+host);
if(!StringUtils.isEmpty(host)) { if(!StringUtils.isEmpty(host)) {
String result = post(host+"/spssync/common/list",null); String result = post(host+"/spssync/common/list",null);
logger.info("fetchTask--->"+result);
if(IDCUtils.isJson(result)) { if(IDCUtils.isJson(result)) {
JSONObject json = JSON.parseObject(result); JSONObject json = JSON.parseObject(result);
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) { if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
@ -166,7 +166,7 @@ public class IdcServiceImpl implements IdcService {
for(Map map:list) { for(Map map:list) {
Map<String,Object> params = new HashMap<String,Object>(); Map<String,Object> params = new HashMap<String,Object>();
params.put("taskId", map.get("taskId")); params.put("taskId", map.get("taskId"));
fetchData(host+"/spssync/common/download",params); fetchData(host,params);
} }
} }
} }
@ -254,13 +254,13 @@ public class IdcServiceImpl implements IdcService {
private String fetchData(String url,Map<String,Object> params) { private String fetchData(String host,Map<String,Object> params) {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.build(); .build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params)); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params));
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(host+"/spssync/common/download")
.method("POST", body) .method("POST", body)
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
.build(); .build();
@ -270,7 +270,6 @@ public class IdcServiceImpl implements IdcService {
boolean success=true; boolean success=true;
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
result = response.body().string(); result = response.body().string();
logger.info("fetchData-->"+result);
JSONObject json = JSONObject.parseObject(result); JSONObject json = JSONObject.parseObject(result);
if(isLastLevel()) { if(isLastLevel()) {
success = analyToDB(json,files); success = analyToDB(json,files);
@ -280,7 +279,6 @@ public class IdcServiceImpl implements IdcService {
syncAddTaskStatus(json,false,success); syncAddTaskStatus(json,false,success);
} }
String host = getNextHost();
if(success) { if(success) {
String ret = post(host+"/spssync/common/success",params); String ret = post(host+"/spssync/common/success",params);
@ -310,7 +308,6 @@ public class IdcServiceImpl implements IdcService {
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
result = response.body().string(); result = response.body().string();
logger.info("post-result-->"+result);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -607,16 +604,17 @@ public class IdcServiceImpl implements IdcService {
if(jsonObject.getJSONObject("data")!=null) { if(jsonObject.getJSONObject("data")!=null) {
JSONObject object = jsonObject.getJSONObject("data"); JSONObject object = jsonObject.getJSONObject("data");
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String,Object>> list = new ArrayList<>();
if(object instanceof List<?>) { if(object instanceof List<?>) {
list = jsonObject.getObject("data", List.class); list = jsonObject.getObject("data", List.class);
} else { } else {
object = jsonObject; list = object.getObject("data", List.class);
if(object.get("data")!=null)
list = object.getObject("data", List.class); }
if(!StringUtils.isEmpty(object.getString("tableName"))) {
return analyData(object.getString("tableName"),object.getString("uniqueColumn"),list);
} else {
logger.error("数据格式错误:无数据标记");
} }
if(!StringUtils.isEmpty(object.getString("tableName")))
return analyData(object.getString("tableName"),jsonObject.getString("uniqueColumn"),list);
//图片处理 //图片处理
} }
return false; return false;
@ -738,6 +736,8 @@ public class IdcServiceImpl implements IdcService {
} }
if(n>0) { if(n>0) {
result = (dbDao.save(sql)>0); result = (dbDao.save(sql)>0);
if(!result)
logger.error(tableName+"-->fetchSave Fail");
} }
} }

@ -35,7 +35,7 @@ public class AsyncFetchTask implements SchedulingConfigurer {
scheduledRequest.setCronName("syncFetch"); scheduledRequest.setCronName("syncFetch");
logger.info("syncFetch----------------"); logger.info("syncFetch----------------");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 0/5 * * * ?"; String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 0/2 * * * ?";
if (cron.isEmpty()) { if (cron.isEmpty()) {
logger.error("cron is null"); logger.error("cron is null");

Loading…
Cancel
Save