1。模板导出和动态导出(注释掉的代码):
@ApiOperation(value = "巡检结果浏览界面导出", notes = "机器人")
@ApiImplicitParams({
@ApiImplicitParam(name = "robotIp", value = "当前机器人ip", required = true, dataType = "String"),
@ApiImplicitParam(name = "type", value = "导出类型(1部分导出2全部导出)", required = true, dataType = "String"),
@ApiImplicitParam(name = "typeImage", value = "图片格式(1原图,2压缩,3无图)", required = true, dataType = "String"),
@ApiImplicitParam(name = "ids", value = "id主键(当type=1时,必传 逗号分隔)", required = false, dataType = "String"),
@ApiImplicitParam(name = "pointIds", value = "设备树pointId,逗号分隔", required = false, dataType = "String"),
@ApiImplicitParam(name = "begin", value = "开始时间(yyyy-MM-dd hh:mm:ss)", required = false, dataType = "String"),
@ApiImplicitParam(name = "end", value = "结束时间(yyyy-MM-dd hh:mm:ss)", required = false, dataType = "String")
})
@RequestMapping(value = "ExpResultView.json", method = RequestMethod.GET)
public void ExpResultView(HttpServletResponse response, HttpServletRequest request, String type, String ids,
String typeImage, String robotIp, String pointIds, String begin, String end) {
if (StringUtils.isAnyBlank(type, typeImage, robotIp)) {
return;
}
if (Global.YES.equals(type) && StringUtils.isBlank(ids)) {
return;
}
if (StringUtils.isNotBlank(begin)) {
if (!DateTimeUtils.isDate(begin, DateTimeUtils.DATETIME_FORMAT_YYYY_MM_DD_HH_MM_SS)) {
return;
}
}
if (StringUtils.isNotBlank(end)) {
if (!DateTimeUtils.isDate(end, DateTimeUtils.DATETIME_FORMAT_YYYY_MM_DD_HH_MM_SS)) {
return ;
}
}
try {
log.debug("巡检结果浏览界面导出开始");
// List<ExcelExportEntity> entity = new ArrayList<>();
// // 构造对象等同于@Excel
// entity.add(new ExcelExportEntity("序号", "index"));
// entity.add(new ExcelExportEntity("任务名称", "taskName"));
// entity.add(new ExcelExportEntity("点位名称", "pointName"));
// entity.add(new ExcelExportEntity("识别时间", "excuteTime"));
// entity.add(new ExcelExportEntity("识别结果", "excuteValue"));
// ExcelExportEntity entity1 = new ExcelExportEntity("高清图片", "hdPicture");
// entity1.setExportImageType(1);
// entity1.setType(2);
// entity.add(entity1);
// ExcelExportEntity entity2 = new ExcelExportEntity("红外图片", "infraredPicture");
// entity2.setExportImageType(1);
// entity2.setType(2);
// entity.add(entity2);
//pic_url string
// 把我们构造好的bean对象放到params就可以了
// ExportParams params = new ExportParams("巡检结果浏览表列表", "巡检结果浏览表列表");
// params.setAddIndex(true);// 索引
TemplateExportParams params = new TemplateExportParams("excel/inspectionResultView.xls");
List<Map<String, Object>> list = resultViewService.ExpResultView(type, ids, typeImage, robotIp, pointIds, begin, end);
Map<String, Object> map = new HashMap<>();
map.put("list", list);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
String str = DateTimeUtils.getNowDateStr(DateTimeUtils.DATETIME_FORMAT_YYYYMMDDHHMMSS);
String fileName = new String(("巡检结果浏览表列表"+ str + ".xls").getBytes("GBK"), "ISO_8859_1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
workbook.write(response.getOutputStream());
log.debug("巡检结果浏览界面导出结束");
} catch (Exception e) {
log.error("ExpResultView.json方法调用异常;类名:" + this.getClass().getName() + ";异常信息:" + e.getMessage());
log.error("巡检结果浏览界面导出异常");
}
}
1.map动态导出包含图片时,hdPicture对应为图片地址。
2.模板导出包含图片时,hdPicture对应为 ImageEntity 对象。