Search in sources :

Example 1 with SurveyQuestionFillVO

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, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Workbook(org.apache.poi.ss.usermodel.Workbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SurveyQuestionFillVO(com.bc.pmpheep.back.vo.SurveyQuestionFillVO) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogDetail (com.bc.pmpheep.annotation.LogDetail)1 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 SurveyQuestionFillVO (com.bc.pmpheep.back.vo.SurveyQuestionFillVO)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1