use of com.bc.pmpheep.back.vo.SurveyQuestionFillVO in project pmph by BCSquad.
the class FileDownLoadController method surveyQuestionExcel.
/**
* <pre>
* 功能描述:导出填空题调查结果Excel 使用示范:
*
* @user tyc
* @param request
* @param response
* 2018.01.08 18:31
*/
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出填空题调查结果")
@RequestMapping(value = "/excel/surveyQuestionExcel", method = RequestMethod.GET)
public void surveyQuestionExcel(HttpServletRequest request, HttpServletResponse response, @RequestParam("surveyId") Long surveyId, @RequestParam("questionId") Long questionId) {
Workbook workbook = null;
List<SurveyQuestionFillVO> surveyQuestionFillVO = null;
try {
PageParameter<SurveyQuestionFillVO> pageParameter = new PageParameter<>(1, 50000);
pageParameter.setParameter(new SurveyQuestionFillVO(surveyId, questionId));
surveyQuestionFillVO = surveyQuestionAnswerService.listFillQuestion(pageParameter).getRows();
if (CollectionUtil.isEmpty(surveyQuestionFillVO)) {
surveyQuestionFillVO.add(new SurveyQuestionFillVO());
}
workbook = excelHelper.fromBusinessObjectList(surveyQuestionFillVO, "填空题调查结果");
} catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
logger.warn("数据表格化的时候失败");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
String name = "填空题调查结果";
String fileName = returnFileName(request, name + ".xls");
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
try (OutputStream out = response.getOutputStream()) {
workbook.write(out);
out.flush();
out.close();
} catch (Exception e) {
logger.warn("文件下载时出现IO异常:{}", e.getMessage());
throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
}
}
Aggregations