From 0d7b31696bef614aaf8ba3d0ea0616b6fd80c68e Mon Sep 17 00:00:00 2001 From: yixian Date: Wed, 31 Jan 2018 16:09:43 +0800 Subject: [PATCH 1/2] invoice --- .../core/impls/TradeLogServiceImpl.java | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) 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 8559400d2..afd17050a 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 @@ -21,9 +21,11 @@ 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.env.PlatformEnvironment; import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.PartnerRole; +import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils; import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils; import com.alibaba.fastjson.JSONObject; @@ -545,41 +547,46 @@ public class TradeLogServiceImpl implements TradeLogService { // File jasperFile = trans_flow.getFile(); JSONObject transFlow = listPartnerTransFlow(query, partner); JSONObject analysis = transFlow.getJSONObject("analysis"); - if (transFlow.getJSONArray("data").size() > 0) { + if (!transFlow.getJSONArray("data").isEmpty()) { try { List dataList = (List) transFlow.get("data"); JSONObject parmerters = new JSONObject(); parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) - ? DateFormatUtils.format(DateUtils.parseDate(query.getDatefrom(), new String[]{"yyyyMMdd"}), "dd/MM/yyyy") : ""); + ? DateFormatUtils.format(DateUtils.parseDate(query.getDatefrom(), "yyyyMMdd"), "dd/MM/yyyy") : ""); parmerters.put("dateTo", StringUtils.isNotBlank(query.getDateto()) - ? DateFormatUtils.format(DateUtils.parseDate(query.getDateto(), new String[]{"yyyyMMdd"}), "dd/MM/yyyy") + ? DateFormatUtils.format(DateUtils.parseDate(query.getDateto(), "yyyyMMdd"), "dd/MM/yyyy") : DateFormatUtils.format(new Date(), "dd/MM/yyyy")); parmerters.put("dateRange", (StringUtils.isNotBlank(parmerters.getString("dateFrom")) ? parmerters.getString("dateFrom") : "") + "~" + parmerters.getString("dateTo")); parmerters.put("partnerCode", partner.getString("client_moniker")); parmerters.put("clientName", partner.getJSONObject("client").getString("company_name")); parmerters.put("clientAddress", partner.getJSONObject("client").getString("address")); - System.out.print(parmerters.toJSONString()); parmerters.put("balance", analysis.getDoubleValue("balance")); parmerters.put("logo", logo.getInputStream()); - parmerters.put("actual_fee", analysis.containsKey("actual_fee") ? analysis.getBigDecimal("actual_fee") : 0); - parmerters.put("totalSettledAmount", - analysis.containsKey("total_settle_amount") ? analysis.getBigDecimal("total_settle_amount").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("royalpay_charge", analysis.containsKey("total_royal_surcharge") ? analysis.getBigDecimal("total_royal_surcharge").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("total_fee", analysis.containsKey("total_surcharge") ? analysis.getBigDecimal("total_surcharge").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("alipay_fee", analysis.containsKey("alipay_fee") ? analysis.getBigDecimal("alipay_fee").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("wechat_fee", analysis.containsKey("wechat_fee") ? analysis.getBigDecimal("wechat_fee").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("bestpay_fee", analysis.containsKey("bestpay_fee") ? analysis.getBigDecimal("bestpay_fee").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("jd_fee", analysis.containsKey("jd_fee") ? analysis.getBigDecimal("jd_fee").setScale(2, BigDecimal.ROUND_DOWN) : 0); - parmerters.put("alipay_online_fee", analysis.containsKey("alipay_online_fee") ? analysis.getBigDecimal("alipay_online_fee").setScale(2, BigDecimal.ROUND_DOWN) : 0); // parmerters.put("gst", analysis.containsKey("clearing_fee") ? + parmerters.put("actual_fee", takeDecimalOrDefault(analysis, "actual_fee", BigDecimal.ZERO)); + parmerters.put("totalSettledAmount", takeDecimalOrDefault(analysis, "total_settle_amount", BigDecimal.ZERO)); + parmerters.put("royalpay_charge", takeDecimalOrDefault(analysis, "total_royal_surcharge", BigDecimal.ZERO)); + parmerters.put("total_fee", takeDecimalOrDefault(analysis, "total_surcharge", BigDecimal.ZERO) + "(GST Inclusive)"); + parmerters.put("alipay_fee", takeDecimalOrDefault(analysis, "alipay_fee", BigDecimal.ZERO)); + parmerters.put("wechat_fee", takeDecimalOrDefault(analysis, "wechat_fee", BigDecimal.ZERO)); + parmerters.put("bestpay_fee", takeDecimalOrDefault(analysis, "bestpay_fee", BigDecimal.ZERO)); + parmerters.put("jd_fee", takeDecimalOrDefault(analysis, "jd_fee", BigDecimal.ZERO)); + parmerters.put("alipay_online_fee", takeDecimalOrDefault(analysis, "alipay_online_fee", BigDecimal.ZERO)); // parmerters.put("gst", analysis.containsKey("clearing_fee") ? // analysis.getBigDecimal("clearing_fee").multiply(new BigDecimal(0.11)).setScale(2, // BigDecimal.ROUND_DOWN) : 0); // parmerters.put("gst", // analysis.containsKey("total_royal_surcharge") ? analysis.getBigDecimal("total_royal_surcharge").divide(new BigDecimal(11), 2, BigDecimal.ROUND_DOWN) : 0); + dataList.parallelStream().forEach(item -> { + scaleDecimalVal(item, "display_amount", item.getString("currency")); + String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency(); + scaleDecimalVal(item, "clearing_amount", platformCurrency); + scaleDecimalVal(item, "settle_amount", platformCurrency); + scaleDecimalVal(item, "total_surcharge", platformCurrency); + }); JRDataSource jrDataSource = new JRBeanCollectionDataSource(dataList); response.setContentType("application/pdf"); - String fileName = parmerters.getString("dateRange").replaceAll("/", ""); + 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(trans_flow.getInputStream(), parmerters, jrDataSource); @@ -593,6 +600,19 @@ public class TradeLogServiceImpl implements TradeLogService { } } + private void scaleDecimalVal(JSONObject obj, String key, String currency) { + BigDecimal decimal = obj.getBigDecimal(key); + if (decimal == null) { + return; + } + obj.put(key, CurrencyAmountUtils.scale(decimal, currency)); + } + + private String takeDecimalOrDefault(JSONObject analysis, String key, BigDecimal defaultVal) { + BigDecimal decimal = analysis.containsKey(key) ? analysis.getBigDecimal(key) : defaultVal; + return CurrencyAmountUtils.scale(decimal, PlatformEnvironment.getEnv().getForeignCurrency()).toPlainString(); + } + @Override public void exportExcel(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception { logger.debug("excel The method======= exportExcel() start......................."); From 2502a96da66c84a19393a4c439d838f2d035e562 Mon Sep 17 00:00:00 2001 From: yixian Date: Wed, 31 Jan 2018 17:07:50 +0800 Subject: [PATCH 2/2] invoice --- .../manage/tradelog/core/impls/TradeLogServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 afd17050a..1694ea999 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 @@ -567,7 +567,7 @@ public class TradeLogServiceImpl implements TradeLogService { parmerters.put("actual_fee", takeDecimalOrDefault(analysis, "actual_fee", BigDecimal.ZERO)); parmerters.put("totalSettledAmount", takeDecimalOrDefault(analysis, "total_settle_amount", BigDecimal.ZERO)); parmerters.put("royalpay_charge", takeDecimalOrDefault(analysis, "total_royal_surcharge", BigDecimal.ZERO)); - parmerters.put("total_fee", takeDecimalOrDefault(analysis, "total_surcharge", BigDecimal.ZERO) + "(GST Inclusive)"); + parmerters.put("total_fee", takeDecimalOrDefault(analysis, "total_surcharge", BigDecimal.ZERO)); parmerters.put("alipay_fee", takeDecimalOrDefault(analysis, "alipay_fee", BigDecimal.ZERO)); parmerters.put("wechat_fee", takeDecimalOrDefault(analysis, "wechat_fee", BigDecimal.ZERO)); parmerters.put("bestpay_fee", takeDecimalOrDefault(analysis, "bestpay_fee", BigDecimal.ZERO)); @@ -608,9 +608,9 @@ public class TradeLogServiceImpl implements TradeLogService { obj.put(key, CurrencyAmountUtils.scale(decimal, currency)); } - private String takeDecimalOrDefault(JSONObject analysis, String key, BigDecimal defaultVal) { + private BigDecimal takeDecimalOrDefault(JSONObject analysis, String key, BigDecimal defaultVal) { BigDecimal decimal = analysis.containsKey(key) ? analysis.getBigDecimal(key) : defaultVal; - return CurrencyAmountUtils.scale(decimal, PlatformEnvironment.getEnv().getForeignCurrency()).toPlainString(); + return CurrencyAmountUtils.scale(decimal, PlatformEnvironment.getEnv().getForeignCurrency()); } @Override