From 03274a4ee0edf6cced33c6e92bd7d6a166e31060 Mon Sep 17 00:00:00 2001 From: luoyang Date: Mon, 27 Aug 2018 18:19:09 +0800 Subject: [PATCH] fix clearing_detail --- .../clearing/core/CleanService.java | 2 + .../clearing/core/impl/CleanServiceImpl.java | 64 +++++++++++++++++++ .../clearing/web/SettlementDevController.java | 10 +++ .../mappers/log/ClearingDetailMapper.java | 5 ++ .../mappers/log/ClearingDetailMapper.xml | 37 +++++++++++ src/main/ui/static/analysis/clearing-log.js | 46 +++++++++++++ .../analysis/templates/settlement_detail.html | 15 +++++ 7 files changed, 179 insertions(+) diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java index 09518584a..da0346bf6 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java @@ -31,6 +31,8 @@ public interface CleanService { JSONObject getClearDetails(Date dt, String managerId); + JSONObject getClearDetailsLimit20(Date dt, String managerId); + JSONObject getCleanLogTransactions(int detailId, JSONObject manager); Map getDayAndChannelOfAnalysisMap(int detailId, String channel,JSONObject manager); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java index b419e9a95..ef03ec115 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java @@ -248,6 +248,70 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider return total; } + @Override + public JSONObject getClearDetailsLimit20(Date settleDate, String managerId) { + List logs = clearingLogMapper.findByDate(settleDate); + if (logs.isEmpty()) { + throw new NotFoundException(); + } + JSONObject total = new JSONObject(); + total.put("settle_date", settleDate); + total.put("total_credit", 0); + total.put("total_debit", 0); + total.put("gross_amount", 0); + total.put("wechat_charge", 0); + total.put("royalpay_charge", 0); + total.put("net_amount", 0); + total.put("total_charge", 0); + total.put("tax_amount", 0); + total.put("charge_cashback", 0); + + List details = new ArrayList<>(); + List totalList = new ArrayList<>(); + for (JSONObject log : logs) { + addBigDecimal(total, log, "total_credit"); + addBigDecimal(total, log, "total_debit"); + addBigDecimal(total, log, "gross_amount"); + addBigDecimal(total, log, "wechat_charge"); + addBigDecimal(total, log, "royalpay_charge"); + addBigDecimal(total, log, "net_amount"); + addBigDecimal(total, log, "total_charge"); + addBigDecimal(total, log, "charge_cashback"); + addBigDecimal(total, log, "tax_amount"); + int clearingId = log.getIntValue("clearing_id"); + List logDetails = clearingDetailMapper.listReportsOfSettlementLimit20(clearingId); + details.addAll(logDetails); + List banks = logDetails.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList()); + + List bankStatistics = banks.stream().map(bank -> { + JSONObject data = new JSONObject(); + data.put("bank", bank); + data.put("total_settle", logDetails.stream() + .filter(detail -> bank.equals(detail.getString("settle_bank"))) + .map(detail -> detail.getBigDecimal("clearing_amount")) + .reduce(BigDecimal::add) + ); + data.put("clients", logDetails.stream() + .filter(detail -> bank.equals(detail.getString("settle_bank"))) + .count()); + return data; + }).collect(Collectors.toList()); + + totalList = clearingDetailMapper.listRepostTotal(clearingId); + //bankStatistics.put() + + log.put("bank_statistics", bankStatistics); + log.put("editable", DateUtils.isSameDay(log.getDate("settle_date"), new Date()) && log.getBooleanValue("editable")); + log.put("channel_analysis", clearingDetailAnalysisMapper.analysisChannelReport(clearingId)); + } + total.put("totalList", totalList); + total.put("logs", logs); + total.put("details", details); + List channels = clearingDetailAnalysisMapper.analysisChannelReportDaily(settleDate); + total.put("channel_analysis", channels); + return total; + } + private void addBigDecimal(JSONObject total, JSONObject log, String key) { total.put(key, total.getBigDecimal(key).add(log.getBigDecimal(key))); } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java index f4dea7830..b010016c2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java @@ -42,6 +42,16 @@ public class SettlementDevController { } @RequestMapping("/reports/{date}") + public JSONObject settleReportLimit20(@PathVariable String date,@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + try { + Date dt = dateFormat.parse(date); + return cleanService.getClearDetailsLimit20(dt, manager.getString("manager_id")); + } catch (ParseException e) { + throw new BadRequestException("error.payment.valid.invalid_date_format"); + } + } + + @RequestMapping("/reports/{date}/all") public JSONObject settleReport(@PathVariable String date, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { try { Date dt = dateFormat.parse(date); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java index 62ff594d9..3ddf28559 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java @@ -29,6 +29,8 @@ public interface ClearingDetailMapper { List listReportsOfSettlement(@Param("clearing_id") int clearingId); + List listReportsOfSettlementLimit20(@Param("clearing_id") int clearingId); + JSONObject listReportsOfSettleCleanDay(@Param("clearing_id") int clearingId, @Param("client_ids") List client_ids); PageList listReportsOfSettlementLogs(JSONObject params, PageBounds pagination); @@ -48,4 +50,7 @@ public interface ClearingDetailMapper { @AutoSql(type = SqlType.DELETE) void deleteSettleLogs(@Param("clearing_id") int clearingId); + + List listRepostTotal(@Param("clearing_id") int clearingId); + } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml index 473d41a81..154ee5abe 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml @@ -25,7 +25,37 @@ INNER JOIN sys_clients c ON c.client_id = d.client_id AND c.is_valid=1 WHERE d.clearing_id = #{clearing_id} + + + \ No newline at end of file diff --git a/src/main/ui/static/analysis/clearing-log.js b/src/main/ui/static/analysis/clearing-log.js index 41e4ec3d8..fe0c60cda 100644 --- a/src/main/ui/static/analysis/clearing-log.js +++ b/src/main/ui/static/analysis/clearing-log.js @@ -243,6 +243,8 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func }]); app.controller('settlementDetailCtrl', ['$scope', '$stateParams', '$http', '$uibModal', '$filter', '$state', 'detail', 'commonDialog', function ($scope, $stateParams, $http, $uibModal, $filter, $state, detail, commonDialog) { + $scope.allButton = false; + $scope.limitButton = true; $scope.detail = detail.data; $scope.hasSentMail = false; $scope.sendNotice = false; @@ -250,6 +252,9 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func $scope.analysisFilter = {}; $scope.currentAnalysis = $scope.detail; $scope.pageCtrl = {visible:{}}; + var t1Amount =0; + var t2Amount =0; + var t3Amount =0; function getAnalysisTemplate() { return [ @@ -266,7 +271,44 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func }; angular.forEach($scope.detail.logs, function (batch) { $scope.batchAnalysis[batch.clearing_id + ''] = getAnalysisTemplate(); + }); + $scope.allClearing = function() { + $http.get('/sys/settlement/reports/' + $stateParams.date + '/all').then(function (resp) { + angular.forEach($scope.settleAnalysis, function (list) { + list.settles.splice(0, list.settles.length); + list.clients = 0; + list.settleAmount = 0; + }); + + angular.forEach(resp.data.details, function (settleItem) { + var settleDays = settleItem.clear_days; + attachAnalysis($scope.settleAnalysis[Math.min(settleDays - 1, 2)]); + attachAnalysis($scope.batchAnalysis[settleItem.clearing_id + ''][Math.min(settleDays - 1, 2)]); + + function attachAnalysis(analysisItem) { + analysisItem.settles.push(settleItem); + analysisItem.clients++; + analysisItem.settleAmount = Decimal.add(analysisItem.settleAmount, settleItem.clearing_amount).toFixed(2, Decimal.ROUND_FLOOR); + } + }); + $scope.allButton = true; + $scope.limitButton = false; + }); + }; + + $scope.packup = function() { + angular.forEach($scope.settleAnalysis, function (list) { + list.settles.splice(20, list.settles.length); + list.clients = 20; + }); + $scope.settleAnalysis[0].settleAmount = t1Amount; + $scope.settleAnalysis[1].settleAmount = t2Amount; + $scope.settleAnalysis[2].settleAmount = t3Amount; + $scope.allButton = false; + $scope.limitButton = true; + + }; angular.forEach($scope.detail.details, function (settleItem) { var settleDays = settleItem.clear_days; @@ -279,6 +321,10 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func analysisItem.settleAmount = Decimal.add(analysisItem.settleAmount, settleItem.clearing_amount).toFixed(2, Decimal.ROUND_FLOOR); } }); + + t1Amount = $scope.settleAnalysis[0].settleAmount; + t2Amount = $scope.settleAnalysis[1].settleAmount; + t3Amount = $scope.settleAnalysis[2].settleAmount; var nowStr = $filter('date')(new Date(), "yyyy-MM-dd"); $scope.datePattern = $stateParams.date; if ($scope.datePattern == nowStr) { diff --git a/src/main/ui/static/analysis/templates/settlement_detail.html b/src/main/ui/static/analysis/templates/settlement_detail.html index 9992dbbf1..828088d13 100644 --- a/src/main/ui/static/analysis/templates/settlement_detail.html +++ b/src/main/ui/static/analysis/templates/settlement_detail.html @@ -169,6 +169,13 @@ +
+
+ +   Amounts: + +
+
@@ -217,6 +224,14 @@ + + + 全部 + + + 收起 + +