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..18bd9dc9f 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 dest = dir + file.filename(); - logger.debug("rmdir success, start uploading file:{}", dest); + String dateString = file.getTransDate().toString("yyyyMMdd"); + Vector folders = command.ls("/royalpay"); + String dir = "/royalpay/" + dateString; + if (folders.parallelStream().noneMatch(entry -> entry.getFilename().endsWith(dateString))) { + logger.debug("mk dir:{}", dir); + command.mkdir(dir); + } + String dest = dir + "/" + file.filename(); + 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);