From 74e059180dadef6f6e3844a1d0a534adc6e76da5 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 16 Aug 2018 13:57:15 +0800 Subject: [PATCH 1/2] hf settle --- .../analysis/core/PlatformClearService.java | 3 + .../PlatformClearAnalysisServiceImpl.java | 202 +++++++++++++++--- .../web/PlatformClearAController.java | 17 +- .../config/platformrevenue/platformrevenue.js | 36 +++- .../templates/platform_settle_logs.html | 97 +++++++++ 5 files changed, 318 insertions(+), 37 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java index 67132f47a..a7025139b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java @@ -2,6 +2,8 @@ package au.com.royalpay.payment.manage.analysis.core; import com.alibaba.fastjson.JSONObject; +import org.springframework.web.multipart.MultipartFile; + import java.text.ParseException; public interface PlatformClearService { @@ -14,4 +16,5 @@ public interface PlatformClearService { void generateSettleLogs(); + void doVerifyHFSettleLog(MultipartFile file, String start, String end); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java index b8a173cf7..d02f978ef 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java @@ -10,31 +10,45 @@ import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper; import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper; import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils; + import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.miemiedev.mybatis.paginator.domain.Order; import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageList; + +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; -import javax.annotation.Resource; +import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; @Service public class PlatformClearAnalysisServiceImpl implements PlatformClearService { private Logger logger = LoggerFactory.getLogger(getClass()); public static final SimpleDateFormat sdfClear = new SimpleDateFormat("yyyy-MM-dd"); - public static final SimpleDateFormat sdfNormal = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); + public static final SimpleDateFormat sdfNormal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Resource private MpPaymentApi mpPaymentApi; @@ -47,7 +61,8 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { @Override public JSONObject getPlatformSettleLog(String channel, int page, int limit) { - PageList list = platformSettlementMapper.findSettleLogsAllMerchant(channel, new PageBounds(page, limit, Order.formString("settle_date.desc"))); + PageList list = platformSettlementMapper.findSettleLogsAllMerchant(channel, + new PageBounds(page, limit, Order.formString("settle_date.desc"))); return PageListUtils.buildPageListResult(list); } @@ -62,9 +77,10 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { sysLogs.put("surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount"))); - sysLogs.put("sys_settle_amount", sysLogs.getBigDecimal("sys_pay_fee").subtract(sysLogs.getBigDecimal("sys_refund_fee")).subtract(sysLogs.getBigDecimal("surcharge"))); - sysLogs.put("start_date","2018-04-05"); - sysLogs.put("end_date",sdfClear.format(new Date())); + sysLogs.put("sys_settle_amount", + sysLogs.getBigDecimal("sys_pay_fee").subtract(sysLogs.getBigDecimal("sys_refund_fee")).subtract(sysLogs.getBigDecimal("surcharge"))); + sysLogs.put("start_date", "2018-04-05"); + sysLogs.put("end_date", sdfClear.format(new Date())); return sysLogs; } @@ -86,11 +102,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } if (StringUtils.equals("Wechat", channel)) { try { - Map settleDate = new HashMap<>(); - settleDate.put("from",sdfClear.parse(start_date)); - settleDate.put("to",sdfClear.parse(end_date)); + Map settleDate = new HashMap<>(); + settleDate.put("from", sdfClear.parse(start_date)); + settleDate.put("to", sdfClear.parse(end_date)); doVerifyWechatSettleLog(settleDate); - }catch (Exception e){ + } catch (Exception e) { logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "微信到账失败:", e); } @@ -98,9 +114,9 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } @Override -// @Transactional + // @Transactional public void generateSettleLogs() { -// deleteSettleLogs(); + // deleteSettleLogs(); generateWechatSettleLogs(); generateAlipaySettleLogs(); generateAlipayOnlineSettleLogs(); @@ -109,7 +125,7 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { @Transactional public void generateWechatSettleLogs() { try { - Map settleDate = TimeZoneUtils.getStatetimeDays(); + Map settleDate = TimeZoneUtils.getStatetimeDays(); logger.info("开始查询" + settleDate.get("from") + "到" + settleDate.get("to") + "的微信清算记录"); doVerifyWechatSettleLog(settleDate); } catch (ParseException e) { @@ -193,8 +209,7 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } } - - public void doVerifyWechatSettleLog(Map settleDate){ + public void doVerifyWechatSettleLog(Map settleDate) { List tencentSettle = new ArrayList<>(); for (WeChatPayConfig.Merchant mch : WechatPayEnvironment.getEnv().getWechatMerchantConfigs()) { try { @@ -209,15 +224,15 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { params.put("end_date", settle.getEnd()); params.put("channel", "Wechat"); params.put("last_update_date", new Date()); - JSONObject sysClearData = getSystemClearingAmount(null,settle,"Wechat"); - if(sysClearData!=null && sysClearData.size()>0){ - params.put("sys_pay_fee",sysClearData.getBigDecimal("sys_pay_fee")); - params.put("sys_refund_fee",sysClearData.getBigDecimal("sys_refund_fee")); - params.put("sys_net_fee",sysClearData.getBigDecimal("sys_net_fee")); - params.put("sys_surcharge",sysClearData.getBigDecimal("sys_surcharge")); - params.put("sys_settlement_fee",sysClearData.getBigDecimal("sys_settle_fee")); + JSONObject sysClearData = getSystemClearingAmount(null, settle, "Wechat"); + if (sysClearData != null && sysClearData.size() > 0) { + params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee")); + params.put("sys_refund_fee", sysClearData.getBigDecimal("sys_refund_fee")); + params.put("sys_net_fee", sysClearData.getBigDecimal("sys_net_fee")); + params.put("sys_surcharge", sysClearData.getBigDecimal("sys_surcharge")); + params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee")); } - params.put("merchants",mch.getMerchantId()); + params.put("merchants", mch.getMerchantId()); params.put("pay_fee", settle.getPayFee()); params.put("refund_fee", settle.getRefundFee()); params.put("net_fee", settle.getPayNetFee()); @@ -225,7 +240,8 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { params.put("surcharge", settle.getPoundageFee()); params.put("unsettle_fee", settle.getUnsettlementFee()); - JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(settle.getSettlementDate()), "Wechat", mch.getMerchantId()); + JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(settle.getSettlementDate()), "Wechat", + mch.getMerchantId()); if (check != null) { params.put("log_id", check.getString("log_id")); platformSettlementMapper.update(params); @@ -242,7 +258,6 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } } - public JSONObject getAliSettle(JSONObject aliSettleLog) { JSONObject alipaySettleLog = new JSONObject(); @@ -269,7 +284,7 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { JSONArray refunds = aliSettleLog.getJSONArray("refunds"); logger.info("alipay的refunds清算总信息" + refunds.toJSONString()); BigDecimal debit = new BigDecimal(0.00); - BigDecimal debitFee = new BigDecimal(0.00); + BigDecimal debitFee = new BigDecimal(0.00); BigDecimal debitSettle = new BigDecimal(0.00); if (refunds != null) { for (int i = 0; i < refunds.size(); i++) { @@ -287,8 +302,8 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } alipaySettleLog.put("debit", debit); alipaySettleLog.put("net_fee", credit.subtract(debit)); - alipaySettleLog.put("surcharge",creditFee.subtract(debitFee)); - alipaySettleLog.put("settlement_fee",creditSettle.subtract(debitSettle)); + alipaySettleLog.put("surcharge", creditFee.subtract(debitFee)); + alipaySettleLog.put("settlement_fee", creditSettle.subtract(debitSettle)); logger.info("阿里清算日志:" + alipaySettleLog.toJSONString()); return alipaySettleLog; } @@ -317,11 +332,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { return null; } - //2017-11-01后微信手续费0.5 + // 2017-11-01后微信手续费0.5 BigDecimal wechat_rate; - if(end_date.compareTo("2017-11-01 03:00:00")<=0){ + if (end_date.compareTo("2017-11-01 03:00:00") <= 0) { wechat_rate = new BigDecimal("0.006"); - }else { + } else { wechat_rate = new BigDecimal("0.005"); } @@ -344,9 +359,128 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { return sysLogs; } catch (Exception e) { - //do nothing + // do nothing + e.printStackTrace(); + } + return null; + } + + @Override + public void doVerifyHFSettleLog(MultipartFile file, String start, String end) { + JSONObject hfSettle = handleHFSettleFile(file); + if (hfSettle == null) { + return; + } + JSONObject record = new JSONObject(); + record.put("settle_date", end); + record.put("start_date", start); + record.put("end_date", end); + record.put("channel", "hf"); + record.put("last_update_date", new Date()); + JSONObject syscleardata = getHFSystemClearingAmount(start, end); + if (syscleardata != null && syscleardata.size() > 0) { + record.put("sys_pay_fee", syscleardata.getBigDecimal("sys_pay_fee")); + record.put("sys_refund_fee", syscleardata.getBigDecimal("sys_refund_fee")); + record.put("sys_net_fee", syscleardata.getBigDecimal("sys_net_fee")); + record.put("sys_surcharge", syscleardata.getBigDecimal("sys_surcharge")); + record.put("sys_settlement_fee", syscleardata.getBigDecimal("sys_settle_fee")); + } + record.put("pay_fee", BigDecimal.ZERO); + record.put("refund_fee", BigDecimal.ZERO); + record.put("net_fee", hfSettle.getBigDecimal("orderAmount")); + record.put("settlement_fee", hfSettle.getBigDecimal("clearingAmount")); + record.put("surcharge", hfSettle.getBigDecimal("surcharge")); + record.put("unsettle_fee", BigDecimal.ZERO); + + List check = null; + try { + check = platformSettlementMapper.findBySettleDate(DateUtils.parseDate(end, "YYYY-MM-dd"), "hf"); + } catch (ParseException e) { e.printStackTrace(); } + if (CollectionUtils.isNotEmpty(check)) { + record.put("log_id", check.get(0).getString("log_id")); + platformSettlementMapper.update(record); + } else { + platformSettlementMapper.save(record); + } + logger.info("汇付清算记录查询完成"); + + } + + private JSONObject handleHFSettleFile(MultipartFile file) { + try { + XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); + XSSFSheet sheet = workbook.getSheetAt(0); + Iterator rowIterator = sheet.rowIterator(); + Row row = null; + Cell cell = null; + // 跳过第一行 + rowIterator.next(); + JSONObject result = new JSONObject(); + BigDecimal orderAmount = BigDecimal.ZERO; + BigDecimal surcharge = BigDecimal.ZERO; + BigDecimal clearingAmount = BigDecimal.ZERO; + while (rowIterator.hasNext()) { + row = rowIterator.next(); + cell = row.getCell(14); + if (cell != null) { + String orderAmountStr = cell.getStringCellValue().trim(); + if (StringUtils.isNotEmpty(orderAmountStr)) { + BigDecimal cellVar = new BigDecimal(orderAmountStr); + if (orderAmount.compareTo(cellVar) == 0) { + result.put("orderAmount", orderAmount); + } else { + orderAmount = orderAmount.add(cellVar); + } + } + } + cell = row.getCell(15); + if (cell != null) { + String surchargeStr = cell.getStringCellValue().trim(); + if (StringUtils.isNotEmpty(surchargeStr)) { + BigDecimal cellVar = new BigDecimal(surchargeStr); + if (surcharge.compareTo(cellVar) == 0) { + result.put("orderAmount", surcharge); + } else { + surcharge = surcharge.add(cellVar); + } + } + } + cell = row.getCell(16); + if (cell != null) { + String clearingAmounStr = cell.getStringCellValue().trim(); + if (StringUtils.isNotEmpty(clearingAmounStr)) { + BigDecimal cellVar = new BigDecimal(clearingAmounStr); + if (clearingAmount.compareTo(cellVar) == 0) { + result.put("clearingAmount", clearingAmount); + } else { + clearingAmount = clearingAmount.add(cellVar); + } + } + } + return result; + } + return result; + } catch (IOException e) { + logger.debug("处理汇付清算文件出错", e); + } + return null; + } + + private JSONObject getHFSystemClearingAmount(String start, String end) { + JSONObject result = new JSONObject(); + try { + JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(start, end, "hf", "Credit", new BigDecimal(0.008)); + result.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount")); + JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start, end, "hf", "Debit", new BigDecimal(0.008)); + result.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount")); + result.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(debitLogs.getBigDecimal("aud_amount"))); + result.put("sys_settle_fee", result.getBigDecimal("sys_net_fee").subtract(result.getBigDecimal("sys_surcharge"))); + result.put("sys_surcharge", platformSettlementMapper.calculateRmbCharge(start, end, "hf", new BigDecimal(0.008))); + return result; + } catch (Exception ignore) { + } return null; } } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java index 248916704..fb8d3b76a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java @@ -3,12 +3,20 @@ package au.com.royalpay.payment.manage.analysis.web; import au.com.royalpay.payment.manage.analysis.core.PlatformClearService; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; + import com.alibaba.fastjson.JSONObject; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + import java.text.ParseException; +import javax.annotation.Resource; + @RestController @RequestMapping(value = "/platform/analysis") public class PlatformClearAController { @@ -35,4 +43,9 @@ public class PlatformClearAController { public void generateSettleLogs() { platformClearService.generateSettleLogs(); } + + @ManagerMapping(value = "/generate/hf/settle", method = RequestMethod.PUT, role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.DEVELOPER}) + public void generatehfSettleLogs(@RequestParam("file") MultipartFile settleFile,@RequestParam String start,@RequestParam String end) { + platformClearService.doVerifyHFSettleLog(settleFile,start,end); + } } diff --git a/src/main/ui/static/config/platformrevenue/platformrevenue.js b/src/main/ui/static/config/platformrevenue/platformrevenue.js index 5b3f3d1ec..81c7ea806 100644 --- a/src/main/ui/static/config/platformrevenue/platformrevenue.js +++ b/src/main/ui/static/config/platformrevenue/platformrevenue.js @@ -16,7 +16,8 @@ define(['angular', 'decimal', 'uiRouter', 'angularEcharts', '../../analysis/repo }); }]); - app.controller('platformSettleLogCtrl', ['$scope', '$http', '$state','commonDialog', function ($scope, $http, $state, commonDialog) { + app.controller('platformSettleLogCtrl', ['$scope', '$http', '$state','Upload','commonDialog', function ($scope, $http, $state,Upload, commonDialog) { + $scope.wechatPagination = {}; $scope.loadWechatLogs = function (page) { var params = $scope.queryParams || {}; @@ -88,6 +89,39 @@ define(['angular', 'decimal', 'uiRouter', 'angularEcharts', '../../analysis/repo $state.reload(); } + + + $scope.hfParam={}; + $scope.hfPagination = {}; + $scope.loadhfLogs = function (page) { + var params = $scope.queryParams || {}; + params.page = page || $scope.hfPagination.page || 1; + params.limit = 20; + params.channel = 'hf'; + $http.get('/platform/analysis/settle/log', {params: params}).then(function (resp) { + $scope.hfLogs = resp.data.data; + $scope.hfPagination = resp.data.pagination; + }); + }; + + $scope.loadhfLogs(1); + $scope.uploadhfSettleFile = function (file) { + $scope.hfParam.file=file; + if(!$scope.hfParam.start){ + alert("请先选择开始时间"); + } + if(!$scope.hfParam.end){ + alert("请先选择结束时间"); + } + var param = angular.copy($scope.hfParam); + if (file != null) { + Upload.upload({ + url: '/platform/analysis/generate/hf/settle', + data: param + }); + } + }; + }]); app.controller('platformRevenueRootCtrl', ['$scope', '$http', '$filter', 'chartParser', function ($scope, $http, $filter, chartParser) { $scope.params = {year: new Date().getFullYear()}; diff --git a/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html b/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html index 09090ead0..0893ac2fd 100644 --- a/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html +++ b/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html @@ -271,5 +271,102 @@ + + +
+
+

HF Logs

+
+
+ +
+
+ +
+ + + + + +
+

No Data

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Date StartDate EndSettle DatePay FeeRefund FeeNet FeePoundageSettlement FeeUnsettledValidation
{{log.net_fee}} +   (System:{{log.sys_net_fee}}) +   (System:{{log.sys_net_fee}}) + {{log.surcharge}} +   (System:{{log.sys_surcharge}}) +   (System:{{log.sys_surcharge}}) + {{log.settlement_fee}} +   (System:{{log.sys_settlement_fee}}) +   (System:{{log.sys_settlement_fee}}) +
+ +
+
\ No newline at end of file From 74835ee47d7b935f711a86e55de5e5d1524dd3c7 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 16 Aug 2018 16:47:59 +0800 Subject: [PATCH 2/2] hf settle --- .../analysis/core/PlatformClearService.java | 4 +- .../PlatformClearAnalysisServiceImpl.java | 71 ++++++++++--------- .../web/PlatformClearAController.java | 6 +- .../config/platformrevenue/platformrevenue.js | 39 +++++++--- .../templates/platform_settle_logs.html | 13 ++-- 5 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java index a7025139b..a6444e4af 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/PlatformClearService.java @@ -2,8 +2,6 @@ package au.com.royalpay.payment.manage.analysis.core; import com.alibaba.fastjson.JSONObject; -import org.springframework.web.multipart.MultipartFile; - import java.text.ParseException; public interface PlatformClearService { @@ -16,5 +14,5 @@ public interface PlatformClearService { void generateSettleLogs(); - void doVerifyHFSettleLog(MultipartFile file, String start, String end); + void doVerifyHFSettleLog(JSONObject param); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java index d02f978ef..9e9064a3e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/PlatformClearAnalysisServiceImpl.java @@ -8,6 +8,7 @@ import au.com.royalpay.payment.channels.wechat.runtime.beans.SettlementLog; import au.com.royalpay.payment.manage.analysis.core.PlatformClearService; import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper; import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper; +import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils; @@ -20,17 +21,17 @@ import com.github.miemiedev.mybatis.paginator.domain.PageList; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMethod; -import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -43,6 +44,8 @@ import java.util.Map; import javax.annotation.Resource; +import cn.yixblog.platform.http.HttpRequestGenerator; + @Service public class PlatformClearAnalysisServiceImpl implements PlatformClearService { @@ -58,6 +61,8 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { private PlatformSettlementMapper platformSettlementMapper; @Resource private EstimateAnalysisMapper estimateAnalysisMapper; + @Resource + private AttachmentClient attachmentClient; @Override public JSONObject getPlatformSettleLog(String channel, int page, int limit) { @@ -366,8 +371,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } @Override - public void doVerifyHFSettleLog(MultipartFile file, String start, String end) { - JSONObject hfSettle = handleHFSettleFile(file); + public void doVerifyHFSettleLog(JSONObject param) { + + String end = param.getString("end"); + String start = param.getString("start"); + JSONObject hfSettle = handleHFSettleFile(param.getString("fileId")); if (hfSettle == null) { return; } @@ -394,7 +402,7 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { List check = null; try { - check = platformSettlementMapper.findBySettleDate(DateUtils.parseDate(end, "YYYY-MM-dd"), "hf"); + check = platformSettlementMapper.findBySettleDate(DateUtils.parseDate(end, "yyyy-MM-dd"), "hf"); } catch (ParseException e) { e.printStackTrace(); } @@ -408,10 +416,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { } - private JSONObject handleHFSettleFile(MultipartFile file) { + private JSONObject handleHFSettleFile(String fileId) { try { - XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); - XSSFSheet sheet = workbook.getSheetAt(0); + HttpRequestGenerator gen = new HttpRequestGenerator(attachmentClient.getFileUrl(fileId), RequestMethod.GET); + HSSFWorkbook workbook = new HSSFWorkbook(gen.execute().getResponseContentStream()); + HSSFSheet sheet = workbook.getSheetAt(0); Iterator rowIterator = sheet.rowIterator(); Row row = null; Cell cell = null; @@ -423,46 +432,38 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { BigDecimal clearingAmount = BigDecimal.ZERO; while (rowIterator.hasNext()) { row = rowIterator.next(); - cell = row.getCell(14); + + cell = row.getCell(0); + if (cell != null) { + continue; + } + cell = row.getCell(15); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); if (cell != null) { String orderAmountStr = cell.getStringCellValue().trim(); if (StringUtils.isNotEmpty(orderAmountStr)) { - BigDecimal cellVar = new BigDecimal(orderAmountStr); - if (orderAmount.compareTo(cellVar) == 0) { - result.put("orderAmount", orderAmount); - } else { - orderAmount = orderAmount.add(cellVar); - } + result.put("orderAmount", new BigDecimal(orderAmountStr)); } } - cell = row.getCell(15); + cell = row.getCell(16); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); if (cell != null) { String surchargeStr = cell.getStringCellValue().trim(); if (StringUtils.isNotEmpty(surchargeStr)) { - BigDecimal cellVar = new BigDecimal(surchargeStr); - if (surcharge.compareTo(cellVar) == 0) { - result.put("orderAmount", surcharge); - } else { - surcharge = surcharge.add(cellVar); - } + result.put("surcharge", new BigDecimal(surchargeStr)); } } - cell = row.getCell(16); + cell = row.getCell(17); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); if (cell != null) { String clearingAmounStr = cell.getStringCellValue().trim(); if (StringUtils.isNotEmpty(clearingAmounStr)) { - BigDecimal cellVar = new BigDecimal(clearingAmounStr); - if (clearingAmount.compareTo(cellVar) == 0) { - result.put("clearingAmount", clearingAmount); - } else { - clearingAmount = clearingAmount.add(cellVar); - } + result.put("clearingAmount", new BigDecimal(clearingAmounStr)); } } - return result; } return result; - } catch (IOException e) { + } catch (Exception e) { logger.debug("处理汇付清算文件出错", e); } return null; @@ -474,13 +475,15 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService { JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(start, end, "hf", "Credit", new BigDecimal(0.008)); result.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount")); JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start, end, "hf", "Debit", new BigDecimal(0.008)); + result.put("sys_surcharge", platformSettlementMapper.calculateRmbCharge(start, end, "hf", new BigDecimal(0.008))); result.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount")); result.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(debitLogs.getBigDecimal("aud_amount"))); result.put("sys_settle_fee", result.getBigDecimal("sys_net_fee").subtract(result.getBigDecimal("sys_surcharge"))); - result.put("sys_surcharge", platformSettlementMapper.calculateRmbCharge(start, end, "hf", new BigDecimal(0.008))); return result; } catch (Exception ignore) { + ignore.printStackTrace(); } return null; } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java index fb8d3b76a..669478b5d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PlatformClearAController.java @@ -7,11 +7,11 @@ import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import com.alibaba.fastjson.JSONObject; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import java.text.ParseException; @@ -45,7 +45,7 @@ public class PlatformClearAController { } @ManagerMapping(value = "/generate/hf/settle", method = RequestMethod.PUT, role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.DEVELOPER}) - public void generatehfSettleLogs(@RequestParam("file") MultipartFile settleFile,@RequestParam String start,@RequestParam String end) { - platformClearService.doVerifyHFSettleLog(settleFile,start,end); + public void generatehfSettleLogs(@RequestBody JSONObject param) { + platformClearService.doVerifyHFSettleLog(param); } } diff --git a/src/main/ui/static/config/platformrevenue/platformrevenue.js b/src/main/ui/static/config/platformrevenue/platformrevenue.js index 81c7ea806..e02654fea 100644 --- a/src/main/ui/static/config/platformrevenue/platformrevenue.js +++ b/src/main/ui/static/config/platformrevenue/platformrevenue.js @@ -16,7 +16,7 @@ define(['angular', 'decimal', 'uiRouter', 'angularEcharts', '../../analysis/repo }); }]); - app.controller('platformSettleLogCtrl', ['$scope', '$http', '$state','Upload','commonDialog', function ($scope, $http, $state,Upload, commonDialog) { + app.controller('platformSettleLogCtrl', ['$scope', '$http', '$state','$filter','Upload','commonDialog', function ($scope, $http, $state,$filter,Upload, commonDialog) { $scope.wechatPagination = {}; $scope.loadWechatLogs = function (page) { @@ -106,21 +106,38 @@ define(['angular', 'decimal', 'uiRouter', 'angularEcharts', '../../analysis/repo $scope.loadhfLogs(1); $scope.uploadhfSettleFile = function (file) { - $scope.hfParam.file=file; - if(!$scope.hfParam.start){ + if (file != null) { + Upload.upload({ + url: '/attachment/secret_files', + data: {file: file} + }).then(function (resp) { + $scope.hfParam.fileId = resp.data.fileid; + commonDialog.alert({title: 'Upload Success', content:'', type: 'success'}) + }, function (resp) { + }, function (evt) { + }) + } + }; + + $scope.dohfSettle = function () { + var param = angular.copy($scope.hfParam); + if(!param.start){ alert("请先选择开始时间"); } - if(!$scope.hfParam.end){ + if(!param.end){ alert("请先选择结束时间"); } - var param = angular.copy($scope.hfParam); - if (file != null) { - Upload.upload({ - url: '/platform/analysis/generate/hf/settle', - data: param - }); + if(!param.fileId){ + alert("请先上传汇付清算文件"); } - }; + param.start = $filter('date')(param.start, "yyyy-MM-dd"); + param.end = $filter('date')(param.end, "yyyy-MM-dd"); + + $http.put('/platform/analysis/generate/hf/settle',param).then(function (resp) { + + }); + + } }]); app.controller('platformRevenueRootCtrl', ['$scope', '$http', '$filter', 'chartParser', function ($scope, $http, $filter, chartParser) { diff --git a/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html b/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html index 0893ac2fd..802d5c3fd 100644 --- a/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html +++ b/src/main/ui/static/config/platformrevenue/templates/platform_settle_logs.html @@ -280,15 +280,15 @@
+ datepicker-options="{maxDate:hfParam.end}">
@@ -296,7 +296,12 @@ + +