商户端清算详情批量导出

master
yangkai 6 years ago
parent a76a1a4cf5
commit 7b7b7079fa

@ -168,4 +168,10 @@ public interface TransactionMapper {
List<JSONObject> listCreditTransactionsForSecure(Date from, Date to);
List<JSONObject> listDebitTransactionsForSecure(Date from, Date to);
JSONObject getClearDetailTotal(JSONObject params);
List<JSONObject> getSettlementLogDetailList(@Param("clientOrders") List<Integer> clientOrders, @Param("client_id") int clientId);
List<JSONObject> getClientOrderByTransactionTime(JSONObject params);
}

@ -50,4 +50,6 @@ public interface TradeLogService {
void fullReleasePreAuthorization(JSONObject account, TradeLogQuery query)throws Exception;
PageList<JSONObject> listPreRefundClients(PreRefundQueryBean params);
void exportSettlementLog(TradeLogQuery query, JSONObject partner, HttpServletResponse response);
}

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

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

@ -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)
]]>
</select>

@ -1032,4 +1032,70 @@
and t.transaction_type = 'Debit'
</select>
<select id="getClearDetailTotal" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT
client_id,
sum(total_payment) total_payment,
sum(total_refund) total_refund,
sum(gross_amount) gross_amount,
SUM(clearing_amount) clearing_amount,
sum(total_charge) total_charge
from (
SELECT
t.client_id,
total_payment,
total_refund,
gross_amount,
cd.clearing_amount,
total_charge
FROM
pmt_transactions t
LEFT JOIN log_clearing_detail cd ON cd.clear_detail_id = t.clearing_order
WHERE
t.channel = 'Settlement' and t.client_id=#{client_id}
]]>
<if test="from!=null">and t.transaction_time &gt;= #{from}</if>
<if test="to!=null">and t.transaction_time &lt; #{to}</if>
GROUP BY
t.order_id) temp
</select>
<select id="getSettlementLogDetailList" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT
t.*, o.display_amount,
o.client_order_id,
o.gateway,
r.out_refund_id,
r.client_refund_id,
o.order_detail,
o.dev_id,
a.rate
FROM
pmt_transactions t
LEFT JOIN pmt_orders o ON o.order_id = t.order_id
LEFT JOIN pmt_refunds r ON r.refund_id = t.refund_id
LEFT JOIN log_clearing_detail_analysis a ON a.clearing_detail_id = t.clearing_order
AND t.channel = a.channel
WHERE t.channel != 'Settlement' AND t.client_id = #{client_id}
]]>
<if test="clientOrders!=null">
AND t.clearing_order IN
<foreach collection="clientOrders" open="(" close=")" separator="," item="clearing_order">
#{clearing_order}
</foreach>
</if>
ORDER BY transaction_time DESC
</select>
<select id="getClientOrderByTransactionTime" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT t.clearing_order
FROM pmt_transactions t
WHERE t.channel='Settlement' AND client_id = #{client_id}
]]>
<if test="from!=null">and t.transaction_time &gt;= #{from}</if>
<if test="to!=null">and t.transaction_time &lt; #{to}</if>
</select>
</mapper>

@ -124,7 +124,8 @@
</thead>
<tbody>
<tr ng-repeat="bd in bds|filter:{get_prize:true}">
<td ng-bind="bd.display_name"></td>
<td ng-if="bd.is_valid==1">{{bd.display_name}}</td>
<td ng-if="bd.is_valid==0"><s>{{bd.display_name}}</s><span style="color: red"> (Left Company)</span></td>
<td>
<input type="number" ng-model="bd.kpi_amount" min="0">
</td>

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

@ -88,6 +88,9 @@
<button class="btn btn-success" type="button" ng-click="loadSettlementLogs()">
<i class="fa fa-search"></i> Search
</button>
<a role="button" class="btn btn-primary" style="float: right;right: 20px;" type="button" ng-href="{{exportSettlementLogs()}}">
<i class="fa fa-download"></i> export
</a>
</div>
</div>
</div>

Loading…
Cancel
Save