secure file fix

master
yixian 6 years ago
parent d05a3f9522
commit 1178b46859

@ -458,9 +458,8 @@ public class TestController implements ApplicationEventPublisherAware {
} }
@ManagerMapping(value = "/secure/hanyin_reports/{date}", role = ManagerRole.DEVELOPER, method = RequestMethod.GET) @ManagerMapping(value = "/secure/hanyin_reports/{date}", role = ManagerRole.DEVELOPER, method = RequestMethod.GET)
public void downloadHanyinSecureReports(@PathVariable String date, HttpServletResponse response) { public void downloadHanyinSecureReports(@PathVariable String date) {
TradeSecureFile file = tradeSecureService.getSecureReportFile(DateTime.parse(date).toDate()); tradeSecureService.uploadSecureReport(DateTime.parse(date).toDate());
file.writeToHttp(response);
} }
} }

@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Vector;
/** /**
* Create by yixian at 2019-01-08 3:26 * Create by yixian at 2019-01-08 3:26
@ -66,15 +67,15 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
Channel channel = session.openChannel("sftp"); Channel channel = session.openChannel("sftp");
channel.connect(); channel.connect();
command = (ChannelSftp) channel; command = (ChannelSftp) channel;
command.ls("/royalpay"); String dateString = file.getTransDate().toString("yyyyMMdd");
String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd"); Vector<ChannelSftp.LsEntry> folders = command.ls("/royalpay");
logger.debug("removing dir:{}", dir); String dir = "/royalpay/" + dateString;
command.rmdir(dir); if (folders.parallelStream().noneMatch(entry -> entry.getFilename().equals(dateString))) {
logger.debug("rmdir success");
logger.debug("mk dir:{}", dir); logger.debug("mk dir:{}", dir);
command.mkdir(dir); command.mkdir(dir);
}
String dest = dir + file.filename(); 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); command.put(new ByteArrayInputStream(file.content()), dest);
} catch (IOException | JSchException | SftpException e) { } catch (IOException | JSchException | SftpException e) {
throw new ChannelNetworkException("Upload Secure file failed", e); throw new ChannelNetworkException("Upload Secure file failed", e);

Loading…
Cancel
Save