|
|
|
@ -79,8 +79,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
"//sup_cert_set/id///updateTime///供应商资质证书设置","companyCert//sup_company/customerId///updateTime///配送企业",
|
|
|
|
|
"manufacturerCert//sup_manufacturer/id///updateTime///生产企业","productCert//sup_product/id///updateTime///产品资质信息",
|
|
|
|
|
"//udicompany/id///updateTime///国际库医疗器械注册人信息"};
|
|
|
|
|
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
|
|
|
|
|
|
|
|
|
|
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
|
|
|
|
|
private int orderNum=0;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@ -109,7 +108,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
if(map==null)
|
|
|
|
|
ResultVOUtils.error(9000, "下载任务不存在");
|
|
|
|
|
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString());
|
|
|
|
|
|
|
|
|
|
JSONObject object = JSON.parseObject(json);
|
|
|
|
|
if(object!=null&&object.getInteger("code")!=null) {
|
|
|
|
|
BaseResponse response = JSON.parseObject(json,BaseResponse.class);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -130,12 +135,29 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncFetchUdiTask() {
|
|
|
|
|
fetchTask(false);
|
|
|
|
|
}
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
|
|
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
|
fetchTask(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fetchTask(boolean isIdc) {
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
if(!isIdc) {
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
|
if(map!=null&&map.get("syncIp")!=null)
|
|
|
|
|
host = map.get("syncIp").toString();
|
|
|
|
|
}
|
|
|
|
|
logger.info("fetch from ip:"+host);
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
String result = post(host+"/spssync/common/list",query);
|
|
|
|
|
String result = post(host+"/spssync/common/list",null);
|
|
|
|
|
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
|
|
|
|
@ -144,15 +166,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
for(Map map:list) {
|
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
|
params.put("taskId", map.get("taskId"));
|
|
|
|
|
fetchData(host+"/spssync/common/list",params);
|
|
|
|
|
fetchData(host,params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncIdcTask() {
|
|
|
|
@ -233,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()
|
|
|
|
|
.build();
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params));
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(url)
|
|
|
|
|
.url(host+"/spssync/common/download")
|
|
|
|
|
.method("POST", body)
|
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
|
.build();
|
|
|
|
@ -248,15 +269,25 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
try {
|
|
|
|
|
boolean success=true;
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
|
result = response.body().toString();
|
|
|
|
|
result = response.body().string();
|
|
|
|
|
JSONObject json = JSONObject.parseObject(result);
|
|
|
|
|
|
|
|
|
|
if(isLastLevel()) {
|
|
|
|
|
success = analyToDB(json,files);
|
|
|
|
|
if(json.get("code")!=null) {
|
|
|
|
|
success = analyToDB(json.getJSONObject("data"),files);
|
|
|
|
|
} else {
|
|
|
|
|
success = analyToDB(json,files);
|
|
|
|
|
}
|
|
|
|
|
if(!success)
|
|
|
|
|
logger.info("fetchData-->解析失败");
|
|
|
|
|
} else {
|
|
|
|
|
syncAddTaskStatus(json,false,success);
|
|
|
|
|
if(json.get("code")!=null) {
|
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"),false,success);
|
|
|
|
|
} else {
|
|
|
|
|
syncAddTaskStatus(json,false,success);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
if(success) {
|
|
|
|
|
String ret = post(host+"/spssync/common/success",params);
|
|
|
|
|
|
|
|
|
@ -265,6 +296,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.error("fetchData-->"+e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -273,7 +305,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.build();
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params));
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "");
|
|
|
|
|
if(params!=null)
|
|
|
|
|
body = RequestBody.create(mediaType,JSON.toJSONString(params));
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(url)
|
|
|
|
|
.method("POST", body)
|
|
|
|
@ -282,7 +316,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
String result = "";
|
|
|
|
|
try {
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
|
result = response.body().toString();
|
|
|
|
|
result = response.body().string();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -527,7 +561,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
success = false;
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">fail:上传地址未连通",i *limit,total);
|
|
|
|
|
saveIdcLog(messageType,"",syncIp+":"+tableName +">fail:上传地址未连通",i *limit,total);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if(!StringUtils.isEmpty(recordSql)) {
|
|
|
|
@ -567,16 +601,38 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
map.put("taskId", json.get("messageId"));
|
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
|
map.put("status", success ? "1" : "0");
|
|
|
|
|
|
|
|
|
|
saveExportStatus(map);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*解析到数据库*/
|
|
|
|
|
private boolean analyToDB(JSONObject jsonObject,MultipartFile[] files) {
|
|
|
|
|
if(!StringUtils.isEmpty(jsonObject.getString("tableName"))) {
|
|
|
|
|
List<Map<String,Object>> list = jsonObject.getObject("data", List.class);
|
|
|
|
|
return analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list);
|
|
|
|
|
|
|
|
|
|
if(jsonObject.get("data")!=null) {
|
|
|
|
|
logger.error("json>>>>>>>>>");
|
|
|
|
|
String tableName = "";
|
|
|
|
|
String uniqueColumn = "";
|
|
|
|
|
Object object = jsonObject.get("data");
|
|
|
|
|
List<Map<String,Object>> list = new ArrayList<>();
|
|
|
|
|
if(object instanceof List<?>) {
|
|
|
|
|
list = jsonObject.getObject("data", List.class);
|
|
|
|
|
tableName = jsonObject.getString("tableName");
|
|
|
|
|
uniqueColumn = jsonObject.getString("uniqueColumn");
|
|
|
|
|
} else {
|
|
|
|
|
JSONObject obj = jsonObject.getJSONObject("data");
|
|
|
|
|
list = obj.getObject("data", List.class);
|
|
|
|
|
tableName = obj.getString("tableName");
|
|
|
|
|
uniqueColumn = obj.getString("uniqueColumn");
|
|
|
|
|
}
|
|
|
|
|
logger.error("table-->"+tableName);
|
|
|
|
|
if(!StringUtils.isEmpty(tableName)) {
|
|
|
|
|
return analyData(tableName,uniqueColumn,list);
|
|
|
|
|
} else {
|
|
|
|
|
logger.error("数据格式错误:无数据标记");
|
|
|
|
|
}
|
|
|
|
|
//图片处理
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -584,7 +640,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
/*按表名解析数据到数据库,子表暂未处理*/
|
|
|
|
|
private boolean analyData(String tableName,String uniqueColumn,List<Map<String,Object>> list) {
|
|
|
|
|
|
|
|
|
|
logger.error("ana-->"+tableName+"--list-->"+JSON.toJSONString(list));
|
|
|
|
|
String tName = DBAUtils.tableRealName(tableName);
|
|
|
|
|
String sql="replace "+tName +"(";
|
|
|
|
|
String del="delete from "+tName+" where ";
|
|
|
|
@ -698,6 +754,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
if(n>0) {
|
|
|
|
|
result = (dbDao.save(sql)>0);
|
|
|
|
|
if(!result)
|
|
|
|
|
logger.error(tableName+"-->fetchSave Fail");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|