Merge remote-tracking branch 'origin/develop' into develop

master
liuxinxin 5 years ago
commit 1fac5ac08c

@ -58,6 +58,8 @@ public interface TradeLogService {
void exportSettlementLog(TradeLogQuery query, JSONObject partner, HttpServletResponse response); void exportSettlementLog(TradeLogQuery query, JSONObject partner, HttpServletResponse response);
void exportSettlementLogCSV(TradeLogQuery query, JSONObject partner, HttpServletResponse response);
void exportPDFSettlement(TradeLogQuery query, JSONObject partner, HttpServletResponse response); void exportPDFSettlement(TradeLogQuery query, JSONObject partner, HttpServletResponse response);
void exportExcelAllPartner(TradeLogQuery query, JSONObject partner, HttpServletResponse httpResponse) throws Exception; void exportExcelAllPartner(TradeLogQuery query, JSONObject partner, HttpServletResponse httpResponse) throws Exception;

@ -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);
} }
} }

@ -44,6 +44,7 @@ public class TradeFlowController {
public void exportExcel(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse httpResponse) throws Exception { public void exportExcel(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse httpResponse) throws Exception {
tradeLogService.exportExcelNew(query, partner, httpResponse); tradeLogService.exportExcelNew(query, partner, httpResponse);
} }
@PartnerMapping(value = "/report/excel_detail", method = RequestMethod.GET) @PartnerMapping(value = "/report/excel_detail", method = RequestMethod.GET)
@ReadOnlyConnection @ReadOnlyConnection
public void exportExcelDetail(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse httpResponse) throws Exception { public void exportExcelDetail(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse httpResponse) throws Exception {
@ -80,6 +81,13 @@ public class TradeFlowController {
tradeLogService.exportSettlementLog(query, partner, response); tradeLogService.exportSettlementLog(query, partner, response);
} }
@PartnerMapping(value = "/settlement/log/csv", method = RequestMethod.GET)
@ReadOnlyConnection
@ResponseBody
public void exportSettlementLogCSV(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse response) {
tradeLogService.exportSettlementLogCSV(query, partner, response);
}
@PartnerMapping(value = "/settlement/log/pdf", method = RequestMethod.GET) @PartnerMapping(value = "/settlement/log/pdf", method = RequestMethod.GET)
@ReadOnlyConnection @ReadOnlyConnection
@ResponseBody @ResponseBody

@ -121,12 +121,14 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) {
$scope.chooseLast7Days(); $scope.chooseLast7Days();
$scope.exportSettlementLogs = function (pattern) { $scope.exportSettlementLogs = function (pattern) {
var params = angular.copy($scope.params); let params = angular.copy($scope.params);
var url = '/client/trans_flow/settlement/log/excel'; let url = '/client/trans_flow/settlement/log/excel';
if (pattern === 'pdf') { if (pattern === 'pdf') {
url = '/client/trans_flow/settlement/log/pdf'; url = '/client/trans_flow/settlement/log/pdf';
} else if (pattern === 'csv') {
url = '/client/trans_flow/settlement/log/csv';
} }
var connectSymbol = '?'; let connectSymbol = '?';
if (params.datefrom) { if (params.datefrom) {
params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd'); params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd');
url += connectSymbol + 'datefrom=' + params.datefrom; url += connectSymbol + 'datefrom=' + params.datefrom;

@ -107,6 +107,7 @@
</button> </button>
<ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="single-button" style="min-width: 80px"> <ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="single-button" style="min-width: 80px">
<li><a target="_blank" ng-href="{{exportSettlementLogs('pdf')}}">PDF</a></li> <li><a target="_blank" ng-href="{{exportSettlementLogs('pdf')}}">PDF</a></li>
<li><a target="_blank" ng-href="{{exportSettlementLogs('csv')}}">CSV</a></li>
<li><a target="_blank" ng-href="{{exportSettlementLogs('excel')}}">EXCEL</a></li> <li><a target="_blank" ng-href="{{exportSettlementLogs('excel')}}">EXCEL</a></li>
</ul> </ul>
</div> </div>

@ -0,0 +1,29 @@
package au.com.royalpay.payment.manage.valid;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.junit.Test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
/**
* Create by davep at 2019-12-24 15:15
*/
public class CSVTest {
@Test
public void test() throws IOException {
File file = File.createTempFile("csvtest",".csv");
FileWriter writer = new FileWriter(file);
CSVFormat format = CSVFormat.DEFAULT.withFirstRecordAsHeader().withHeader("title", "标题1", "abc");//.withQuoteMode(QuoteMode.ALL_NON_NULL);
CSVPrinter printer = new CSVPrinter(writer, format);
printer.printRecord("test", "订单1234", "hello");
writer.flush();
System.out.println(file.getAbsolutePath());
}
}
Loading…
Cancel
Save