use of com.bc.pmpheep.back.vo.OrgExclVO in project pmph by BCSquad.
the class FileDownLoadController method org.
/**
* <pre>
* 功能描述:导出已发布教材下的学校
* 使用示范:
*
* @param materialId 教材ID
* @param request
* @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, "文件在传输时中断");
}
}
use of com.bc.pmpheep.back.vo.OrgExclVO in project pmph by BCSquad.
the class FileDownLoadController method allOrg.
/**
* <pre>
* 功能描述:导出所有学校
* 使用示范:
*
* @param request
* @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, "文件在传输时中断");
}
}
Aggregations