From c55232b23db95998ce71b4c18cf40d9456f0ea4b Mon Sep 17 00:00:00 2001 From: yangkai Date: Fri, 18 Jan 2019 16:17:47 +0800 Subject: [PATCH] =?UTF-8?q?alipay=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/ChannelsAnalysisService.java | 3 ++ .../impls/ChannelsAnalysisServiceImpl.java | 48 +++++++++++++++++++ .../CustomerAndOrdersStatisticsMapper.java | 2 + .../web/ChannelsAnalysisController.java | 16 +++++++ .../CustomerAndOrdersStatisticsMapper.xml | 45 +++++++++++++++++ .../ui/static/analysis/channels_analysis.js | 15 ++++++ .../analysis/templates/channels_analysis.html | 3 ++ 7 files changed, 132 insertions(+) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/ChannelsAnalysisService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/ChannelsAnalysisService.java index bfc59f823..d40b4a3d3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/ChannelsAnalysisService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/ChannelsAnalysisService.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.analysis.core; import com.alibaba.fastjson.JSONObject; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -12,4 +13,6 @@ public interface ChannelsAnalysisService { List getChannelMount(JSONObject params); List getChannelDate(JSONObject params); + + void exportData(JSONObject params, HttpServletResponse resp); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ChannelsAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ChannelsAnalysisServiceImpl.java index 98477eb2d..df844b86b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ChannelsAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ChannelsAnalysisServiceImpl.java @@ -3,9 +3,21 @@ package au.com.royalpay.payment.manage.analysis.core.impls; import au.com.royalpay.payment.manage.analysis.core.ChannelsAnalysisService; import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -66,6 +78,42 @@ public class ChannelsAnalysisServiceImpl implements ChannelsAnalysisService { return list; } + @Override + public void exportData(JSONObject params, HttpServletResponse resp) { + params.put("channels", new String []{"Alipay", "AlipayOnline"}); + String[] title = {"Channel", "Total Amount(AUD)", "Total orders", "Transaction Partners", "Enable Partners"}; + JSONObject count = customerAndOrdersStatisticsMapper.countChannel(params); + int enablePartners = customerAndOrdersStatisticsMapper.countEnableAlipay(params); + String begin = params.getString("begin") == null ? "":DateFormatUtils.format(params.getDate("begin"),"yyyy-MM-dd"); + String end = params.getString("end") == null ? "":DateFormatUtils.format(params.getDate("end"),"yyyy-MM-dd"); + OutputStream ous = null; + try { + resp.setContentType("application/octet-stream;"); + resp.addHeader("Content-Disposition", + "attachment; filename=" + "Alipay_Data_" + begin + "_" + end + ".xlsx"); + ous = resp.getOutputStream(); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(); + int rowNum = 0; + Row row = sheet.createRow(rowNum); + for (int i = 0; i < title.length; i++) { + row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]); + } + row = sheet.createRow(++rowNum); + row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue("Alipay+AlipayOnline"); + row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(count.getIntValue("total")); + row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(count.getIntValue("orders")); + row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(count.getIntValue("transaction_partners")); + row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(enablePartners); + wb.write(ous); + ous.flush(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + IOUtils.closeQuietly(ous); + } + } + private void analysisChannelCustomers(JSONObject params, Map analysisMap, String channel) { params.put("channel", channel); List customerAnalysis = customerAndOrdersStatisticsMapper.getSumChannelAnalysis(params); 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 c05f71b19..4a80f3efb 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 @@ -63,4 +63,6 @@ public interface CustomerAndOrdersStatisticsMapper { int countTotalOldCustomers(JSONObject params); int countEnableChannel(JSONObject params); + + int countEnableAlipay(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/ChannelsAnalysisController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/ChannelsAnalysisController.java index 12418a2d7..7efe709f7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/ChannelsAnalysisController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/ChannelsAnalysisController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -52,4 +53,19 @@ public class ChannelsAnalysisController { } return channelsAnalysisService.getChannelDate(params); } + + @ManagerMapping(value = "/alipay/data/export") + public void exportAlipayData(AnalysisBean analysis, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse reps) { + JSONObject params = analysis.toParams(null); + if (manager.getInteger("org_id") != null) { + params.put("org_id", manager.getIntValue("org_id")); + } + if (analysis.isOnlyGroup() && ManagerRole.BD_LEADER.hasRole(manager.getIntValue("role"))) { + params.put("bd_group", manager.getString("manager_id")); + if (analysis.getGroup_bd()>0){ + params.put("bd_group_bd",analysis.getGroup_bd()); + } + } + channelsAnalysisService.exportData(params, reps); + } } 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 d207115b5..a61b70a2f 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 @@ -291,6 +291,12 @@ and s.client_id=#{client_id} and s.channel = #{channel} + + and s.channel IN + + #{channel} + + and s.date >= #{begin} and s.date < #{end} and c.org_id = #{org_id} @@ -614,4 +620,43 @@ ) + diff --git a/src/main/ui/static/analysis/channels_analysis.js b/src/main/ui/static/analysis/channels_analysis.js index 2ebcd186f..ea549c05a 100644 --- a/src/main/ui/static/analysis/channels_analysis.js +++ b/src/main/ui/static/analysis/channels_analysis.js @@ -112,6 +112,21 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', ' $scope.channel_single_amount_chart = chartParser.parse(channels_single_amount_chart, resp.data); }); }; + $scope.exportAlipayData = function() { + var params = angular.copy($scope.params); + var url = '/analysis/channels/alipay/data/export'; + var connectSymbol = '?'; + if (params.begin) { + params.begin = $filter('date')(params.begin, 'yyyyMMdd'); + url += connectSymbol + 'begin=' + params.begin; + connectSymbol = '&'; + } + if (params.end) { + params.end = $filter('date')(params.end, 'yyyyMMdd'); + url += connectSymbol + 'end=' + params.end; + } + return url; + }; var tradePartnersInTypeConfig = function (legend) { return { chart: { diff --git a/src/main/ui/static/analysis/templates/channels_analysis.html b/src/main/ui/static/analysis/templates/channels_analysis.html index 0207fee64..d709513bc 100644 --- a/src/main/ui/static/analysis/templates/channels_analysis.html +++ b/src/main/ui/static/analysis/templates/channels_analysis.html @@ -67,6 +67,9 @@ + + Alipay数据导出 +