Search in sources :

Example 6 with CmsExtra

use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.

the class CmsContentServiceImpl method getCmsContentAndContentAndAttachmentById.

@Override
public Map<String, Object> getCmsContentAndContentAndAttachmentById(Long id) throws CheckedServiceException {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    // 按id 获取CmsContent对象
    CmsContent cmsContent = cmsContentDao.getCmsContentById(id);
    String authDate = cmsContent.getAuthDate();
    if (StringUtil.notEmpty(authDate)) {
        cmsContent.setAuthDate(DateUtil.date2Str(DateUtil.str2Date(authDate)));
    }
    String deadlinePromote = cmsContent.getDeadlinePromote();
    if (StringUtil.notEmpty(deadlinePromote)) {
        cmsContent.setDeadlinePromote(DateUtil.date2Str(DateUtil.str2Date(deadlinePromote)));
    }
    String deadlineStick = cmsContent.getDeadlineStick();
    if (StringUtil.notEmpty(deadlineStick)) {
        cmsContent.setDeadlineStick(DateUtil.date2Str(DateUtil.str2Date(deadlineStick)));
    }
    String deadlineHot = cmsContent.getDeadlineHot();
    if (StringUtil.notEmpty(deadlineHot)) {
        cmsContent.setDeadlineHot(DateUtil.date2Str(DateUtil.str2Date(deadlineHot)));
    }
    resultMap.put("cmsContent", cmsContent);
    // 判断内容是否已经发布或审核通过
    String fileDownLoadType = null;
    if (cmsContent.getIsPublished() || Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue()) {
        fileDownLoadType = Const.CMS_FILE_DOWNLOAD;
    } else {
        fileDownLoadType = Const.FILE_DOWNLOAD;
    }
    // 按mid 获取Content对象
    Content content = contentService.get(cmsContent.getMid());
    if (ObjectUtil.isNull(content)) {
        content = new Content();
        content.setId(cmsContent.getMid());
        content.setContent("");
    }
    resultMap.put("content", content);
    // 按contentId 获取CMS内容附件
    List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(id);
    List<CmsExtra> cmsList = new ArrayList<CmsExtra>(cmsExtras.size());
    for (CmsExtra cmsExtra : cmsExtras) {
        String attachment = cmsExtra.getAttachment();
        if (!attachment.equals(cmsContent.getCover())) {
            // 拼接附件下载路径
            cmsExtra.setAttachment(fileDownLoadType + attachment);
            cmsList.add(cmsExtra);
        }
    }
    resultMap.put("cmsExtras", cmsList);
    // 根据MaterialId 获取教材备注附件
    List<MaterialNoteAttachment> materialNoteAttachments = null;
    if (cmsContent.getIsMaterialEntry()) {
        MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(cmsContent.getMaterialId());
        if (ObjectUtil.notNull(materialExtra)) {
            // 教材备注附件
            materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
        }
    }
    resultMap.put("MaterialNoteAttachment", materialNoteAttachments);
    if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue()) {
        // 文章封面图片
        CmsExtra cmsExtra = cmsExtraService.getCmsExtraByAttachment(cmsContent.getCover());
        String imgFileName = "默认封面.png";
        String imgFilePath = RouteUtil.DEFAULT_USER_AVATAR;
        if (ObjectUtil.notNull(cmsExtra)) {
            imgFileName = cmsExtra.getAttachmentName();
        } else {
            GridFSDBFile file = fileService.get(cmsContent.getCover());
            if (ObjectUtil.notNull(file)) {
                imgFileName = file.getFilename();
            }
        }
        resultMap.put("imgFileName", imgFileName);
        if (!"DEFAULT".equals(cmsContent.getCover())) {
            imgFilePath = cmsContent.getCover();
        }
        resultMap.put("imgFilePath", imgFilePath);
    }
    return resultMap;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) HashMap(java.util.HashMap) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) CmsExtra(com.bc.pmpheep.back.po.CmsExtra) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 7 with CmsExtra

use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.

the class CmsExtraServiceTest method testUpdateCmsExtra.

@Test
public void testUpdateCmsExtra() {
    CmsExtra cmsExtra = this.addCmsExtra();
    Integer count = cmsExtraService.updateCmsExtra(new CmsExtra(cmsExtra.getId(), 2L, "图片路径"));
    Assert.assertTrue("是否更新CmsExtra成功", count > 0);
}
Also used : CmsExtra(com.bc.pmpheep.back.po.CmsExtra) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Aggregations

CmsExtra (com.bc.pmpheep.back.po.CmsExtra)7 BaseTest (com.bc.pmpheep.test.BaseTest)4 Test (org.junit.Test)4 CmsContent (com.bc.pmpheep.back.po.CmsContent)3 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)3 ArrayList (java.util.ArrayList)3 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)2 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)2 Content (com.bc.pmpheep.general.po.Content)2 Material (com.bc.pmpheep.back.po.Material)1 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)1 GridFSDBFile (com.mongodb.gridfs.GridFSDBFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1