alipay数据导出

master
yangkai 6 years ago
parent 9b210a224e
commit c55232b23d

@ -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<JSONObject> getChannelMount(JSONObject params);
List<JSONObject> getChannelDate(JSONObject params);
void exportData(JSONObject params, HttpServletResponse resp);
}

@ -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<Date, JSONObject> analysisMap, String channel) {
params.put("channel", channel);
List<JSONObject> customerAnalysis = customerAndOrdersStatisticsMapper.getSumChannelAnalysis(params);

@ -63,4 +63,6 @@ public interface CustomerAndOrdersStatisticsMapper {
int countTotalOldCustomers(JSONObject params);
int countEnableChannel(JSONObject params);
int countEnableAlipay(JSONObject params);
}

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

@ -291,6 +291,12 @@
and s.client_id=#{client_id}
</if>
<if test="channel!=null">and s.channel = #{channel}</if>
<if test="channels!=null">
and s.channel IN
<foreach collection="channels" open="(" close=")" separator="," item="channel">
#{channel}
</foreach>
</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 c.org_id = #{org_id}</if>
@ -614,4 +620,43 @@
)
</if>
</select>
<select id="countEnableAlipay" resultType="java.lang.Integer">
<![CDATA[
SELECT
IFNULL(
COUNT(DISTINCT c.client_id),
0
) count
FROM
sys_clients c
INNER JOIN sys_client_config cc ON cc.client_id = c.client_id
INNER JOIN sys_org o ON o.org_id = c.org_id
WHERE
c.open_status = 5
AND c.approve_result = 1
AND c.approve_time IS NOT NULL
AND (cc.gateway_alipay_online = 1 or cc.enable_alipay = 1)
]]>
<if test="client_ids!=null">
AND c.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 c.client_id=#{client_id}
</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>
<if test="bd_group!=null">and c.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now())
AND (c.bd_group=#{bd_group} or c.manager_id=#{bd_group})
<if test="bd_group_bd">and c.manager_id=#{bd_group_bd}</if>
)
</if>
</select>
</mapper>

@ -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: {

@ -67,6 +67,9 @@
<button class="btn btn-success" type="button" ng-click="loadTradePartnersInTypes()">
<i class="fa fa-search"></i>
</button>
<a role="button" class="btn btn-primary" ng-href="{{exportAlipayData()}}">
<i class="fa fa-download"></i>Alipay数据导出
</a>
</div>
</div>
</div>

Loading…
Cancel
Save