Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -6,7 +6,9 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.customizeExcel.vo.OrderExcelVO;
|
||||
import cn.iocoder.yudao.module.member.service.customizeExcel.CustomizeExcelService;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.converters.longconverter.LongStringConverter;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -18,9 +20,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@ -47,4 +52,37 @@ public class CustomizeExcelController {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间导出多个sheet 页
|
||||
* @param list
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
public void exporOrderDate(List<OrderExcelVO> list,HttpServletResponse response) throws IOException {
|
||||
Map<String, List<OrderExcelVO>> collect = list.stream().collect(Collectors.groupingBy(OrderExcelVO::getDayTime));
|
||||
// 按key(时间)排序,将数据按时间顺序放入列表
|
||||
List<Map.Entry<String, List<OrderExcelVO>>> sortedEntries = collect.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByKey()) // 按时间排序
|
||||
.collect(Collectors.toList());
|
||||
// 创建输出流
|
||||
try (OutputStream outputStream = response.getOutputStream();
|
||||
ExcelWriter excelWriter = EasyExcel.write(outputStream).build()) {
|
||||
int sheetIndex = 0;
|
||||
// 逐个创建Sheet,并写入每个时间段的数据
|
||||
for (Map.Entry<String, List<OrderExcelVO>> entry : sortedEntries) {
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet(sheetIndex, "数据 " + entry.getKey()) // 使用时间作为sheet名
|
||||
.head(OrderExcelVO.class)
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自动列宽策略
|
||||
.build();
|
||||
// 写入数据到当前Sheet
|
||||
excelWriter.write(entry.getValue(), writeSheet);
|
||||
sheetIndex++;
|
||||
}
|
||||
// 下载EXCEL,返回给前段stream流
|
||||
excelWriter.finish();
|
||||
outputStream.flush();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user