|
|
@ -44,47 +44,92 @@ import static io.netty.handler.codec.smtp.SmtpRequests.data; |
|
|
|
@RestController |
|
|
|
@RequestMapping("/report") |
|
|
|
public class GdSalesReportRest { |
|
|
|
private static final String EXCEL_FILE_NAME="门店销售明细报表"+ System.currentTimeMillis() +".xlsx"; |
|
|
|
private static final String EXCEL_FILE_NAME="D:\\opt\\upFiles"+"\\门店销售明细报表"+ System.currentTimeMillis() +".xlsx"; |
|
|
|
private static final String TEMPLATE_FILE_NAME="C:\\Users\\www19\\Desktop\\1.xlsx"; |
|
|
|
@Autowired |
|
|
|
GdSalesReportService gdSalesReportService; |
|
|
|
|
|
|
|
@PostMapping("/getStoreSalesReport") |
|
|
|
public ResultBean<GdSalesReportVo> getStoreSalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq){ |
|
|
|
System.out.println("主线程开启"); |
|
|
|
if(true){ |
|
|
|
new Thread(new GdSalesThread(pq)).start(); |
|
|
|
} |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
List<GdSalesReportVo> pv = gdSalesReportService.getStoreSalesReport(pq); |
|
|
|
System.out.println("主线程结束"); |
|
|
|
return rb.success().setData(pv); |
|
|
|
} |
|
|
|
@PostMapping("/exportStoreSalesReport") |
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
*/ |
|
|
|
public class GdSalesThread extends Thread{ |
|
|
|
PagerQuery<GdSalesReportQuery> pq=new PagerQuery<>(); |
|
|
|
public GdSalesThread(PagerQuery<GdSalesReportQuery> pq) { |
|
|
|
this.pq = pq; |
|
|
|
} |
|
|
|
public void run(){ |
|
|
|
try { |
|
|
|
System.out.println("excel线程开启"); |
|
|
|
SalesReport(pq); |
|
|
|
System.out.println("excel线程结束"); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping("/SalesReport") |
|
|
|
@ApiOperation(value = "门店销售明细报表") |
|
|
|
public void exportStoreSalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq, HttpServletResponse response) throws IOException { |
|
|
|
List<StoreSalesReportExcelVo> excelVos =gdSalesReportService.getAllStoreSalesReport(pq); |
|
|
|
//获取模板(模板你可以放在任何位置,前提是你能获取到。这里放在resource下)
|
|
|
|
response.setContentType( "application/vnd.ms-excel"); |
|
|
|
response.setCharacterEncoding("utf8"); |
|
|
|
response.setHeader("Content-disposition","attachment;filename="+ EXCEL_FILE_NAME ); |
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
public void SalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq) throws IOException { |
|
|
|
List<StoreSalesReportExcelVo> StoreSalesVos =gdSalesReportService.getAllStoreSalesReport(pq); |
|
|
|
List<GoodsSalesReportExcelVo>goodsSalesVos= gdSalesReportService.getAllGoodsSalesReport(pq); |
|
|
|
List<StoreSalesReportExcelVo> StoreSalesYcVos = gdSalesReportService.StoreSalesYcReportExcelVo(pq); |
|
|
|
List<GoodsSalesReportExcelVo> goodsSalesYcVos=gdSalesReportService.GoodsSalesReportYcExcelVo(pq); |
|
|
|
// 创建ExcelWriterBuilder
|
|
|
|
ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(EXCEL_FILE_NAME).withTemplate(TEMPLATE_FILE_NAME); |
|
|
|
ExcelWriter excelWriter = excelWriterBuilder.build(); |
|
|
|
// 写入list之前的数据
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
map.put("date",StoreSalesVos.get(1).getDate()); |
|
|
|
map.put("storeNum",StoreSalesVos.size()); |
|
|
|
|
|
|
|
//门店销售明细表
|
|
|
|
exportStoreSalesReport(map,excelWriter,StoreSalesVos); |
|
|
|
//门店商品销售明细表
|
|
|
|
exportGoodsSalesReport(map,excelWriter,goodsSalesVos); |
|
|
|
//烟草门店销售明细表
|
|
|
|
exportStoreSalesReportYc(map,excelWriter,StoreSalesYcVos); |
|
|
|
//烟草门店商品销售明细表
|
|
|
|
exportGoodsSalesReportYc(map,excelWriter,goodsSalesYcVos); |
|
|
|
|
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 门店销售明细表 |
|
|
|
* @param map |
|
|
|
* @param excelWriter |
|
|
|
* @param StoreSalesVos |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
public void exportStoreSalesReport(Map<String, Object> map,ExcelWriter excelWriter,List<StoreSalesReportExcelVo> StoreSalesVos) throws IOException { |
|
|
|
List<CellRangeAddress> list = new ArrayList<>(); |
|
|
|
//new CellRangeAddress(开始行,结束行,开始列,结束列)
|
|
|
|
list.add(new CellRangeAddress(3, excelVos.size(), 1, 3)); |
|
|
|
// 创建ExcelWriterBuilder
|
|
|
|
ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(outputStream).withTemplate(TEMPLATE_FILE_NAME); |
|
|
|
ExcelWriter excelWriter = excelWriterBuilder.build(); |
|
|
|
list.add(new CellRangeAddress(3, StoreSalesVos.size(), 1, 3)); |
|
|
|
// 创建writeSheet,并注册合并单元格handler
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(0).registerWriteHandler(new MyHandler(0,list)).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(1).registerWriteHandler(new MyHandler(0,list)).build(); |
|
|
|
// 填写配置,forceNewRow true表示自动创建一行,后面的数据后移
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
//填写数据
|
|
|
|
excelWriter.fill(excelVos, fillConfig, writeSheet); |
|
|
|
excelWriter.fill(StoreSalesVos, fillConfig, writeSheet); |
|
|
|
//excelWriter.fill(excelVos, writeSheet);
|
|
|
|
// 写入list之前的数据
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
Date date = new Date(); |
|
|
|
cal.setTime(date); |
|
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
map.put("date",excelVos.get(1).getDate()); |
|
|
|
map.put("storeNum",excelVos.size()); |
|
|
|
map.put("number","mdxsmxb"+dateFormat.format(date)); |
|
|
|
map.put("number","mdxsmxb"+cal.get(Calendar.YEAR)+cal.get(Calendar.MONTH)+1+cal.get(Calendar.DAY_OF_MONTH)); |
|
|
|
excelWriter.fill(map, writeSheet); |
|
|
|
// list 后面还有个统计 想办法手动写入
|
|
|
|
// 这里偷懒直接用list 也可以用对象
|
|
|
@ -92,7 +137,7 @@ public class GdSalesReportRest { |
|
|
|
List<String> totalList = ListUtils.newArrayList(); |
|
|
|
totalListList.add(totalList); |
|
|
|
BigDecimal total=new BigDecimal("0"); |
|
|
|
for(StoreSalesReportExcelVo i:excelVos){ |
|
|
|
for(StoreSalesReportExcelVo i:StoreSalesVos){ |
|
|
|
total=total.add(i.getSalesVolume()); |
|
|
|
} |
|
|
|
totalList.add(""); |
|
|
@ -100,29 +145,43 @@ public class GdSalesReportRest { |
|
|
|
totalList.add(""); |
|
|
|
totalList.add("统计:"); |
|
|
|
totalList.add(String.valueOf(total)); |
|
|
|
// 这里是write 别和fill 搞错了
|
|
|
|
List<CellRangeAddress> list1 = new ArrayList<>(); |
|
|
|
//new CellRangeAddress(开始行,结束行,开始列,结束列)
|
|
|
|
list1.add(new CellRangeAddress(excelVos.size()+1, excelVos.size()+2, 0, 4)); |
|
|
|
WriteSheet writeSheet1 = EasyExcel.writerSheet(0).registerWriteHandler(new MyHandler(0,list1)).build(); |
|
|
|
// 这里是write 别和fill 搞错了
|
|
|
|
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build(); |
|
|
|
excelWriter.write(totalListList,writeSheet1); |
|
|
|
//2
|
|
|
|
List<GoodsSalesReportExcelVo>goodsSalesReportExcelVos= gdSalesReportService.getAllGoodsSalesReport(pq); |
|
|
|
WriteSheet writeSheetGood = EasyExcel.writerSheet(1).build(); |
|
|
|
// 填写配置,forceNewRow true表示自动创建一行,后面的数据后移
|
|
|
|
//FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
|
} |
|
|
|
@PostMapping("/getGoodsSalesReport") |
|
|
|
public ResultBean<GdSalesReportVo> getGoodsSalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq){ |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
List<GdSalesReportVo> pv = gdSalesReportService.getGoodsSalesReport(pq); |
|
|
|
return rb.success().setData(pv); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 门店商品销售明细表 |
|
|
|
* @param map |
|
|
|
* @param excelWriter |
|
|
|
* @param goodsSalesReportExcelVos |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
public void exportGoodsSalesReport(Map<String, Object> map,ExcelWriter excelWriter,List<GoodsSalesReportExcelVo>goodsSalesReportExcelVos) throws IOException { |
|
|
|
//得到所有要导出的数据
|
|
|
|
WriteSheet writeSheetGood = EasyExcel.writerSheet(2).build(); |
|
|
|
//填写数据
|
|
|
|
excelWriter.fill(goodsSalesReportExcelVos, fillConfig, writeSheetGood); |
|
|
|
excelWriter.fill(goodsSalesReportExcelVos, writeSheetGood); |
|
|
|
//excelWriter.fill(goodsSalesReportExcelVos, writeSheetGood);
|
|
|
|
// 写入list之前的数据
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
Date date = new Date(); |
|
|
|
cal.setTime(date); |
|
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
map.put("number","mdspxsmxb"+cal.get(Calendar.YEAR)+cal.get(Calendar.MONTH)+1+cal.get(Calendar.DAY_OF_MONTH)); |
|
|
|
map.put("storeNum",goodsSalesReportExcelVos.size()); |
|
|
|
excelWriter.fill(map, writeSheetGood); |
|
|
|
// list 后面还有个统计 想办法手动写入
|
|
|
|
// 这里偷懒直接用list 也可以用对象
|
|
|
|
List<List<String>> totalListList1 = ListUtils.newArrayList(); |
|
|
|
List<String> totalList1 = ListUtils.newArrayList(); |
|
|
|
totalListList1.add(totalList1); |
|
|
|
|
|
|
|
BigDecimal total=new BigDecimal("0"); |
|
|
|
for(GoodsSalesReportExcelVo i:goodsSalesReportExcelVos){ |
|
|
|
total=total.add(i.getTotal()); |
|
|
|
} |
|
|
@ -136,32 +195,6 @@ public class GdSalesReportRest { |
|
|
|
totalList1.add(String.valueOf(total)); |
|
|
|
// 这里是write 别和fill 搞错了
|
|
|
|
excelWriter.write(totalListList1,writeSheetGood); |
|
|
|
|
|
|
|
excelWriter.finish(); |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
} |
|
|
|
@PostMapping("/getGoodsSalesReport") |
|
|
|
public ResultBean<GdSalesReportVo> getGoodsSalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq){ |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
List<GdSalesReportVo> pv = gdSalesReportService.getGoodsSalesReport(pq); |
|
|
|
return rb.success().setData(pv); |
|
|
|
} |
|
|
|
@PostMapping("/exportGoodsSalesReport") |
|
|
|
@ApiOperation(value = "门店商品销售明细报表") |
|
|
|
public void exportGoodsSalesReport(@RequestBody PagerQuery<GdSalesReportQuery> pq, HttpServletResponse response) throws IOException { |
|
|
|
//得到所有要导出的数据
|
|
|
|
List<GoodsSalesReportExcelVo> excelVos = gdSalesReportService.getAllGoodsSalesReport(pq); |
|
|
|
String fileName = "门店商品销售明细报表" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
response.setContentType( "application/vnd.ms-excel"); |
|
|
|
response.setCharacterEncoding("utf8"); |
|
|
|
response.setHeader("Content-disposition","attachment;filename="+ fileName ); |
|
|
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
|
// 如果这里想使用03 则 传入excelType参数即可
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
EasyExcel.write(outputStream, StoreSalesReportExcelVo.class).sheet("门店商品销售明细报表").doWrite(excelVos); |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
} |
|
|
|
@PostMapping("/getStoreSalesReportYc") |
|
|
|
public ResultBean<GdSalesReportVo> getStoreSalesReportYc(@RequestBody PagerQuery<GdSalesReportQuery> pq){ |
|
|
@ -169,21 +202,40 @@ public class GdSalesReportRest { |
|
|
|
List<GdSalesReportVo> pv = gdSalesReportService.getStoreSalesReportYc(pq); |
|
|
|
return rb.success().setData(pv); |
|
|
|
} |
|
|
|
@PostMapping("/exportgetStoreSalesReportYc") |
|
|
|
@ApiOperation(value = "门店销售明细报表(烟草)") |
|
|
|
public void exportgetStoreSalesReportYc(@RequestBody PagerQuery<GdSalesReportQuery> pq, HttpServletResponse response) throws IOException { |
|
|
|
//得到所有要导出的数据
|
|
|
|
List<StoreSalesReportExcelVo> excelVos = gdSalesReportService.StoreSalesYcReportExcelVo(pq); |
|
|
|
String fileName = "门店销售明细报表(烟草)" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
response.setContentType( "application/vnd.ms-excel"); |
|
|
|
response.setCharacterEncoding("utf8"); |
|
|
|
response.setHeader("Content-disposition","attachment;filename="+ fileName ); |
|
|
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
|
// 如果这里想使用03 则 传入excelType参数即可
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
EasyExcel.write(outputStream, StoreSalesReportExcelVo.class).sheet("门店销售明细报表(烟草)").doWrite(excelVos); |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
|
|
|
|
public void exportStoreSalesReportYc(Map<String, Object> map,ExcelWriter excelWriter,List<StoreSalesReportExcelVo> StoreSalesYcVos) throws IOException { |
|
|
|
List<CellRangeAddress> list = new ArrayList<>(); |
|
|
|
//new CellRangeAddress(开始行,结束行,开始列,结束列)
|
|
|
|
list.add(new CellRangeAddress(3, StoreSalesYcVos.size(), 1, 3)); |
|
|
|
// 创建writeSheet,并注册合并单元格handler
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(3).registerWriteHandler(new MyHandler(0,list)).build(); |
|
|
|
// 填写配置,forceNewRow true表示自动创建一行,后面的数据后移
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
//填写数据
|
|
|
|
excelWriter.fill(StoreSalesYcVos, fillConfig, writeSheet); |
|
|
|
// 写入list之前的数据
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
Date date = new Date(); |
|
|
|
cal.setTime(date); |
|
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
map.put("number","ycmdxsmxb"+cal.get(Calendar.YEAR)+cal.get(Calendar.MONTH)+1+cal.get(Calendar.DAY_OF_MONTH)); |
|
|
|
excelWriter.fill(map, writeSheet); |
|
|
|
// list 后面还有个统计 想办法手动写入
|
|
|
|
List<List<String>> totalListList = ListUtils.newArrayList(); |
|
|
|
List<String> totalList = ListUtils.newArrayList(); |
|
|
|
totalListList.add(totalList); |
|
|
|
BigDecimal total=new BigDecimal("0"); |
|
|
|
for(StoreSalesReportExcelVo i:StoreSalesYcVos){ |
|
|
|
total=total.add(i.getSalesVolume()); |
|
|
|
} |
|
|
|
totalList.add(""); |
|
|
|
totalList.add(""); |
|
|
|
totalList.add(""); |
|
|
|
totalList.add("统计:"); |
|
|
|
totalList.add(String.valueOf(total)); |
|
|
|
// 这里是write 别和fill 搞错了
|
|
|
|
WriteSheet writeSheet1 = EasyExcel.writerSheet(3).build(); |
|
|
|
excelWriter.write(totalListList,writeSheet1); |
|
|
|
} |
|
|
|
@PostMapping("/getGoodsSalesReportYc") |
|
|
|
public ResultBean<GdSalesReportVo> getGoodsSalesReportYc(@RequestBody PagerQuery<GdSalesReportQuery> pq){ |
|
|
@ -191,20 +243,36 @@ public class GdSalesReportRest { |
|
|
|
List<GdSalesReportVo> pv = gdSalesReportService.getGoodsSalesReportYc(pq); |
|
|
|
return rb.success().setData(pv); |
|
|
|
} |
|
|
|
@PostMapping("/exportGoodsSalesReportYc") |
|
|
|
@ApiOperation(value = "门店商品销售明细报表(烟草)") |
|
|
|
public void exportGoodsSalesReportYc(@RequestBody PagerQuery<GdSalesReportQuery> pq, HttpServletResponse response) throws IOException { |
|
|
|
//得到所有要导出的数据
|
|
|
|
List<GoodsSalesReportExcelVo> excelVos = gdSalesReportService.GoodsSalesReportYcExcelVo(pq); |
|
|
|
String fileName = "门店商品销售明细报表(烟草)" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
response.setContentType( "application/vnd.ms-excel"); |
|
|
|
response.setCharacterEncoding("utf8"); |
|
|
|
response.setHeader("Content-disposition","attachment;filename="+ fileName ); |
|
|
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
|
// 如果这里想使用03 则 传入excelType参数即可
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
EasyExcel.write(outputStream, StoreSalesReportExcelVo.class).sheet("门店商品销售明细报表(烟草)").doWrite(excelVos); |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
|
|
|
|
public void exportGoodsSalesReportYc(Map<String, Object> map,ExcelWriter excelWriter,List<GoodsSalesReportExcelVo>goodsSalesReportExcelVos) throws IOException { |
|
|
|
WriteSheet writeSheetGood = EasyExcel.writerSheet(4).build(); |
|
|
|
//填写数据
|
|
|
|
excelWriter.fill(goodsSalesReportExcelVos, writeSheetGood); |
|
|
|
// 写入list之前的数据
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
Date date = new Date(); |
|
|
|
cal.setTime(date); |
|
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
map.put("number","ycmdspxsmxb"+cal.get(Calendar.YEAR)+cal.get(Calendar.MONTH)+1+cal.get(Calendar.DAY_OF_MONTH)); |
|
|
|
map.put("storeNum",goodsSalesReportExcelVos.size()); |
|
|
|
excelWriter.fill(map, writeSheetGood); |
|
|
|
// list 后面还有个统计 想办法手动写入
|
|
|
|
List<List<String>> totalListList1 = ListUtils.newArrayList(); |
|
|
|
List<String> totalList1 = ListUtils.newArrayList(); |
|
|
|
totalListList1.add(totalList1); |
|
|
|
BigDecimal total=new BigDecimal("0"); |
|
|
|
for(GoodsSalesReportExcelVo i:goodsSalesReportExcelVos){ |
|
|
|
total=total.add(i.getTotal()); |
|
|
|
} |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add(""); |
|
|
|
totalList1.add("统计:"); |
|
|
|
totalList1.add(String.valueOf(total)); |
|
|
|
// 这里是write 别和fill 搞错了
|
|
|
|
excelWriter.write(totalListList1,writeSheetGood); |
|
|
|
} |
|
|
|
} |
|
|
|