Search in sources :

Example 1 with OrgVO

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

the class OrgSeviceTest method testListOrgByOrgName.

@Test
public void testListOrgByOrgName() {
    PageParameter pageParameter = new PageParameter<>();
    PageResult<OrgVO> pageResult = new PageResult<OrgVO>();
    OrgVO orgVO = new OrgVO();
    orgVO.setOrgName(null);
    orgVO.setAreaId(null);
    orgVO.setRealname(null);
    pageParameter.setPageNumber(1);
    pageParameter.setPageSize(20);
    pageParameter.setParameter(orgVO);
    pageResult = orgService.getSchoolAdminCheckList(pageParameter);
    Assert.assertNotNull("在新增用户与修改用户时查询机构失败", orgService.listOrgByOrgName("机构名称"));
}
Also used : OrgVO(com.bc.pmpheep.back.vo.OrgVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) PageResult(com.bc.pmpheep.back.plugin.PageResult) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 2 with OrgVO

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

the class OrgSeviceTest method testListSendToSchoolAdminOrAllUser.

@Test
public void testListSendToSchoolAdminOrAllUser() {
    PageParameter pageParameter = new PageParameter<>();
    PageResult<OrgVO> pageResult = new PageResult<OrgVO>();
    OrgVO orgVO = new OrgVO();
    orgVO.setOrgName(null);
    orgVO.setAreaId(null);
    orgVO.setRealname(null);
    pageParameter.setPageNumber(1);
    pageParameter.setPageSize(20);
    pageParameter.setParameter(orgVO);
    pageResult = orgService.getSchoolAdminCheckList(pageParameter);
    Assert.assertNotNull("系统消息——发送新消息——发送对象失败", orgService.listSendToSchoolAdminOrAllUser("机构名称", 1L));
}
Also used : OrgVO(com.bc.pmpheep.back.vo.OrgVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) PageResult(com.bc.pmpheep.back.plugin.PageResult) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 3 with OrgVO

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

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

the class ExcelHelper method fromOrgVO.

public Workbook fromOrgVO(List<OrgVO> dataSource, String sheetName) throws CheckedServiceException, IllegalAccessException, IllegalArgumentException {
    if (null == dataSource || dataSource.isEmpty()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.NULL_PARAM, "用于导出的数据源为空");
    }
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet(sheetName);
    Row header = sheet.createRow(0);
    header.createCell(0).setCellValue("序号");
    header.createCell(1).setCellValue("机构名称");
    header.createCell(2).setCellValue("机构账号");
    header.createCell(3).setCellValue("管理员名称");
    header.createCell(4).setCellValue("机构类型");
    headerStyleSetup(workbook, 1);
    int rowCount = 1;
    for (OrgVO orgVO : dataSource) {
        Row row = sheet.createRow(rowCount);
        row.createCell(0).setCellValue(rowCount);
        row.createCell(1).setCellValue(orgVO.getOrgName());
        row.createCell(2).setCellValue(orgVO.getUsername());
        row.createCell(3).setCellValue(orgVO.getRealname());
        row.createCell(4).setCellValue(orgVO.getOrgTypeName());
        rowCount++;
    }
    int[] maxLength = { 2, 15, 15, 10, 15 };
    return dataStyleSetup(workbook, 1, rowCount, new ColumnProperties(5, maxLength));
}
Also used : OrgVO(com.bc.pmpheep.back.vo.OrgVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 5 with OrgVO

use of com.bc.pmpheep.back.vo.OrgVO 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)

Aggregations

OrgVO (com.bc.pmpheep.back.vo.OrgVO)9 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)6 PageResult (com.bc.pmpheep.back.plugin.PageResult)4 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)4 BaseTest (com.bc.pmpheep.test.BaseTest)4 Test (org.junit.Test)4 LogDetail (com.bc.pmpheep.annotation.LogDetail)3 IOException (java.io.IOException)3 Workbook (org.apache.poi.ss.usermodel.Workbook)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)2 ArrayList (java.util.ArrayList)2 HttpSession (javax.servlet.http.HttpSession)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 Row (org.apache.poi.ss.usermodel.Row)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 OrgAndOrgUserVO (com.bc.pmpheep.back.vo.OrgAndOrgUserVO)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1