/**
* 导出订单统计Excel数据
*
* @param order
* @param title
* @param createTime_begin
* @param createTime_end
* @return
*/
public ModelAndView exportExcelByStatistics(OrderCount order, String title, String createTime_begin, String createTime_end) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
Result<?> result = orderService.statisticsWaterOrderList(order, createTime_begin, createTime_end);
// 导出的数据
List<Map<String, Object>> list = new ArrayList<>();
// 自定义导出字段
String[] exportFields;
// 统计类型(statisticsType) 0:按院区统计 1:按楼栋统计 2:按科室统计 3:按公司统计
if (StringUtils.equals(order.getStatisticsType(), "3")) {
// 核销人统计导出数据
List<OrderCount> exportListWriteOffPerson = (List<OrderCount>) ((Map) result.getResult()).get("writeOffPersonStatistics");
Map<String, Object> WriteOffPersonList = new HashMap<>();
WriteOffPersonList.put(NormalExcelConstants.CLASS, OrderCount.class);
WriteOffPersonList.put(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(),"核销人统计"));
WriteOffPersonList.put(NormalExcelConstants.DATA_LIST, exportListWriteOffPerson);
list.add(WriteOffPersonList);
// 公司统计导出数据
List<OrderCount> exportList = (List<OrderCount>) ((Map) result.getResult()).get("companyStatistics");
Map<String, Object> companyList = new HashMap<>();
companyList.put(NormalExcelConstants.CLASS, OrderCount.class);
companyList.put(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(),"公司统计"));
companyList.put(NormalExcelConstants.DATA_LIST, exportList);
list.add(companyList);
// 自定义导出字段
exportFields = new String[]{"statisticsTitle", "goodsNum", "companyName"};
} else {
List<OrderCount> exportList = (List<OrderCount>) result.getResult();
Map<String, Object> otherList = new HashMap<>();
otherList.put(NormalExcelConstants.CLASS, OrderCount.class);
otherList.put(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
otherList.put(NormalExcelConstants.DATA_LIST, exportList);
list.add(otherList);
// 自定义导出字段
exportFields = new String[]{"statisticsTitle", "goodsNum"};
}
// Step.3 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.MAP_LIST, list);
// 自定义导出列(字段)
mv.addObject(NormalExcelConstants.EXPORT_FIELDS, StringUtils.join(exportFields, ","));
return mv;
}