use of com.bc.pmpheep.service.exception.CheckedServiceException 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.service.exception.CheckedServiceException in project pmph by BCSquad.
the class FileDownLoadController method exportTopic.
/**
* Description:设置选题号页面导出选题号
*
* @author:lyc
* @date:2018年1月23日下午6:18:41
* @param
* @return void
*/
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "设置选题号页面导出选题号信息")
@RequestMapping(value = "/textbook/exportTopic", method = RequestMethod.GET)
public void exportTopic(Long materialId, HttpServletRequest request, HttpServletResponse response) {
List<Textbook> list = textbookService.listTopicNumber(materialId);
Workbook workbook = null;
if (list.size() == 0) {
list.add(new Textbook());
}
try {
workbook = excelHelper.fromTextbookTopic(list, "选题号导出");
} catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
logger.warn("数据表格化的时候失败");
}
Material material = materialService.getMaterialById(materialId);
String fileName = returnFileName(request, material.getMaterialName() + ".xls");
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
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.service.exception.CheckedServiceException in project pmph by BCSquad.
the class FileDownLoadController method exportExcel.
/**
* 导出书籍遴选名单/批量导出
*
* @param request
* @param response
* @param textbookIds
* @throws CheckedServiceException
* @throws Exception
*/
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出书籍遴选名单/批量导出")
@RequestMapping(value = "/chosenPosition/exportExcel", method = RequestMethod.GET)
public void exportExcel(HttpServletRequest request, HttpServletResponse response, @RequestParam("textbookIds") Long[] textbookIds) throws CheckedServiceException, Exception {
Workbook workbook = null;
List<ExcelDecAndTextbookVO> list = null;
try {
list = textbookService.getExcelDecAndTextbooks(textbookIds);
if (list.size() == 0) {
// 设置表头 ,放置初始化表出错
list.add(new ExcelDecAndTextbookVO());
}
workbook = excelHelper.fromBusinessObjectList(list, "遴选名单");
} catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
logger.warn("数据表格化的时候失败");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
String fileName = null;
if (textbookIds.length > 1) {
// 当批量导出的时候 文件名为教材名称
// 书籍名称
String materialName = list.get(0).getMaterialName();
if (null == materialName) {
materialName = "遴选名单导出";
}
fileName = returnFileName(request, materialName + ".xls");
} else {
// 当单个导出的时候 文件名为书籍名称
// 书籍名称
String TextbookName = list.get(0).getTextbookName();
if (null == TextbookName) {
TextbookName = "遴选名单导出";
}
fileName = returnFileName(request, TextbookName + ".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.service.exception.CheckedServiceException in project pmph by BCSquad.
the class FileDownLoadController method download.
/**
* 小组文件下载
*
* @param id
* 图片在MongoDB中的id
* @param groupId
* 小组id
* @param response
* 服务响应
* @return ResponseBean对象
*/
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "小组文件下载")
@RequestMapping(value = "/groupfile/download/{id}", method = RequestMethod.GET)
public ResponseBean download(@PathVariable("id") String id, @RequestParam("groupId") long groupId, HttpServletRequest request, HttpServletResponse response) {
if (groupId < 1) {
throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "小组id错误(负数或零)");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
GridFSDBFile file = fileService.get(id);
if (null == file) {
logger.warn("未找到id为'{}'的文件", id);
throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "未找到对应文件");
}
String fileName = returnFileName(request, file.getFilename());
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
try (OutputStream out = response.getOutputStream()) {
file.writeTo(out);
out.flush();
out.close();
return new ResponseBean(groupFileService.updatePmphGroupFileOfDown(groupId, id));
} catch (IOException ex) {
logger.warn("文件下载时出现IO异常:{}", ex.getMessage());
throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
}
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class FileDownLoadController method exportResultSchool.
/**
* Description:申报结果统计页面按申报单位统计导出统计结果
*
* @author:lyc
* @date:2018年1月9日上午11:16:01
* @param
* @return void
*/
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报结果统计页面按申报单位统计导出统计结果")
@RequestMapping(value = "/result/exportResultSchool", method = RequestMethod.GET)
public void exportResultSchool(Long materialId, String schoolName, Integer state, HttpServletRequest request, HttpServletResponse response) {
PageParameter<DeclarationResultSchoolVO> pageParameter = new PageParameter<>(1, 50000);
DeclarationResultSchoolVO declarationResultSchoolVO = new DeclarationResultSchoolVO();
declarationResultSchoolVO.setMaterialId(materialId);
declarationResultSchoolVO.setSchoolName(schoolName);
pageParameter.setParameter(declarationResultSchoolVO);
Workbook workbook = null;
List<DeclarationResultSchoolVO> list = null;
String sheetName = "";
if (state.intValue() == 1) {
list = decPositionService.listChosenDeclarationResultSchoolVOs(pageParameter).getRows();
sheetName = "申报结果按单位统计(按当选数排序)";
} else if (state.intValue() == 2) {
list = decPositionService.listPresetDeclarationResultSchoolVOs(pageParameter).getRows();
sheetName = "申报结果按单位统计(按申报数排序)";
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "未知的排序方式");
}
if (list.size() == 0) {
list.add(new DeclarationResultSchoolVO());
}
try {
workbook = excelHelper.fromBusinessObjectList(list, sheetName);
} catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
logger.warn("数据表格化的时候失败");
}
Material material = materialService.getMaterialById(materialId);
String fileName = returnFileName(request, material.getMaterialName() + ".xls");
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
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