master
yuan 7 years ago
parent ff5494efc3
commit a1b2ff0474

@ -16,6 +16,8 @@ public interface DashboardService {
JSONObject getCommonAnalysis2(JSONObject params);
JSONObject getCommonAnalysis4(JSONObject params);
// JSONObject getCommonAnalysis(JSONObject params);
List<JSONObject> getTradeInTypes(JSONObject params);

@ -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<JSONObject> 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<JSONObject> 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

@ -44,4 +44,8 @@ public interface CustomerAndOrdersStatisticsMapper {
JSONObject countChannel(JSONObject params);
JSONObject getChannelCommonCount(JSONObject params);
JSONObject getCommonCount(JSONObject params);
}

@ -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);

@ -30,4 +30,10 @@ public interface ClientCustomersMapper {
PageList<JSONObject> listCustomerInfo(JSONObject params, PageBounds pageBounds);
int countTradedClients(JSONObject params);
int countTotalCustomers(JSONObject params);
int countTotalOldCustomers(JSONObject params);
}

@ -302,4 +302,66 @@
</if>
</where>
</select>
<select id="getChannelCommonCount" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
select ifnull(sum(CASE WHEN s.channel = 'Alipay' THEN s.total ELSE 0 END),0) alipayamount,
ifnull(sum(CASE WHEN s.channel = 'Alipay' THEN s.orders ELSE 0 END),0) alipay_order_count,
ifnull(sum(CASE WHEN s.channel = 'Bestpay' THEN s.total ELSE 0 END),0) bestpayamount,
ifnull(sum(CASE WHEN s.channel = 'Bestpay' THEN s.orders ELSE 0 END),0) bestpay_order_count,
ifnull(sum(CASE WHEN s.channel = 'Wechat' THEN s.total ELSE 0 END),0) wechatamount,
ifnull(sum(CASE WHEN s.channel = 'Wechat' THEN s.orders ELSE 0 END),0) wechat_order_count,
ifnull(sum(CASE WHEN s.channel = 'jd' THEN s.total ELSE 0 END),0) jdamount,
ifnull(sum(CASE WHEN s.channel = 'jd' THEN s.orders ELSE 0 END),0) jd_order_count,
ifnull(sum(CASE WHEN s.channel = 'AlipayOnline' THEN s.total ELSE 0 END),0) alipayonlineamount,
ifnull(sum(CASE WHEN s.channel = 'AlipayOnline' THEN s.orders ELSE 0 END),0) alipayonline_order_count
FROM statistics_customer_order s
LEFT JOIN sys_clients c ON c.client_id = s.client_id and c.is_valid=1
]]>
<where>
s.client_id != 0
<if test="client_ids!=null">
AND s.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id != null">
and s.client_id=#{client_id}
</if>
<if test="begin!=null">and s.date &gt;= #{begin}</if>
<if test="end!=null">and s.date &lt; #{end}</if>
<if test="org_id!=null and org_ids==null">and c.org_id=#{org_id}</if>
<if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
</where>
</select>
<select id="getCommonCount" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
select
ifnull(sum(s.orders),0) trade_count,
ifnull(sum(s.total),0) trade_amount
FROM statistics_customer_order s
LEFT JOIN sys_clients c ON c.client_id = s.client_id and c.is_valid=1
]]>
<where>
s.client_id != 0
<if test="client_ids!=null">
AND s.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id != null">
and s.client_id=#{client_id}
</if>
<if test="begin!=null">and s.date &gt;= #{begin}</if>
<if test="end!=null">and s.date &lt; #{end}</if>
<if test="channel!=null">and s.channel=#{channel}</if>
<if test="org_id!=null and org_ids==null">and c.org_id=#{org_id}</if>
<if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
</where>
</select>
</mapper>

@ -43,4 +43,31 @@
and customer_id = #{customer_id}
</update>
<select id="countTradedClients" resultType="java.lang.Integer">
select COUNT(DISTINCT client_id) traded_partners
FROM sys_clients_customers
<where>
<if test="begin!=null">and last_payment_time &gt;= #{begin}</if>
<if test="end!=null">and last_payment_time &lt; #{end}</if>
</where>
</select>
<select id="countTotalCustomers" resultType="java.lang.Integer">
select COUNT(DISTINCT customer_id) traded_partners
FROM sys_clients_customers
<where>
<if test="begin!=null">and last_payment_time &gt;= #{begin}</if>
<if test="end!=null">and last_payment_time &lt; #{end}</if>
</where>
</select>
<select id="countTotalOldCustomers" resultType="java.lang.Integer">
select COUNT(DISTINCT customer_id) traded_partners
FROM sys_clients_customers
<where>
<if test="begin!=null">and update_time &lt; #{begin} AND last_payment_time &gt; #{begin}</if>
<if test="end!=null">and last_payment_time &lt; #{end}</if>
</where>
</select>
</mapper>

@ -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;
});

@ -83,7 +83,7 @@
<div class="description-block border-right">
<div class="description-text">交易额:
<label class="description-header text-red"
ng-bind="totalChannelAmount.wechatAmount|currency: ' $ '"></label>
ng-bind="totalChannelAmount.wechatamount|currency: ' $ '"></label>
</div>
<div class="description-text">订单数:
<label class="description-header text-red"
@ -96,7 +96,7 @@
<div class="description-block border-right">
<div class="description-text">交易额:
<label class="description-header text-red"
ng-bind="totalChannelAmount.alipayAmount|currency: ' $ '"></label>
ng-bind="totalChannelAmount.alipayamount|currency: ' $ '"></label>
</div>
<div class="description-text">订单数:
<label class="description-header text-red"
@ -109,11 +109,11 @@
<div class="description-block">
<div class="description-text">交易额:
<label class="description-text text-red"
ng-bind="totalChannelAmount.aliOnlineAmount|currency: ' $ '"></label>
ng-bind="totalChannelAmount.alipayonlineamount|currency: ' $ '"></label>
</div>
<div class="description-text">订单数:
<label class="description-text text-red"
ng-bind="totalChannelAmount.aliOnline_order_count"></label>
ng-bind="totalChannelAmount.alipayonline_order_count"></label>
</div>
<div class="description-header text-bold"><img src="/static/images/alipay_sign.png"/> AlipayOnline</div>
</div>
@ -124,11 +124,11 @@
<div class="description-block border-right">
<div class="description-text">交易额:
<label class="description-text text-red"
ng-bind="totalChannelAmount.bestPayAmount|currency: ' $ '"></label>
ng-bind="totalChannelAmount.bestpayamount|currency: ' $ '"></label>
</div>
<div class="description-text">订单数:
<label class="description-text text-red"
ng-bind="totalChannelAmount.bestPay_order_count"></label>
ng-bind="totalChannelAmount.bestpay_order_count"></label>
</div>
<div class="description-header text-bold"><img src="/static/images/bestpay_sign.png"/> Bestpay</div>
</div>
@ -137,7 +137,7 @@
<div class="description-block">
<div class="description-text">交易额:
<label class="description-text text-red"
ng-bind="totalChannelAmount.jdAmount|currency: ' $ '"></label>
ng-bind="totalChannelAmount.jdamount|currency: ' $ '"></label>
</div>
<div class="description-text">订单数:
<label class="description-text text-red"

Loading…
Cancel
Save