From 1178b46859ee6116ddff719f181ce9dd7859b26b Mon Sep 17 00:00:00 2001 From: yixian Date: Fri, 11 Jan 2019 09:45:34 +0800 Subject: [PATCH] secure file fix --- .../payment/manage/dev/web/TestController.java | 5 ++--- .../core/impl/TradeSecureServiceHanyinImpl.java | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java index 4e823422f..570197848 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java @@ -458,9 +458,8 @@ public class TestController implements ApplicationEventPublisherAware { } @ManagerMapping(value = "/secure/hanyin_reports/{date}", role = ManagerRole.DEVELOPER, method = RequestMethod.GET) - public void downloadHanyinSecureReports(@PathVariable String date, HttpServletResponse response) { - TradeSecureFile file = tradeSecureService.getSecureReportFile(DateTime.parse(date).toDate()); - file.writeToHttp(response); + public void downloadHanyinSecureReports(@PathVariable String date) { + tradeSecureService.uploadSecureReport(DateTime.parse(date).toDate()); } } diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java index 34ffe6f09..bf1f77bf8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java @@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Date; import java.util.List; +import java.util.Vector; /** * Create by yixian at 2019-01-08 3:26 @@ -66,15 +67,15 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService { Channel channel = session.openChannel("sftp"); channel.connect(); command = (ChannelSftp) channel; - command.ls("/royalpay"); - String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd"); - logger.debug("removing dir:{}", dir); - command.rmdir(dir); - logger.debug("rmdir success"); - logger.debug("mk dir:{}", dir); - command.mkdir(dir); + String dateString = file.getTransDate().toString("yyyyMMdd"); + Vector folders = command.ls("/royalpay"); + String dir = "/royalpay/" + dateString; + if (folders.parallelStream().noneMatch(entry -> entry.getFilename().equals(dateString))) { + logger.debug("mk dir:{}", dir); + command.mkdir(dir); + } String dest = dir + file.filename(); - logger.debug("rmdir success, start uploading file:{}", dest); + logger.debug("find dir, start uploading file:{}", dest); command.put(new ByteArrayInputStream(file.content()), dest); } catch (IOException | JSchException | SftpException e) { throw new ChannelNetworkException("Upload Secure file failed", e);