Perfecting the export of statistics excel.
This commit is contained in:
parent
ad0f0833ed
commit
45cc45f7d7
@ -1,7 +1,6 @@
|
||||
package com.xhpc.general.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.xhpc.general.mapper.XhpcStatisticsExcelMapper;
|
||||
import com.xhpc.general.service.IXhpcStatisticsExcelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -13,8 +12,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author HongYun on 2021/11/15
|
||||
@ -27,20 +24,16 @@ public class XhpcStatisticsExcelController {
|
||||
@Autowired
|
||||
private IXhpcStatisticsExcelService iXhpcStatisticsExcelService;
|
||||
|
||||
@Autowired
|
||||
private XhpcStatisticsExcelMapper xhpcStatisticsExcelMapper;
|
||||
|
||||
|
||||
@GetMapping(value = "/downByDay")
|
||||
public Object test(HttpServletResponse response) {
|
||||
public Object downByDay(HttpServletResponse response) {
|
||||
|
||||
String[] titles = {"时段(某天)", " 电量(度)", "充电时长(小时)", "充电次数(次)", "电费(元)", "服务费(元)"
|
||||
, "订单总金额(元)", "电站折扣(元)", "运营商实收电费(元)", "运营商实收服务费(元)", "运营商实收合计(元)", "用户实际支出(元)"
|
||||
String[] titles = {"时段", " 电量(度)", "充电时长(小时)", "充电次数(次)", "电费(元)", "服务费(元)"
|
||||
, "订单总金额(元)", "抵扣的总金额(元)", "用户支付的金额(元)", "运营商电费(元)", "运营商服务费(元)"
|
||||
, "流量方总金额抽成(元)", "流量方服务费抽成(元)", "平台总金额抽成(元)", "平台服务费抽成(元)", "运维总金额抽成(元)", "运维服务费抽成(元)"};
|
||||
String[] keys = {"time", "chargingDegree", "chargingTime", "chargingNumber", "powerPrice", "servicePrice", "totalPrice"
|
||||
, "promotionDiscount", "actPowerPrice", "actServicePrice", "actTotalPrice", "actPrice", "internetCommission", "internetSvcCommission"
|
||||
, "promotionDiscount", "actPrice", "actPowerPrice", "actServicePrice", "internetCommission", "internetSvcCommission"
|
||||
, "platformCommission", "platformSvcCommission", "operationCommission", "operationSvcCommission"};
|
||||
List<Map<String, Object>> data = xhpcStatisticsExcelMapper.selectByDay();
|
||||
response.setContentType("application/x-xls");
|
||||
try {
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
@ -50,7 +43,7 @@ public class XhpcStatisticsExcelController {
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
iXhpcStatisticsExcelService.exportByDay(out, titles, keys, data);
|
||||
iXhpcStatisticsExcelService.exportByDay(out, titles, keys);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -10,7 +10,8 @@ import java.util.Map;
|
||||
|
||||
public interface IXhpcStatisticsExcelService {
|
||||
|
||||
void exportByDay(ServletOutputStream out, String[] titles, String[] keys, List<Map<String, Object>> data) throws Exception;
|
||||
|
||||
void export(ServletOutputStream out, String[] titles, String[] keys, List<Map<String, Object>> data) throws Exception;
|
||||
|
||||
void exportByDay(ServletOutputStream out, String[] titles, String[] keys) throws Exception;
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package com.xhpc.general.service;
|
||||
|
||||
import com.xhpc.general.mapper.XhpcStatisticsExcelMapper;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@ -15,8 +17,13 @@ import java.util.Map;
|
||||
public class XhpcStatisticsExcelServiceImpl implements IXhpcStatisticsExcelService {
|
||||
|
||||
|
||||
public void exportByDay(ServletOutputStream out, String[] titles, String[] keys, List<Map<String, Object>> data) throws Exception {
|
||||
@Autowired
|
||||
private XhpcStatisticsExcelMapper xhpcStatisticsExcelMapper;
|
||||
|
||||
@Override
|
||||
public void exportByDay(ServletOutputStream out, String[] titles, String[] keys) throws Exception {
|
||||
|
||||
List<Map<String, Object>> data = xhpcStatisticsExcelMapper.selectByDay();
|
||||
export(out, titles, keys, data);
|
||||
}
|
||||
|
||||
@ -61,7 +68,6 @@ public class XhpcStatisticsExcelServiceImpl implements IXhpcStatisticsExcelServi
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user