|
@@ -1,12 +1,12 @@
|
|
package com.txz.mall.service.impl;
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
@@ -43,9 +43,7 @@ import vo.*;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.OutputStream;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
-import java.net.URLEncoder;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -245,7 +243,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
@Override
|
|
@Override
|
|
public void exportFile(StoreOrderDTO dto, HttpServletResponse response) {
|
|
public void exportFile(StoreOrderDTO dto, HttpServletResponse response) {
|
|
List<StoreOrderVO> list = orderList(dto);
|
|
List<StoreOrderVO> list = orderList(dto);
|
|
- List<String> rowHead = CollUtil.newArrayList("编号");
|
|
|
|
|
|
+ List<String> rowHead = CollUtil.newArrayList("订单号", "商品信息", "数量", "用户名", "付款金额", "订单状态", "物流信息", "下单时间", "付款时间");
|
|
ExcelWriter writer = ExcelUtil.getWriter();
|
|
ExcelWriter writer = ExcelUtil.getWriter();
|
|
try {
|
|
try {
|
|
writer.writeHeadRow(rowHead);
|
|
writer.writeHeadRow(rowHead);
|
|
@@ -253,20 +251,15 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
for (StoreOrderVO vo : list) {
|
|
for (StoreOrderVO vo : list) {
|
|
List<Object> rowA = CollUtil.newArrayList(
|
|
List<Object> rowA = CollUtil.newArrayList(
|
|
- vo.getId()
|
|
|
|
-// vo.getOrderNo(),
|
|
|
|
-// vo.getAmount() == null ? "0" : vo.getAmount().toPlainString(),
|
|
|
|
-// vo.getDiscount() == null ? "0" : vo.getDiscount().toPlainString(),
|
|
|
|
-// vo.getStatus() + "",
|
|
|
|
-// vo.getChannel(),
|
|
|
|
-// vo.getCurrency(),
|
|
|
|
-// vo.getUserName(),
|
|
|
|
-// vo.getUserPhone(),
|
|
|
|
-// vo.getTransTime() == null ? "" : DateUtil.format(vo.getTransTime(), "yyyy-MM-dd HH:mm:ss"),
|
|
|
|
-// vo.getSuccessTime() == null ? "" : DateUtil.format(vo.getSuccessTime(), "yyyy-MM-dd HH:mm:ss"),
|
|
|
|
-// vo.getBank(),
|
|
|
|
-// vo.getBankAccount(),
|
|
|
|
-// vo.getBankAccountName()
|
|
|
|
|
|
+ vo.getOrderId(),
|
|
|
|
+ JSONObject.toJSONString(vo.getOrderInfoVO()),
|
|
|
|
+ vo.getTotalNum(),
|
|
|
|
+ vo.getRealName(),
|
|
|
|
+ vo.getPayPrice(),
|
|
|
|
+ vo.getStatus(),
|
|
|
|
+ vo.getDeliveryId(),
|
|
|
|
+ vo.getCreateTime() == null ? "" : DateUtil.format(vo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"),
|
|
|
|
+ vo.getPayTime() == null ? "" : DateUtil.format(vo.getPayTime(), "yyyy-MM-dd HH:mm:ss")
|
|
);
|
|
);
|
|
rows.add(rowA);
|
|
rows.add(rowA);
|
|
}
|
|
}
|
|
@@ -1361,18 +1354,31 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void exportDelivery(HttpServletResponse response) {
|
|
public void exportDelivery(HttpServletResponse response) {
|
|
- OutputStream outputStream = null;
|
|
|
|
|
|
+ List<String> rowHead = CollUtil.newArrayList("订单号", "配送方式", "配送单号");
|
|
|
|
+ ExcelWriter writer = ExcelUtil.getWriter();
|
|
try {
|
|
try {
|
|
- outputStream = response.getOutputStream();
|
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
|
- String fileName = URLEncoder.encode("导出发货模版", "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
- response.setHeader(
|
|
|
|
- "Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
|
- List<OrderDeliveryPO> list = new ArrayList<>();
|
|
|
|
- EasyExcel.write(outputStream, OrderDeliveryPO.class).sheet("导出发货模版").doWrite(list);
|
|
|
|
|
|
+ writer.writeHeadRow(rowHead);
|
|
|
|
+ List<List<Object>> rows = new LinkedList<>();
|
|
|
|
+ List<Object> rowA = CollUtil.newArrayList();
|
|
|
|
+ rows.add(rowA);
|
|
|
|
+ writer.write(rows);
|
|
|
|
+ //设置宽度自适应
|
|
|
|
+ writer.setColumnWidth(-1, 22);
|
|
|
|
+ //response为HttpServletResponse对象
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
|
+ //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(("导出发货模版").getBytes("UTF-8"), "ISO-8859-1") + ".xls");
|
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
|
+ //out为OutputStream,需要写出到的目标流
|
|
|
|
+ writer.flush(out);
|
|
|
|
+ log.info("导出结束");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- throw new ServiceException("模板下载失败, 请联系管理员");
|
|
|
|
|
|
+ log.error("导出异常", e);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ // 关闭writer,释放内存
|
|
|
|
+ writer.close();
|
|
|
|
+ log.info("导出结束");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|