|
|
|
@ -1660,4 +1660,95 @@ public class ElectricReportServiceImpl implements IElectricReportService {
|
|
|
|
|
table.put("tableDate",tableDates); |
|
|
|
|
return table; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 运行报表导出 |
|
|
|
|
* @param response |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void runExport(HttpServletResponse response, RunParamVo param) { |
|
|
|
|
Map<String, Object> runs = this.run(param); |
|
|
|
|
if(MapUtils.isEmpty(runs)){ |
|
|
|
|
throw new ServiceException("暂无可进行导出报表!"); |
|
|
|
|
} |
|
|
|
|
// 创建Excel文件
|
|
|
|
|
HSSFWorkbook hssWB = new HSSFWorkbook(); |
|
|
|
|
// 添加sheet页
|
|
|
|
|
HSSFSheet sheet = hssWB.createSheet("运行报表"); |
|
|
|
|
// 行高
|
|
|
|
|
sheet.setDefaultRowHeight((short) (20 * 25)); |
|
|
|
|
// 列宽
|
|
|
|
|
sheet.setDefaultColumnWidth(15); |
|
|
|
|
// 填充数据
|
|
|
|
|
List<Object> tableHeads = JSONObject.parseArray(JSONObject.toJSONString(runs.get("tableHead")),Object.class); |
|
|
|
|
List<List<Object>> tableBodys = JSON.parseObject(JSONObject.toJSONString(runs.get("tableDate")), new TypeReference<List<List<Object>>>() {}); |
|
|
|
|
// 表头
|
|
|
|
|
this.setRunHeader(hssWB, sheet,tableHeads); |
|
|
|
|
if (!CollectionUtil.isEmpty(tableBodys)) { |
|
|
|
|
// 数据填充
|
|
|
|
|
this.setRunWork(hssWB, sheet, tableBodys); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 下载导出
|
|
|
|
|
String filename = param.getTime() + "日_运行报表"; |
|
|
|
|
// 设置头信息
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
ServletOutputStream outputStream; |
|
|
|
|
try { |
|
|
|
|
//设置xlsx格式
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xls", "UTF-8")); |
|
|
|
|
//创建一个输出流
|
|
|
|
|
outputStream = response.getOutputStream(); |
|
|
|
|
//写入数据
|
|
|
|
|
hssWB.write(outputStream); |
|
|
|
|
// 关闭
|
|
|
|
|
outputStream.close(); |
|
|
|
|
hssWB.close(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 运行报表表头 |
|
|
|
|
* @param hssWB |
|
|
|
|
* @param sheet |
|
|
|
|
* @param tableHeads |
|
|
|
|
*/ |
|
|
|
|
private void setRunHeader(HSSFWorkbook hssWB, HSSFSheet sheet, List<Object> tableHeads) { |
|
|
|
|
// 第一行
|
|
|
|
|
int size = tableHeads.size(); |
|
|
|
|
HSSFRow row = sheet.createRow(0); |
|
|
|
|
// 下标从0开始,所以要减1
|
|
|
|
|
this.setTitileStyle(hssWB, row, size - 1 , true); |
|
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
|
HSSFCell heade_cell = row.getCell(i); |
|
|
|
|
heade_cell.setCellValue(tableHeads.get(i).toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 运行报表内容 |
|
|
|
|
* @param hssWB |
|
|
|
|
* @param sheet |
|
|
|
|
* @param tableBodys |
|
|
|
|
*/ |
|
|
|
|
private void setRunWork(HSSFWorkbook hssWB, HSSFSheet sheet, List<List<Object>> tableBodys) { |
|
|
|
|
// 第一行
|
|
|
|
|
int rowIndex = 1; |
|
|
|
|
// 下标从0开始,所以要减1
|
|
|
|
|
for(List<Object> bodys : tableBodys){ |
|
|
|
|
HSSFRow bodyRow = sheet.createRow(rowIndex); |
|
|
|
|
// 下标从0开始,所以要减1
|
|
|
|
|
this.setTitileStyle(hssWB, bodyRow, bodys.size() - 1, false); |
|
|
|
|
// 内容填充
|
|
|
|
|
for(int i = 0; i < bodys.size() ; i++){ |
|
|
|
|
HSSFCell body_cell = bodyRow.getCell(i); |
|
|
|
|
body_cell.setCellValue(bodys.get(i).toString()); |
|
|
|
|
} |
|
|
|
|
rowIndex++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |