|
|
|
@ -28,6 +28,7 @@ import au.com.royalpay.payment.manage.organizations.core.OrgManager;
|
|
|
|
|
import au.com.royalpay.payment.manage.tradelog.beans.PreRefundQueryBean;
|
|
|
|
|
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
|
|
|
|
|
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
|
|
|
|
|
import au.com.royalpay.payment.tools.defines.TradeType;
|
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
@ -68,6 +69,8 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -1177,4 +1180,97 @@ public class TradeLogServiceImpl implements TradeLogService {
|
|
|
|
|
return transactionMapper.listPreRefundClients(new PageBounds(params.getPage(), params.getLimit()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportSettlementLog(TradeLogQuery query, JSONObject partner, HttpServletResponse resp) {
|
|
|
|
|
int client_id = partner.getIntValue("client_id");
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
OutputStream ous = null;
|
|
|
|
|
try {
|
|
|
|
|
JSONObject clearDetailTotal = transactionMapper.getClearDetailTotal(params);
|
|
|
|
|
resp.setContentType("application/octet-stream;");
|
|
|
|
|
resp.addHeader("Content-Disposition",
|
|
|
|
|
"attachment; filename=" + "Merchant_Settlement_Info_" + begin + "_" + end + ".xlsx");
|
|
|
|
|
ous = resp.getOutputStream();
|
|
|
|
|
Workbook wb = new XSSFWorkbook();
|
|
|
|
|
Cell cell = null;
|
|
|
|
|
Font font = wb.createFont();
|
|
|
|
|
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
|
|
|
|
font.setFontHeightInPoints((short) 10);
|
|
|
|
|
CellStyle analysisStyle = wb.createCellStyle();
|
|
|
|
|
analysisStyle.setFont(font);
|
|
|
|
|
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + begin + "_" + end);
|
|
|
|
|
int rowNum = 0;
|
|
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
|
String[] title = {"order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
|
|
|
|
|
"Input Amount", "Total Amount", "Clearing Amount", "Sruchange Rate", "Settle Amount", "Remark", "Dev No"};
|
|
|
|
|
String[] analysis = {"Total Credit", "Total Debit", "Gross Amount", "Total Charge", "Net Amount"};
|
|
|
|
|
for (int i = 0; i < title.length; i++) {
|
|
|
|
|
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject device;
|
|
|
|
|
String clientDevId = "";
|
|
|
|
|
for (JSONObject settle : settlementLogDetailList) {
|
|
|
|
|
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
row = sheet.createRow(++rowNum);
|
|
|
|
|
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("order_id"));
|
|
|
|
|
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("client_order_id"));
|
|
|
|
|
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("transaction_time"));
|
|
|
|
|
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("channel"));
|
|
|
|
|
if (settle.getInteger("gateway") != null) {
|
|
|
|
|
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(TradeType.fromGatewayNumber(settle.getIntValue("gateway")).getTradeType());
|
|
|
|
|
} else {
|
|
|
|
|
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue("-");
|
|
|
|
|
}
|
|
|
|
|
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("exchange_rate").setScale(5, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("transaction_type"));
|
|
|
|
|
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("transaction_currency"));
|
|
|
|
|
row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("display_amount") == null ? ""
|
|
|
|
|
: settle.getBigDecimal("display_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("transaction_amount") == null ? ""
|
|
|
|
|
: settle.getBigDecimal("transaction_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("clearing_amount") == null ? ""
|
|
|
|
|
: settle.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
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"));
|
|
|
|
|
device = clientDeviceMapper.find(settle.getString("dev_id"));
|
|
|
|
|
if (device != null)
|
|
|
|
|
clientDevId = device.getString("client_dev_id");
|
|
|
|
|
row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(clientDevId);
|
|
|
|
|
}
|
|
|
|
|
row = sheet.createRow(++rowNum);
|
|
|
|
|
for (int i = 0; i < analysis.length; i++) {
|
|
|
|
|
cell = row.createCell(i, Cell.CELL_TYPE_STRING);
|
|
|
|
|
cell.setCellStyle(analysisStyle);
|
|
|
|
|
cell.setCellValue(analysis[i]);
|
|
|
|
|
}
|
|
|
|
|
row = sheet.createRow(++rowNum);
|
|
|
|
|
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(clearDetailTotal.getString("total_payment"));
|
|
|
|
|
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(clearDetailTotal.getString("total_refund"));
|
|
|
|
|
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(clearDetailTotal.getString("gross_amount"));
|
|
|
|
|
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(clearDetailTotal.getString("total_charge"));
|
|
|
|
|
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(clearDetailTotal.getString("clearing_amount"));
|
|
|
|
|
|
|
|
|
|
wb.write(ous);
|
|
|
|
|
ous.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
IOUtils.closeQuietly(ous);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|