6 changed files with 88 additions and 6 deletions
@ -0,0 +1,59 @@ |
|||||||
|
package com.logpm.distribution.bean; |
||||||
|
|
||||||
|
import com.alibaba.excel.EasyExcel; |
||||||
|
import com.alibaba.excel.ExcelWriter; |
||||||
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder; |
||||||
|
import com.alibaba.excel.write.handler.WriteHandler; |
||||||
|
import com.alibaba.excel.write.metadata.WriteSheet; |
||||||
|
import com.logpm.distribution.excel.DistributionStockupPackageListDetailExcel; |
||||||
|
import org.apache.commons.codec.Charsets; |
||||||
|
import org.springblade.core.excel.util.ExcelUtil; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.net.URLEncoder; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
public class MyExcelUtil extends ExcelUtil { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static <T> void export(HttpServletResponse response, List<DistributionStockupPackageListDetailExcel> stockupList) { |
||||||
|
try { |
||||||
|
response.setContentType("application/vnd.ms-excel"); |
||||||
|
response.setCharacterEncoding(Charsets.UTF_8.name()); |
||||||
|
response.setHeader("Content-disposition", "attachment;filename=" + "备货清单列表" + ".xlsx"); |
||||||
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
||||||
|
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build(); |
||||||
|
//将清单进行分组,首先区分是否是库存品,其次进行区分订制品和零担
|
||||||
|
Map<Integer, List<DistributionStockupPackageListDetailExcel>> isInventoryMap = stockupList.stream().collect(Collectors.groupingBy(DistributionStockupPackageListDetailExcel::getIsInventory)); |
||||||
|
isInventoryMap.forEach((k,v)->{ |
||||||
|
if (k.equals(0)){ |
||||||
|
//进行是否零担的区分
|
||||||
|
Map<String, List<DistributionStockupPackageListDetailExcel>> isZeroMap = v.stream().collect(Collectors.groupingBy(DistributionStockupPackageListDetailExcel::getIsZero)); |
||||||
|
isZeroMap.forEach((m,n)->{ |
||||||
|
if (m.equals(0)){ |
||||||
|
//订制品
|
||||||
|
WriteSheet writeSheet = EasyExcel.writerSheet("订制品备货清单").head(DistributionStockupPackageListDetailExcel.class).build(); |
||||||
|
}else { |
||||||
|
//零担
|
||||||
|
WriteSheet writeSheet = EasyExcel.writerSheet("零担备货清单").head(DistributionStockupPackageListDetailExcel.class).build(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
}else { |
||||||
|
//库存品
|
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
|
||||||
|
throw new RuntimeException("请稍后再试...."); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue