Search in sources :

Example 1 with OrgExclVO

use of com.bc.pmpheep.back.vo.OrgExclVO in project pmph by BCSquad.

the class FileDownLoadController method org.

/**
 * <pre>
 * 功能描述:导出已发布教材下的学校
 * 使用示范:
 *
 * &#64;param materialId 教材ID
 * &#64;param request
 * &#64;param response
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出已发布教材下的学校")
@RequestMapping(value = "/excel/published/org", method = RequestMethod.GET)
public void org(@RequestParam("materialId") Long materialId, HttpServletRequest request, HttpServletResponse response) {
    Workbook workbook = null;
    List<OrgExclVO> orgList = null;
    try {
        orgList = materialOrgService.getOutPutExclOrgByMaterialId(materialId);
        if (orgList.isEmpty()) {
            orgList.add(new OrgExclVO());
        }
        workbook = excelHelper.fromBusinessObjectList(orgList, "学校信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String materialName = null;
    if (CollectionUtil.isNotEmpty(orgList)) {
        // 教材名称
        materialName = orgList.get(0).getMaterialName();
    }
    if (StringUtil.isEmpty(materialName)) {
        materialName = "已发布学校";
    }
    String fileName = returnFileName(request, materialName + ".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 : OrgExclVO(com.bc.pmpheep.back.vo.OrgExclVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) 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) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with OrgExclVO

use of com.bc.pmpheep.back.vo.OrgExclVO in project pmph by BCSquad.

the class FileDownLoadController method allOrg.

/**
 * <pre>
 * 功能描述:导出所有学校
 * 使用示范:
 *
 * &#64;param request
 * &#64;param response
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出所有学校")
@RequestMapping(value = "/excel/allOrg", method = RequestMethod.GET)
public void allOrg(HttpServletRequest request, HttpServletResponse response) {
    Workbook workbook = null;
    List<OrgExclVO> orgList = null;
    try {
        orgList = orgService.listAllOrgToExcel();
        workbook = excelHelper.fromBusinessObjectList(orgList, "所有学校信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String fileName = returnFileName(request, "所有学校" + ".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 : OrgExclVO(com.bc.pmpheep.back.vo.OrgExclVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) 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) 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)2 OrgExclVO (com.bc.pmpheep.back.vo.OrgExclVO)2 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 BufferedOutputStream (java.io.BufferedOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2