|
|
@ -22,6 +22,7 @@ import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
|
|
|
|
import au.com.royalpay.payment.tools.defines.TradeType;
|
|
|
|
import au.com.royalpay.payment.tools.defines.TradeType;
|
|
|
|
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.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
|
|
|
|
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
|
|
|
|
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
|
|
|
@ -40,6 +41,9 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
|
|
|
import net.sf.jasperreports.engine.export.JRXlsExporter;
|
|
|
|
import net.sf.jasperreports.engine.export.JRXlsExporter;
|
|
|
|
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
|
|
|
|
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
|
|
|
|
import net.sf.jasperreports.export.*;
|
|
|
|
import net.sf.jasperreports.export.*;
|
|
|
|
|
|
|
|
import org.apache.commons.csv.CSVFormat;
|
|
|
|
|
|
|
|
import org.apache.commons.csv.CSVPrinter;
|
|
|
|
|
|
|
|
import org.apache.commons.csv.QuoteMode;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@ -58,9 +62,7 @@ import org.springframework.ui.Model;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.DateFormat;
|
|
|
@ -151,7 +153,9 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
params.put("org_id", manager.getIntValue("org_id"));
|
|
|
|
params.put("org_id", manager.getIntValue("org_id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
params.put("trade_type",new ArrayList<Integer>(){{add(query.getGatewayChild());}});
|
|
|
|
params.put("trade_type", new ArrayList<Integer>() {{
|
|
|
|
|
|
|
|
add(query.getGatewayChild());
|
|
|
|
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageList<JSONObject> logs = orderMapper.listOrdersByClients(params,
|
|
|
|
PageList<JSONObject> logs = orderMapper.listOrdersByClients(params,
|
|
|
|
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
@ -186,7 +190,9 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
params.put("org_id", manager.getIntValue("org_id"));
|
|
|
|
params.put("org_id", manager.getIntValue("org_id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
params.put("trade_type",new ArrayList<Integer>(){{add(query.getGatewayChild());}});
|
|
|
|
params.put("trade_type", new ArrayList<Integer>() {{
|
|
|
|
|
|
|
|
add(query.getGatewayChild());
|
|
|
|
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageList<JSONObject> logs = orderMapper.listIncrementalOrdersByClients(params,
|
|
|
|
PageList<JSONObject> logs = orderMapper.listIncrementalOrdersByClients(params,
|
|
|
|
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
@ -223,7 +229,9 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
orgManager.checkOrgIds(manager, params);
|
|
|
|
orgManager.checkOrgIds(manager, params);
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
params.put("trade_type",new ArrayList<Integer>(){{add(query.getGatewayChild());}});
|
|
|
|
params.put("trade_type", new ArrayList<Integer>() {{
|
|
|
|
|
|
|
|
add(query.getGatewayChild());
|
|
|
|
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageList<JSONObject> logs = orderMapper.listOrders(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
PageList<JSONObject> logs = orderMapper.listOrders(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
JSONObject result = PageListUtils.buildPageListResult(logs);
|
|
|
|
JSONObject result = PageListUtils.buildPageListResult(logs);
|
|
|
@ -247,7 +255,9 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
orgManager.checkOrgIds(manager, params);
|
|
|
|
orgManager.checkOrgIds(manager, params);
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
if (query.getGatewayChild() != null) {
|
|
|
|
params.put("trade_type",new ArrayList<Integer>(){{add(query.getGatewayChild());}});
|
|
|
|
params.put("trade_type", new ArrayList<Integer>() {{
|
|
|
|
|
|
|
|
add(query.getGatewayChild());
|
|
|
|
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageList<JSONObject> logs = orderMapper.listIncrementalOrders(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
PageList<JSONObject> logs = orderMapper.listIncrementalOrders(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
for (JSONObject log : logs) {
|
|
|
@ -1471,29 +1481,17 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("transaction_currency"));
|
|
|
|
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("transaction_currency"));
|
|
|
|
cell = row.createCell(8, Cell.CELL_TYPE_STRING);
|
|
|
|
cell = row.createCell(8, Cell.CELL_TYPE_STRING);
|
|
|
|
cell.setCellValue(settle.getBigDecimal("display_amount") == null ? ""
|
|
|
|
cell.setCellValue(convertMarkedAmountString(settle, "display_amount"));
|
|
|
|
: "Credit".equals(settle.getString("transaction_type"))?
|
|
|
|
|
|
|
|
settle.getBigDecimal("display_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString():
|
|
|
|
|
|
|
|
"-"+settle.getBigDecimal("display_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell = row.createCell(9, Cell.CELL_TYPE_STRING);
|
|
|
|
cell = row.createCell(9, Cell.CELL_TYPE_STRING);
|
|
|
|
cell.setCellValue(settle.getBigDecimal("transaction_amount") == null ? ""
|
|
|
|
cell.setCellValue(convertMarkedAmountString(settle, "transaction_amount"));
|
|
|
|
: "Credit".equals(settle.getString("transaction_type"))?
|
|
|
|
|
|
|
|
settle.getBigDecimal("transaction_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString():
|
|
|
|
|
|
|
|
"-"+settle.getBigDecimal("transaction_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell = row.createCell(10, Cell.CELL_TYPE_STRING);
|
|
|
|
cell = row.createCell(10, Cell.CELL_TYPE_STRING);
|
|
|
|
cell.setCellValue(settle.getBigDecimal("clearing_amount") == null ? ""
|
|
|
|
cell.setCellValue(convertMarkedAmountString(settle, "clearing_amount"));
|
|
|
|
: "Credit".equals(settle.getString("transaction_type"))?
|
|
|
|
|
|
|
|
settle.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString():
|
|
|
|
|
|
|
|
"-"+settle.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("rate") == null ? "" : settle.getBigDecimal("rate").toPlainString() + "%");
|
|
|
|
row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("rate") == null ? "" : settle.getBigDecimal("rate").toPlainString() + "%");
|
|
|
|
cell = row.createCell(12, Cell.CELL_TYPE_STRING);
|
|
|
|
cell = row.createCell(12, Cell.CELL_TYPE_STRING);
|
|
|
|
cell.setCellValue(settle.getBigDecimal("settle_amount") == null ? ""
|
|
|
|
cell.setCellValue(convertMarkedAmountString(settle, "settle_amount"));
|
|
|
|
: "Credit".equals(settle.getString("transaction_type"))?
|
|
|
|
|
|
|
|
settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString():
|
|
|
|
|
|
|
|
"-"+settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("total_surcharge") == null ? ""
|
|
|
|
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("total_surcharge") == null ? ""
|
|
|
|
: settle.getBigDecimal("total_surcharge").setScale(2, RoundingMode.DOWN).toPlainString());
|
|
|
|
: settle.getBigDecimal("total_surcharge").setScale(2, RoundingMode.DOWN).toPlainString());
|
|
|
@ -1524,9 +1522,99 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
wb.write(ous);
|
|
|
|
wb.write(ous);
|
|
|
|
ous.flush();
|
|
|
|
ous.flush();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new ServerErrorException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void exportSettlementLogCSV(TradeLogQuery query, JSONObject partner, HttpServletResponse response) {
|
|
|
|
|
|
|
|
String begin = query.getDatefrom() == null ? "" : query.getDatefrom();
|
|
|
|
|
|
|
|
String end = query.getDateto() == null ? "" : query.getDateto();
|
|
|
|
|
|
|
|
String timezone = partner.getJSONObject("client").getString("timezone");
|
|
|
|
|
|
|
|
JSONObject params = query.toParams(timezone);
|
|
|
|
|
|
|
|
if (params.get("client_ids") == null) {
|
|
|
|
|
|
|
|
params.put("client_id", partner.getJSONObject("client").getString("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);
|
|
|
|
|
|
|
|
String[] title = {"order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
|
|
|
|
|
|
|
|
"Input Amount", "Total Amount", "Clearing Amount", "Surcharge Rate", "Settle Amount", "Surcharge", "GST", "Remark", "Dev No", "Company Name", "Short Name", "Settlement Date"};
|
|
|
|
|
|
|
|
CSVFormat format = CSVFormat.DEFAULT.withFirstRecordAsHeader().withHeader(title);
|
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
|
|
|
|
response.setContentType("application/octet-stream;");
|
|
|
|
|
|
|
|
response.addHeader("Content-Disposition",
|
|
|
|
|
|
|
|
"attachment; filename=" + "Merchant_Settlement_Info_" + begin + "_" + end + ".csv");
|
|
|
|
|
|
|
|
try (PrintWriter writer = response.getWriter();
|
|
|
|
|
|
|
|
CSVPrinter printer = new CSVPrinter(writer, format)) {
|
|
|
|
|
|
|
|
printer.printRecord((Object[]) title);
|
|
|
|
|
|
|
|
JSONObject clearDetailTotal = transactionMapper.getClearDetailTotal(params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject settle : settlementLogDetailList) {
|
|
|
|
|
|
|
|
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String gateway = settle.getInteger("gateway") != null ? TradeType.fromGatewayNumber(settle.getIntValue("gateway")).getTradeType() : "-";
|
|
|
|
|
|
|
|
String displayAmount = convertMarkedAmountString(settle, "display_amount");
|
|
|
|
|
|
|
|
String transAmt = convertMarkedAmountString(settle, "transaction_amount");
|
|
|
|
|
|
|
|
String clearAmt = convertMarkedAmountString(settle, "clearing_amount");
|
|
|
|
|
|
|
|
String settleAmt = convertMarkedAmountString(settle, "settle_amount");
|
|
|
|
|
|
|
|
JSONObject device = clientDeviceMapper.find(settle.getString("dev_id"));
|
|
|
|
|
|
|
|
String clientDevId = device == null ? "" : device.getString("client_dev_id");
|
|
|
|
|
|
|
|
//print row
|
|
|
|
|
|
|
|
printer.printRecord(
|
|
|
|
|
|
|
|
settle.getString("order_id"),
|
|
|
|
|
|
|
|
settle.getString("client_order_id"),
|
|
|
|
|
|
|
|
settle.getString("transaction_time"),
|
|
|
|
|
|
|
|
settle.getString("channel"),
|
|
|
|
|
|
|
|
gateway,
|
|
|
|
|
|
|
|
settle.getBigDecimal("exchange_rate").setScale(5, RoundingMode.DOWN).toPlainString(),
|
|
|
|
|
|
|
|
settle.getString("transaction_type"),
|
|
|
|
|
|
|
|
settle.getString("transaction_currency"),
|
|
|
|
|
|
|
|
displayAmount,
|
|
|
|
|
|
|
|
transAmt,
|
|
|
|
|
|
|
|
clearAmt,
|
|
|
|
|
|
|
|
settle.getBigDecimal("rate") == null ? "" : settle.getBigDecimal("rate").toPlainString() + "%",
|
|
|
|
|
|
|
|
settleAmt,
|
|
|
|
|
|
|
|
settle.getBigDecimal("total_surcharge") == null ? ""
|
|
|
|
|
|
|
|
: settle.getBigDecimal("total_surcharge").setScale(2, RoundingMode.DOWN).toPlainString(),
|
|
|
|
|
|
|
|
settle.getBigDecimal("tax_amount") == null ? ""
|
|
|
|
|
|
|
|
: settle.getBigDecimal("tax_amount").setScale(2, RoundingMode.DOWN).toPlainString(),
|
|
|
|
|
|
|
|
settle.getString("remark"),
|
|
|
|
|
|
|
|
clientDevId, settle.getString("company_name"),
|
|
|
|
|
|
|
|
settle.getString("short_name"),
|
|
|
|
|
|
|
|
settle.getString("settle_date"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] analysisRow = {"Total Credit",
|
|
|
|
|
|
|
|
clearDetailTotal.getString("total_payment"),
|
|
|
|
|
|
|
|
"Total Debit",
|
|
|
|
|
|
|
|
clearDetailTotal.getString("total_refund"),
|
|
|
|
|
|
|
|
"Gross Amount",
|
|
|
|
|
|
|
|
clearDetailTotal.getString("gross_amount"),
|
|
|
|
|
|
|
|
"Total Charge",
|
|
|
|
|
|
|
|
clearDetailTotal.getBigDecimal("total_charge").add(clearDetailTotal.getBigDecimal("tax_amount")).toPlainString(),
|
|
|
|
|
|
|
|
"Net Amount",
|
|
|
|
|
|
|
|
clearDetailTotal.getString("clearing_amount")};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printer.printRecord((Object[]) analysisRow);
|
|
|
|
|
|
|
|
writer.flush();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new ServerErrorException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String convertMarkedAmountString(JSONObject settle, String key) {
|
|
|
|
|
|
|
|
if (settle.getBigDecimal(key) == null) {
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "Credit".equals(settle.getString("transaction_type")) ?
|
|
|
|
|
|
|
|
settle.getBigDecimal(key).setScale(2, RoundingMode.DOWN).toPlainString() :
|
|
|
|
|
|
|
|
"-" + settle.getBigDecimal(key).setScale(2, RoundingMode.DOWN).toPlainString();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -1574,7 +1662,7 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
outs.flush();
|
|
|
|
outs.flush();
|
|
|
|
outs.close();
|
|
|
|
outs.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new ServerErrorException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|