Search in sources :

Example 41 with LogDetail

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

the class FileDownLoadController method downloadZip.

/**
 * word打包文件
 *
 * @param id
 *            生成的唯一标识符
 * @param response
 *            服务响应
 * @throws UnsupportedEncodingException
 */
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "word打包文件")
@RequestMapping(value = "/zip/download", method = RequestMethod.GET)
public void downloadZip(@RequestParam("id") String id, HttpServletRequest request, HttpServletResponse response) {
    String src = this.getClass().getResource("/").getPath();
    src = src.substring(1);
    if (!src.endsWith(File.separator)) {
        src += File.separator;
    }
    String materialName = Const.WORD_EXPORT_MAP.get(id).getMaterialName();
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String filePath = src + id + File.separator + materialName + ".zip";
    String fileName = returnFileName(request, materialName + ".zip");
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    OutputStream fos = null;
    InputStream fis = null;
    try {
        fis = new FileInputStream(filePath);
        bis = new BufferedInputStream(fis);
        fos = response.getOutputStream();
        bos = new BufferedOutputStream(fos);
        int byteRead = 0;
        byte[] buffer = new byte[1024];
        while ((byteRead = bis.read(buffer, 0, 1024)) != -1) {
            bos.write(buffer, 0, byteRead);
        }
        bos.flush();
        fis.close();
        bis.close();
        fos.close();
        bos.close();
    } catch (Exception e) {
        e.printStackTrace();
        logger.warn("文件下载时出现IO异常:{}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    } finally {
        Const.WORD_EXPORT_MAP.remove(id);
        ZipDownload.DeleteFolder(src + id);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream) 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)

Example 42 with LogDetail

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

the class FileDownLoadController method exportOrgInfo.

@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出机构用户对比后的信息")
@RequestMapping(value = "/org/exportOrgInfo", method = RequestMethod.GET)
public void exportOrgInfo(HttpServletRequest request, HttpServletResponse response, String uuid) {
    if (StringUtil.isEmpty(uuid)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.NULL_PARAM, "参数不能为空");
    }
    String sessionId = CookiesUtil.getSessionId(request);
    HttpSession session = SessionContext.getSession(sessionId);
    List<OrgVO> list = (List<OrgVO>) session.getAttribute(uuid);
    if (null == list || list.isEmpty()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.NULL_PARAM, "导出的机构信息不能为空");
    }
    Workbook workbook = null;
    try {
        workbook = excelHelper.fromOrgVO(list, "机构用户信息");
    } catch (CheckedServiceException | IllegalAccessException | IllegalArgumentException 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 (IOException e) {
        logger.warn("文件下载时出现IO异常: {}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : OrgVO(com.bc.pmpheep.back.vo.OrgVO) HttpSession(javax.servlet.http.HttpSession) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Workbook(org.apache.poi.ss.usermodel.Workbook) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with LogDetail

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

the class FileDownLoadController method declarationWord.

/**
 * 功能描述:申报表批量导出word
 *
 * @param ids
 *            申报表ids
 * @param response
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报表批量导出word")
@RequestMapping(value = "/front/word/declaration", method = RequestMethod.GET)
public String declarationWord(String selectedIds) {
    List<Long> decIds = new ArrayList<>();
    String[] decId = selectedIds.split(",");
    for (int i = 0; i < decId.length; i++) {
        decIds.add(Long.valueOf(decId[i]));
    }
    String id = String.valueOf(System.currentTimeMillis()).concat(String.valueOf(RandomUtil.getRandomNum()));
    taskExecutor.execute(new Front(logger, zipHelper, wordHelper, materialService, textbookService, declarationService, materialExtensionService, decIds, id));
    return '"' + id + '"';
}
Also used : Front(com.bc.pmpheep.general.runnable.Front) ArrayList(java.util.ArrayList) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with LogDetail

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

the class FileDownLoadController method exportSituationBook.

/**
 * Description:申报情况统计页面按书名统计导出统计结果
 *
 * @author:lyc
 * @date:2018年1月9日上午11:41:10
 * @param
 * @return void
 */
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报情况统计页面按书名统计导出统计结果")
@RequestMapping(value = "/result/exportSituationBook", method = RequestMethod.GET)
public void exportSituationBook(Long materialId, String bookName, HttpServletRequest request, HttpServletResponse response) {
    PageParameter<DeclarationSituationBookResultVO> pageParameter = new PageParameter<>(1, 50000);
    DeclarationSituationBookResultVO declarationSituationBookResultVO = new DeclarationSituationBookResultVO();
    declarationSituationBookResultVO.setMaterialId(materialId);
    declarationSituationBookResultVO.setBookName(bookName);
    pageParameter.setParameter(declarationSituationBookResultVO);
    Workbook workbook = null;
    List<DeclarationSituationBookResultVO> list = null;
    list = decPositionService.listDeclarationSituationBookResultVOs(pageParameter).getRows();
    if (list.size() == 0) {
        list.add(new DeclarationSituationBookResultVO());
    }
    try {
        workbook = excelHelper.fromBusinessObjectList(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) DeclarationSituationBookResultVO(com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with LogDetail

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

the class BookController method list.

/**
 * 功能描述:初始化/条件查询书籍信息
 *
 * @param pageSize
 *            当页条数
 * @param pageNumber
 *            当前页数
 * @param type
 *            书籍类别
 * @param name
 *            书籍名称/ISBN
 * @param isOnSale
 *            是否上架
 * @param isNew
 *            是否新书
 * @param isPromote
 *            是否推荐
 * @param path
 *            书籍类别根路径
 * @return
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "初始化/条件查询书籍信息")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseBean list(Integer pageSize, Integer pageNumber, Long type, String name, Boolean isOnSale, Boolean isNew, Boolean isPromote, String path) {
    PageParameter<BookVO> pageParameter = new PageParameter<>(pageNumber, pageSize);
    BookVO bookVO = new BookVO();
    bookVO.setName(name);
    bookVO.setIsNew(isNew);
    bookVO.setPath(path);
    bookVO.setType(type);
    bookVO.setIsOnSale(isOnSale);
    bookVO.setIsPromote(isPromote);
    pageParameter.setParameter(bookVO);
    return new ResponseBean(bookService.listBookVO(pageParameter));
}
Also used : BookVO(com.bc.pmpheep.back.vo.BookVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) 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)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