use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.
the class FileDownLoadController method download.
/**
* <pre>
* 功能描述:普通文件下载(更新下载数)
* 使用示范:
*
* @param type 模块类型
* @param id 文件在MongoDB中的id
* @param response 服务响应
* </pre>
*
* @throws UnsupportedEncodingException
*/
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "普通文件下载(更新下载数)")
@RequestMapping(value = "/file/{type}/download/{id}", method = RequestMethod.GET)
public void download(@PathVariable("type") String type, @PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
response.setCharacterEncoding("utf-8");
response.setContentType("application/force-download");
GridFSDBFile file = fileService.get(id);
if (null == file) {
logger.warn("未找到id为'{}'的文件", id);
return;
}
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();
if (Const.CMS_TYPE.equals(type)) {
// CMS附件
cmsExtraService.updateCmsExtraDownLoadCountsByAttachment(id);
}
if (Const.MATERIAL_NOTICE_TYPE.equals(type)) {
// 教材通知
materialNoticeAttachmentService.updateMaterialNoticeAttachmentDownLoadCountsByAttachment(id);
}
if (Const.MATERIAL_NOTE_TYPE.equals(type)) {
// 教材备注
materialNoteAttachmentService.updateMaterialNoteAttachmentDownLoadCountsByAttachment(id);
}
} catch (IOException ex) {
logger.error("文件下载时出现IO异常:{}", ex.getMessage());
}
}
use of com.bc.pmpheep.annotation.LogDetail 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.annotation.LogDetail in project pmph by BCSquad.
the class FileDownLoadController method progress.
/**
* 功能描述:查询进度
*
* @param id
* @return
*/
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "查询word打包进度")
@RequestMapping(value = "/word/progress", method = RequestMethod.GET)
public ZipDownload progress(String id) {
ZipDownload zipDownload = new ZipDownload();
if (Const.WORD_EXPORT_MAP.containsKey(id)) {
zipDownload.setId(Const.WORD_EXPORT_MAP.get(id).getId());
zipDownload.setState(Const.WORD_EXPORT_MAP.get(id).getState());
zipDownload.setDetail(Const.WORD_EXPORT_MAP.get(id).getDetail());
zipDownload.setCreateTime(Const.WORD_EXPORT_MAP.get(id).getCreateTime());
}
return zipDownload;
}
use of com.bc.pmpheep.annotation.LogDetail 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.annotation.LogDetail 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, "文件在传输时中断");
}
}
Aggregations