fix导出商户交易流水详情

master
yangkai 6 years ago
parent c40e0d8bb1
commit 516a5014dc

@ -672,64 +672,99 @@ public class TradeLogServiceImpl implements TradeLogService {
} }
@Override @Override
public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception { public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse resp) throws Exception {
logger.debug("excel The method======= exportExcel() start......................."); logger.debug("excel The method======= exportExcel() start.......................");
JSONObject transFlow = listPartnerTransFlow(query, partner); JSONObject transFlow = listPartnerTransFlow(query, partner);
// JSONObject analysis = transFlow.getJSONObject("analysis"); // JSONObject analysis = transFlow.getJSONObject("analysis");
if (transFlow.getJSONArray("data").size() > 0) { if (transFlow.getJSONArray("data").size() > 0) {
OutputStream ous = null;
try { try {
List<JSONObject> dataList = (List<JSONObject>) transFlow.get("data"); List<JSONObject> dataList = (List<JSONObject>) transFlow.get("data");
String transType; String transType;
JSONObject device; JSONObject device;
int status; int status;
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition",
"attachment; filename=" + "Merchant_Settlement_Info_" + query.getDatefrom() + "_" + query.getDateto() + ".xlsx");
ous = resp.getOutputStream();
Workbook wb = new XSSFWorkbook();
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 10);
CellStyle analysisStyle = wb.createCellStyle();
analysisStyle.setFont(font);
String[] clientIds = query.getClient_ids();
List<String> clientIdList = new ArrayList<>();
clientIdList.add("ALL");
if (clientIds.length >= 2) {
clientIdList.addAll(Arrays.asList(clientIds));
}
Sheet sheet = null;
JSONObject client = null;
for (int i = 0;i < clientIdList.size();i++) {
if (i == 0) {
sheet = wb.createSheet("ALL");
} else {
client = clientManager.getClientInfo(Integer.parseInt(clientIdList.get(i)));
sheet = wb.createSheet(client == null ? clientIdList.get(i) : client.getString("client_moniker"));
}
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"Transaction Time", "Client Order ID", "System Order ID", "Client Moniker", "Short Name", "Order ID", "Channel", "Input Amount", "Transaction Amount", "Transaction Currency", "Clearing Amount", "Exchange Rate",
"Transaction Type", "Clearing Status", "Gateway", "Remark", "Dev No"};
for (int j = 0; j < title.length; j++) {
row.createCell(j, Cell.CELL_TYPE_STRING).setCellValue(title[j]);
}
String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency();
for (JSONObject data : dataList) { for (JSONObject data : dataList) {
transType = data.getString("trans_type"); if (!clientIdList.get(i).equals(data.getString("client_id")) && i != 0) {
if (!"refund".equals(transType))
continue; continue;
}
if (i == 0) {
transType = data.getString("trans_type");
if (!"refund".equals(transType)) {
status = data.getIntValue("status"); status = data.getIntValue("status");
if (status == 6) if (status == 6)
transType = "Partly " + transType; transType = "Partly " + transType;
else if (status == 7) { else if (status == 7) {
transType = "Fully " + transType; transType = "Fully " + transType;
} }
}
data.put("trans_type", transType); data.put("trans_type", transType);
device = clientDeviceMapper.find(data.getString("order_dev_id")); device = clientDeviceMapper.find(data.getString("order_dev_id"));
if (device != null) if (device != null)
data.put("dev_id", device.getString("client_dev_id")); data.put("dev_id", device.getString("client_dev_id"));
scaleDecimalVal(data, "display_amount", platformCurrency);
scaleDecimalVal(data, "transaction_amount", platformCurrency);
scaleDecimalVal(data, "clearing_amount", platformCurrency);
} }
JSONObject parmerters = new JSONObject(); row = sheet.createRow(++rowNum);
parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) ? query.getDatefrom() : ""); row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_time"));
parmerters.put("dateTo", StringUtils.isNotBlank(query.getDateto()) ? query.getDateto() : DateFormatUtils.format(new Date(), "yyyyMMdd")); row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_order_id"));
parmerters.put("partnerCode", partner.getString("client_moniker")); row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(data.getString("system_transaction_id"));
// parmerters.put("actual_fee", analysis.containsKey("actual_fee") ? row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_moniker"));
// analysis.getBigDecimal("actual_fee") : 0); row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(data.getString("short_name"));
JRDataSource jrDataSource = new JRBeanCollectionDataSource(dataList); row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_id"));
response.setContentType("application/vnd.ms-excel"); row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(data.getString("channel"));
String fileName = StringUtils.isEmpty(parmerters.getString("dateFrom")) ? parmerters.getString("dateTo") row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(data.getString("display_amount"));
: (parmerters.getString("dateFrom") + "~" + parmerters.getString("dateTo")); row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_amount"));
// String fileName = new String(URLEncoder.encode(defaultname,"utf8")); row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(data.getString("currency"));
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clearing_amount"));
OutputStream outputStream = response.getOutputStream(); row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type").equals("clearing")?"-":data.getBigDecimal("exchange_rate").toString());
JasperPrint jasperPrint = JasperFillManager.fillReport(trans_excel.getInputStream(), parmerters, jrDataSource); row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type"));
// JRXlsExporter exporter = new JRXlsExporter(); row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clear_status"));
JRXlsxExporter exporter = new JRXlsxExporter(); row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(data.getString("gateway"));
ExporterInput exporterInput = new SimpleExporterInput(jasperPrint); row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_detail"));
exporter.setExporterInput(exporterInput); row.createCell(16, Cell.CELL_TYPE_STRING).setCellValue(data.getString("dev_id"));
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(outputStream); }
exporter.setExporterOutput(exporterOutput); }
// 设置导出时参数 wb.write(ous);
SimpleXlsxReportConfiguration xlsReportConfiguration = new SimpleXlsxReportConfiguration(); ous.flush();
xlsReportConfiguration.setOnePagePerSheet(false); } catch (IOException e) {
xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true);
xlsReportConfiguration.setDetectCellType(true);
xlsReportConfiguration.setWhitePageBackground(false);
exporter.setConfiguration(xlsReportConfiguration);
exporter.exportReport();
outputStream.close();
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
IOUtils.closeQuietly(ous);
} }
} }
} }

@ -58,6 +58,8 @@
<select id="listTransFlow" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransFlow" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*, SELECT t.*,
o.status, o.status,
c.client_moniker,
c.short_name,
o.dev_id order_dev_id, o.dev_id order_dev_id,
ifnull(o.client_order_id,'--') client_order_id, ifnull(o.client_order_id,'--') client_order_id,
if(t.channel='Settlement','clearing', if(t.channel='Settlement','clearing',
@ -109,6 +111,7 @@
FROM pmt_transactions t FROM pmt_transactions t
LEFT JOIN pmt_orders o ON o.order_id=t.order_id LEFT JOIN pmt_orders o ON o.order_id=t.order_id
left join sys_customer_relation_alipay ra on ra.alipay_uid = o.customer_id left join sys_customer_relation_alipay ra on ra.alipay_uid = o.customer_id
LEFT JOIN sys_clients c on c.client_id = t.client_id
<where> <where>
<if test="client_ids!=null"> <if test="client_ids!=null">
AND t.client_id IN AND t.client_id IN

Loading…
Cancel
Save