diff --git a/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java b/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java index b0012b06..5ed08118 100644 --- a/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java +++ b/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java @@ -116,9 +116,13 @@ public class IdcServiceImpl implements IdcService { Map map = dbDao.get("select * from basic_export_status where id='"+params.get("taskId")+"'"); if(map==null) ResultVOUtils.error(9000, "下载任务不存在"); + if(!FileUtils.isFileExist(map.get("cacheFilePath").toString())) + ResultVOUtils.error(9000, "下载文件不存在"); String json = FileUtils.readFileAll(map.get("cacheFilePath").toString()); - + JSONObject object = JSON.parseObject(json); + if(object==null) + ResultVOUtils.error(9000, "任务下载失败"); if(object!=null&&object.getInteger("code")!=null) { BaseResponse response = JSON.parseObject(json,BaseResponse.class); return response; @@ -147,14 +151,20 @@ public class IdcServiceImpl implements IdcService { public void asyncFetchUdiTask() { fetchTask(false); } - @Async + @Async @Override public void asyncFetchTask() { + initTable(); + Map map = dbDao.get("select * from idc_var where code='system_type'"); + if(map==null) { + dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')"); + } fetchTask(true); } private void fetchTask(boolean isIdc) { + String host = getNextHost(); if(!isIdc) { Map map = dbDao.get("select * from sync_data_set limit 1"); @@ -284,22 +294,20 @@ public class IdcServiceImpl implements IdcService { JSONObject json = JSONObject.parseObject(result); if(isLastLevel()) { - if(json.get("code")!=null) { + if(json.get("code")!=null&&json.getInteger("code")==2000) { success = analyMiddle(host,json.getJSONObject("data"),files,false,true); + if(!success) + logger.info("fetchData-->解析失败"); } else { - success = analyMiddle(host,json,files,false,true); + success = false; } - if(!success) - logger.info("fetchData-->解析失败"); + } else { - if(json.get("code")!=null) { - + if(json.get("code")!=null&&json.get("data")!=null) { + logger.info("res1-->"+JSON.toJSONString(json)); syncAddTaskStatus(json.getJSONObject("data"),false,success); analyMiddle(host,json.getJSONObject("data"),files,false,false); - } else { - syncAddTaskStatus(json,false,success); - analyMiddle(host,json,files,false,false); - } + } } if(success) { @@ -425,10 +433,14 @@ public class IdcServiceImpl implements IdcService { return ResultVOUtils.error(9999, ""); } + @Override public void downloadFile(String fileName,HttpServletResponse response) { OutputStream os; String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : fileName.substring(0,1).equals("/") ? "" : "/"; + if(!FileUtils.isFileExist(filePath+filePathSlash+fileName)) + fileName = "11.jpg"; + logger.info(filePath+filePathSlash+fileName); try { if(FileUtils.isFileExist(filePath+filePathSlash+fileName)) { byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName); @@ -554,8 +566,14 @@ public class IdcServiceImpl implements IdcService { List list = JSONObject.parseArray(JSON.toJSONString(data.get("data")), Map.class); if(list!=null&&list.size()>0) { for(int m=0;m0) { for(int x=0;x json,boolean isUpload,boolean success) { - String content = JSON.toJSONString(json); - String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd"); - String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; - String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; - if(!FileUtils.makeDirectory( filePath +datePath)) - IDCUtils.createDirectory(filePath +datePath+"/"); - if(!FileUtils.makeDirectory(backFilePath +datePath)) - IDCUtils.createDirectory(filePath +datePath+"/"); - - FileUtils.SaveFileAs(content, fileName); - FileUtils.SaveFileAs(content, backFileName); - - //type,transportType,superiorService,subordinateService,cacheFilePath - Map map = new HashMap<>(); - map.put("type", json.get("messageType")); - map.put("transportType", isUpload ? "1" : "2"); - map.put("scheduleType", isUpload ? "1" : "0"); - map.put("taskId", json.get("messageId")); - map.put("cacheFilePath", fileName); - map.put("status", success ? "1" : "0"); - - saveExportStatus(map); + try + { + String content = JSON.toJSONString(json); + String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd"); + String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; + String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; + if(!FileUtils.makeDirectory( filePath +datePath)) + IDCUtils.createDirectory(filePath +datePath+"/"); + if(!FileUtils.makeDirectory(backFilePath +datePath)) + IDCUtils.createDirectory(filePath +datePath+"/"); + + FileUtils.SaveFileAs(content, fileName); + FileUtils.SaveFileAs(content, backFileName); + + //type,transportType,superiorService,subordinateService,cacheFilePath + Map map = new HashMap<>(); + map.put("type", json.get("messageType")); + map.put("transportType", isUpload ? "1" : "2"); + map.put("scheduleType", isUpload ? "1" : "0"); + map.put("taskId", json.get("messageId")); + map.put("cacheFilePath", fileName); + map.put("status", success ? "1" : "0"); + + saveExportStatus(map); + } catch (Exception ex) { + logger.error(ex.getMessage()); + } } @@ -698,7 +724,7 @@ public class IdcServiceImpl implements IdcService { for(int z=0;z<30;z++) { if(list.get(i).get("data"+z)!=null) { if(list.get(i).get("filePathColumn"+z)!=null) { - List> childList = (ArrayList>)list.get(i).get("data"+z); + List> childList = (List>)list.get(i).get("data"+z); analyToFile(host,list.get(i).get("filePathColumn"+z).toString(),childList); } } else { @@ -903,29 +929,34 @@ public class IdcServiceImpl implements IdcService { boolean success = true; for(String fileName:files) { if(!StringUtils.isEmpty(fileName)) { - if(!signleDownloadFile(syncIp,fileName)) - success = false; + String[] str = fileName.split(","); + for(int i=0;i"+str[i]); + if(!signleDownloadFile(syncIp,str[i])) + success = false; + } + } } } return success; } private boolean signleDownloadFile(String syncIp,String fileName) { - OkHttpClient client = new OkHttpClient(); - RequestBody requestBody = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("fileName", fileName) - .build(); - + OkHttpClient client = new OkHttpClient().newBuilder() + .build();; + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + + RequestBody body = RequestBody.create(mediaType, "fileName="+fileName); Request request = new Request.Builder() .url(syncIp+"/spssync/common/downloadFile") - .post(requestBody) + .post(body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") .build(); try { Response result = client.newCall(request).execute(); - if (MediaType.parse("application/force-download").equals(result.body().contentType())) { try (InputStream inputStream = result.body().byteStream()) { String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : "/";