Search in sources :

Example 1 with OrgAndOrgUserVO

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

the class OrgUserSeviceTest method testUpdateOrgUserOfBack.

@Test
public void testUpdateOrgUserOfBack() {
    OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
    Org org = new Org();
    OrgUser orgUser = new OrgUser();
    // 所属区域
    org.setAreaId(12345L);
    // 机构id
    org.setOrgTypeId(4L);
    orgUser.setRealname("s");
    orgUser.setOrgId(org.getId());
    // 管理员姓名
    org.setOrgName("asdasdasdasda");
    // 机构代码
    orgUser.setUsername("m1001021");
    orgUserService.addOrgUserAndOrgOfBack(orgUser, org);
    orgAndOrgUserVO.setId(orgUser.getId());
    orgAndOrgUserVO.setRealname("机构");
    orgAndOrgUserVO.setUsername(orgUser.getUsername());
    orgAndOrgUserVO.setOrgId(org.getId());
    orgAndOrgUserVO.setOrgName("name");
    Object result = orgUserService.updateOrgUserOfBack(orgAndOrgUserVO);
    Assert.assertTrue("更新失败", result.equals("SUCCESS"));
}
Also used : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 2 with OrgAndOrgUserVO

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

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

the class OrgUserController method allOrgUser.

/**
 * Description:分页查询机构用户
 *
 * @author:lyc
 * @date:2017年9月26日下午5:43:59
 * @Param: OrgUserManagerVO
 * @Return:分页数据集
 */
@RequestMapping(value = "/list/allOrgUser", method = RequestMethod.GET)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "分页查询机构用户")
@ResponseBody
public ResponseBean allOrgUser(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNumber") Integer pageNumber, @RequestParam("name") String name, @RequestParam("orgName") String orgName) {
    PageParameter pageParameter = new PageParameter<>();
    OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
    if (StringUtil.notEmpty(orgName)) {
        orgAndOrgUserVO.setOrgName(StringUtil.toAllCheck(orgName));
    }
    if (StringUtil.notEmpty(name)) {
        // 去除空格
        orgAndOrgUserVO.setName(StringUtil.toAllCheck(name));
    }
    pageParameter.setPageNumber(pageNumber);
    pageParameter.setPageSize(pageSize);
    pageParameter.setParameter(orgAndOrgUserVO);
    return new ResponseBean(orgUserService.getListAllOrgUser(pageParameter));
}
Also used : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with OrgAndOrgUserVO

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

the class FileDownLoadController method orgUserExportEcel.

/**
 * 机构用户export
 */
@RequestMapping(value = "/orgUserExportEcel", method = RequestMethod.GET)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出excel")
@ResponseBody
public void orgUserExportEcel(HttpServletRequest request, HttpServletResponse response, String name, String orgName, String orgTypeName, Integer isHospital) {
    PageParameter pageParameter = new PageParameter<>();
    OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
    if (StringUtil.notEmpty(orgName)) {
        orgAndOrgUserVO.setOrgName(orgName.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(name)) {
        // 去除空格
        orgAndOrgUserVO.setName(name.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(orgTypeName)) {
        // 去除空格
        orgAndOrgUserVO.setOrgTypeName(orgTypeName.replaceAll(" ", ""));
    }
    orgAndOrgUserVO.setIsHospital(isHospital);
    pageParameter.setParameter(orgAndOrgUserVO);
    pageParameter.setStart(null);
    // export
    Workbook workbook = null;
    List<OrgAndOrgUserVO> orgList = null;
    try {
        orgList = orgUserService.getListOrgUser(pageParameter).getRows();
        workbook = excelHelper.fromBusinessObjectList(orgList, "机构账户信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException 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 (Exception e) {
        logger.warn("文件下载时出现IO异常:{}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) 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) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with OrgAndOrgUserVO

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

the class OrgUserController method orgUser.

/**
 * Description:分页查询机构用户
 *
 * @author:lyc
 * @date:2017年9月26日下午5:43:59
 * @Param: OrgUserManagerVO
 * @Return:分页数据集
 */
@RequestMapping(value = "/list/orgUser", method = RequestMethod.GET)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "分页查询机构用户")
@ResponseBody
public ResponseBean orgUser(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNumber") Integer pageNumber, @RequestParam("name") String name, @RequestParam("orgName") String orgName, @RequestParam("orgTypeName") String orgTypeName, @RequestParam("isHospital") Integer isHospital) {
    PageParameter pageParameter = new PageParameter<>();
    OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
    if (StringUtil.notEmpty(orgName)) {
        orgAndOrgUserVO.setOrgName(orgName.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(name)) {
        // 去除空格
        orgAndOrgUserVO.setName(name.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(orgTypeName)) {
        // 去除空格
        orgAndOrgUserVO.setOrgTypeName(orgTypeName.replaceAll(" ", ""));
    }
    orgAndOrgUserVO.setIsHospital(isHospital);
    pageParameter.setPageNumber(pageNumber);
    pageParameter.setPageSize(pageSize);
    pageParameter.setParameter(orgAndOrgUserVO);
    return new ResponseBean(orgUserService.getListOrgUser(pageParameter));
}
Also used : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

OrgAndOrgUserVO (com.bc.pmpheep.back.vo.OrgAndOrgUserVO)6 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)5 LogDetail (com.bc.pmpheep.annotation.LogDetail)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 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 BaseTest (com.bc.pmpheep.test.BaseTest)2 IOException (java.io.IOException)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 Test (org.junit.Test)2 PageResult (com.bc.pmpheep.back.plugin.PageResult)1 Org (com.bc.pmpheep.back.po.Org)1 OrgUser (com.bc.pmpheep.back.po.OrgUser)1 OrgVO (com.bc.pmpheep.back.vo.OrgVO)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1