商户清算文件pdf导出

master
yangkai 6 years ago
parent 5f12f2fc94
commit c40e0d8bb1

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

@ -156,6 +156,8 @@ public class TradeLogServiceImpl implements TradeLogService {
private org.springframework.core.io.Resource trans_excel; private org.springframework.core.io.Resource trans_excel;
@Value("classpath:/jasper/austrac_report.jasper") @Value("classpath:/jasper/austrac_report.jasper")
private org.springframework.core.io.Resource austrac_report; private org.springframework.core.io.Resource austrac_report;
@Value("classpath:/jasper/partner_settlement_detail.jasper")
private org.springframework.core.io.Resource partner_settlement_flow;
@Override @Override
public JSONObject listPartnerTradeLogs(JSONObject manager, JSONObject account, String shortId, TradeLogQuery query, String timezone) throws Exception { public JSONObject listPartnerTradeLogs(JSONObject manager, JSONObject account, String shortId, TradeLogQuery query, String timezone) throws Exception {
@ -1246,7 +1248,7 @@ public class TradeLogServiceImpl implements TradeLogService {
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() + "%");
row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("settle_amount") == null ? "" row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("settle_amount") == null ? ""
: settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString()); : settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("order_detail")); row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("remark"));
device = clientDeviceMapper.find(settle.getString("dev_id")); device = clientDeviceMapper.find(settle.getString("dev_id"));
if (device != null) if (device != null)
clientDevId = device.getString("client_dev_id"); clientDevId = device.getString("client_dev_id");
@ -1273,4 +1275,54 @@ public class TradeLogServiceImpl implements TradeLogService {
IOUtils.closeQuietly(ous); IOUtils.closeQuietly(ous);
} }
} }
@Override
public void exportPDFSettlement(TradeLogQuery query, JSONObject partner, HttpServletResponse response) {
int client_id = partner.getIntValue("client_id");
String begin = query.getDatefrom() == null ?"":query.getDatefrom();
String end = query.getDateto() == null ?"":query.getDateto();
JSONObject client = partner.getJSONObject("client");
String timezone = 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);
TimeZoneUtils.switchTimeZoneToString(settlementLogDetailList, timezone, "yyyy-MM-dd HH:mm:ss", Arrays.asList("transaction_time"));
try {
JSONObject parmerters = new JSONObject();
parmerters.put("dateRange", "(Statement Period " + begin + "~"
+ end + ")");
parmerters.put("clientName", client.getString("company_name"));
parmerters.put("clientAddress", client.getString("address"));
parmerters.put("clientLocation", client.getString("suburb") + "," + client.getString("state") + "," + client.getString("postcode"));
parmerters.put("logo", logo.getInputStream());
settlementLogDetailList.parallelStream().forEach(item -> {
scaleDecimalVal(item, "display_amount", item.getString("transaction_currency"));
String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency();
scaleDecimalVal(item, "clearing_amount", platformCurrency);
scaleDecimalVal(item, "settle_amount", platformCurrency);
scaleDecimalVal(item, "total_surcharge", platformCurrency);
scaleDecimalVal(item, "transaction_amount", platformCurrency);
item.put("exchange_rate", item.getBigDecimal("exchange_rate").setScale(5, BigDecimal.ROUND_DOWN));
item.put("gateway" , item.getInteger("gateway") == null ? "-" : TradeType.fromGatewayNumber(item.getIntValue("gateway")).getTradeType());
item.put("rate", item.getBigDecimal("rate") == null? "-": item.getBigDecimal("rate").toPlainString() + "%");
});
JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList);
response.setContentType("application/pdf");
String fileName = partner.getString("client_moniker") + "_" + parmerters.getString("dateRange").replaceAll("/", "");
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf");
OutputStream outs = response.getOutputStream();
byte[] bytes = JasperRunManager.runReportToPdf(partner_settlement_flow.getInputStream(), parmerters, jrDataSource);
outs.write(bytes, 0, bytes.length);
outs.flush();
outs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} }

@ -65,4 +65,10 @@ public class TradeFlowController {
tradeLogService.exportSettlementLog(query, partner, response); tradeLogService.exportSettlementLog(query, partner, response);
} }
@PartnerMapping(value = "/settlement/log/pdf",method = RequestMethod.GET)
@ResponseBody
public void exportLogPDF(TradeLogQuery query, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse response) {
tradeLogService.exportPDFSettlement(query, partner, response);
}
} }

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

@ -88,9 +88,15 @@
<button class="btn btn-success" type="button" ng-click="loadSettlementLogs()"> <button class="btn btn-success" type="button" ng-click="loadSettlementLogs()">
<i class="fa fa-search"></i> Search <i class="fa fa-search"></i> Search
</button> </button>
<a role="button" class="btn btn-primary" style="float: right;right: 20px;" type="button" ng-href="{{exportSettlementLogs()}}"> <div class="btn-group" uib-dropdown ng-if="pagination.totalCount>0" style="float: right;right: 20px;">
<i class="fa fa-download"></i> export <button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
</a> Export Settlement <span class="caret"></span>
</button>
<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('excel')}}">EXCEL</a></li>
</ul>
</div>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save