|
|
@ -4,7 +4,6 @@ import au.com.royalpay.payment.manage.analysis.beans.ato.*;
|
|
|
|
import au.com.royalpay.payment.manage.analysis.core.ATOReportService;
|
|
|
|
import au.com.royalpay.payment.manage.analysis.core.ATOReportService;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
@ -12,8 +11,9 @@ import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import org.apache.commons.codec.Charsets;
|
|
|
|
import org.apache.commons.codec.Charsets;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
@ -28,9 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -54,13 +52,11 @@ public class ATOReportServiceImpl implements ATOReportService {
|
|
|
|
private Map<String, String> industryMap;
|
|
|
|
private Map<String, String> industryMap;
|
|
|
|
private final StringRedisTemplate redisTemplate;
|
|
|
|
private final StringRedisTemplate redisTemplate;
|
|
|
|
private final String prefix;
|
|
|
|
private final String prefix;
|
|
|
|
private final AttachmentClient client;
|
|
|
|
|
|
|
|
private Progress progress;
|
|
|
|
private Progress progress;
|
|
|
|
|
|
|
|
|
|
|
|
public ATOReportServiceImpl(StringRedisTemplate redisTemplate, @Value("${app.redis.prefix}") String prefix, AttachmentClient client) {
|
|
|
|
public ATOReportServiceImpl(StringRedisTemplate redisTemplate, @Value("${app.redis.prefix}") String prefix) {
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
|
this.prefix = prefix;
|
|
|
|
this.prefix = prefix;
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
@ -150,11 +146,12 @@ public class ATOReportServiceImpl implements ATOReportService {
|
|
|
|
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
|
|
|
|
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
|
|
|
|
progress.setStatus("Uploading,filesize:" + contentBytes.length);
|
|
|
|
progress.setStatus("Uploading,filesize:" + contentBytes.length);
|
|
|
|
String filename = "royalpay_ato_report_" + new DateTime(from).toString("yyyyMMdd") + "_to_" + new DateTime(to).toString("yyyyMMdd") + ".bttps";
|
|
|
|
String filename = "royalpay_ato_report_" + new DateTime(from).toString("yyyyMMdd") + "_to_" + new DateTime(to).toString("yyyyMMdd") + ".bttps";
|
|
|
|
JSONObject file = client.uploadFile(new ByteArrayInputStream(contentBytes), filename, true);
|
|
|
|
File saveFile = new File("/var/log/payment/" + filename);
|
|
|
|
String fileid = file.getString("fileid");
|
|
|
|
FileUtils.writeByteArrayToFile(saveFile, contentBytes);
|
|
|
|
logger.info("uploaded ATO report to {}", fileid);
|
|
|
|
String path = saveFile.getAbsolutePath();
|
|
|
|
progress.setFileid(fileid);
|
|
|
|
logger.info("uploaded ATO report to {}", path);
|
|
|
|
redisTemplate.boundValueOps(reportFileKey()).set(file.toJSONString(), Duration.ofDays(1));
|
|
|
|
progress.setFileid(path);
|
|
|
|
|
|
|
|
redisTemplate.boundValueOps(reportFileKey()).set(path, Duration.ofDays(1));
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
progress.setStatus(e.getMessage());
|
|
|
|
progress.setStatus(e.getMessage());
|
|
|
|
logger.error("output bttps file failed", e);
|
|
|
|
logger.error("output bttps file failed", e);
|
|
|
@ -188,12 +185,12 @@ public class ATOReportServiceImpl implements ATOReportService {
|
|
|
|
public void downloadFile(HttpServletResponse resp) throws IOException {
|
|
|
|
public void downloadFile(HttpServletResponse resp) throws IOException {
|
|
|
|
String file = redisTemplate.boundValueOps(reportFileKey()).get();
|
|
|
|
String file = redisTemplate.boundValueOps(reportFileKey()).get();
|
|
|
|
if (file != null) {
|
|
|
|
if (file != null) {
|
|
|
|
JSONObject fileInfo = JSON.parseObject(file);
|
|
|
|
String filename = FilenameUtils.getName(file);
|
|
|
|
String filename = StringUtils.substringAfterLast(fileInfo.getString("url"), "/");
|
|
|
|
|
|
|
|
resp.setHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.builder("attachment").filename(filename).build().toString());
|
|
|
|
resp.setHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.builder("attachment").filename(filename).build().toString());
|
|
|
|
resp.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
resp.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
try (OutputStream out = resp.getOutputStream()) {
|
|
|
|
try (OutputStream out = resp.getOutputStream();
|
|
|
|
client.getFileContent(fileInfo.getString("fileid"), out);
|
|
|
|
InputStream in = new FileInputStream(file)) {
|
|
|
|
|
|
|
|
IOUtils.copy(in, out);
|
|
|
|
out.flush();
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|