From 2e6f1633c47588c823b6328fcf7cb6e6de715461 Mon Sep 17 00:00:00 2001 From: yixian Date: Fri, 28 Aug 2020 19:51:28 +1000 Subject: [PATCH 1/5] version update, fix refund balance check --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 212490d6e..5c0223ff0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,11 @@ au.com.royalpay.payment payment-parent - 2.2.10 + 2.2.11 4.0.0 manage - 2.3.65 + 2.3.66 UTF-8 2.4.0 From 231540d310ecfa4cbd7fae31a554a7fe2f94b544 Mon Sep 17 00:00:00 2001 From: "xiao.tang" Date: Fri, 4 Sep 2020 14:51:42 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8feat(royalpay):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dindustry=E2=80=94=E2=80=94alipay=20category=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/commons/css/multiLevelSelect.css | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/ui/static/commons/css/multiLevelSelect.css b/src/main/ui/static/commons/css/multiLevelSelect.css index c7ae4c85e..3b2476ffc 100644 --- a/src/main/ui/static/commons/css/multiLevelSelect.css +++ b/src/main/ui/static/commons/css/multiLevelSelect.css @@ -1,33 +1,35 @@ -.ml-select-box{ - position: absolute; - height: 300px; - white-space: nowrap; - z-index: 9999; +.ml-select-box { + position: absolute; + height: 300px; + white-space: nowrap; + z-index: 9999; + background: white; } -.ml-select-box ul.select-group{ - display: inline-block; - width: 240px; - overflow: auto; - height: 200px; - margin: 0; - padding: 0; - list-style: none; +.ml-select-box ul.select-group { + display: inline-block; + /* width: 240px; */ + overflow: auto; + height: 200px; + margin: 0; + padding: 0; + list-style: none; } -.ml-select-box ul.select-group li{ - list-style: none; - width: 100%; - display: block; - height: 30px; - line-height: 30px; - cursor:pointer; - background: #fff; - font-size: 14px; - padding: 0 5px; +.ml-select-box ul.select-group li { + list-style: none; + width: 100%; + display: block; + height: 30px; + line-height: 30px; + cursor: pointer; + background: #fff; + font-size: 14px; + padding: 0 5px; } -.ml-select-box ul.select-group li:hover,.ml-select-box ul.select-group li.active{ - background: #c0c0c0; - font-weight: bold; -} \ No newline at end of file +.ml-select-box ul.select-group li:hover, +.ml-select-box ul.select-group li.active { + background: #c0c0c0; + font-weight: bold; +} From da729610d6681c5d0d8a8ed77833c9eaaa0f2d62 Mon Sep 17 00:00:00 2001 From: coral chen Date: Fri, 4 Sep 2020 15:25:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=A7=A3=E9=99=A4=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=95=86=E6=9C=8D=E5=BC=80=E5=BA=97=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/appclient/core/impls/RetailRSvcServiceImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java index c26fdab76..63b0fcc73 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java @@ -66,12 +66,7 @@ public class RetailRSvcServiceImpl implements RetailRSvcService { public JSONObject findMchInfoBySourceCode(JSONObject device, String sourceCode, boolean debug) { String clientType = device.getString("client_type"); deviceSupport.findRegister(clientType); - JSONObject clientConfig = clientConfigMapper.find(device.getIntValue("client_id")); - if (!debug && !clientConfig.getBooleanValue("geek_shop_status") - && device.getIntValue("client_id") != 9 - && device.getIntValue("client_id") != 4181) { - throw new NotFoundException(); - } + JSONObject svcInfo = commonIncrementalChannelMapper.findIncreamentalChannelBySourceCode(sourceCode); if (svcInfo == null || StringUtils.isEmpty(svcInfo.getString("channel_pub_key")) || StringUtils.isEmpty(svcInfo.getString("platform_pub_key")) || StringUtils.isEmpty("platform_pri_key")) { From 93e1f8bc9475cd727faf8deba84541aff0750440 Mon Sep 17 00:00:00 2001 From: coral chen Date: Fri, 4 Sep 2020 15:26:59 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=A7=A3=E9=99=A4=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=95=86=E6=9C=8D=E5=BC=80=E5=BA=97=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/appclient/core/impls/RetailRSvcServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java index 63b0fcc73..eb74c75fb 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java @@ -66,7 +66,7 @@ public class RetailRSvcServiceImpl implements RetailRSvcService { public JSONObject findMchInfoBySourceCode(JSONObject device, String sourceCode, boolean debug) { String clientType = device.getString("client_type"); deviceSupport.findRegister(clientType); - + JSONObject svcInfo = commonIncrementalChannelMapper.findIncreamentalChannelBySourceCode(sourceCode); if (svcInfo == null || StringUtils.isEmpty(svcInfo.getString("channel_pub_key")) || StringUtils.isEmpty(svcInfo.getString("platform_pub_key")) || StringUtils.isEmpty("platform_pri_key")) { From 285d96b5170e8ab73b19b3755cb64d0f03dc2b30 Mon Sep 17 00:00:00 2001 From: dalong306 <304592994@qq.com> Date: Fri, 4 Sep 2020 16:28:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?settle,invoice=20pdf=20=E6=8E=A8=E9=80=81Se?= =?UTF-8?q?curePay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/dev/web/TestController.java | 19 +- .../system/core/TradeSecureService.java | 2 + .../impl/TradeSecureServiceHanyinImpl.java | 20 + .../manage/task/SecurePayInvoiceFileTask.java | 39 ++ .../manage/tradelog/core/TradeLogService.java | 2 + .../core/impls/TradeLogServiceImpl.java | 406 ++++++++++++++---- src/main/resources/templates/app/invoice.html | 43 +- .../reports/securepay_settlement.html | 250 +++++++++++ 8 files changed, 674 insertions(+), 107 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/task/SecurePayInvoiceFileTask.java create mode 100644 src/main/resources/templates/reports/securepay_settlement.html diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java index acfe399d9..2590040df 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java @@ -71,6 +71,7 @@ import java.math.RoundingMode; import java.net.URISyntaxException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -581,7 +582,21 @@ public class TestController { } @GetMapping(value = "/securepay/settle/file") - public void sendSecurePaySettleFile() { - tradeSecureService.sendSecurePaySettleFile("20200803"); + public void sendSecurePaySettleFile(@RequestParam String dateStr) { + tradeSecureService.sendSecurePaySettleFile(dateStr); + } + @GetMapping(value = "/securepay/invoice/file") + public void sendSecurePayInvoiceFile() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + //获取前一个月第一天 + Calendar calendar1 = Calendar.getInstance(); + calendar1.add(Calendar.MONTH, -1); + calendar1.set(Calendar.DAY_OF_MONTH,1); + String firstDay = sdf.format(calendar1.getTime()); + //获取前一个月最后一天 + Calendar calendar2 = Calendar.getInstance(); + calendar2.set(Calendar.DAY_OF_MONTH, 0); + String lastDay = sdf.format(calendar2.getTime()); + tradeSecureService.sendSecurePayInvoiceFile(firstDay,lastDay); } } diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/TradeSecureService.java b/src/main/java/au/com/royalpay/payment/manage/system/core/TradeSecureService.java index 33dcb175f..60f90ab8e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/TradeSecureService.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/TradeSecureService.java @@ -18,4 +18,6 @@ public interface TradeSecureService { TradeSecureFile getSecureReportFile(Date date); void sendSecurePaySettleFile(String dateStr); + + void sendSecurePayInvoiceFile(String beginDate,String endDate); } diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java index 23ee9beaa..dceef926d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/TradeSecureServiceHanyinImpl.java @@ -147,7 +147,27 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService { }); } + @Override + public void sendSecurePayInvoiceFile(String begin,String end) { + List scpayMchs = clientAnalysisMapper.listSecurePayMchs(); + scpayMchs.forEach(mch -> { + TradeLogQuery query = new TradeLogQuery(); + query.setDatefrom(begin); + query.setDateto(end); + query.setClearing_status(-1); + byte[] fileData = new byte[0]; + try { + fileData=tradeLogService.exportTransFlowForSecurePay(query, mch); + } catch (Exception e) { + e.printStackTrace(); + } + String fileName = StringUtils.substring(begin, 0, 6) + "-Invoice-" + RandomStringUtils.random(9, true, true).toUpperCase() + "-" + + mch.getString("client_moniker") + ".pdf"; + sendSftpFile(begin, fileName, fileData); + }); + + } private void sendSftpFile(String dateStr, String fileName, byte[] data) { Session session = null; ChannelSftp command = null; diff --git a/src/main/java/au/com/royalpay/payment/manage/task/SecurePayInvoiceFileTask.java b/src/main/java/au/com/royalpay/payment/manage/task/SecurePayInvoiceFileTask.java new file mode 100644 index 000000000..0e52a13f6 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/task/SecurePayInvoiceFileTask.java @@ -0,0 +1,39 @@ +package au.com.royalpay.payment.manage.task; + +import au.com.royalpay.payment.manage.system.core.TradeSecureService; +import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Component +@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true") +public class SecurePayInvoiceFileTask { + + @Resource + private SynchronizedScheduler synchronizedScheduler; + @Resource + private TradeSecureService tradeSecureService; + + @Scheduled(cron = "0 30 3 1 * *") + public void sendSecurePaySettleFile() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + //获取前一个月第一天 + Calendar calendar1 = Calendar.getInstance(); + calendar1.add(Calendar.MONTH, -1); + calendar1.set(Calendar.DAY_OF_MONTH,1); + String firstDay = sdf.format(calendar1.getTime()); + //获取前一个月最后一天 + Calendar calendar2 = Calendar.getInstance(); + calendar2.set(Calendar.DAY_OF_MONTH, 0); + String lastDay = sdf.format(calendar2.getTime()); + + synchronizedScheduler.executeProcess("task:securepay_invoice_file_sending", 60_000, () -> + tradeSecureService.sendSecurePayInvoiceFile(firstDay,lastDay) + ); + } +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java index e79e3201a..2476fa1c2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/TradeLogService.java @@ -37,6 +37,8 @@ public interface TradeLogService { void exportTransFlow(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception; + byte[] exportTransFlowForSecurePay(TradeLogQuery query, JSONObject client) throws Exception; + ModelAndView exportTransFlow(TradeLogQuery query, JSONObject partner, Model model) throws Exception; void exportUpayTransFlow(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception; 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 67c3765b9..15df99b94 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 @@ -153,6 +153,10 @@ public class TradeLogServiceImpl implements TradeLogService { private org.springframework.core.io.Resource austrac_report; @Value("classpath:/jasper/partner_settlement_detail.jasper") private org.springframework.core.io.Resource partner_settlement_flow; + @Value("classpath:/jasper/securepay_logo.png") + private org.springframework.core.io.Resource securepay_logo; + @Value("classpath:/jasper/securepay_settlement_detail.jasper") + private org.springframework.core.io.Resource securepay_settlement_flow; @Override public JSONObject listPartnerTradeLogs(JSONObject manager, JSONObject account, String shortId, TradeLogQuery query, String timezone) throws Exception { @@ -589,6 +593,32 @@ public class TradeLogServiceImpl implements TradeLogService { result.put("analysis", analysis); return result; } + private JSONObject listPartnerTransFlowByExportPdfSecurePay(TradeLogQuery query, JSONObject client, String[] channels) throws Exception { + int clientId = client.getIntValue("client_id"); + String timezone = client.getString("timezone"); + JSONObject params = query.toParams(timezone); +// params.put("channel", channels); + clientManager.validateClients(clientId, params); + params.put("client_id", clientId); + JSONObject mchConfig = merchantInfoProvider.getMchExtParams(client.getIntValue("client_id")); + params.put("hide_sub_mch", mchConfig.getBooleanValue("hide_sub_mch")); + params.put("channel", channels); + clientManager.queryModifyClientIds(clientId, params); + List logs = transactionMapper.listTransFlow(params); + TimeZoneUtils.switchTimeZoneToString(logs, timezone, "dd/MM/yyyy HH:mm:ss", Collections.singletonList("transaction_time")); + TimeZoneUtils.switchTimeZoneToString(logs, timezone, "dd/MM/yyyy", Collections.singletonList("clearing_time")); + + final JSONObject analysis = analysisTransLogs(logs); + + JSONObject result = new JSONObject(); + result.put("data", logs); + analysis.put("balance", transactionMapper.analysisBalance(params)); + if (analysis.containsKey("paid_fee") && analysis.containsKey("refund_fee")) { + analysis.put("actual_fee", analysis.getBigDecimal("paid_fee").add(analysis.getBigDecimal("refund_fee"))); + } + result.put("analysis", analysis); + return result; + } private JSONObject analysisTransLogs(List logs) { final JSONObject analysis = new JSONObject(); @@ -771,93 +801,180 @@ public class TradeLogServiceImpl implements TradeLogService { JSONObject analysis = transFlow.getJSONObject("analysis"); JSONObject client = clientManager.getClientInfo(partner.getIntValue("client_id")); Context ctx = new Context(); - if (!transFlow.getJSONArray("data").isEmpty()) { - try (OutputStream outs = response.getOutputStream(); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ) { - List dataList = transFlow.getJSONArray("data").toJavaList(JSONObject.class); - JSONObject parmerters = new JSONObject(); - parmerters.put("records", dataList.size()); - parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) - ? DateFormatUtils.format(DateUtils.parseDate(query.getDatefrom(), "yyyyMMdd"), "dd/MM/yyyy") : ""); - parmerters.put("dateTo", - StringUtils.isNotBlank(query.getDateto()) - ? 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", client.getString("client_moniker")); - parmerters.put("clientName", client.getString("company_name")); - parmerters.put("clientAddress", client.getString("address")); - parmerters.put("balance", analysis.getDoubleValue("balance")); - parmerters.put("logo", logo.getInputStream()); - 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)); - parmerters.put("alipay_fee", takeDecimalOrDefault(analysis, "alipay_fee", BigDecimal.ZERO)); - parmerters.put("wechat_fee", takeDecimalOrDefault(analysis, "wechat_fee", BigDecimal.ZERO)); - parmerters.put("alipay_online_fee", takeDecimalOrDefault(analysis, "alipay_online_fee", BigDecimal.ZERO)); - parmerters.put("gst", takeDecimalOrDefault(analysis, "tax_amount", BigDecimal.ZERO)); - parmerters.put("royalpay_fee", takeDecimalOrDefault(analysis, "total_royalpay_fee", BigDecimal.ZERO)); - parmerters.put("incremental_fee", takeDecimalOrDefault(analysis, "total_incremental_surcharge", BigDecimal.ZERO)); - parmerters.put("incremental_gst", takeDecimalOrDefault(analysis, "total_incremental_tax", BigDecimal.ZERO)); - parmerters.put("royalpay_gst", analysis.getBigDecimal("tax_amount").subtract(analysis.getBigDecimal("total_incremental_tax")).setScale(2, RoundingMode.HALF_UP)); + JSONObject parmerters = new JSONObject(); + int recordsSize=transFlow.getJSONArray("data").isEmpty()?0:transFlow.getJSONArray("data").size(); + parmerters.put("records",recordsSize); + parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) + ? DateFormatUtils.format(DateUtils.parseDate(query.getDatefrom(), "yyyyMMdd"), "dd/MM/yyyy") : ""); + parmerters.put("dateTo", + StringUtils.isNotBlank(query.getDateto()) + ? 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", client.getString("client_moniker")); + parmerters.put("clientName", client.getString("company_name")); + parmerters.put("clientAddress", client.getString("address")); + parmerters.put("balance", analysis.getDoubleValue("balance")); + parmerters.put("logo", logo.getInputStream()); + 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)); + parmerters.put("alipay_fee", takeDecimalOrDefault(analysis, "alipay_fee", BigDecimal.ZERO)); + parmerters.put("wechat_fee", takeDecimalOrDefault(analysis, "wechat_fee", BigDecimal.ZERO)); + parmerters.put("alipay_online_fee", takeDecimalOrDefault(analysis, "alipay_online_fee", BigDecimal.ZERO)); + parmerters.put("gst", takeDecimalOrDefault(analysis, "tax_amount", BigDecimal.ZERO)); + parmerters.put("royalpay_fee", takeDecimalOrDefault(analysis, "total_royalpay_fee", BigDecimal.ZERO)); + parmerters.put("incremental_fee", takeDecimalOrDefault(analysis, "total_incremental_surcharge", BigDecimal.ZERO)); + parmerters.put("incremental_gst", takeDecimalOrDefault(analysis, "total_incremental_tax", BigDecimal.ZERO)); + parmerters.put("royalpay_gst", analysis.getBigDecimal("tax_amount").subtract(analysis.getBigDecimal("total_incremental_tax")).setScale(2, RoundingMode.HALF_UP)); + ctx.setVariable("parmerters", parmerters); + JSONObject orgInfo = orgManager.getOrgDetail(client.getIntValue("org_id"), null); + if (!orgInfo.containsKey("logo") || orgInfo.getIntValue("org_id") == 1) { + orgInfo.put("logo", "none"); + } + ctx.setVariable("orgInfo", orgInfo); + try { + OutputStream outs = response.getOutputStream(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + List dataList= transTransform(transFlow); + ctx.setVariable("dataList", dataList); + final String html = thymeleaf.process("app/invoice.html", ctx); + response.setContentType("application/pdf"); + String fileName = client.getString("client_moniker") + "_Cross_Border_" + parmerters.getString("dateRange").replaceAll("/", ""); + response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf"); + ITextRenderer renderer = new ITextRenderer(); + //添加字体库end + renderer.setDocumentFromString(html); + renderer.layout(); + renderer.createPDF(os); + byte[] bytes = os.toByteArray(); + outs.write(bytes, 0, bytes.length); + outs.flush(); + renderer.finishPDF(); + } - dataList.parallelStream().forEach(item -> { - BigDecimal incrementalSurcharge = item.containsKey("incremental_surcharge") ? item.getBigDecimal("incremental_surcharge") : BigDecimal.ZERO; - BigDecimal taxAmount = item.containsKey("tax_amount") ? item.getBigDecimal("tax_amount") : BigDecimal.ZERO; - BigDecimal royalpaySurhcarge = item.containsKey("royal_surcharge") ? item.getBigDecimal("royal_surcharge") : BigDecimal.ZERO; - BigDecimal surhcargeBack = item.containsKey("surcharge_cashback") ? item.getBigDecimal("surcharge_cashback") : BigDecimal.ZERO; - BigDecimal channelSurcharge = item.containsKey("channel_surcharge") ? item.getBigDecimal("channel_surcharge") : BigDecimal.ZERO; - BigDecimal incrementalTax = incrementalSurcharge.divide(new BigDecimal(10), 2, RoundingMode.HALF_UP); - BigDecimal royalpayTax = taxAmount.subtract(incrementalTax); - BigDecimal realRoyalpayCharge = royalpaySurhcarge - .add(surhcargeBack) - .add(channelSurcharge) - .add(royalpayTax); - item.put("incremental_surcharge", incrementalSurcharge.add(incrementalTax).setScale(2, RoundingMode.HALF_UP)); - item.put("real_royalpay_surcharge", realRoyalpayCharge.setScale(2, RoundingMode.HALF_UP)); - 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); - String debit = item.getString("transaction_type").equals("Debit") ? item.getBigDecimal("clearing_amount").toString() - : "-"; - String credit = item.getString("transaction_type").equals("Credit") ? item.getBigDecimal("clearing_amount").toString() - : "-"; - item.put("debit", debit); - item.put("credit", credit); - item.putIfAbsent("settle_amount", "-"); - }); - ctx.setVariable("parmerters", parmerters); - ctx.setVariable("dataList", dataList); - JSONObject orgInfo = orgManager.getOrgDetail(client.getIntValue("org_id"), null); - if (!orgInfo.containsKey("logo") || orgInfo.getIntValue("org_id") == 1) { - orgInfo.put("logo", "none"); - } - ctx.setVariable("orgInfo", orgInfo); - final String html = thymeleaf.process("app/invoice.html", ctx); - response.setContentType("application/pdf"); - String fileName = client.getString("client_moniker") + "_Cross_Border_" + parmerters.getString("dateRange").replaceAll("/", ""); - response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf"); - ITextRenderer renderer = new ITextRenderer(); - //添加字体库end - renderer.setDocumentFromString(html); - renderer.layout(); - renderer.createPDF(os); - byte[] bytes = os.toByteArray(); - outs.write(bytes, 0, bytes.length); - outs.flush(); - renderer.finishPDF(); - } catch (Exception e) { - e.printStackTrace(); - } + catch (Exception e) { + e.printStackTrace(); + } + + + + } + @Override + public byte[] exportTransFlowForSecurePay(TradeLogQuery query, JSONObject client) throws Exception { + JSONObject transFlow = listPartnerTransFlowByExportPdfSecurePay(query, client, new String[]{"Wechat", "Alipay", "AlipayOnline"}); + JSONObject analysis = transFlow.getJSONObject("analysis"); +// JSONObject client = clientManager.getClientInfo(partner.getIntValue("client_id")); + Context ctx = new Context(); + JSONObject parmerters = new JSONObject(); + int recordsSize=transFlow.getJSONArray("data").isEmpty()?0:transFlow.getJSONArray("data").size(); + parmerters.put("records",recordsSize); + parmerters.put("dateFrom", StringUtils.isNotBlank(query.getDatefrom()) + ? DateFormatUtils.format(DateUtils.parseDate(query.getDatefrom(), "yyyyMMdd"), "dd/MM/yyyy") : ""); + parmerters.put("dateTo", + StringUtils.isNotBlank(query.getDateto()) + ? 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", client.getString("client_moniker")); + parmerters.put("clientName", client.getString("company_name")); + parmerters.put("clientAddress", client.getString("address")); + parmerters.put("balance", analysis.getDoubleValue("balance")); + parmerters.put("logo", logo.getInputStream()); + 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)); + parmerters.put("alipay_fee", takeDecimalOrDefault(analysis, "alipay_fee", BigDecimal.ZERO)); + parmerters.put("wechat_fee", takeDecimalOrDefault(analysis, "wechat_fee", BigDecimal.ZERO)); + parmerters.put("alipay_online_fee", takeDecimalOrDefault(analysis, "alipay_online_fee", BigDecimal.ZERO)); + parmerters.put("gst", takeDecimalOrDefault(analysis, "tax_amount", BigDecimal.ZERO)); + parmerters.put("royalpay_fee", takeDecimalOrDefault(analysis, "total_royalpay_fee", BigDecimal.ZERO)); + parmerters.put("incremental_fee", takeDecimalOrDefault(analysis, "total_incremental_surcharge", BigDecimal.ZERO)); + parmerters.put("incremental_gst", takeDecimalOrDefault(analysis, "total_incremental_tax", BigDecimal.ZERO)); + parmerters.put("royalpay_gst", analysis.getBigDecimal("tax_amount").subtract(analysis.getBigDecimal("total_incremental_tax")).setScale(2, RoundingMode.HALF_UP)); + ctx.setVariable("parmerters", parmerters); + JSONObject orgInfo = orgManager.getOrgDetail(client.getIntValue("org_id"), null); + if (!orgInfo.containsKey("logo") || orgInfo.getIntValue("org_id") == 1) { + orgInfo.put("logo", "none"); + } + ctx.setVariable("orgInfo", orgInfo); + try { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + List dataList= transTransform(transFlow); + ctx.setVariable("dataList", dataList); + + final String html = thymeleaf.process("app/invoice.html", ctx); + ITextRenderer renderer = new ITextRenderer(); + //添加字体库end + renderer.setDocumentFromString(html); + renderer.layout(); + renderer.createPDF(os); + byte[] bytes = os.toByteArray(); + + renderer.finishPDF(); + os.close(); + return bytes; } + + catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private List transTransform( JSONObject transFlow ){ + List dataList; + if (!transFlow.getJSONArray("data").isEmpty()) { + dataList = transFlow.getJSONArray("data").toJavaList(JSONObject.class); + dataList.parallelStream().forEach(item -> { + BigDecimal incrementalSurcharge = item.containsKey("incremental_surcharge") ? item.getBigDecimal("incremental_surcharge") : BigDecimal.ZERO; + BigDecimal taxAmount = item.containsKey("tax_amount") ? item.getBigDecimal("tax_amount") : BigDecimal.ZERO; + BigDecimal royalpaySurhcarge = item.containsKey("royal_surcharge") ? item.getBigDecimal("royal_surcharge") : BigDecimal.ZERO; + BigDecimal surhcargeBack = item.containsKey("surcharge_cashback") ? item.getBigDecimal("surcharge_cashback") : BigDecimal.ZERO; + BigDecimal channelSurcharge = item.containsKey("channel_surcharge") ? item.getBigDecimal("channel_surcharge") : BigDecimal.ZERO; + BigDecimal incrementalTax = incrementalSurcharge.divide(new BigDecimal(10), 2, RoundingMode.HALF_UP); + BigDecimal royalpayTax = taxAmount.subtract(incrementalTax); + BigDecimal realRoyalpayCharge = royalpaySurhcarge + .add(surhcargeBack) + .add(channelSurcharge) + .add(royalpayTax); + item.put("incremental_surcharge", incrementalSurcharge.add(incrementalTax).setScale(2, RoundingMode.HALF_UP)); + item.put("real_royalpay_surcharge", realRoyalpayCharge.setScale(2, RoundingMode.HALF_UP)); + 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); + String debit = item.getString("transaction_type").equals("Debit") ? item.getBigDecimal("clearing_amount").toString() + : "-"; + String credit = item.getString("transaction_type").equals("Credit") ? item.getBigDecimal("clearing_amount").toString() + : "-"; + item.put("debit", debit); + item.put("credit", credit); + item.putIfAbsent("settle_amount", "-"); + }); + }else{ + dataList=new ArrayList<>(); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("transaction_time","-"); + jsonObject.put("client_order_id","-"); + jsonObject.put("order_id","-"); + jsonObject.put("debit","-"); + jsonObject.put("credit","-"); + jsonObject.put("real_royalpay_surcharge","-"); + jsonObject.put("incremental_surcharge","-"); + jsonObject.put("settle_amount","-"); + dataList.add(jsonObject); + } + return dataList; } + @Override public ModelAndView exportTransFlow(TradeLogQuery query, JSONObject partner, Model model) throws Exception { JSONObject transFlow = listPartnerTransFlowByExportPdf(query, partner, new String[]{"Wechat", "Alipay", "AlipayOnline"}); @@ -1969,6 +2086,69 @@ public class TradeLogServiceImpl implements TradeLogService { } } + // @Override +// public byte[] exportPDFSettlement(TradeLogQuery query, JSONObject client) { +// String begin = query.getDatefrom() == null ? "" : query.getDatefrom(); +// String end = query.getDateto() == null ? "" : query.getDateto(); +// String timezone = client.getString("timezone"); +// JSONObject params = query.toParams(timezone); +// if (params.get("client_ids") == null) { +// params.put("client_id", client.getString("client_id")); +// } +// clientManager.queryModifyClientIds(client.getIntValue("client_id"), params); +// List clientOrderList = transactionMapper.getClientOrderByTransactionTime(params); +// JSONObject parmerters = new JSONObject(); +// parmerters.put("dateRange", "(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")); +// List settlementLogDetailList = new ArrayList<>(); +// try { +// parmerters.put("logo", logo.getInputStream()); +// parmerters.put("org_logo", securepay_logo.getInputStream()); +// if (!clientOrderList.isEmpty()) { +// List clientOrders = new ArrayList<>(clientOrderList.size()); +// clientOrderList.parallelStream().forEach(p -> clientOrders.add(p.getInteger("clearing_order"))); +// settlementLogDetailList = transactionMapper.getSettlementLogDetailList(clientOrders); +// TimeZoneUtils.switchTimeZoneToString(settlementLogDetailList, timezone, "yyyy-MM-dd HH:mm:ss", Collections.singletonList("transaction_time")); +// settlementLogDetailList.parallelStream().forEach(item -> { +// 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, RoundingMode.DOWN).stripTrailingZeros()); +// item.put("gateway", item.getInteger("gateway") == null ? "-" : TradeType.fromGatewayNumber(item.getIntValue("gateway")).getTradeType()); +// item.put("rate", item.getBigDecimal("rate") == null ? "-" : item.getBigDecimal("rate").stripTrailingZeros().toPlainString() + "%"); +// }); +// } +// if (clientOrderList.size() <= 0) { +// JSONObject mockJson = new JSONObject(); +// mockJson.put("order_id", "-"); +// mockJson.put("client_order_id", "-"); +// mockJson.put("transaction_time", "-"); +// mockJson.put("channel", "-"); +// mockJson.put("gateway", "-"); +// mockJson.put("exchange_rate", BigDecimal.ZERO); +// mockJson.put("transaction_type", "-"); +// mockJson.put("transaction_currency", "-"); +// mockJson.put("settle_amount", BigDecimal.ZERO); +// mockJson.put("remark", ""); +// mockJson.put("transaction_amount", BigDecimal.ZERO); +// mockJson.put("total_surcharge", BigDecimal.ZERO); +// mockJson.put("clearing_amount", BigDecimal.ZERO); +// mockJson.put("transaction_fee", BigDecimal.ZERO); +// mockJson.put("tax_amount", BigDecimal.ZERO); +// mockJson.put("rate", BigDecimal.ZERO); +// settlementLogDetailList.add(mockJson); +// } +// JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList); +// return JasperRunManager.runReportToPdf(securepay_settlement_flow.getInputStream(), parmerters, jrDataSource); +// } catch (Exception e) { +// throw new ServerErrorException(e); +// } +// } @Override public byte[] exportPDFSettlement(TradeLogQuery query, JSONObject client) { String begin = query.getDatefrom() == null ? "" : query.getDatefrom(); @@ -1981,33 +2161,81 @@ public class TradeLogServiceImpl implements TradeLogService { clientManager.queryModifyClientIds(client.getIntValue("client_id"), params); List clientOrderList = transactionMapper.getClientOrderByTransactionTime(params); JSONObject parmerters = new JSONObject(); - parmerters.put("dateRange", "(Statement Period " + begin + "~" - + end + ")"); + try { + String beginParse= DateFormatUtils.format(DateUtils.parseDate(begin,"yyyyMMdd"),"dd.MM.yyyy"); + parmerters.put("dateRange", "Your Statement For:"+beginParse+""); + + } catch (ParseException e) { + e.printStackTrace(); + } 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")); List settlementLogDetailList = new ArrayList<>(); try { parmerters.put("logo", logo.getInputStream()); + parmerters.put("org_logo", securepay_logo.getInputStream()); if (!clientOrderList.isEmpty()) { List clientOrders = new ArrayList<>(clientOrderList.size()); clientOrderList.parallelStream().forEach(p -> clientOrders.add(p.getInteger("clearing_order"))); settlementLogDetailList = transactionMapper.getSettlementLogDetailList(clientOrders); TimeZoneUtils.switchTimeZoneToString(settlementLogDetailList, timezone, "yyyy-MM-dd HH:mm:ss", Collections.singletonList("transaction_time")); 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, RoundingMode.DOWN)); + item.put("exchange_rate", item.getBigDecimal("exchange_rate").setScale(5, RoundingMode.DOWN).stripTrailingZeros()); item.put("gateway", item.getInteger("gateway") == null ? "-" : TradeType.fromGatewayNumber(item.getIntValue("gateway")).getTradeType()); - item.put("rate", item.getBigDecimal("rate") == null ? "-" : item.getBigDecimal("rate").toPlainString() + "%"); + item.put("rate", item.getBigDecimal("rate") == null ? "-" : item.getBigDecimal("rate").stripTrailingZeros().toPlainString() + "%"); }); } - JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList); - return JasperRunManager.runReportToPdf(partner_settlement_flow.getInputStream(), parmerters, jrDataSource); + if (clientOrderList.size() <= 0) { + JSONObject mockJson = new JSONObject(); + mockJson.put("order_id", "-"); + mockJson.put("client_order_id", "-"); + mockJson.put("transaction_time", "-"); + mockJson.put("channel", "-"); + mockJson.put("gateway", "-"); + mockJson.put("exchange_rate", BigDecimal.ZERO); + mockJson.put("transaction_type", "-"); + mockJson.put("transaction_currency", "-"); + mockJson.put("settle_amount", BigDecimal.ZERO); + mockJson.put("remark", ""); + mockJson.put("transaction_amount", BigDecimal.ZERO); + mockJson.put("total_surcharge", BigDecimal.ZERO); + mockJson.put("clearing_amount", BigDecimal.ZERO); + mockJson.put("transaction_fee", BigDecimal.ZERO); + mockJson.put("tax_amount", BigDecimal.ZERO); + mockJson.put("rate", BigDecimal.ZERO); + settlementLogDetailList.add(mockJson); + } + Context ctx = new Context(); + JSONObject orgInfo = orgManager.getOrgDetail(client.getIntValue("org_id"), null); + if (!orgInfo.containsKey("logo") || orgInfo.getIntValue("org_id") == 1) { + orgInfo.put("logo", "none"); + } + ctx.setVariable("orgInfo", orgInfo); + ctx.setVariable("parmerters",parmerters); + ctx.setVariable("settlementLogDetailList",settlementLogDetailList); + System.out.println("=====>reports/securepay_settlement.html:"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + final String html = thymeleaf.process("reports/securepay_settlement.html", ctx); + + ITextRenderer renderer = new ITextRenderer(); + //添加字体库end + renderer.setDocumentFromString(html); + renderer.layout(); + renderer.createPDF(os); + byte[] bytes = os.toByteArray(); + + renderer.finishPDF(); + os.close(); + +// JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList); +// return JasperRunManager.runReportToPdf(securepay_settlement_flow.getInputStream(), parmerters, jrDataSource); + return bytes; } catch (Exception e) { throw new ServerErrorException(e); } diff --git a/src/main/resources/templates/app/invoice.html b/src/main/resources/templates/app/invoice.html index 35ab771a2..f85d4f216 100644 --- a/src/main/resources/templates/app/invoice.html +++ b/src/main/resources/templates/app/invoice.html @@ -11,6 +11,9 @@ [[${#dates.format((new java.util.Date()), 'dd-MM-yyyy')}]] [[${parmerters.partnerCode}]] Invoice + + + +
+
+ + +
+
+
+
+
+ +

+ + +
+
+ Tunnel Show Pty Ltd trading as
+ ABN 16 601 619 685 Representative of AFSL
+ Level 11, 15 William Street, Melbourne, Victoria +

+
+
+
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Transaction IDClient Order IdTransaction TimeChannelExchange RateTransaction TypeCurrency Total AmountSurcharge RateSettle amountTransaction Feegst
+
+ +