|
|
@@ -1,7 +1,6 @@
|
|
|
package com.kym.service.miniapp.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
-import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
@@ -15,16 +14,15 @@ import com.kym.entity.admin.vo.StationStatVo;
|
|
|
import com.kym.entity.common.PageBean;
|
|
|
import com.kym.entity.miniapp.ChargeOrder;
|
|
|
import com.kym.mapper.miniapp.ChargeOrderMapper;
|
|
|
+import com.kym.service.admin.ExportService;
|
|
|
import com.kym.service.miniapp.ChargeOrderService;
|
|
|
import com.kym.service.utils.KymCache;
|
|
|
-import jakarta.servlet.ServletOutputStream;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URLEncoder;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
@@ -47,8 +45,11 @@ public class ChargeOrderServiceImpl extends ServiceImpl<ChargeOrderMapper, Charg
|
|
|
|
|
|
private final KymCache kymCache;
|
|
|
|
|
|
- public ChargeOrderServiceImpl(KymCache kymCache) {
|
|
|
+ private final ExportService exportService;
|
|
|
+
|
|
|
+ public ChargeOrderServiceImpl(KymCache kymCache, ExportService exportService) {
|
|
|
this.kymCache = kymCache;
|
|
|
+ this.exportService = exportService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -103,7 +104,7 @@ public class ChargeOrderServiceImpl extends ServiceImpl<ChargeOrderMapper, Charg
|
|
|
|
|
|
// stationId,startChargeSeq,connectorId,startTime,endTime,totalPower,totalMoney,elecMoney,serviceMoney,orderStatus,chargeStatus,stopReason,invoiceStatus
|
|
|
var rows = result.stream().map(item -> {
|
|
|
- var map = new HashMap<>();
|
|
|
+ var map = new HashMap<String, Object>();
|
|
|
map.put("stationId", item.getStationId());
|
|
|
map.put("startChargeSeq", item.getStartChargeSeq());
|
|
|
map.put("connectorId", item.getConnectorId());
|
|
|
@@ -133,30 +134,7 @@ public class ChargeOrderServiceImpl extends ServiceImpl<ChargeOrderMapper, Charg
|
|
|
writer.addHeaderAlias("serviceMoney", "累积服务费(元)");
|
|
|
writer.addHeaderAlias("orderStatus", "订单状态");
|
|
|
writer.addHeaderAlias("chargeStatus", "充电状态");
|
|
|
-
|
|
|
- // TODO: 2023-09-25 抽公共导出工具
|
|
|
-
|
|
|
- // 默认的,未添加alias的属性也会写出,如果想只写出加了别名的字段,可以调用此方法排除之
|
|
|
- writer.setOnlyAlias(true);
|
|
|
- // 合并单元格后的标题行,使用默认标题样式 从0开始计算
|
|
|
- writer.merge(10, "订单列表");
|
|
|
- // 一次性写出内容,使用默认样式,强制输出标题
|
|
|
- writer.write(rows, true);
|
|
|
- // 自适应列宽 必须在列数据写出后调用
|
|
|
- writer.autoSizeColumnAll();
|
|
|
- //out为OutputStream,需要写出到的目标流
|
|
|
- //response为HttpServletResponse对象
|
|
|
- response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
- //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
- var fileName = new String("订单列表.xls".getBytes("ISO-8859-1"), "utf-8");
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
- ServletOutputStream out = response.getOutputStream();
|
|
|
-
|
|
|
- writer.flush(out, true);
|
|
|
- // 关闭writer,释放内存
|
|
|
- writer.close();
|
|
|
- //此处记得关闭输出Servlet流
|
|
|
- IoUtil.close(out);
|
|
|
+ exportService.exportExcel("订单列表", writer, rows, response);
|
|
|
}
|
|
|
|
|
|
|