From 7ca7c0b3c9f56fc6ecf606c9a9b241451a4bb0b4 Mon Sep 17 00:00:00 2001 From: luoyang Date: Wed, 27 Feb 2019 19:23:55 +0800 Subject: [PATCH] fix Estimate --- .../core/EstimateAnalysisService.java | 6 +- .../analysis/core/EstimateCacheSupport.java | 6 ++ .../impls/EstimateAnalysisServiceImpl.java | 66 +++++++++++++++++-- .../core/impls/EstimateCacheSupportImpl.java | 14 ++++ .../mappers/EstimateAnalysisMapper.java | 2 +- .../web/EstimateAnalysisController.java | 25 +++---- .../mappers/payment/TransactionMapper.java | 4 +- .../mappers/EstimateAnalysisMapper.xml | 1 + .../mappers/payment/TransactionMapper.xml | 14 ++++ .../analysis/settle_estimate_analysis.js | 12 +++- .../templates/settle_estimate_analysis.html | 56 +++++++++++++++- .../analysis/templates/trans_analysis.html | 2 +- src/main/ui/static/analysis/trans-analysis.js | 5 +- 13 files changed, 185 insertions(+), 28 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateCacheSupport.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateCacheSupportImpl.java diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateAnalysisService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateAnalysisService.java index 9f95fa86a..cdf011d0b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateAnalysisService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateAnalysisService.java @@ -9,13 +9,15 @@ import java.util.List; */ public interface EstimateAnalysisService { - List listFurtureInfo() throws Exception; + List listFutureInfo() throws Exception; + + void clearEstimateFutureCache(); void generateSettleAmount(); void generateTransactionData(); - List listEstimateLog(int logType); + List listEstimateLog(int logType, String date); void initSettleAmount(String date) throws Exception; diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateCacheSupport.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateCacheSupport.java new file mode 100644 index 000000000..74c42db1a --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/EstimateCacheSupport.java @@ -0,0 +1,6 @@ +package au.com.royalpay.payment.manage.analysis.core; + +public interface EstimateCacheSupport { + + void clearEstimateFutureCache(); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateAnalysisServiceImpl.java index 5e5abe65e..ab56608af 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateAnalysisServiceImpl.java @@ -5,22 +5,29 @@ import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment; import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi; import au.com.royalpay.payment.channels.wechat.runtime.beans.SettlementLog; import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService; +import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport; import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper; import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper; +import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.NotFoundException; import au.com.royalpay.payment.tools.utils.TimeZoneUtils; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.jsoup.helper.DataUtil; import org.slf4j.LoggerFactory; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -51,6 +58,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { @Resource private ClearingDetailMapper clearingDetailMapper; + @Resource + private EstimateCacheSupport estimateCacheSupport; + @Resource + private TransactionMapper transactionMapper; public static List t1client; @@ -71,10 +82,16 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { private EstimateAnalysisMapper estimateAnalysisMapper; @Override - public List listFurtureInfo() throws Exception { + @Cacheable(value = ":estimate_analysis_future:", key = "''") + public List listFutureInfo() throws Exception { return listSettlementInfo(); } + @Override + public void clearEstimateFutureCache() { + estimateCacheSupport.clearEstimateFutureCache(); + } + public List listSettlementInfo() throws Exception { initClient(); @@ -102,6 +119,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { today.put("t2", realToday.getBigDecimal("t2")); today.put("t3", realToday.getBigDecimal("t3")); today.put("total", realToday.getBigDecimal("total")); + today.put("net_amount", realToday.getBigDecimal("net_amount")); } catch (Exception e) { logger.error("今日清算记录未生成,使用自助查询!"); } @@ -138,13 +156,13 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { dayInfo.put("t1", new BigDecimal(0.00)); dayInfo.put("t2", new BigDecimal(0.00)); dayInfo.put("t3", new BigDecimal(0.00)); + dayInfo.put("net_amount", new BigDecimal(0.00)); //todo 支持多个清算记录 List logs = clearingLogMapper.findByDate(settleDate); if (logs == null || logs.size() <= 0) { throw new NotFoundException(); } for (JSONObject log : logs) { - dayInfo.put("total", log.getBigDecimal("net_amount")); JSONObject details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t1client); dayInfo.put("t1", dayInfo.getBigDecimal("t1").add(details.getBigDecimal("total_amount"))); details.clear(); @@ -155,7 +173,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t3client); dayInfo.put("t3", dayInfo.getBigDecimal("t3").add(details.getBigDecimal("total_amount"))); + + dayInfo.put("net_amount", dayInfo.getBigDecimal("net_amount").add(log.getBigDecimal("net_amount"))); } + dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3"))); return dayInfo; } @@ -202,6 +223,30 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { } dayInfo.put("estimate_date", endStr); dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3"))); + + + //预计到账金额 + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0); + Date datefrom = cal.getTime(); + + if (new Date().getDate() == datefrom.getDate()) { + JSONObject params = new JSONObject(); + params.put("datefrom", DateFormatUtils.format(datefrom, "yyyy-MM-dd HH:mm:ss")); + params.put("dateto", DateFormatUtils.format(DateUtils.addDays(datefrom, 1),"yyyy-MM-dd HH:mm:ss")); + + List lastDayClearingAmount = transactionMapper.getLastDaytransAmount(params); + BigDecimal total_clearing = BigDecimal.ZERO; + BigDecimal total_surcharge = BigDecimal.ZERO; + for (JSONObject e : lastDayClearingAmount) { + total_clearing = total_clearing.add(e.getBigDecimal("clearing_amount")); + total_surcharge = total_surcharge.add(e.getBigDecimal("channel_surcharge")); + } + + dayInfo.put("total_clearing", total_clearing.subtract(total_surcharge)); + dayInfo.put("clearing", lastDayClearingAmount); + } return dayInfo; } @@ -277,7 +322,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { @Override public void generateSettleAmount() { - String report_date = DateFormatUtils.format(new Date(), "yyyy/MM/dd"); + String report_date = DateFormatUtils.format(DateUtils.addDays(new Date(),-1), "yyyy/MM/dd"); logger.info("系统开始生成[ " + report_date + " ]清算总额"); JSONObject isClearDay = estimateAnalysisMapper.checkIsClearDay(report_date); @@ -327,8 +372,19 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService { } @Override - public List listEstimateLog(int logType) { - return estimateAnalysisMapper.listEstimateLog(logType); + public List listEstimateLog(int logType, String date) { + Date monthDate; + try { + monthDate = DateUtils.parseDate(date, new String[] { "yyyy-MM" }); + } catch (ParseException e) { + throw new BadRequestException("Invalid month format"); + } + Calendar monthCal = Calendar.getInstance(); + monthCal.setTime(monthDate); + int year = monthCal.get(Calendar.YEAR); + int month = monthCal.get(Calendar.MONTH) + 1; + + return estimateAnalysisMapper.listEstimateLog(logType, year, month); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateCacheSupportImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateCacheSupportImpl.java new file mode 100644 index 000000000..ca1fab8ff --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/EstimateCacheSupportImpl.java @@ -0,0 +1,14 @@ +package au.com.royalpay.payment.manage.analysis.core.impls; + +import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Service; + +@Service +public class EstimateCacheSupportImpl implements EstimateCacheSupport { + + @Override + @CacheEvict(value = ":estimate_analysis_future:", key = "''") + public void clearEstimateFutureCache() { + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.java b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.java index 7b507b649..74a37d1a2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.java @@ -34,7 +34,7 @@ public interface EstimateAnalysisMapper { JSONObject getCleanAmount(@Param("start_date") String start_date, @Param("end") String end_date); - List listEstimateLog(@Param("log_type") int log_type); + List listEstimateLog(@Param("log_type") int log_type, @Param("year") int year, @Param("month") int month); List findCleanLogsByDate(@Param("start_date") String start_date, @Param("end_date") String end_date); diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/EstimateAnalysisController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/EstimateAnalysisController.java index af022d1b8..afa6c1e87 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/EstimateAnalysisController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/EstimateAnalysisController.java @@ -3,10 +3,7 @@ package au.com.royalpay.payment.manage.analysis.web; import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import com.alibaba.fastjson.JSONObject; -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.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -23,17 +20,23 @@ public class EstimateAnalysisController { @ManagerMapping(value = "/future",method = RequestMethod.GET) public List getFutureSettleInfo() throws Exception { - return estimateAnalysisService.listFurtureInfo(); + return estimateAnalysisService.listFutureInfo(); } - @ManagerMapping(value = "/log",method = RequestMethod.GET) - public List getEstimateLogInfo() throws Exception { - return estimateAnalysisService.listEstimateLog(1); + @ManagerMapping(value = "/future/refresh", method = RequestMethod.PUT) + public void clearEstimateFutureCache() { + estimateAnalysisService.clearEstimateFutureCache(); } - @ManagerMapping(value = "/transaction/log",method = RequestMethod.GET) - public List getTransactionLogInfo() throws Exception { - return estimateAnalysisService.listEstimateLog(2); + @ManagerMapping(value = "/log/{date}", method = RequestMethod.GET) + public List getEstimateLogInfo(@PathVariable String date) throws Exception { + + return estimateAnalysisService.listEstimateLog(1, date); + } + + @ManagerMapping(value = "/transaction/log/{date}",method = RequestMethod.GET) + public List getTransactionLogInfo(@PathVariable String date) throws Exception { + return estimateAnalysisService.listEstimateLog(2,date); } @ManagerMapping(value = "/query", method = RequestMethod.GET) diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java index 9ecac4225..b570d7d7d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java @@ -174,5 +174,7 @@ public interface TransactionMapper { List getSettlementLogDetailList(@Param("clientOrders") List clientOrders, @Param("client_id") int clientId); List getClientOrderByTransactionTime(JSONObject params); - + + List getLastDaytransAmount(JSONObject params); + } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.xml index 8a2ff2538..020df407e 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/EstimateAnalysisMapper.xml @@ -86,6 +86,7 @@ ( IFNULL(one_clean_amount,0) + IFNULL(two_clean_amount,0) +IFNULL(three_clean_amount,0)) total_amount FROM log_clearing_estimate WHERE log_type = #{log_type} + AND year(log_date) = #{year} AND month(log_date) = #{month} ORDER BY log_date DESC diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index ce2a4134b..0d6261d8b 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -1111,4 +1111,18 @@ and t.transaction_time >= #{from} and t.transaction_time < #{to} + + diff --git a/src/main/ui/static/analysis/settle_estimate_analysis.js b/src/main/ui/static/analysis/settle_estimate_analysis.js index d40581d9c..f89daa8dc 100644 --- a/src/main/ui/static/analysis/settle_estimate_analysis.js +++ b/src/main/ui/static/analysis/settle_estimate_analysis.js @@ -13,8 +13,8 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', ' }) }]); app.controller('estimateCtrl', ['$scope', '$http', '$filter','chartParser',function ($scope, $http, $filter,chartParser) { - $scope.listLogs = function () { - $http.get('/analysis/estimate/log').then(function (resp) { + $scope.listLogs = function (month) { + $http.get('/analysis/estimate/log/' + $filter('date')(month, 'yyyy-MM')).then(function (resp) { $scope.logs = resp.data; $scope.logArray = {}; angular.forEach($scope.logs, function (item) { @@ -22,7 +22,6 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', ' }); }); } - $scope.listLogs(); $scope.future_loading = true; $scope.listEsitimate = function () { $http.get('/analysis/estimate/future').then(function (resp) { @@ -34,6 +33,13 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', ' } $scope.listEsitimate(); + $scope.refresh = function () { + $http.put('/analysis/estimate/future/refresh').then(function (resp) { + $scope.listEsitimate(); + $scope.future_loading = true; + }); + } + $scope.params = {}; $scope.today = new Date(); $scope.chooseToday = function () { diff --git a/src/main/ui/static/analysis/templates/settle_estimate_analysis.html b/src/main/ui/static/analysis/templates/settle_estimate_analysis.html index b1307193d..b5d485a5a 100644 --- a/src/main/ui/static/analysis/templates/settle_estimate_analysis.html +++ b/src/main/ui/static/analysis/templates/settle_estimate_analysis.html @@ -51,6 +51,10 @@ Total: + + + +

+
+
+ 预计到账金额详情: +
+
+
+

到账金额:

+ +

到账金额:

+

Alipay Online到账金额:

+

到账金额:

+

到账金额:

+ +
+

总到账金额:

+
+
+ +
+ +
@@ -183,7 +237,7 @@
Settlement Logs
-
+
总清算额:
Transaction Logs
-
+
总交易额: diff --git a/src/main/ui/static/analysis/trans-analysis.js b/src/main/ui/static/analysis/trans-analysis.js index 7bccea5a0..48815798d 100644 --- a/src/main/ui/static/analysis/trans-analysis.js +++ b/src/main/ui/static/analysis/trans-analysis.js @@ -27,8 +27,8 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts','./transaction/an $scope.switchScale = function (scale) { $scope.currentScale = scale; }; - $scope.listTransLogs = function () { - $http.get('/analysis/estimate/transaction/log').then(function (resp) { + $scope.listTransLogs = function (month) { + $http.get('/analysis/estimate/transaction/log/' + $filter('date')(month, 'yyyy-MM')).then(function (resp) { $scope.logs = resp.data; $scope.logArray = {}; angular.forEach($scope.logs, function (item) { @@ -36,7 +36,6 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts','./transaction/an }); }); } - $scope.listTransLogs(); $scope.params = {}; $scope.today = new Date(new Date().getTime() - 24*60*60*1000);