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 db7b1aa77..a6422e90a 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 @@ -174,4 +174,6 @@ public interface TransactionMapper { List getSettlementLogDetailList(@Param("clientOrders") List clientOrders, @Param("client_id") int clientId); List getClientOrderByTransactionTime(JSONObject params); + + List listTransFlowDetail(JSONObject params); } 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 0409db451..ef5de2650 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 @@ -70,6 +70,7 @@ 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.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -674,100 +675,112 @@ public class TradeLogServiceImpl implements TradeLogService { @Override public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse resp) throws Exception { logger.debug("excel The method======= exportExcel() start......................."); - JSONObject transFlow = listPartnerTransFlow(query, partner); - // JSONObject analysis = transFlow.getJSONObject("analysis"); - if (transFlow.getJSONArray("data").size() > 0) { + int client_id = partner.getIntValue("client_id"); + String timezone = partner.getJSONObject("client").getString("timezone"); + JSONObject params = query.toParams(timezone); + clientManager.validateClients(client_id, params); + params.put("client_id", client_id); + List logs = transactionMapper.listTransFlowDetail(params); + + TimeZoneUtils.switchTimeZoneToString(logs, timezone, "dd/MM/yyyy HH:mm:ss", Arrays.asList("transaction_time")); + if (logs.size() > 0) { OutputStream ous = null; - try { - List dataList = (List) transFlow.get("data"); - String transType; - JSONObject device; - 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 clientIdList = new ArrayList<>(); - clientIdList.add("ALL"); - if (clientIds.length >= 2) { - clientIdList.addAll(Arrays.asList(clientIds)); + String transType; + int status; + HSSFWorkbook wb = new HSSFWorkbook(); + 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 clientIdList = new ArrayList<>(); + clientIdList.add("ALL"); + if (clientIds.length >= 2) { + clientIdList.addAll(Arrays.asList(clientIds)); + } + HSSFSheet sheet = null; + JSONObject client = null; + String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency(); + for (String clientId : clientIdList) { + if ("ALL".equals(clientId)) { + sheet = wb.createSheet(clientId); + } else { + client = clientManager.getClientInfo(Integer.parseInt(clientId)); + sheet = wb.createSheet(client == null ? clientId : client.getString("client_moniker")); } - 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) { - if (!clientIdList.get(i).equals(data.getString("client_id")) && i != 0) { - continue; + 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]); + } + if ("ALL".equals(clientId)) { + for (JSONObject log : logs) { + String login_id = log.getString("login_id"); + if (StringUtils.isNotEmpty(login_id)) { + log.put("order_detail", (StringUtils.isEmpty(log.getString("order_detail")) ? "" : login_id+":"+log.getString("order_detail"))); + }else{ + log.put("order_detail", (StringUtils.isEmpty(log.getString("order_detail")) ? "" : log.getString("order_detail"))); } - if (i == 0) { - transType = data.getString("trans_type"); - if (!"refund".equals(transType)) { - status = data.getIntValue("status"); - if (status == 6) - transType = "Partly " + transType; - else if (status == 7) { - transType = "Fully " + transType; - } + transType = log.getString("trans_type"); + if (!"refund".equals(transType)) { + status = log.getIntValue("status"); + if (status == 6) + transType = "Partly " + transType; + else if (status == 7) { + transType = "Fully " + transType; } - data.put("trans_type", transType); - device = clientDeviceMapper.find(data.getString("order_dev_id")); - if (device != null) - data.put("dev_id", device.getString("client_dev_id")); - scaleDecimalVal(data, "display_amount", platformCurrency); - scaleDecimalVal(data, "transaction_amount", platformCurrency); - scaleDecimalVal(data, "clearing_amount", platformCurrency); } + log.put("trans_type", transType); + scaleDecimalVal(log, "display_amount", platformCurrency); + scaleDecimalVal(log, "transaction_amount", platformCurrency); + scaleDecimalVal(log, "clearing_amount", platformCurrency); row = sheet.createRow(++rowNum); - row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_time")); - row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_order_id")); - row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(data.getString("system_transaction_id")); - row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_moniker")); - row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(data.getString("short_name")); - row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_id")); - row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(data.getString("channel")); - row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(data.getString("display_amount")); - row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_amount")); - row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(data.getString("currency")); - row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clearing_amount")); - row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type").equals("clearing")?"-":data.getBigDecimal("exchange_rate").toString()); - row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type")); - row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clear_status")); - row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(data.getString("gateway")); - row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_detail")); - row.createCell(16, Cell.CELL_TYPE_STRING).setCellValue(data.getString("dev_id")); + excelTrans(row, log); + } + } else { + List logsByClientId = logs.stream().filter(log -> log.getString("client_id").equals(clientId)).collect(Collectors.toList()); + for (JSONObject log : logsByClientId) { + row = sheet.createRow(++rowNum); + excelTrans(row, log); } } + } + resp.setContentType("application/octet-stream;"); + resp.addHeader("Content-Disposition", + "attachment; filename=" + "Merchant_Settlement_Info_" + query.getDatefrom() + "_" + query.getDateto() + ".xls"); + ous = resp.getOutputStream(); + try { wb.write(ous); - ous.flush(); - } catch (IOException e) { + ous.close(); + } catch (Exception e) { e.printStackTrace(); - } finally { - IOUtils.closeQuietly(ous); } } } + private void excelTrans(Row row, JSONObject data) { + row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_time")); + row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_order_id")); + row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(data.getString("system_transaction_id")); + row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(data.getString("client_moniker")); + row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(data.getString("short_name")); + row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_id")); + row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(data.getString("channel")); + row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(data.getString("display_amount")); + row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(data.getString("transaction_amount")); + row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(data.getString("currency")); + row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clearing_amount")); + row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type").equals("clearing")?"-":data.getBigDecimal("exchange_rate").toString()); + row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(data.getString("trans_type")); + row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(data.getString("clear_status")); + row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(data.getString("gateway")); + row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(data.getString("order_detail")); + row.createCell(16, Cell.CELL_TYPE_STRING).setCellValue(data.getString("dev_id")); + } + @Override public void exportExcelNew(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception { logger.debug("excel The method======= exportExcelNew() start......................."); 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 4572cdea4..23b2f5ecf 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 @@ -58,8 +58,6 @@ + +