更改BD销售页行业展示,增加表格导出

master
yuan 7 years ago
parent 5f8acdb6d2
commit 8073bf876c

@ -35,6 +35,7 @@ public class AnalysisBean {
private String client_moniker;
private String amount_from;
private String amount_to;
private String bd_name;
public JSONObject toParams(String timezone) {
JSONObject params = new JSONObject();
if (timezone != null) {
@ -78,6 +79,9 @@ public class AnalysisBean {
if(channel!=null){
params.put("channel",channel);
}
if(bd_name!=null){
params.put("bd_name",bd_name);
}
if (client_moniker!=null){
params.put("client_moniker", client_moniker);
}
@ -217,4 +221,12 @@ public class AnalysisBean {
public void setClient_moniker(String client_moniker) {
this.client_moniker = client_moniker;
}
public String getBd_name() {
return bd_name;
}
public void setBd_name(String bd_name) {
this.bd_name = bd_name;
}
}

@ -19,6 +19,10 @@ public interface BDAnalysisService {
void exportSalesExcel(AnalysisBean analysisBean, HttpServletResponse httpResponse, JSONObject manager) throws IOException;
void exportPartnerExcelByBd(AnalysisBean analysisBean, HttpServletResponse httpResponse,JSONObject manager) throws IOException;
void exportPartnerExcelByData(AnalysisBean analysisBean, HttpServletResponse httpResponse,JSONObject manager) throws IOException;
/**
* bd
*

@ -4,9 +4,12 @@ import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean;
import au.com.royalpay.payment.manage.analysis.core.BDAnalysisService;
import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.stereotype.Service;
@ -15,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
@ -29,7 +33,20 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Override
public List<JSONObject> getSalesAnalysis(JSONObject jsonObject) {
return bdAnalysisMapper.getBDSaleList(jsonObject);
return listSalesAnalysis(jsonObject);
}
private List<JSONObject> listSalesAnalysis(JSONObject jsonObject){
List<JSONObject> listCountApproved = bdAnalysisMapper.countApproved(jsonObject);
List<JSONObject> bdSaleList = bdAnalysisMapper.getBDSaleList(jsonObject);
for(JSONObject countApproved : listCountApproved){
for(JSONObject saleList : bdSaleList){
if(countApproved.getIntValue("bd_id") == saleList.getIntValue("bd_id")){
saleList.put("num",countApproved.getString("num"));
}
}
}
return bdSaleList;
}
@Override
@ -39,7 +56,37 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Override
public List<JSONObject> getSalesPartnersReportByBD(JSONObject jsonObject) {
return bdAnalysisMapper.getBDSalePartnerReport(jsonObject);
List<JSONObject> bdAnalysis = bdAnalysisMapper.getBDSalePartnerReport(jsonObject);
List<JSONObject> result = new ArrayList<>();
String keys_1[] = {"1","2","3","4","5","6","7","8","9"};
String key_2[] = {"10","11","12"};
result = getPartnerTypes(keys_1,result,1,5,bdAnalysis);
return getPartnerTypes(key_2,result,2,6,bdAnalysis);
}
private List<JSONObject> getPartnerTypes(String keys[],List<JSONObject> result,int short_length,int long_length,List<JSONObject> bdAnalysis){
for(String key : keys){
int countValue = 0;
int countTotal = 0;
JSONObject object = new JSONObject();
JSONArray list = new JSONArray();
for(JSONObject type : bdAnalysis){
if(type.getString("royalpayindustry") != null && type.getString("royalpayindustry").startsWith(key) && (type.getString("royalpayindustry").length()==short_length || type.getString("royalpayindustry").length()==long_length)){
countValue += type.getIntValue("partner_counts");
countTotal += type.getIntValue("total");
list.add(type);
}
}
if(countValue == 0){
continue;
}
object.put("count_value",countValue);
object.put("count_total",countTotal);
object.put("mccCode",key);
object.put("children",list);
result.add(object);
}
return result;
}
@Override
@ -97,6 +144,84 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
return bdAnalysisMapper.countApproved(params);
}
@Override
public void exportPartnerExcelByBd(AnalysisBean analysisBean, HttpServletResponse httpResponse, JSONObject manager) throws IOException {
OutputStream ous = null;
try{
JSONObject parmerters = analysisBean.toParams(null);
List<JSONObject> listPartnerByBd = bdAnalysisMapper.getBDSalePartnerList(parmerters);
httpResponse.setContentType("application/octet-stream;");
httpResponse.addHeader("Content-Disposition", "attachment; filename=" + "Merchant_list--" +parmerters.getString("bd_name") + analysisBean.getBegin() + "~" + analysisBean.getEnd() + ".xls");
ous = httpResponse.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFFont font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 15);
CellStyle analysisStyle = wb.createCellStyle();
analysisStyle.setFont(font);
Sheet sheet = wb.createSheet("Merchant list" );
sheet.createFreezePane(1, 2);
sheet.setDefaultColumnWidth((short) 25);
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"Short Name", "Client Moniker", "AUD Amount"};
for (int i = 0; i < title.length; i++) {
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
}
for(JSONObject partner : listPartnerByBd){
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("short_name"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("client_moniker"));
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("total"));
}
wb.write(ous);
ous.flush();
}catch (IOException e){
} finally {
IOUtils.closeQuietly(ous);
}
}
@Override
public void exportPartnerExcelByData(AnalysisBean analysisBean, HttpServletResponse httpResponse, JSONObject manager) throws IOException {
OutputStream ous = null;
try{
JSONObject parmerters = analysisBean.toParams(null);
List<JSONObject> listPartnerByData = listSalesAnalysis(parmerters);
httpResponse.setContentType("application/octet-stream;");
httpResponse.addHeader("Content-Disposition", "attachment; filename=" + "Merchant_sale" + analysisBean.getBegin() + "~" + analysisBean.getEnd() + ".xls");
ous = httpResponse.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFFont font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 15);
CellStyle analysisStyle = wb.createCellStyle();
analysisStyle.setFont(font);
Sheet sheet = wb.createSheet("Merchant Sale List" );
sheet.createFreezePane(1, 2);
sheet.setDefaultColumnWidth((short) 25);
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"BD Name", "AUD Amount", "Refund Fee","New Merchants"};
for (int i = 0; i < title.length; i++) {
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
}
for(JSONObject dataSale : listPartnerByData){
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(dataSale.getString("bd_name"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(dataSale.getString("total"));
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(dataSale.getString("refund_fee"));
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(dataSale.getString("num") == null? "0" : dataSale.getString("num"));
}
wb.write(ous);
ous.flush();
}catch (IOException e){
} finally {
IOUtils.closeQuietly(ous);
}
}
private void exportExcel(HSSFWorkbook workbook,String title,List<JSONObject> monthTotalSale) {
// 声明一个工作薄
// 生成一个表格

@ -51,4 +51,14 @@ public class BDSaleAnalysisController {
return bdAnalysisService.getSalesPartnersReportByBD(analysis.toParams(null));
}
@ManagerMapping("/sales/partners/excel_bd")
public void exportPartnerExcelByBd(AnalysisBean analysis, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse httpResponse) throws Exception {
bdAnalysisService.exportPartnerExcelByBd(analysis,httpResponse,manager);
}
@ManagerMapping("/sales/partners/excel_data")
public void exportPartnerExcelByData(AnalysisBean analysis, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse httpResponse) throws Exception {
bdAnalysisService.exportPartnerExcelByData(analysis,httpResponse,manager);
}
}

@ -149,7 +149,7 @@
order by num desc
</select>
<select id="getBDSalePartnerReport" resultType="com.alibaba.fastjson.JSONObject">
SELECT c.industry,
SELECT c.industry,c.royalpayindustry,
count(DISTINCT c.client_id) partner_counts,
IFNULL(sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,-temp.clearing_amount*d.proportion)),0)
total
@ -166,7 +166,7 @@
<where>
<if test="bd_id!=null">AND d.bd_id = #{bd_id}</if>
</where>
GROUP BY c.industry
GROUP BY c.royalpayindustry
ORDER BY partner_counts DESC;
</select>

@ -12,6 +12,7 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
}]);
app.controller('bdSaleAnalysisCtrl', ['$scope', '$http', '$filter', '$timeout', 'commonDialog', 'chartParser','industryMap',
function ($scope, $http, $filter, $timeout, commonDialog, chartParser,industryMap) {
$scope.showItems = true;
$scope.params = {};
$scope.today = new Date();
$scope.chooseToday = function () {
@ -151,9 +152,33 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
}
})
};
$scope.loadRoyalpayindustry = function () {
$http.get('/static/data/royalpayindustry.json').then(function (resp) {
$scope.royalpayindustry = resp.data;
})
};
$scope.loadRoyalpayindustry();
var getType = function (industryCode) {
var industryLabel = '';
angular.forEach($scope.royalpayindustry, function (industry) {
if (industry.mccCode == industryCode) {
industryLabel = industry.label;
}else {
angular.forEach(industry.children, function (children){
if (children.mccCode == industryCode) {
industryLabel = children.label;
}
})
}
});
if (!industryLabel) {
industryLabel = industryCode;
}
return industryLabel;
};
$scope.loadPartnersChart = function (bd_id, bd_name) {
$scope.chooseBdName = bd_name;
$scope.bd_id = bd_id
var params = angular.copy($scope.params);
if (params.begin) {
params.begin = $filter('date')(params.begin, 'yyyyMMdd');
@ -188,7 +213,7 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
}
});
var getType = function (industryCode) {
/* var getType = function (industryCode) {
var industryLabel = '';
angular.forEach(industryMap.configs(), function (industry) {
if (industry.value == industryCode) {
@ -199,21 +224,22 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
industryLabel = industryCode;
}
return industryLabel;
};
};*/
$http.get('/analysis/bd/sales/partners/report', {params: params}).then(function (resp) {
$scope.legends = [];
for (var i = 0; i < resp.data.length; i++) {
$scope.legends[i] = resp.data[i].partner_type;
var partner_type = getType(resp.data[i].industry);
/* $scope.legends[i] = resp.data[i].partner_type;*/
var partner_type = getType(resp.data[i].mccCode);
resp.data[i].partner_type = partner_type;
$scope.legends[i] = partner_type;
/* $scope.legends[i] = partner_type;*/
}
$scope.PartnerTypes = angular.copy(resp.data);
var legend = $scope.legends;
$scope.partners_type_chart = chartParser.parse(partnerTypesConfig(), $scope.PartnerTypes);
/* var legend = $scope.legends;*/
childrenType(0);
$scope.partners_type_chart = partnerTypesConfig($scope.PartnerTypes,$scope.children);
$scope.partnersAnalysischart = chartParser.parse(analysisPartner(), $scope.PartnerTypes);
function partnerTypesConfig() {
/*function partnerTypesConfig() {
return {
chart: {
tooltip: {
@ -237,7 +263,7 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
column: {key: 'partner_counts', name: 'partner_type'}
}]
}
};
};*/
function analysisPartner() {
return {
@ -279,7 +305,7 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
}
,
column: {
key: 'total', name: 'total', color: function (idx) {
key: 'count_total', name: 'total', color: function (idx) {
return colors[idx % colors.length]
}
}
@ -292,6 +318,103 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
});
};
var partnerTypesConfig = function (innerData,outerData) {
outerData = outerData||[];
var innerSeriesTemplate = {
name: '商户类别',
type: 'pie',
radius: outerData.length==0?'80%':'40%',
center: ['50%', '40%'],
selectedMode: 'single',
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
},
normal : {
label : {
position : 'inner'
},
labelLine : {
show : false
}
}
},
data:[]
};
angular.forEach(innerData,function (item) {
innerSeriesTemplate.data.push({
name:item.partner_type,
value:item.count_value,
selected:$scope.partners_type.partner_type===item.partner_type
})
});
var outerSeriesTemplate = {
name: '商户类别', type: 'pie',
radius : ['50%', '63%'],
center: ['50%', '40%'],
label: {
normal: {
formatter: '{b} : {c} ({d}%)'
}
},
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
data:[]
};
angular.forEach(outerData,function (item) {
outerSeriesTemplate.data.push({
name:item.children_partner_type,
value:item.partner_counts})
});
var series = [innerSeriesTemplate];
if(outerData.length){
series.push(outerSeriesTemplate)
}
return {
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
color: colors,
/* legend: {
orient: 'horizontal',
/!*y: '450px',
left: 'right',*!/
x: 'center',
y: 'bottom',
data: $scope.legends
},*/
series: series
}
};
$scope.partner_type_chart = function (chart) {
chart.on('click', function (params) {
childrenType(params.dataIndex);
$scope.partners_type_chart = partnerTypesConfig($scope.PartnerTypes,$scope.children);
try {
$scope.$digest();
}catch (err){}
});
};
var childrenType = function (index) {
$scope.partners_type = $scope.PartnerTypes[index];
$scope.children = $scope.partners_type.children;
for (var i = 0; i < $scope.children.length; i++) {
$scope.legends[i] = $scope.children.children_partner_type;
var children_partner_type= getType($scope.children[i].royalpayindustry);
$scope.children[i].children_partner_type = children_partner_type;
}
$scope.PartnerTypes[index].children = $scope.children;
/*$scope.type_count = $scope.PartnerTypes[index].count_value;*/
}
$scope.exportMonthSale = function () {
var params = angular.copy($scope.params);
if (params.begin_month) {
@ -314,6 +437,36 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts', './bd/analysis-b
return url;
}
$scope.exportExcelByBdOrDate = function (type) {
if (type=='data'){
url = '/analysis/bd/sales/partners/excel_data';
}
if (type=='bd'){
var url = '/analysis/bd/sales/partners/excel_bd';
}
var params = angular.copy($scope.params);
if (params.begin) {
params.begin = $filter('date')(params.begin, 'yyyyMMdd');
} else {
params.begin = $filter('date')('2016-01-01', 'yyyyMMdd');
}
if (params.end) {
params.end = $filter('date')(params.end, 'yyyyMMdd');
} else {
params.end = $filter('date')(new Date(), 'yyyyMMdd');
}
var connectSymbol = '?';
url += connectSymbol + 'begin=' + params.begin + '&' + 'end=' + params.end;
if (type=='bd') {
url += '&'+'bd_id=' + $scope.bd_id + '&'+ 'bd_name=' + $scope.chooseBdName;
}
if (params.org_id) {
url += '&' + 'org_id=' + params.org_id;
}
return url;
}
}]);
return app;

@ -98,7 +98,7 @@
</div>
</div>
</div>
<div class="form-group col-xs-12" ng-if="currentUser.org_id==null">
<!--<div class="form-group col-xs-12" ng-if="currentUser.org_id==null">
<label class="control-label col-xs-4 col-sm-1">Export Range</label>
<div class="col-sm-11">
<div style="display: inline-block">
@ -121,7 +121,7 @@
ng-href="{{exportMonthSale()}}">Export</a>
</div>
</div>
</div>
</div>-->
</div>
</div>
</div>
@ -130,16 +130,26 @@
<div class="box">
<div class="box-header">
<h3 class="box-title">BD Sales</h3>
<a class="btn btn-success pull-right"
type="button" ng-if="!showItems"
ng-href="{{exportExcelByBdOrDate('data')}}">
<span>Export</span>
</a>
<button class="btn btn-success pull-right" type="button" ng-click="showItems = !showItems">
<span ng-if="showItems">列表</span>
<span ng-if="!showItems">图表</span>
</button>
</div>
<div class="box-body">
<div class="row cen">
<div class="col-sm-7 col-xs-12">
<div class="col-sm-12 col-xs-12" ng-if="showItems">
<p class="text-center">BD销售数据统计</p>
<div class="chart" style="height: 600px" id="bdSaleChart" echarts="bdSaleChart"
chart-setter="bdEchart($chart)"
ng-class="{nodata:bdSaleChart.nodata}"></div>
</div>
<div class="col-sm-5 col-xs-12">
<div class="col-sm-12 col-xs-12" ng-if="!showItems">
<p class="text-center">BD销售数据统计</p>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
@ -147,6 +157,7 @@
<th>BD</th>
<th>AUD Amount</th>
<th>Refund Fee</th>
<th>New Merchants</th>
</tr>
</thead>
<tbody>
@ -157,6 +168,10 @@
ng-click="loadPartnersChart(sale.bd_id,sale.bd_name)"></td>
<td ng-bind="sale.total"></td>
<td ng-bind="sale.refund_fee"></td>
<td>
<span ng-if="sale.num" ng-bind="sale.num"></span>
<span ng-if="!sale.num">0</span>
</td>
</tr>
</tbody>
</table>
@ -166,17 +181,24 @@
<div class="row cen">
<div class="col-sm-6 col-xs-12">
<p class="text-center">{{chooseBdName}} 商户类别分布</p>
<div class="chart" style="height: 600px" id="bdKindSaleChart" echarts="partners_type_chart"
<div class="chart" style="height: 500px" id="bdKindSaleChart" echarts="partners_type_chart"
chart-setter="partner_type_chart($chart)"
ng-class="{nodata:partners_type_chart.nodata}"></div>
</div>
<div class="col-sm-6 col-xs-12">
<p class="text-center">{{chooseBdName}} 商户类别交易量分布</p>
<div class="chart" style="height: 600px" id="bdKindChart" echarts="partnersAnalysischart"
<div class="chart" style="height: 500px" id="bdKindChart" echarts="partnersAnalysischart"
ng-class="{nodata:partnersAnalysischart.nodata}"></div>
</div>
</div>
<div class="row cen" ng-if="partners.length>0">
<hr>
<div class="box-header">
<a class="btn btn-success pull-right"
ng-href="{{exportExcelByBdOrDate('bd')}}"
type="button">
Export
</a>
</div>
<p style="text-align: center;">{{chooseBdName}} 商户销售排行</p>
<div class="col-sm-12 col-xs-12">
<!--<p class="text-center">{{}}商户销售统计</p>-->
@ -224,3 +246,4 @@
</div>
</div>
</div>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Loading…
Cancel
Save