From 7b7b7079fa5cc353ef1ac964d30e6df11dd22572 Mon Sep 17 00:00:00 2001 From: yangkai Date: Tue, 8 Jan 2019 20:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E7=AB=AF=E6=B8=85=E7=AE=97?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=89=B9=E9=87=8F=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappers/payment/TransactionMapper.java | 6 ++ .../manage/tradelog/core/TradeLogService.java | 2 + .../core/impls/TradeLogServiceImpl.java | 96 +++++++++++++++++++ .../tradelog/web/TradeFlowController.java | 5 + .../financial/FinancialBDConfigMapper.xml | 5 +- .../mappers/payment/TransactionMapper.xml | 66 +++++++++++++ .../bd_commission_config_dialog.html | 3 +- .../tradelog/partner-settlement-log.js | 16 ++++ .../templates/partner_settlement_logs.html | 3 + 9 files changed, 199 insertions(+), 3 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java index f598de889..f73031649 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java @@ -168,4 +168,10 @@ public interface TransactionMapper { List listCreditTransactionsForSecure(Date from, Date to); List listDebitTransactionsForSecure(Date from, Date to); + + JSONObject getClearDetailTotal(JSONObject params); + + List getSettlementLogDetailList(@Param("clientOrders") List clientOrders, @Param("client_id") int clientId); + + List getClientOrderByTransactionTime(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java index 48b32e802..1fb0b3185 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java @@ -50,4 +50,6 @@ public interface TradeLogService { void fullReleasePreAuthorization(JSONObject account, TradeLogQuery query)throws Exception; PageList listPreRefundClients(PreRefundQueryBean params); + + void exportSettlementLog(TradeLogQuery query, JSONObject partner, HttpServletResponse response); } diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java index 64eff18d1..a992efea2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java @@ -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 clientOrderList = transactionMapper.getClientOrderByTransactionTime(params); + List clientOrders = new ArrayList<>(clientOrderList.size()); + clientOrderList.parallelStream().forEach(p->{ + clientOrders.add(p.getInteger("clearing_order")); + }); + List 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); + } + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/web/TradeFlowController.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/web/TradeFlowController.java index 8e8761618..27275b973 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/web/TradeFlowController.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/web/TradeFlowController.java @@ -59,5 +59,10 @@ public class TradeFlowController { return tradeLogService.getClientUnClearedAmount(partner).toString(); } + @PartnerMapping(value = "/settlement/log/excel",method = RequestMethod.GET) + @ResponseBody + public void exportSettlementLog(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse response) { + tradeLogService.exportSettlementLog(query, partner, response); + } } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDConfigMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDConfigMapper.xml index 55dd4eb35..563654312 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDConfigMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDConfigMapper.xml @@ -10,10 +10,11 @@ c.city, c.get_prize, c.bd_group, - c.kpi_amount + c.kpi_amount, + m.is_valid FROM sys_managers m LEFT JOIN financial_bd_config c ON c.manager_id = m.manager_id - WHERE m.role & 4 > 0 AND m.is_valid = 1 AND (m.org_id = 1 OR m.org_id IS NULL) + WHERE m.role & 4 > 0 AND (m.org_id = 1 OR m.org_id IS NULL) ]]> diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index b1de748ac..16a367b1b 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -1032,4 +1032,70 @@ and t.transaction_type = 'Debit' + + + + + diff --git a/src/main/ui/static/config/bdprize/templates/bd_commission_config_dialog.html b/src/main/ui/static/config/bdprize/templates/bd_commission_config_dialog.html index 4a5a96951..7e507227d 100644 --- a/src/main/ui/static/config/bdprize/templates/bd_commission_config_dialog.html +++ b/src/main/ui/static/config/bdprize/templates/bd_commission_config_dialog.html @@ -124,7 +124,8 @@ - + {{bd.display_name}} + {{bd.display_name}} (Left Company) diff --git a/src/main/ui/static/payment/tradelog/partner-settlement-log.js b/src/main/ui/static/payment/tradelog/partner-settlement-log.js index d7fa5454e..113cf4a85 100644 --- a/src/main/ui/static/payment/tradelog/partner-settlement-log.js +++ b/src/main/ui/static/payment/tradelog/partner-settlement-log.js @@ -92,6 +92,22 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { }; $scope.loadSettlementLogs(1); + $scope.exportSettlementLogs = function() { + var params = angular.copy($scope.params); + var url = '/client/trans_flow/settlement/log/excel'; + var connectSymbol = '?'; + if (params.datefrom) { + params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd'); + url += connectSymbol + 'datefrom=' + params.datefrom; + connectSymbol = '&'; + } + if (params.dateto) { + params.dateto = $filter('date')(params.dateto, 'yyyyMMdd'); + url += connectSymbol + 'dateto=' + params.dateto; + } + + return url; + }; var getClientUnClearedAmount = function () { $http.get('/client/trans_flow/settlement/unclear').then(function (resp) { $scope.unclear = resp.data; diff --git a/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html b/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html index aeeaf8dbf..f9b7990a3 100644 --- a/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html +++ b/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html @@ -88,6 +88,9 @@ + + export +