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