From ac00e9052ae3e934b7e42b3dd564798c72652f36 Mon Sep 17 00:00:00 2001 From: luoyang Date: Tue, 21 May 2019 16:45:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?add=20=E5=90=8E=E6=B8=85=E7=AE=97invoice?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../ClearingDistributedSurchargeMapper.java | 3 + .../core/SurchargeAccountService.java | 2 + .../impl/SurchargeAccountServiceImpl.java | 87 ++++++++++++++++++- .../web/SurchargeAccountController.java | 7 ++ .../static/payment/partner/partner-manage.js | 5 +- .../templates/client_partner_detail.html | 2 +- .../partner/templates/partner_detail.html | 2 +- .../partner_surcharge_account_dialog.html | 2 +- ...artner_surcharge_account_month_dialog.html | 2 +- 10 files changed, 102 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 08118d1cf..5ab2a115a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.1.2 - 1.0.4 + 1.0.5 diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java index e04890a4a..11f8b00e6 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java @@ -22,6 +22,9 @@ public interface ClearingDistributedSurchargeMapper { @AutoSql(type = SqlType.INSERT) void save(JSONObject transactions); + @AutoSql(type = SqlType.SELECT) + JSONObject findByClearingId(@Param("client_id") int clientId, @Param("clearing_detail_id") String clearingDetailId); + List getMonthDetailByClientId(@Param("datefrom") Date datefrom, @Param("dateto") Date dateto); List findSurchargeTransactionsByDetailId(@Param("client_id") int clientId, @Param("detailId") String detailId); diff --git a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/SurchargeAccountService.java b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/SurchargeAccountService.java index a5250a2be..ba97930ce 100644 --- a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/SurchargeAccountService.java +++ b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/SurchargeAccountService.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.surchargeAccount.core; import com.alibaba.fastjson.JSONObject; +import javax.servlet.http.HttpServletResponse; import java.util.List; public interface SurchargeAccountService { @@ -12,4 +13,5 @@ public interface SurchargeAccountService { void fillMothsSurcharge(JSONObject manager, String detailId); + void exportInvoicePDF(int clientId, String clearingDetailIdJSONObject,JSONObject manager, HttpServletResponse httpResponse); } diff --git a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java index ddd70edac..df89a5844 100644 --- a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java @@ -1,6 +1,9 @@ package au.com.royalpay.payment.manage.surchargeAccount.core.impl; +import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; +import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper; import au.com.royalpay.payment.manage.mappers.system.ClearingDistributedSurchargeMapper; +import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ClientsSurchargeAccountsMapper; import au.com.royalpay.payment.manage.mappers.system.FinancialSurchargeAccountDetailMapper; import au.com.royalpay.payment.manage.surchargeAccount.core.SurchargeAccountService; @@ -10,7 +13,9 @@ import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.lock.Locker; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; +import au.com.royalpay.payment.tools.utils.PdfUtils; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.time.DateFormatUtils; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,11 +23,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; import java.math.BigDecimal; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.math.RoundingMode; +import java.util.*; import java.util.stream.Collectors; @Service @@ -33,6 +41,10 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService { @Resource private FinancialSurchargeAccountDetailMapper financialSurchargeAccountDetailMapper; @Resource + private ClientMapper clientMapper; + @Resource + private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper; + @Resource private Locker locker; @Resource private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper; @@ -129,4 +141,71 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService { locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill"); } } + + @Override + public void exportInvoicePDF(int clientId, String clearingDetailId,JSONObject manager, HttpServletResponse httpResponse) { + JSONObject client = clientMapper.findClient(clientId); + if (client == null) { + throw new InvalidShortIdException(); + } + JSONObject distributedDetail = clearingDistributedSurchargeMapper.findByClearingId(clientId, clearingDetailId); + String date = DateFormatUtils.format(distributedDetail.getDate("settle_date"), "dd MMM yyyy", Locale.US); + httpResponse.setContentType("application/pdf"); + httpResponse.setHeader("content-disposition", "attachment;filename="+ client.getString("client_moniker") + "_Invoice_" + date + ".pdf"); + ServletOutputStream sos = null; + JSONObject pdfInfo = new JSONObject(); + + try { + sos = httpResponse.getOutputStream(); + List clearingAnalysis = clearingDetailAnalysisMapper.listReportChannels(clearingDetailId); + invoiceChannelAmount(clearingAnalysis, pdfInfo); + httpResponse.getOutputStream(); + pdfInfo.put("date", date); + pdfInfo.put("company_name", client.getString("company_name")); + pdfInfo.put("address", client.getString("address")); + pdfInfo.put("suburb", client.getString("suburb") +" " + client.getString("state") +" " +client.getString("postcode")); + pdfInfo.put("country", client.getString("country")); + PdfUtils pdu = new PdfUtils(); + pdu.setTemplatePdfPath("https://file.royalpay.com.au/open/2019/05/21/1558428021205_9pyF7U1rEloxVOXx2k7bTeRxzJaXi0.pdf"); + pdu.setPdfTemplate(pdfInfo); + File file = new File(client.getString("client_moniker") + "_Invoice_"+ date + ".pdf"); + ByteArrayOutputStream bos = pdu.templetPdfBos(file); + sos.write(bos.toByteArray()); + sos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void invoiceChannelAmount(List analysis,JSONObject pdfInfo) { + BigDecimal wechatSurcharge = BigDecimal.ZERO; + BigDecimal wechatTaxAmount = BigDecimal.ZERO; + BigDecimal wechatAmount = BigDecimal.ZERO; + BigDecimal alipaySurcharge = BigDecimal.ZERO; + BigDecimal alipayTaxAmount = BigDecimal.ZERO; + BigDecimal alipayAmount = BigDecimal.ZERO; + for (JSONObject detail : analysis) { + switch (detail.getString("channel")) { + case "Wechat": + wechatSurcharge = detail.getBigDecimal("total_charge"); + wechatTaxAmount = detail.getBigDecimal("tax_amount"); + wechatAmount = detail.getBigDecimal("distributed_surcharge"); + break; + case "Alipay": + alipaySurcharge = detail.getBigDecimal("total_charge"); + alipayTaxAmount = detail.getBigDecimal("tax_amount"); + alipayAmount = detail.getBigDecimal("distributed_surcharge"); + break; + default: + break; + } + } + pdfInfo.put("surcharge_wechat", wechatSurcharge); + pdfInfo.put("amount_wechat", wechatSurcharge); + pdfInfo.put("surcharge_alipay", alipaySurcharge); + pdfInfo.put("amount_alipay", alipaySurcharge); + pdfInfo.put("amount", wechatSurcharge.add(alipaySurcharge)); + pdfInfo.put("gst", wechatTaxAmount.add(alipayTaxAmount)); + pdfInfo.put("total_amount", (wechatAmount.add(alipayAmount)).setScale(2, RoundingMode.DOWN)); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/web/SurchargeAccountController.java b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/web/SurchargeAccountController.java index bd021e8a6..6c7a893fa 100644 --- a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/web/SurchargeAccountController.java +++ b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/web/SurchargeAccountController.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.List; @RequestMapping("/sys/surcharge_account") @@ -26,4 +27,10 @@ public class SurchargeAccountController { public void fillMothsSurcharge(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, @PathVariable String detailId) { surchargeAccountService.fillMothsSurcharge(manager, detailId); } + + @ManagerMapping(value = "/{clientId}/settlement_logs/{clearingDetailId}/export", role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF}, method = RequestMethod.GET) + public void exportInvoicePDF(@PathVariable int clientId, @PathVariable String clearingDetailId, + @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse httpResponse) throws Exception { + surchargeAccountService.exportInvoicePDF(clientId, clearingDetailId, manager, httpResponse); + } } diff --git a/src/main/ui/static/payment/partner/partner-manage.js b/src/main/ui/static/payment/partner/partner-manage.js index 53c85d1e3..0eb1c26be 100644 --- a/src/main/ui/static/payment/partner/partner-manage.js +++ b/src/main/ui/static/payment/partner/partner-manage.js @@ -2404,13 +2404,12 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter }]); app.controller('surchargeAccountDetailCtrl', ['$scope', '$http', 'balance', 'partner', 'transactions', 'commonDialog', function ($scope, $http, balance, partner, transactions, commonDialog) { $scope.surcharge = angular.copy(balance); - $scope.transactions = angular.copy(transactions.data); + $scope.surchargeDetailData = angular.copy(transactions.data); $scope.partner = angular.copy(partner); $scope.canAddDetail = false; $scope.params = {}; $scope.getBalance = function () { - if ($scope.partner.surcharge_mode != undefined && $scope.partner.surcharge_mode == "distributed") { $http.get('/sys/partners/' + $scope.partner.client_moniker + '/surcharge_account').then(function (resp) { $scope.surcharge = resp.data; @@ -2421,7 +2420,7 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter $scope.getTransactions = function () { $http.get('/sys/partners/' + $scope.partner.client_moniker + '/account/transactions').then(function (resp) { - $scope.transactions = resp.data; + $scope.surchargeDetailData = resp.data; }); } diff --git a/src/main/ui/static/payment/partner/templates/client_partner_detail.html b/src/main/ui/static/payment/partner/templates/client_partner_detail.html index 0e1ccad1a..6ebd7bb0e 100644 --- a/src/main/ui/static/payment/partner/templates/client_partner_detail.html +++ b/src/main/ui/static/payment/partner/templates/client_partner_detail.html @@ -315,7 +315,7 @@
- +

diff --git a/src/main/ui/static/payment/partner/templates/partner_detail.html b/src/main/ui/static/payment/partner/templates/partner_detail.html index e1e775dd4..fbc94df1f 100644 --- a/src/main/ui/static/payment/partner/templates/partner_detail.html +++ b/src/main/ui/static/payment/partner/templates/partner_detail.html @@ -708,7 +708,7 @@
- +

diff --git a/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_dialog.html b/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_dialog.html index 10729bd43..87e709b28 100644 --- a/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_dialog.html +++ b/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_dialog.html @@ -49,7 +49,7 @@ {{surcharge.remark}} - diff --git a/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_month_dialog.html b/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_month_dialog.html index 4c2f98838..1e41d32d6 100644 --- a/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_month_dialog.html +++ b/src/main/ui/static/payment/surchargeaccount/templates/partner_surcharge_account_month_dialog.html @@ -51,7 +51,7 @@ - From 049e6705a3ddec1f4e66829d0165b698c5de3084 Mon Sep 17 00:00:00 2001 From: luoyang Date: Tue, 21 May 2019 16:59:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20=E5=90=8E=E6=B8=85=E7=AE=97=E6=89=8B?= =?UTF-8?q?=E7=BB=AD=E8=B4=B9Invoice=E6=A8=A1=E6=9D=BF=20=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=9B=9E=E6=BB=9A=E6=B8=85=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/ClearingDistributedSurchargeMapper.java | 2 +- .../core/impl/SurchargeAccountServiceImpl.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java index 11f8b00e6..950877f1e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClearingDistributedSurchargeMapper.java @@ -23,7 +23,7 @@ public interface ClearingDistributedSurchargeMapper { void save(JSONObject transactions); @AutoSql(type = SqlType.SELECT) - JSONObject findByClearingId(@Param("client_id") int clientId, @Param("clearing_detail_id") String clearingDetailId); + List findByClearingId(@Param("client_id") int clientId, @Param("clearing_detail_id") String clearingDetailId); List getMonthDetailByClientId(@Param("datefrom") Date datefrom, @Param("dateto") Date dateto); diff --git a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java index df89a5844..f53d0f34c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/surchargeAccount/core/impl/SurchargeAccountServiceImpl.java @@ -148,8 +148,12 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService { if (client == null) { throw new InvalidShortIdException(); } - JSONObject distributedDetail = clearingDistributedSurchargeMapper.findByClearingId(clientId, clearingDetailId); - String date = DateFormatUtils.format(distributedDetail.getDate("settle_date"), "dd MMM yyyy", Locale.US); + List distributedDetail = clearingDistributedSurchargeMapper.findByClearingId(clientId, clearingDetailId); + if (distributedDetail.size() > 1) { + throw new BadRequestException("此次清算扣款已回滚"); + } + JSONObject detial = distributedDetail.get(0); + String date = DateFormatUtils.format(detial.getDate("settle_date"), "dd MMM yyyy", Locale.US); httpResponse.setContentType("application/pdf"); httpResponse.setHeader("content-disposition", "attachment;filename="+ client.getString("client_moniker") + "_Invoice_" + date + ".pdf"); ServletOutputStream sos = null; From bb41d026b4a394ffa5fa30d214b61910100d3d0f Mon Sep 17 00:00:00 2001 From: "james.zhao" Date: Wed, 22 May 2019 11:10:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?kpi=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../analysis/core/impls/DailyReportImp.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java index cfd767040..823285900 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.analysis.core.impls; import au.com.royalpay.payment.manage.analysis.core.DailyReport; import au.com.royalpay.payment.manage.mappers.cashback.CashbackRecordsMapper; +import au.com.royalpay.payment.manage.mappers.financial.FinancialBDCommissionConfigMapper; import au.com.royalpay.payment.manage.mappers.financial.FinancialBDPrizeLogMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper; import au.com.royalpay.payment.manage.mappers.log.DailyReportMapper; @@ -22,7 +23,6 @@ import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -54,6 +54,8 @@ public class DailyReportImp implements DailyReport { private MpWechatApiProvider mpWechatApiProvider; @Resource private FinancialBDPrizeLogMapper financialBDPrizeLogMapper; + @Resource + private FinancialBDCommissionConfigMapper financialBDCommissionConfigMapper; private Logger logger = LoggerFactory.getLogger(getClass()); @@ -98,8 +100,8 @@ public class DailyReportImp implements DailyReport { private JSONObject getKPI(Date dt){ JSONObject report = new JSONObject(); List kpiList =new ArrayList<>(); - List prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.MONTH)); - List prizeAmountAndBdTypeListYesterDay = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt,-2), Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-2), Calendar.MONTH)); + List prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,1), Calendar.DATE),DateUtils.truncate(dt, Calendar.MONTH)); + List prizeAmountAndBdTypeListYesterDay = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.MONTH)); List clientsAmount = clientMapper.createClientsByGroup(DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(dt, Calendar.DATE)); //BD团队总KPI BigDecimal total_kpi_amount = BigDecimal.ZERO; @@ -114,7 +116,8 @@ public class DailyReportImp implements DailyReport { kpi.put("total_amount",p.getBigDecimal("total_amount")); //当月数据 kpi.put("month_amount",p.getBigDecimal("month_amount")); - kpi.put("kpi_amount",p.getBigDecimal("kpi_amount")); + BigDecimal kpi_amount = financialBDCommissionConfigMapper.findCurrentCommissionMaxAmount(DateFormatUtils.format(DateUtils.truncate(dt,Calendar.MONTH),"yyyy-MM"), p.getIntValue("bd_type")); + kpi.put("kpi_amount",kpi_amount); for(JSONObject prize : prizeAmountAndBdTypeListYesterDay){ if(prize.getString("bd_group").equals(kpi.getString("bd_group"))){ BigDecimal compare = kpi.getBigDecimal("total_amount").subtract(prize.getBigDecimal("total_amount")); @@ -122,14 +125,14 @@ public class DailyReportImp implements DailyReport { kpi.put("compare_value",Math.abs(compare.doubleValue())); } } - kpi.put("kpi_percent", p.getBigDecimal("month_amount").divide(p.getBigDecimal("kpi_amount"),4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0,5)+"%"); + kpi.put("kpi_percent", p.getBigDecimal("month_amount").divide(kpi_amount,4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0,5)+"%"); for(JSONObject clientAmount :clientsAmount ){ if(clientAmount.getString("bd_group").equals(kpi.getString("bd_group"))){ kpi.put("clients_history",clientAmount.getIntValue("clients_history")); kpi.put("clients_yesterday",clientAmount.getIntValue("clients_yesterday")); } } - total_kpi_amount = total_kpi_amount.add(p.getBigDecimal("kpi_amount")); + total_kpi_amount = total_kpi_amount.add(kpi_amount); total_month_amount = total_month_amount.add(p.getBigDecimal("month_amount")); kpiList.add(kpi); }