Search in sources :

Example 11 with PageParameter

use of com.bc.pmpheep.back.plugin.PageParameter in project pmph by BCSquad.

the class WriterPointServiceTest method getListWriterPoint.

@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
@Test
@Rollback(Const.ISROLLBACK)
public void getListWriterPoint() {
    WriterPoint writerPoint = this.addWriterPoints();
    PageParameter pageParameter = new PageParameter<>();
    PageResult pageResult = new PageResult<>();
    WriterPointVO writerPointVO = new WriterPointVO();
    pageParameter.setParameter(writerPointVO);
    pageParameter.setPageSize(10);
    pageResult = writerPointService.getListWriterPoint(pageParameter);
    Assert.assertNotNull("分页数据失败", pageResult);
}
Also used : WriterPointVO(com.bc.pmpheep.back.vo.WriterPointVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) PageResult(com.bc.pmpheep.back.plugin.PageResult) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 12 with PageParameter

use of com.bc.pmpheep.back.plugin.PageParameter 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, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) DeclarationResultSchoolVO(com.bc.pmpheep.back.vo.DeclarationResultSchoolVO) 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 13 with PageParameter

use of com.bc.pmpheep.back.plugin.PageParameter in project pmph by BCSquad.

the class DeclarationServiceImpl method pageDeclaration.

@Override
public PageResult<DeclarationListVO> pageDeclaration(Integer pageNumber, Integer pageSize, Long materialId, String textBookids, String realname, String position, String title, String orgName, Long orgId, String unitName, Integer positionType, Integer onlineProgress, Integer offlineProgress, Boolean haveFile) throws CheckedServiceException {
    if (null == materialId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材为空");
    }
    Gson gson = new Gson();
    List<Long> bookIds = gson.fromJson(textBookids, new TypeToken<ArrayList<Long>>() {
    }.getType());
    // 拼装复合参数
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("materialId", materialId);
    if (null != bookIds && bookIds.size() > 0) {
        // 书籍ids
        map.put("bookIds", bookIds);
    }
    if (StringUtil.notEmpty(realname)) {
        // 账号或者姓名
        map.put("realname", StringUtil.toAllCheck(realname));
    }
    if (StringUtil.notEmpty(position)) {
        // 职务
        map.put("position", StringUtil.toAllCheck(position));
    }
    if (StringUtil.notEmpty(title)) {
        // 职称
        map.put("title", StringUtil.toAllCheck(title));
    }
    if (StringUtil.notEmpty(orgName)) {
        // 工作单位
        map.put("orgName", StringUtil.toAllCheck(orgName));
    }
    if (null != orgId) {
        // 申报单位
        map.put("orgId", orgId);
    }
    if (StringUtil.notEmpty(unitName)) {
        // 申报单位
        map.put("unitName", StringUtil.toAllCheck(unitName));
    }
    if (null != positionType && positionType != 0) {
        // 申报职位
        map.put("positionType", positionType);
    }
    if (null != onlineProgress && onlineProgress != 0) {
        // 学校审核进度
        map.put("onlineProgress", onlineProgress);
    }
    if (null != offlineProgress) {
        // 0 未收到 // 2 已收到
        // 纸质表进度
        map.put("offlineProgress", offlineProgress);
    }
    if (null != haveFile) {
        // 有无教材大纲
        map.put("haveFile", haveFile);
    }
    // 包装参数实体
    PageParameter<Map<String, Object>> pageParameter = new PageParameter<Map<String, Object>>(pageNumber, pageSize, map);
    // 返回实体
    PageResult<DeclarationListVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // 获取总数
    Integer total = declarationDao.listDeclarationTotal(pageParameter);
    if (null != total && total > 0) {
        List<DeclarationListVO> rows = declarationDao.listDeclaration(pageParameter);
        pageResult.setRows(rows);
    }
    pageResult.setTotal(total);
    return pageResult;
}
Also used : HashMap(java.util.HashMap) DeclarationListVO(com.bc.pmpheep.back.vo.DeclarationListVO) Gson(com.google.gson.Gson) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) PageResult(com.bc.pmpheep.back.plugin.PageResult) TypeToken(com.google.gson.reflect.TypeToken) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with PageParameter

use of com.bc.pmpheep.back.plugin.PageParameter in project pmph by BCSquad.

the class OrgUserServiceImpl method importExcel.

@SuppressWarnings("resource")
@Override
public List<OrgVO> importExcel(MultipartFile file) throws CheckedServiceException {
    String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
    Workbook workbook = null;
    InputStream in = null;
    try {
        in = file.getInputStream();
    } catch (FileNotFoundException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.NULL_PARAM, "获取上传的文件失败");
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "读取文件失败");
    }
    try {
        if (".xls".equals(fileType)) {
            workbook = new HSSFWorkbook(in);
        } else if (".xlsx".equals(fileType)) {
            workbook = new XSSFWorkbook(in);
        } else {
            throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "读取的不是Excel文件");
        }
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "文件读取失败");
    } catch (OfficeXmlFileException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "此文档不是对应的.xls或.xlsx的Excel文档,请修改为正确的后缀名再进行上传");
    }
    PageParameter<OrgAndOrgUserVO> pageParameter = new PageParameter<>();
    pageParameter.setParameter(new OrgAndOrgUserVO());
    pageParameter.setStart(null);
    List<OrgAndOrgUserVO> orgUsers = orgUserDao.getListAllOrgUser(pageParameter);
    List<OrgVO> list = new ArrayList<>();
    for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
        Sheet sheet = workbook.getSheetAt(numSheet);
        if (null == sheet) {
            continue;
        }
        for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
            OrgVO orgVO = new OrgVO();
            Row row = sheet.getRow(rowNum);
            if (null == row) {
                break;
            }
            Cell second = row.getCell(1);
            String orgName = StringUtil.getCellValue(second);
            if (StringUtil.isEmpty(orgName)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.NULL_PARAM, "Excel文件里序号为" + rowNum + "的机构名称为空");
            }
            orgVO.setOrgName(orgName);
            if (null == orgUsers || orgUsers.isEmpty()) {
                list.add(orgVO);
                continue;
            }
            for (OrgAndOrgUserVO orgAndOrgUserVO : orgUsers) {
                if (orgName.equals(orgAndOrgUserVO.getOrgName())) {
                    orgVO.setUsername(orgAndOrgUserVO.getUsername());
                    orgVO.setOrgTypeName(orgAndOrgUserVO.getOrgTypeName());
                    orgVO.setRealname(orgAndOrgUserVO.getRealname());
                    break;
                }
            }
            list.add(orgVO);
        }
    }
    return list;
}
Also used : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) IOException(java.io.IOException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) OrgVO(com.bc.pmpheep.back.vo.OrgVO) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Example 15 with PageParameter

use of com.bc.pmpheep.back.plugin.PageParameter in project pmph by BCSquad.

the class TextbookLogServiceImpl method listTextbookLogByTextBookId.

@Override
public PageResult<TextbookLogVO> listTextbookLogByTextBookId(Long textbookId, Integer pageSize, Integer pageNumber, String updaterName) throws CheckedServiceException {
    if (null == textbookId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK_LOG, CheckedExceptionResult.NULL_PARAM, "书籍为空!");
    }
    Map<String, Object> map = new HashMap<String, Object>(2);
    map.put("textbookId", textbookId);
    updaterName = StringUtil.toAllCheck(updaterName);
    if (null != updaterName) {
        map.put("updaterName", updaterName);
    }
    // 包装参数实体
    PageParameter<Map<String, Object>> pageParameter = new PageParameter<Map<String, Object>>(pageNumber, pageSize, map);
    // 返回实体
    PageResult<TextbookLogVO> pageResult = new PageResult<TextbookLogVO>();
    // 参数拷贝
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // 获取总数
    Integer total = textbookLogDao.listTotalTextbookLogByTextBookId(pageParameter);
    if (null != total && total > 0) {
        List<TextbookLog> rows = textbookLogDao.listTextbookLogByTextBookId(pageParameter);
        List<TextbookLogVO> newRows = new ArrayList<TextbookLogVO>(rows.size());
        for (TextbookLog textbookLog : rows) {
            Long id = textbookLog.getId();
            String detail = textbookLog.getDetail();
            Timestamp gmtCreate = textbookLog.getGmtCreate();
            detail = detail.replace("{gmt_create}", DateUtil.format(gmtCreate));
            newRows.add(new TextbookLogVO(id, detail));
        }
        pageResult.setRows(newRows);
    }
    pageResult.setTotal(total);
    return pageResult;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) Timestamp(java.sql.Timestamp) PageResult(com.bc.pmpheep.back.plugin.PageResult) TextbookLog(com.bc.pmpheep.back.po.TextbookLog) TextbookLogVO(com.bc.pmpheep.back.vo.TextbookLogVO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PageParameter (com.bc.pmpheep.back.plugin.PageParameter)78 LogDetail (com.bc.pmpheep.annotation.LogDetail)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)43 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)39 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)37 BaseTest (com.bc.pmpheep.test.BaseTest)28 Test (org.junit.Test)28 PageResult (com.bc.pmpheep.back.plugin.PageResult)24 Rollback (org.springframework.test.annotation.Rollback)14 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)12 IOException (java.io.IOException)8 WriterUserManagerVO (com.bc.pmpheep.back.vo.WriterUserManagerVO)7 Workbook (org.apache.poi.ss.usermodel.Workbook)7 OrgVO (com.bc.pmpheep.back.vo.OrgVO)6 ArrayList (java.util.ArrayList)6 Material (com.bc.pmpheep.back.po.Material)5 OrgAndOrgUserVO (com.bc.pmpheep.back.vo.OrgAndOrgUserVO)5 BufferedOutputStream (java.io.BufferedOutputStream)5 OutputStream (java.io.OutputStream)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5