diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java index 8611fcd09..4276877f0 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java @@ -18,10 +18,10 @@ import com.glxp.api.req.sync.BasicExportTimeRequest; import com.glxp.api.req.sync.ManualUploadDataReq; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.res.PageSimpleResponse; -import com.glxp.api.res.system.SyncDataSetResponse; -import com.glxp.api.service.sync.*; -import com.glxp.api.task.TaskExecutorConfig; -import com.glxp.api.util.BeanCopyUtils; +import com.glxp.api.service.sync.BasicDownloadService; +import com.glxp.api.service.sync.BasicExportService; +import com.glxp.api.service.sync.BasicExportTimeService; +import com.glxp.api.service.sync.HeartService; import com.glxp.api.util.DateUtil; import com.glxp.api.util.RedisUtil; import lombok.RequiredArgsConstructor; 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 80854e168..52207534d 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 @@ -1162,11 +1162,68 @@ public class IdcServiceImpl implements IdcService { return success; } + @Override + public boolean signleDownloadFile(String syncIp, String fileName) { + String filePathSlash = fileName.substring(filePath.length() - 1).equals("/") ? "" : "/"; + if(!FileUtils.makeDirectory(filePath + filePathSlash + imagePath)) + IDCUtils.createDirectory(filePath + filePathSlash + imagePath); + 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(body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .build(); + int total = 0; + try { + Response result = client.newCall(request).execute(); + String msg = result!=null ? result.message().length()>200 ? result.message().substring(0,200) : result.message() : ""; + + if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) { + try (InputStream inputStream = result.body().byteStream()) { + + + FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + imagePath+fileName); + + byte b[] = new byte[1024]; + + int len = 0; + while ((len = inputStream.read(b)) != -1) { + total += len; + outputStream.write(b, 0, len); + + } + + outputStream.flush(); + outputStream.close(); + if(!(total>0)) { + new File(filePath + filePathSlash + imagePath+fileName).delete(); + executeSql("delete from idc_file where filePath='"+fileName+"'"); + } + + } catch (Exception e) { + + + } + } + if(!(total>0)) { + String sql = "replace idc_file (filePath,createTime,msg) values ('"+fileName+"',now(),'"+msg+"')"; + executeSql(sql); + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return (total>0); + } // @Override // public boolean signleDownloadFile(String syncIp, String fileName) { -// String filePathSlash = fileName.substring(filePath.length() - 1).equals("/") ? "" : "/"; -// if(!FileUtils.makeDirectory(filePath + filePathSlash + imagePath)) -// IDCUtils.createDirectory(filePath + filePathSlash + imagePath); // OkHttpClient client = new OkHttpClient().newBuilder() // .build(); // ; @@ -1187,8 +1244,12 @@ public class IdcServiceImpl implements IdcService { // if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) { // try (InputStream inputStream = result.body().byteStream()) { // +// String path = fileName.substring(0,fileName.lastIndexOf("/")); +// if(!FileUtils.makeDirectory(path)) +// IDCUtils.createDirectory(path); // -// FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + imagePath+fileName); +// +// FileOutputStream outputStream = new FileOutputStream(fileName); // // byte b[] = new byte[1024]; // @@ -1202,7 +1263,7 @@ public class IdcServiceImpl implements IdcService { // outputStream.flush(); // outputStream.close(); // if(!(total>0)) { -// new File(filePath + filePathSlash + imagePath+fileName).delete(); +// new File(fileName).delete(); // executeSql("delete from idc_file where filePath='"+fileName+"'"); // } // @@ -1222,67 +1283,6 @@ public class IdcServiceImpl implements IdcService { // } // return (total>0); // } - @Override - public boolean signleDownloadFile(String syncIp, String fileFullName) { - OkHttpClient client = new OkHttpClient().newBuilder() - .build(); - ; - MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - - RequestBody body = RequestBody.create(mediaType, "fileName=" + fileFullName); - - Request request = new Request.Builder() - .url(syncIp + "/spssync/common/downloadFile") - .post(body) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .build(); - int total = 0; - try { - Response result = client.newCall(request).execute(); - String msg = result!=null ? result.message().length()>200 ? result.message().substring(0,200) : result.message() : ""; - - if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) { - try (InputStream inputStream = result.body().byteStream()) { - - String path = fileFullName.substring(0,fileFullName.lastIndexOf("/")); - if(!FileUtils.makeDirectory(path)) - IDCUtils.createDirectory(path); - - - FileOutputStream outputStream = new FileOutputStream(fileFullName); - - byte b[] = new byte[1024]; - - int len = 0; - while ((len = inputStream.read(b)) != -1) { - total += len; - outputStream.write(b, 0, len); - - } - - outputStream.flush(); - outputStream.close(); - if(!(total>0)) { - new File(fileFullName).delete(); - executeSql("delete from idc_file where filePath='"+fileFullName+"'"); - } - - } catch (Exception e) { - - - } - } - if(!(total>0)) { - String sql = "replace idc_file (filePath,createTime,msg) values ('"+fileFullName+"',now(),'"+msg+"')"; - executeSql(sql); - } - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return (total>0); - } /*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/ private String getNextHost() {