Search in sources :

Example 1 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class FileDownLoadController method download.

/**
 * <pre>
 * 功能描述:普通文件下载(更新下载数)
 * 使用示范:
 *
 * &#64;param type 模块类型
 * &#64;param id 文件在MongoDB中的id
 * &#64;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());
    }
}
Also used : GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail 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 3 with LogDetail

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;
}
Also used : ZipDownload(com.bc.pmpheep.general.bean.ZipDownload) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with LogDetail

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, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) Textbook(com.bc.pmpheep.back.po.Textbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) 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 5 with LogDetail

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, "文件在传输时中断");
    }
}
Also used : ExcelDecAndTextbookVO(com.bc.pmpheep.back.vo.ExcelDecAndTextbookVO) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogDetail (com.bc.pmpheep.annotation.LogDetail)83 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)82 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)61 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)43 IOException (java.io.IOException)28 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)24 OutputStream (java.io.OutputStream)18 BufferedOutputStream (java.io.BufferedOutputStream)17 Workbook (org.apache.poi.ss.usermodel.Workbook)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 ArrayList (java.util.ArrayList)7 Material (com.bc.pmpheep.back.po.Material)6 TopicLog (com.bc.pmpheep.back.po.TopicLog)5 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 BookVideo (com.bc.pmpheep.back.po.BookVideo)3 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)3 Topic (com.bc.pmpheep.back.po.Topic)3 DeclarationResultSchoolVO (com.bc.pmpheep.back.vo.DeclarationResultSchoolVO)3