Search in sources :

Example 1 with DeclarationSituationBookResultVO

use of com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO in project pmph by BCSquad.

the class DecPositionServiceImpl method listDeclarationSituationBookResultVOs.

@Override
public PageResult<DeclarationSituationBookResultVO> listDeclarationSituationBookResultVOs(PageParameter<DeclarationSituationBookResultVO> pageParameter) throws CheckedServiceException {
    if (ObjectUtil.isNull(pageParameter.getParameter().getMaterialId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材id不能为空");
    }
    String bookName = pageParameter.getParameter().getBookName();
    if (StringUtil.notEmpty(bookName)) {
        pageParameter.getParameter().setBookName(bookName);
    }
    PageResult<DeclarationSituationBookResultVO> pageResult = new PageResult<DeclarationSituationBookResultVO>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    int total = decPositionDao.getBooks(pageParameter.getParameter().getMaterialId());
    if (total > 0) {
        List<DeclarationSituationBookResultVO> books = decPositionDao.getBookListOne(pageParameter);
        List<DeclarationSituationBookResultVO> presets = decPositionDao.getBookResultPreset(pageParameter);
        List<DeclarationSituationBookResultVO> chosens = decPositionDao.getBookResultChosen(pageParameter);
        List<DeclarationSituationBookResultVO> middle = new ArrayList<>();
        List<DeclarationSituationBookResultVO> list = new ArrayList<>();
        if (null == presets || presets.isEmpty()) {
            for (DeclarationSituationBookResultVO book : books) {
                // 计算申报人数
                Integer presetPersons = book.getPresetPositionEditor() + book.getPresetPositionSubeditor() + book.getPresetPositionEditorial() + book.getPresetDigitalEditor();
                book.setPresetPersons(presetPersons);
                list.add(book);
            }
            pageResult.setRows(list);
            pageResult.setTotal(total);
            return pageResult;
        }
        for (DeclarationSituationBookResultVO book : books) {
            for (DeclarationSituationBookResultVO preset : presets) {
                if (preset.getId().equals(book.getId())) {
                    book.setPresetPositionEditor(preset.getPresetPositionEditor());
                    book.setPresetPositionSubeditor(preset.getPresetPositionSubeditor());
                    book.setPresetPositionEditorial(preset.getPresetPositionEditorial());
                    book.setPresetDigitalEditor(preset.getPresetDigitalEditor());
                    break;
                }
            }
            // 计算申报人数
            Integer presetPersons = book.getPresetPositionEditor() + book.getPresetPositionSubeditor() + book.getPresetPositionEditorial() + book.getPresetDigitalEditor();
            book.setPresetPersons(presetPersons);
            middle.add(book);
        }
        if (null == chosens || chosens.isEmpty()) {
            pageResult.setRows(middle);
            pageResult.setTotal(total);
            return pageResult;
        }
        for (DeclarationSituationBookResultVO book : middle) {
            for (DeclarationSituationBookResultVO chosen : chosens) {
                if (chosen.getId().equals(book.getId())) {
                    book.setChosenPositionEditor(chosen.getChosenPositionEditor());
                    book.setChosenPositionSubeditor(chosen.getChosenPositionSubeditor());
                    book.setChosenPositionEditorial(chosen.getChosenPositionEditorial());
                    book.setIsDigitalEditor(chosen.getIsDigitalEditor());
                    break;
                }
            }
            // 计算当选人数
            Integer chosenPersons = book.getChosenPositionEditor() + book.getChosenPositionSubeditor() + book.getChosenPositionEditorial() + book.getIsDigitalEditor();
            book.setChosenPersons(chosenPersons);
            list.add(book);
        }
        pageResult.setRows(list);
        pageResult.setTotal(total);
    }
    return pageResult;
}
Also used : ArrayList(java.util.ArrayList) DeclarationSituationBookResultVO(com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult)

Example 2 with DeclarationSituationBookResultVO

use of com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO 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 3 with DeclarationSituationBookResultVO

use of com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO in project pmph by BCSquad.

the class DecPositionController method bookResults.

/**
 * Description:加载书本申报情况统计结果
 *
 * @author:lyc
 * @date:2017年12月1日下午5:44:16
 * @param
 * @return ResponseBean
 */
@ResponseBody
@RequestMapping(value = "/list/bookResults", method = RequestMethod.GET)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "加载书本申报情况统计结果")
public ResponseBean bookResults(Integer pageSize, Integer pageNumber, Long materialId, String bookName) {
    PageParameter<DeclarationSituationBookResultVO> pageParameter = new PageParameter<>(pageNumber, pageSize);
    DeclarationSituationBookResultVO declarationSituationBookResultVO = new DeclarationSituationBookResultVO();
    declarationSituationBookResultVO.setMaterialId(materialId);
    declarationSituationBookResultVO.setBookName(bookName);
    pageParameter.setParameter(declarationSituationBookResultVO);
    return new ResponseBean(decPositionService.listDeclarationSituationBookResultVOs(pageParameter));
}
Also used : DeclarationSituationBookResultVO(com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO) 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

DeclarationSituationBookResultVO (com.bc.pmpheep.back.vo.DeclarationSituationBookResultVO)3 LogDetail (com.bc.pmpheep.annotation.LogDetail)2 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)2 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PageResult (com.bc.pmpheep.back.plugin.PageResult)1 Material (com.bc.pmpheep.back.po.Material)1 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1