Search in sources :

Example 1 with ProductType

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

the class ProductTypeController method deleteType.

@RequestMapping("/{type}/delete")
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "删除分类")
@ResponseBody
public ResponseBean deleteType(HttpServletRequest request, @PathVariable("type") String pathType, @RequestParam(value = "id", required = true) Long id) {
    ResponseBean responseBean = new ResponseBean();
    String sessionId = CookiesUtil.getSessionId(request);
    ProductType productType = new ProductType();
    productType.setId(id);
    if ("subject".equals(pathType)) {
        productType.setTypeType(1);
    } else if ("content".equals(pathType)) {
        productType.setTypeType(2);
    } else if ("profession".equals(pathType)) {
        productType.setTypeType(3);
    } else {
        responseBean.setCode(ResponseBean.WRONG_REQ_PARA);
        responseBean.setMsg("未知的分类: " + pathType);
        return responseBean;
    }
    responseBean = productTypeService.deleteTypeById(productType, sessionId);
    return responseBean;
}
Also used : ProductType(com.bc.pmpheep.back.vo.ProductType) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail)

Example 2 with ProductType

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

the class ProductTypeController method importExcel.

@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "临床决策产品分类导入Excel文件")
@RequestMapping(value = "/{ptype}/{type}/importExcel", method = RequestMethod.POST)
public ResponseBean importExcel(@RequestParam(name = "file") MultipartFile file, @PathVariable("ptype") Long ptype, @PathVariable("type") String pathType, HttpServletRequest request) {
    ResponseBean responseBean = null;
    Map<String, Object> map = new HashedMap();
    String sessionId = CookiesUtil.getSessionId(request);
    if (StringUtil.isEmpty(sessionId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.SESSION, CheckedExceptionResult.NULL_PARAM, "用户登陆超时,请重新登陆再试");
    }
    HttpSession session = SessionContext.getSession(sessionId);
    String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
    int typeType = 1;
    if ("subject".equals(pathType)) {
        typeType = 1;
    } else if ("content".equals(pathType)) {
        typeType = 2;
    } else if ("profession".equals(pathType)) {
        typeType = 3;
    }
    try {
        List<ProductType> list = productTypeService.importExcel(file, typeType, ptype);
        map.put("uuid", uuid);
        // 如果需要加确认后再存入数据库,这个list可以传到前台显示
        map.put("list", list);
        session.setAttribute(uuid, list);
        // 现直接插入此list
        responseBean = productTypeService.insertProductTypeTree(list, typeType);
        responseBean.setData(map);
    } catch (CheckedServiceException e) {
        return new ResponseBean(e);
    }
    return responseBean;
}
Also used : HttpSession(javax.servlet.http.HttpSession) ProductType(com.bc.pmpheep.back.vo.ProductType) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) HashedMap(org.apache.commons.collections.map.HashedMap) LogDetail(com.bc.pmpheep.annotation.LogDetail)

Example 3 with ProductType

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

the class ProductTypeController method getSubjectList.

/**
 * 分页查询 产品分类
 * @param request
 * @param pathType subject:学科分类;content:内容分类 profession 专业分类
 * @param type_name 分类名称的模糊查询条件
 * @param pageSize
 * @param pageNumber
 * @return
 */
@RequestMapping("/{ptype}/{ttype}/list")
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "查询产品分类")
@ResponseBody
public ResponseBean getSubjectList(HttpServletRequest request, @PathVariable("ptype") Long ptype, @PathVariable("ttype") String pathType, String type_name, Integer pageSize, Integer pageNumber) {
    ResponseBean responseBean = new ResponseBean();
    String sessionId = CookiesUtil.getSessionId(request);
    PageParameter<ProductType> pageParameter = new PageParameter<>(pageNumber, pageSize);
    ProductType productType = new ProductType(ptype);
    pageParameter.setParameter(productType);
    productType.setType_name(type_name != null ? type_name.trim() : null);
    if ("subject".equals(pathType)) {
        productType.setTypeType(1);
    } else if ("content".equals(pathType)) {
        productType.setTypeType(2);
    } else if ("profession".equals(pathType)) {
        productType.setTypeType(3);
    } else {
        responseBean.setCode(ResponseBean.WRONG_REQ_PARA);
        return responseBean;
    }
    PageResult pageResult = productTypeService.getTypeList(pageParameter, sessionId);
    responseBean.setData(pageResult);
    return responseBean;
}
Also used : ProductType(com.bc.pmpheep.back.vo.ProductType) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) PageResult(com.bc.pmpheep.back.plugin.PageResult) LogDetail(com.bc.pmpheep.annotation.LogDetail)

Example 4 with ProductType

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

the class MaterialSurveyWordHelper method fillProductTypeData.

private XWPFTable fillProductTypeData(XWPFTable table, List<ProductType> productTypeList) {
    if (CollectionUtil.isEmpty(productTypeList)) {
        return table;
    }
    /*if (productTypeList.size() > 1) {
			int height = table.getRow(1).getHeight();
			for (int i = 1; i < productTypeList.size(); i++) {
				table.createRow().setHeight(height);
			}
		}*/
    List<XWPFTableRow> rows = table.getRows();
    String typeName = "";
    for (ProductType productType : productTypeList) {
        if (StringUtil.notEmpty(productType.getType_name())) {
            typeName = typeName + productType.getType_name() + ",     ";
        }
    }
    typeName = typeName.substring(0, typeName.lastIndexOf(","));
    if (StringUtil.notEmpty(typeName)) {
        // 每次添加一个换行符
        rows.get(0).getCell(0).setText(typeName);
    }
    return table;
}
Also used : ProductType(com.bc.pmpheep.back.vo.ProductType)

Example 5 with ProductType

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

the class MaterialSurveyTemplateServiceImpl method importExcel.

@Override
public ResponseBean importExcel(MultipartFile file, String sessionId) {
    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文档,请修改为正确的后缀名再进行上传");
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    // 以fullNamePath为key
    Map<String, ProductType> productTypeMap = new HashMap<String, ProductType>();
    List<MaterialSurveyTemplate> surveyTemplateList = new ArrayList<>();
    for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
        List<SurveyQuestionListVO> surveyQuestionListVO = new ArrayList<SurveyQuestionListVO>();
        Set<String> categoryNameSet = new HashSet<String>();
        MaterialSurveyTemplate surveyTemplateVO = new MaterialSurveyTemplate();
        Sheet sheet = workbook.getSheetAt(numSheet);
        if (null == sheet || sheet.getRow(0) == null) {
            continue;
        }
        // 调研表名称
        String templateName = StringUtil.getCellValue(sheet.getRow(0).getCell(1));
        templateName = StringUtil.isEmpty(templateName) ? sheet.getSheetName() : templateName;
        templateName = StringUtil.isEmpty(templateName) ? file.getOriginalFilename() : templateName;
        surveyTemplateVO.setTemplateName(templateName);
        if (StringUtil.isEmpty(templateName)) {
            continue;
        }
        // 调研表说明
        String intro = StringUtil.getCellValue(sheet.getRow(1).getCell(1));
        surveyTemplateVO.setIntro(intro);
        surveyTemplateVO.setTypeId(3L);
        surveyTemplateVO.setUserId(pmphUser.getId());
        int questSort = 1;
        for (int rowNum = 3; rowNum <= sheet.getLastRowNum(); rowNum++) {
            Row row = sheet.getRow(rowNum);
            if (null == row) {
                break;
            }
            SurveyQuestionListVO surveyQuestion = new SurveyQuestionListVO();
            // 问题类型
            String qTypeStr = StringUtil.getCellValue(row.getCell(0));
            Short typeId = 4;
            switch(qTypeStr) {
                case "单行文本":
                    typeId = 4;
                    break;
                case "多行文本":
                    typeId = 5;
                    break;
                case "单项选择":
                    typeId = 1;
                    break;
                case "多项选择":
                    typeId = 2;
                    break;
                default:
                    typeId = 4;
                    break;
            }
            // 问题分类
            String categoryName = StringUtil.getCellValue(row.getCell(1));
            surveyQuestion.setCategoryName(categoryName);
            if (StringUtil.notEmpty(categoryName)) {
                categoryNameSet.add(categoryName);
            }
            // 问题题干
            surveyQuestion.setTitle(StringUtil.getCellValue(row.getCell(2)));
            if (StringUtil.isEmpty(surveyQuestion.getTitle())) {
                break;
            }
            List<SurveyQuestionOption> optionList = new ArrayList<>();
            surveyQuestion.setSurveyQuestionOptionList(optionList);
            if (typeId != null && (typeId == 1 || typeId == 2)) {
                // 问题选项
                for (int cellNum = 3; cellNum < row.getLastCellNum(); cellNum++) {
                    // 给每个单元格创建或关联实体类
                    Cell cell = row.getCell(cellNum);
                    String cellOptionName = StringUtil.getCellValue(cell);
                    if (StringUtil.isEmpty(cellOptionName)) {
                        /*throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL,
                                CheckedExceptionResult.NULL_PARAM, "Excel文件里序号为" + rowNum + "的分类名称为空");*/
                        continue;
                    } else {
                        SurveyQuestionOption option = new SurveyQuestionOption();
                        option.setOptionContent(cellOptionName);
                        optionList.add(option);
                    }
                }
                // 若无选项 设为单行文本
                if (CollectionUtil.isEmpty(optionList)) {
                    typeId = 4;
                }
            }
            surveyQuestion.setType(typeId);
            surveyQuestion.setSort(questSort);
            questSort += 1;
            surveyQuestionListVO.add(surveyQuestion);
        }
        if (CollectionUtil.isEmpty(surveyQuestionListVO)) {
            break;
        }
        // TODO 如果插入速度太慢 此处可以改为启动线程
        surveyTemplateVO = addSurveyTemplateFromExcel(surveyQuestionListVO, categoryNameSet, surveyTemplateVO, sessionId);
        surveyTemplateList.add(surveyTemplateVO);
    }
    return new ResponseBean(surveyTemplateList);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Cell(org.apache.poi.ss.usermodel.Cell) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) InputStream(java.io.InputStream) ProductType(com.bc.pmpheep.back.vo.ProductType) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) 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) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

ProductType (com.bc.pmpheep.back.vo.ProductType)6 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)4 LogDetail (com.bc.pmpheep.annotation.LogDetail)3 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 PageResult (com.bc.pmpheep.back.plugin.PageResult)1 SurveyQuestionListVO (com.bc.pmpheep.back.vo.SurveyQuestionListVO)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpSession (javax.servlet.http.HttpSession)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 OfficeXmlFileException (org.apache.poi.poifs.filesystem.OfficeXmlFileException)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1