|
|
|
@ -156,6 +156,8 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
|
private org.springframework.core.io.Resource trans_excel;
|
|
|
|
|
@Value("classpath:/jasper/austrac_report.jasper")
|
|
|
|
|
private org.springframework.core.io.Resource austrac_report;
|
|
|
|
|
@Value("classpath:/jasper/partner_settlement_detail.jasper")
|
|
|
|
|
private org.springframework.core.io.Resource partner_settlement_flow;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject listPartnerTradeLogs(JSONObject manager, JSONObject account, String shortId, TradeLogQuery query, String timezone) throws Exception {
|
|
|
|
@ -670,64 +672,99 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception {
|
|
|
|
|
public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse resp) throws Exception {
|
|
|
|
|
logger.debug("excel The method======= exportExcel() start.......................");
|
|
|
|
|
JSONObject transFlow = listPartnerTransFlow(query, partner);
|
|
|
|
|
// JSONObject analysis = transFlow.getJSONObject("analysis");
|
|
|
|
|
if (transFlow.getJSONArray("data").size() > 0) {
|
|
|
|
|
OutputStream ous = null;
|
|
|
|
|
try {
|
|
|
|
|
List<JSONObject> dataList = (List<JSONObject>) transFlow.get("data");
|
|
|
|
|
String transType;
|
|
|
|
|
JSONObject device;
|
|
|
|
|
int status;
|
|
|
|
|
for (JSONObject data : dataList) {
|
|
|
|
|
transType = data.getString("trans_type");
|
|
|
|
|
if (!"refund".equals(transType))
|
|
|
|
|
continue;
|
|
|
|
|
status = data.getIntValue("status");
|
|
|
|
|
if (status == 6)
|
|
|
|
|
transType = "Partly " + transType;
|
|
|
|
|
else if (status == 7) {
|
|
|
|
|
transType = "Fully " + transType;
|
|
|
|
|
resp.setContentType("application/octet-stream;");
|
|
|
|
|
resp.addHeader("Content-Disposition",
|
|
|
|
|
"attachment; filename=" + "Merchant_Settlement_Info_" + query.getDatefrom() + "_" + query.getDateto() + ".xlsx");
|
|
|
|
|
ous = resp.getOutputStream();
|
|
|
|
|
Workbook wb = new XSSFWorkbook();
|
|
|
|
|
Font font = wb.createFont();
|
|
|
|
|
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
|
|
|
|
font.setFontHeightInPoints((short) 10);
|
|
|
|
|
CellStyle analysisStyle = wb.createCellStyle();
|
|
|
|
|
analysisStyle.setFont(font);
|
|
|
|
|
String[] clientIds = query.getClient_ids();
|
|
|
|
|
List<String> clientIdList = new ArrayList<>();
|
|
|
|
|
clientIdList.add("ALL");
|
|
|
|
|
if (clientIds.length >= 2) {
|
|
|
|
|
clientIdList.addAll(Arrays.asList(clientIds));
|
|
|
|
|
}
|
|
|
|
|
Sheet sheet = null;
|
|
|
|
|
JSONObject client = null;
|
|
|
|
|
for (int i = 0;i < clientIdList.size();i++) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
sheet = wb.createSheet("ALL");
|
|
|
|
|
} else {
|
|
|
|
|
client = clientManager.getClientInfo(Integer.parseInt(clientIdList.get(i)));
|
|
|
|
|
sheet = wb.createSheet(client == null ? clientIdList.get(i) : client.getString("client_moniker"));
|
|
|
|
|
}
|
|
|
|
|
int rowNum = 0;
|
|
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
|
String[] title = {"Transaction Time", "Client Order ID", "System Order ID", "Client Moniker", "Short Name", "Order ID", "Channel", "Input Amount", "Transaction Amount", "Transaction Currency", "Clearing Amount", "Exchange Rate",
|
|
|
|
|
"Transaction Type", "Clearing Status", "Gateway", "Remark", "Dev No"};
|
|
|
|
|
for (int j = 0; j < title.length; j++) {
|
|
|
|
|
row.createCell(j, Cell.CELL_TYPE_STRING).setCellValue(title[j]);
|
|
|
|
|
}
|
|
|
|
|
String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency();
|
|
|
|
|
for (JSONObject data : dataList) {
|
|
|
|
|
if (!clientIdList.get(i).equals(data.getString("client_id")) && i != 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
transType = data.getString("trans_type");
|
|
|
|
|
if (!"refund".equals(transType)) {
|
|
|
|
|
status = data.getIntValue("status");
|
|
|
|
|
if (status == 6)
|
|
|
|
|
transType = "Partly " + transType;
|
|
|
|
|
else if (status == 7) {
|
|
|
|
|
transType = "Fully " + transType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
data.put("trans_type", transType);
|
|
|
|
|
device = clientDeviceMapper.find(data.getString("order_dev_id"));
|
|
|
|
|
if (device != null)
|
|
|
|
|
data.put("dev_id", device.getString("client_dev_id"));
|
|
|
|
|
scaleDecimalVal(data, "display_amount", platformCurrency);
|
|
|
|
|
scaleDecimalVal(data, "transaction_amount", platformCurrency);
|
|
|
|
|
scaleDecimalVal(data, "clearing_amount", platformCurrency);
|
|
|
|
|
}
|
|
|
|
|
row = sheet.createRow(++rowNum);
|
|
|
|
|
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_time"));
|
|
|
|
|
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_order_id"));
|
|
|
|
|
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(data.getString("system_transaction_id"));
|
|
|
|
|
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_moniker"));
|
|
|
|
|
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(data.getString("short_name"));
|
|
|
|
|
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_id"));
|
|
|
|
|
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(data.getString("channel"));
|
|
|
|
|
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(data.getString("display_amount"));
|
|
|
|
|
row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_amount"));
|
|
|
|
|
row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(data.getString("currency"));
|
|
|
|
|
row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clearing_amount"));
|
|
|
|
|
row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type").equals("clearing")?"-":data.getBigDecimal("exchange_rate").toString());
|
|
|
|
|
row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type"));
|
|
|
|
|
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clear_status"));
|
|
|
|
|
row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(data.getString("gateway"));
|
|
|
|
|
row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_detail"));
|
|
|
|
|
row.createCell(16, Cell.CELL_TYPE_STRING).setCellValue(data.getString("dev_id"));
|
|
|
|
|
}
|
|
|
|
|
data.put("trans_type", transType);
|
|
|
|
|
device = clientDeviceMapper.find(data.getString("order_dev_id"));
|
|
|
|
|
if (device != null)
|
|
|
|
|
data.put("dev_id", device.getString("client_dev_id"));
|
|
|
|
|
}
|
|
|
|
|
JSONObject parmerters = new JSONObject();
|
|
|
|
|
parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) ? query.getDatefrom() : "");
|
|
|
|
|
parmerters.put("dateTo", StringUtils.isNotBlank(query.getDateto()) ? query.getDateto() : DateFormatUtils.format(new Date(), "yyyyMMdd"));
|
|
|
|
|
parmerters.put("partnerCode", partner.getString("client_moniker"));
|
|
|
|
|
// parmerters.put("actual_fee", analysis.containsKey("actual_fee") ?
|
|
|
|
|
// analysis.getBigDecimal("actual_fee") : 0);
|
|
|
|
|
JRDataSource jrDataSource = new JRBeanCollectionDataSource(dataList);
|
|
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
|
|
String fileName = StringUtils.isEmpty(parmerters.getString("dateFrom")) ? parmerters.getString("dateTo")
|
|
|
|
|
: (parmerters.getString("dateFrom") + "~" + parmerters.getString("dateTo"));
|
|
|
|
|
// String fileName = new String(URLEncoder.encode(defaultname,"utf8"));
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
|
|
OutputStream outputStream = response.getOutputStream();
|
|
|
|
|
JasperPrint jasperPrint = JasperFillManager.fillReport(trans_excel.getInputStream(), parmerters, jrDataSource);
|
|
|
|
|
// JRXlsExporter exporter = new JRXlsExporter();
|
|
|
|
|
JRXlsxExporter exporter = new JRXlsxExporter();
|
|
|
|
|
ExporterInput exporterInput = new SimpleExporterInput(jasperPrint);
|
|
|
|
|
exporter.setExporterInput(exporterInput);
|
|
|
|
|
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(outputStream);
|
|
|
|
|
exporter.setExporterOutput(exporterOutput);
|
|
|
|
|
// 设置导出时参数
|
|
|
|
|
SimpleXlsxReportConfiguration xlsReportConfiguration = new SimpleXlsxReportConfiguration();
|
|
|
|
|
xlsReportConfiguration.setOnePagePerSheet(false);
|
|
|
|
|
xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true);
|
|
|
|
|
xlsReportConfiguration.setDetectCellType(true);
|
|
|
|
|
xlsReportConfiguration.setWhitePageBackground(false);
|
|
|
|
|
exporter.setConfiguration(xlsReportConfiguration);
|
|
|
|
|
exporter.exportReport();
|
|
|
|
|
outputStream.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
wb.write(ous);
|
|
|
|
|
ous.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
IOUtils.closeQuietly(ous);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1246,7 +1283,7 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
|
row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("rate") == null? "": settle.getBigDecimal("rate").toPlainString() + "%");
|
|
|
|
|
row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("settle_amount") == null ? ""
|
|
|
|
|
: settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("order_detail"));
|
|
|
|
|
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("remark"));
|
|
|
|
|
device = clientDeviceMapper.find(settle.getString("dev_id"));
|
|
|
|
|
if (device != null)
|
|
|
|
|
clientDevId = device.getString("client_dev_id");
|
|
|
|
@ -1273,4 +1310,54 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
|
IOUtils.closeQuietly(ous);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportPDFSettlement(TradeLogQuery query, JSONObject partner, HttpServletResponse response) {
|
|
|
|
|
int client_id = partner.getIntValue("client_id");
|
|
|
|
|
String begin = query.getDatefrom() == null ?"":query.getDatefrom();
|
|
|
|
|
String end = query.getDateto() == null ?"":query.getDateto();
|
|
|
|
|
JSONObject client = partner.getJSONObject("client");
|
|
|
|
|
String timezone = client.getString("timezone");
|
|
|
|
|
JSONObject params = query.toParams(timezone);
|
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
|
List<JSONObject> clientOrderList = transactionMapper.getClientOrderByTransactionTime(params);
|
|
|
|
|
List<Integer> clientOrders = new ArrayList<>(clientOrderList.size());
|
|
|
|
|
clientOrderList.parallelStream().forEach(p->{
|
|
|
|
|
clientOrders.add(p.getInteger("clearing_order"));
|
|
|
|
|
});
|
|
|
|
|
List<JSONObject> settlementLogDetailList = transactionMapper.getSettlementLogDetailList(clientOrders, client_id);
|
|
|
|
|
TimeZoneUtils.switchTimeZoneToString(settlementLogDetailList, timezone, "yyyy-MM-dd HH:mm:ss", Arrays.asList("transaction_time"));
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
JSONObject parmerters = new JSONObject();
|
|
|
|
|
parmerters.put("dateRange", "(Statement Period " + begin + "~"
|
|
|
|
|
+ end + ")");
|
|
|
|
|
parmerters.put("clientName", client.getString("company_name"));
|
|
|
|
|
parmerters.put("clientAddress", client.getString("address"));
|
|
|
|
|
parmerters.put("clientLocation", client.getString("suburb") + "," + client.getString("state") + "," + client.getString("postcode"));
|
|
|
|
|
parmerters.put("logo", logo.getInputStream());
|
|
|
|
|
settlementLogDetailList.parallelStream().forEach(item -> {
|
|
|
|
|
scaleDecimalVal(item, "display_amount", item.getString("transaction_currency"));
|
|
|
|
|
String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency();
|
|
|
|
|
scaleDecimalVal(item, "clearing_amount", platformCurrency);
|
|
|
|
|
scaleDecimalVal(item, "settle_amount", platformCurrency);
|
|
|
|
|
scaleDecimalVal(item, "total_surcharge", platformCurrency);
|
|
|
|
|
scaleDecimalVal(item, "transaction_amount", platformCurrency);
|
|
|
|
|
item.put("exchange_rate", item.getBigDecimal("exchange_rate").setScale(5, BigDecimal.ROUND_DOWN));
|
|
|
|
|
item.put("gateway" , item.getInteger("gateway") == null ? "-" : TradeType.fromGatewayNumber(item.getIntValue("gateway")).getTradeType());
|
|
|
|
|
item.put("rate", item.getBigDecimal("rate") == null? "-": item.getBigDecimal("rate").toPlainString() + "%");
|
|
|
|
|
});
|
|
|
|
|
JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList);
|
|
|
|
|
response.setContentType("application/pdf");
|
|
|
|
|
String fileName = partner.getString("client_moniker") + "_" + parmerters.getString("dateRange").replaceAll("/", "");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf");
|
|
|
|
|
OutputStream outs = response.getOutputStream();
|
|
|
|
|
byte[] bytes = JasperRunManager.runReportToPdf(partner_settlement_flow.getInputStream(), parmerters, jrDataSource);
|
|
|
|
|
outs.write(bytes, 0, bytes.length);
|
|
|
|
|
outs.flush();
|
|
|
|
|
outs.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|