Search in sources :

Example 1 with BookListVO

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

the class TextbookServiceImpl method getBookListVOs.

public List<BookListVO> getBookListVOs(Long materialId) throws CheckedServiceException {
    if (ObjectUtil.isNull(materialId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "教材id不能为空");
    }
    Material material = materialService.getMaterialById(materialId);
    Long materialType = material.getMaterialType();
    String path;
    try {
        path = materialTypeService.getMaterialTypeById(materialType).getPath();
    } catch (NullPointerException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "找不到此教材的分类");
    }
    if (StringUtil.isEmpty(path)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_TYPE, CheckedExceptionResult.NULL_PARAM, "分类路径为空");
    }
    if (path.indexOf("0-") != -1) {
        path = path.replaceFirst("0-", "");
    }
    String[] pathType = path.split("-");
    for (int i = 0; i < pathType.length; i++) {
        String type = materialTypeService.getMaterialTypeById(Long.valueOf(pathType[i])).getTypeName();
        pathType[i] = pathType[i].replace(pathType[i], type);
    }
    List<Textbook> bookList = textbookDao.getTextbookByMaterialId(materialId);
    List<BookListVO> books = new ArrayList<>();
    if (null == bookList || bookList.isEmpty()) {
        BookListVO bookListVO = new BookListVO();
        bookListVO.setMaterialId(material.getId());
        bookListVO.setMaterialName(material.getMaterialName());
        bookListVO.setMaterialRound(material.getMaterialRound());
        bookListVO.setMaterialType(pathType);
        bookListVO.setIsPublic(material.getIsPublic());
        books.add(bookListVO);
        return books;
    }
    for (Textbook textbook : bookList) {
        BookListVO bookListVO = new BookListVO();
        bookListVO.setMaterialId(material.getId());
        bookListVO.setMaterialName(material.getMaterialName());
        bookListVO.setMaterialRound(material.getMaterialRound());
        bookListVO.setMaterialType(pathType);
        bookListVO.setIsPublic(material.getIsPublic());
        bookListVO.setTextbook(textbook);
        if (CollectionUtil.isNotEmpty(decPositionService.listDecPositionsByTextbookId(textbook.getId())) && decPositionService.listDecPositionsByTextbookId(textbook.getId()).size() > 0) {
            bookListVO.setAllowedDelete(false);
        } else {
            bookListVO.setAllowedDelete(true);
        }
        books.add(bookListVO);
    }
    return books;
}
Also used : BookListVO(com.bc.pmpheep.back.vo.BookListVO) Textbook(com.bc.pmpheep.back.po.Textbook) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material)

Aggregations

Material (com.bc.pmpheep.back.po.Material)1 Textbook (com.bc.pmpheep.back.po.Textbook)1 BookListVO (com.bc.pmpheep.back.vo.BookListVO)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 ArrayList (java.util.ArrayList)1