From a1b2ff04742f7065c0891c88311d3d061c6cc3d4 Mon Sep 17 00:00:00 2001 From: yuan <1551130722@qq.com> Date: Fri, 1 Jun 2018 15:14:53 +0800 Subject: [PATCH] fix~~ --- .../analysis/core/DashboardService.java | 2 + .../core/impls/DashboardServiceImpl.java | 138 +++++++++++++++--- .../CustomerAndOrdersStatisticsMapper.java | 4 + .../analysis/web/DashboardController.java | 7 + .../mappers/client/ClientCustomersMapper.java | 6 + .../CustomerAndOrdersStatisticsMapper.xml | 62 ++++++++ .../mappers/client/ClientCustomersMapper.xml | 27 ++++ src/main/ui/static/dashboard/dashboard.js | 29 +--- .../static/dashboard/templates/dashboard.html | 14 +- 9 files changed, 238 insertions(+), 51 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/DashboardService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/DashboardService.java index 7dfd56520..eb071d334 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/DashboardService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/DashboardService.java @@ -16,6 +16,8 @@ public interface DashboardService { JSONObject getCommonAnalysis2(JSONObject params); + JSONObject getCommonAnalysis4(JSONObject params); + // JSONObject getCommonAnalysis(JSONObject params); List getTradeInTypes(JSONObject params); diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java index be08de126..ae10bf486 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java @@ -7,6 +7,7 @@ import au.com.royalpay.payment.manage.analysis.core.DashboardService; import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper; import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; +import au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ExchangeRateMapper; @@ -17,7 +18,6 @@ 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.lang3.time.DateUtils; import org.apache.commons.lang3.time.DurationFormatUtils; import org.slf4j.Logger; @@ -65,6 +65,9 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT @Resource private StringRedisTemplate stringRedisTemplate; + @Resource + private ClientCustomersMapper clientCustomersMapper; + @Override @@ -74,45 +77,90 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT if(commonAnalysis1 != null){ return commonAnalysis1; } - JSONObject res = transactionAnalysisMapper.getClientTransaction(params); + JSONObject res = new JSONObject(); + if(params.getDate("end").after(new Date())){ + if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){ + res = transactionAnalysisMapper.getClientTransaction(params); + }else { + JSONObject today = new JSONObject(); + today.put("end",params.getDate("end")); + today.put("begin", DateUtils.addDays(params.getDate("end"), -1)); + JSONObject isToday = transactionAnalysisMapper.getClientTransaction(params); + JSONObject isNotToday = customerAndOrdersStatisticsMapper.getCommonCount(today); + res.put("trade_count",isToday.getIntValue("trade_count") + isNotToday.getIntValue("trade_count")); + res.put("trade_amount",isToday.getBigDecimal("trade_amount").add(isNotToday.getBigDecimal("trade_amount"))); + } + }else { + res = customerAndOrdersStatisticsMapper.getCommonCount(params); + } stringRedisTemplate.boundValueOps("org_commonAnalysis1"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES); return res; - // res.put("new_partners", clientAnalysisMapper.countNewClients(params)); -// res.put("total_partners", clientAnalysisMapper.countClients(params)); -// res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); -// List topOrders = transactionAnalysisMapper.getTopOrders(params, new PageBounds(1, 1, Order.formString("aud_fee.desc"))); -// if (!topOrders.isEmpty()) { -// res.put("top_amount_order", topOrders.get(0)); -// } -// res.put("total_customers", transactionAnalysisMapper.countCustomers(params)); -// //res.put("new_customers", transactionAnalysisMapper.countNewCustomers(params)); -// res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params)); + } @Override public JSONObject getCommonAnalysis3(JSONObject params) { + String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis3"+ params.getString("org_id")+ params.getString("begin")).get(); + JSONObject commonAnalysis3 = JSONObject.parseObject(jsonStr); + if(commonAnalysis3 != null){ + return commonAnalysis3; + } JSONObject res = new JSONObject(); res.put("new_partners", clientAnalysisMapper.countNewClients(params)); res.put("total_partners", clientAnalysisMapper.countClients(params)); - res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); + stringRedisTemplate.boundValueOps("org_commonAnalysis3"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES); return res; } @Override public JSONObject getCommonAnalysis2(JSONObject params) { + String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis2"+ params.getString("org_id")+ params.getString("begin")).get(); + JSONObject commonAnalysis2 = JSONObject.parseObject(jsonStr); + if(commonAnalysis2 != null){ + return commonAnalysis2; + } + JSONObject res = new JSONObject(); + if(params.getDate("end").after(new Date())){ + if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){ + res.put("total_customers", transactionAnalysisMapper.countCustomers(params)); + res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params)); + res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); + }else { + JSONObject today = new JSONObject(); + today.put("end",params.getDate("end")); + today.put("begin", DateUtils.addDays(params.getDate("end"), -1)); + res = getSevenOrMonth(params,today); + } + }else { + res.put("traded_partners", clientCustomersMapper.countTradedClients(params)); + res.put("total_customers", clientCustomersMapper.countTotalCustomers(params)); + res.put("old_customers", clientCustomersMapper.countTotalOldCustomers(params)); + } + stringRedisTemplate.boundValueOps("org_commonAnalysis2"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES); + return res; + } + + @Override + public JSONObject getCommonAnalysis4(JSONObject params) { + String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis4"+ params.getString("org_id")+ params.getString("begin")).get(); + JSONObject commonAnalysis4 = JSONObject.parseObject(jsonStr); + if(commonAnalysis4 != null){ + return commonAnalysis4; + } JSONObject res = new JSONObject(); -// res.put("new_partners", clientAnalysisMapper.countNewClients(params)); -// res.put("total_partners", clientAnalysisMapper.countClients(params)); -// res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); -// res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params)); -// res.put("trade_count", transactionAnalysisMapper.getClientTransaction(params).getIntValue("trade_count")); List topOrders = transactionAnalysisMapper.getTopOrders(params, new PageBounds(1, 1, Order.formString("aud_fee.desc"))); if (!topOrders.isEmpty()) { res.put("top_amount_order", topOrders.get(0)); } - res.put("total_customers", transactionAnalysisMapper.countCustomers(params)); - //res.put("new_customers", transactionAnalysisMapper.countNewCustomers(params)); - res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params)); + stringRedisTemplate.boundValueOps("org_commonAnalysis4"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES); + return res; + } + + private JSONObject getSevenOrMonth(JSONObject params, JSONObject today){ + JSONObject res = new JSONObject(); + res.put("traded_partners", clientCustomersMapper.countTradedClients(params) + clientAnalysisMapper.countNewClients(today)); + res.put("total_customers", clientCustomersMapper.countTotalCustomers(params) + clientAnalysisMapper.countClients(today)); + res.put("old_customers", clientCustomersMapper.countTotalOldCustomers(params) + clientAnalysisMapper.countTradedPartners(params)); return res; } @@ -469,7 +517,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT } } - @Override +/* @Override public JSONObject getPlatformAmount(JSONObject params) { JSONObject resp = new JSONObject(); @@ -493,6 +541,52 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT resp.put("aliOnlineAmount",transactionAnalysisMapper.getPlatformAmount(params).getBigDecimal("amount")); resp.put("aliOnline_order_count",transactionAnalysisMapper.getPlatformAmount(params).getIntValue("order_count")); return resp; + }*/ + @Override + public JSONObject getPlatformAmount(JSONObject params) { + String jsonStr = stringRedisTemplate.boundValueOps("org_ChannelAnalysis" + params.getString("begin")).get(); + JSONObject channelAnalysis = JSONObject.parseObject(jsonStr); + if(channelAnalysis != null){ + return channelAnalysis; + }else { + JSONObject resp; + if(params.getDate("end").compareTo(new Date()) > 0){ + if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){ + resp = getTodayChannelCount(params); + }else { + JSONObject today = new JSONObject(); + today.put("end",params.getDate("end")); + today.put("begin", DateUtils.addDays(params.getDate("end"), -1)); + resp = getChannelSevenOrMonth(params,today); + } + }else { + resp = customerAndOrdersStatisticsMapper.getChannelCommonCount(params); + } + stringRedisTemplate.boundValueOps("org_ChannelAnalysis"+ params.getString("begin")).set(resp.toJSONString(), 5, TimeUnit.MINUTES); + return resp; + } + } + private JSONObject getTodayChannelCount(JSONObject params){ + String[] channels = new String[]{"Bestpay","Wechat","Alipay","jd","AlipayOnline"}; + JSONObject resp = new JSONObject(); + for(String channel:channels) { + params.put("channel", channel); + resp.put(channel.toLowerCase()+"amount", transactionAnalysisMapper.getPlatformAmount(params).getBigDecimal("amount")); + resp.put(channel.toLowerCase()+"_order_count", transactionAnalysisMapper.getPlatformAmount(params).getIntValue("order_count")); + } + return resp; + } + private JSONObject getChannelSevenOrMonth(JSONObject params,JSONObject today){ + JSONObject channelCount = customerAndOrdersStatisticsMapper.getChannelCommonCount(params); + String[] channels = new String[]{"Bestpay","Wechat","Alipay","jd","AlipayOnline"}; + JSONObject resp = new JSONObject(); + for(String channel:channels) { + today.put("channel", channel); + JSONObject channelAna = transactionAnalysisMapper.getPlatformAmount(today); + resp.put(channel.toLowerCase()+"amount", channelAna.getBigDecimal("amount").add(channelCount.getBigDecimal(channel.toLowerCase()+"amount"))); + resp.put(channel.toLowerCase()+"_order_count", channelAna.getIntValue("order_count") + channelCount.getIntValue(channel.toLowerCase()+"_order_count")); + } + return resp; } @Override diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java index f67167909..03950cdc3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java @@ -44,4 +44,8 @@ public interface CustomerAndOrdersStatisticsMapper { JSONObject countChannel(JSONObject params); + JSONObject getChannelCommonCount(JSONObject params); + + JSONObject getCommonCount(JSONObject params); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/DashboardController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/DashboardController.java index 0b6ed61a1..0daf33a47 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/DashboardController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/DashboardController.java @@ -43,6 +43,13 @@ public class DashboardController { return dashboardService.getCommonAnalysis3(params); } + @ManagerMapping("/common_analysis_4") + public JSONObject commonAnalysis4(AnalysisBean analysis, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + JSONObject params = analysis.toParams(null); + orgManager.checkOrg(manager,params); + return dashboardService.getCommonAnalysis4(params); + } + @ManagerMapping("/common_analysis_2") public JSONObject commonAnalysis2(AnalysisBean analysis, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { JSONObject params = analysis.toParams(null); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java index b15607431..a14fa2289 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java @@ -30,4 +30,10 @@ public interface ClientCustomersMapper { PageList listCustomerInfo(JSONObject params, PageBounds pageBounds); + int countTradedClients(JSONObject params); + + int countTotalCustomers(JSONObject params); + + int countTotalOldCustomers(JSONObject params); + } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml index ebbe47c9e..6a0768d44 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml @@ -302,4 +302,66 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml index ae1d2d552..e81b71dde 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml @@ -43,4 +43,31 @@ and customer_id = #{customer_id} + + + + + + \ No newline at end of file diff --git a/src/main/ui/static/dashboard/dashboard.js b/src/main/ui/static/dashboard/dashboard.js index 2f9d7c595..933cb265a 100644 --- a/src/main/ui/static/dashboard/dashboard.js +++ b/src/main/ui/static/dashboard/dashboard.js @@ -77,7 +77,7 @@ define(['angular', 'uiRouter', 'uiBootstrap', 'angularEcharts'], function (angul var end = $filter('date')(date-oneDay, 'yyyyMMdd'); var date2 = new Date(); - date2.setMonth(date2.getMonth() - 1); + date2.setMonth(date2.getMonth() - 2); date2 = date2.setDate(1); var begin = $filter('date')(date2, 'yyyyMMdd'); return { @@ -124,43 +124,28 @@ define(['angular', 'uiRouter', 'uiBootstrap', 'angularEcharts'], function (angul function loadAnalysis() { $http.get('/dashboard/system/common_analysis_1', {params: $scope.currentScale.params()}).then(function (resp) { - // $scope.analysis.new_partners = resp.data.new_partners; - // $scope.analysis.total_partners = resp.data.total_partners; - // $scope.analysis.traded_partners = resp.data.traded_partners; $scope.analysis.trade_amount = resp.data.trade_amount; $scope.analysis.trade_count = resp.data.trade_count; - // $scope.analysis.top_amount_order = resp.data.top_amount_order; - // $scope.analysis.trade_count = resp.data.trade_count; - // $scope.analysis.total_customers = resp.data.total_customers; - // $scope.analysis.new_customers = resp.data.total_customers-resp.data.old_customers; - // $scope.analysis.old_customers = resp.data.old_customers; }); $http.get('/dashboard/system/common_analysis_3', {params: $scope.currentScale.params()}).then(function (resp) { $scope.analysis.new_partners = resp.data.new_partners; $scope.analysis.total_partners = resp.data.total_partners; - $scope.analysis.traded_partners = resp.data.traded_partners; - - // $scope.analysis.top_amount_order = resp.data.top_amount_order; - // $scope.analysis.trade_count = resp.data.trade_count; - // $scope.analysis.total_customers = resp.data.total_customers; - // $scope.analysis.new_customers = resp.data.total_customers-resp.data.old_customers; - // $scope.analysis.old_customers = resp.data.old_customers; }); $http.get('/dashboard/system/common_analysis_2', {params: $scope.currentScale.params()}).then(function (resp) { - // $scope.analysis.new_partners = resp.data.new_partners; - // $scope.analysis.total_partners = resp.data.total_partners; - // $scope.analysis.traded_partners = resp.data.traded_partners; - // $scope.analysis.trade_amount = resp.data.trade_amount; - $scope.analysis.top_amount_order = resp.data.top_amount_order; - // $scope.analysis.trade_count = resp.data.trade_count; + + $scope.analysis.traded_partners = resp.data.traded_partners; $scope.analysis.total_customers = resp.data.total_customers; $scope.analysis.new_customers = resp.data.total_customers - resp.data.old_customers; $scope.analysis.old_customers = resp.data.old_customers; }); + $http.get('/dashboard/system/common_analysis_4', {params: $scope.currentScale.params()}).then(function (resp) { + $scope.analysis.top_amount_order = resp.data.top_amount_order; + }); + $http.get('/dashboard/system/Total_platform_amount', {params: $scope.currentScale.params()}).then(function (resp) { $scope.totalChannelAmount = resp.data; }); diff --git a/src/main/ui/static/dashboard/templates/dashboard.html b/src/main/ui/static/dashboard/templates/dashboard.html index 1eb8df98a..157e72dd2 100644 --- a/src/main/ui/static/dashboard/templates/dashboard.html +++ b/src/main/ui/static/dashboard/templates/dashboard.html @@ -83,7 +83,7 @@
交易额: + ng-bind="totalChannelAmount.wechatamount|currency: ' $ '">
订单数: