Search in sources :

Example 16 with CmsContent

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

the class CmsContentServiceImpl method saveFileToMongoDB.

/**
 * <pre>
 * 功能描述:保存文件到MongoDB
 * 使用示范:
 *
 * &#64;param files 临时文件路径
 * &#64;param contentId cms内容ID
 * &#64;throws CheckedServiceException
 * </pre>
 */
private void saveFileToMongoDB(HttpServletRequest request, String[] files, String[] imgFile, Long contentId) throws CheckedServiceException, IOException {
    // 保存附件到MongoDB
    if (ArrayUtil.isNotEmpty(files)) {
        for (int i = 0; i < files.length; i++) {
            byte[] fileByte = (byte[]) request.getSession(false).getAttribute(files[i]);
            String fileName = (String) request.getSession(false).getAttribute("fileName_" + files[i]);
            InputStream sbs = new ByteArrayInputStream(fileByte);
            String gridFSFileId = fileService.save(sbs, fileName, FileType.CMS_ATTACHMENT, contentId);
            if (StringUtil.isEmpty(gridFSFileId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
            }
            // 保存对应数据
            CmsExtra cmsExtra = cmsExtraService.addCmsExtra(new CmsExtra(contentId, gridFSFileId, fileName, null));
            if (ObjectUtil.isNull(cmsExtra.getId())) {
                throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsExtra对象新增失败");
            }
        }
    }
    if (ArrayUtil.isNotEmpty(imgFile)) {
        for (int i = 0; i < imgFile.length; i++) {
            byte[] fileByte = (byte[]) request.getSession(false).getAttribute(imgFile[i]);
            String gridFSFileId = imgFile[i];
            if (ObjectUtil.notNull(fileByte)) {
                String fileName = (String) request.getSession(false).getAttribute("fileName_" + imgFile[i]);
                InputStream sbs = new ByteArrayInputStream(fileByte);
                gridFSFileId = fileService.save(sbs, fileName, ImageType.CMS_CONTENT_COVER_IMG, contentId);
                if (StringUtil.isEmpty(gridFSFileId)) {
                    throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
                }
                // 保存对应数据
                CmsExtra cmsExtra = cmsExtraService.addCmsExtra(new CmsExtra(contentId, gridFSFileId, fileName, null));
                if (ObjectUtil.isNull(cmsExtra.getId())) {
                    throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "上传封面失败");
                }
            }
            // 更新封面ID
            this.updateCmsContent(new CmsContent(contentId, gridFSFileId));
        }
    }
}
Also used : CmsExtra(com.bc.pmpheep.back.po.CmsExtra) CmsContent(com.bc.pmpheep.back.po.CmsContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 17 with CmsContent

use of com.bc.pmpheep.back.po.CmsContent 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 18 with CmsContent

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

the class CmsContentServiceImpl method publishCmsContentById.

@Override
public Integer publishCmsContentById(Long id, String sessionId) throws CheckedServiceException {
    // 获取当前登陆用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    // count = cmsContentDao.publishCmsContentById(id);
    Integer count = cmsContentDao.updateCmsContent(new CmsContent(id, Boolean.TRUE, Boolean.FALSE, Const.CMS_AUTHOR_STATUS_2, pmphUser.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
    CmsContent cmsContent = this.getCmsContentById(id);
    writerUserTrendstService.addWriterUserTrendst(new WriterUserTrendst(cmsContent.getAuthorId(), Const.WRITER_USER_TRENDST_TYPE_1, id));
    return count;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) WriterUserTrendst(com.bc.pmpheep.back.po.WriterUserTrendst) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 19 with CmsContent

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

the class CmsContentServiceImpl method addHelp.

@Override
public CmsContent addHelp(CmsContent cmsContent, String content, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
    // 获取当前登陆用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (StringUtil.isEmpty(content)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容参数为空");
    }
    List<CmsContent> listContents = this.listCmsContentByTitle(cmsContent.getTitle());
    if (CollectionUtil.isNotEmpty(listContents)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "添加的常见问题已存在,请确认后再添加");
    }
    // MongoDB 内容插入
    Content contentObj = contentService.add(new Content(content));
    if (StringUtil.isEmpty(contentObj.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
    }
    // 内容保存
    cmsContent.setCategoryId(Const.CMS_CATEGORY_ID_4);
    // 上级id
    cmsContent.setParentId(Const.CMS_CATEGORY_ID_4);
    cmsContent.setPath("0");
    // 内容id
    cmsContent.setMid(contentObj.getId());
    // 作者类型
    cmsContent.setAuthorType(Const.CMS_AUTHOR_TYPE_1);
    // 作者id
    cmsContent.setAuthorId(pmphUser.getId());
    // 获取新增后的主键ID
    Long contentId = this.addCmsContent(cmsContent).getId();
    if (ObjectUtil.isNull(contentId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsContent添加内容失败");
    }
    return cmsContent;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) PmphUser(com.bc.pmpheep.back.po.PmphUser) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 20 with CmsContent

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

the class MaterialExtraServiceImpl method getMaterialExtraAndNoticeDetail.

/**
 * <pre>
 * 功能描述:根据教材ID查询教材通知详情及附件
 * 使用示范:
 *
 * @param materialId 教材ID
 * @return Map<String, Object> 集合
 * @throws CheckedServiceException
 * </pre>
 *
 * @throws UnsupportedEncodingException
 */
@Override
public Map<String, Object> getMaterialExtraAndNoticeDetail(Long materialId) throws CheckedServiceException {
    if (ObjectUtil.isNull(materialId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材主键为空");
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();
    // 教材通知备注
    MaterialExtra materialExtra = null;
    // MongoDB中教材通知
    String contentText = null;
    // 联系人
    List<MaterialContact> materialContacts = null;
    // 教材通知附件
    List<MaterialNoticeAttachment> materialNoticeAttachments = null;
    // 教材备注附件
    List<MaterialNoteAttachment> materialNoteAttachments = null;
    // 教材
    Material material = materialService.getMaterialById(materialId);
    if (ObjectUtil.notNull(material)) {
        // 联系人
        materialContacts = materialContactService.listMaterialContactByMaterialId(materialId);
        materialExtra = this.getMaterialExtraByMaterialId(materialId);
        if (ObjectUtil.notNull(materialExtra)) {
            Long materialExtraId = materialExtra.getId();
            // 教材通知附件
            materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
            // 教材备注附件
            materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
        }
        // 判断内容是否已经发布或审核通过
        String fileNoticeDownLoadType = null;
        String fileNoteDownLoadType = null;
        if (Const.TRUE.booleanValue() == material.getIsPublished().booleanValue()) {
            fileNoticeDownLoadType = Const.MATERIAL_NOTICE_FILE_DOWNLOAD;
            fileNoteDownLoadType = Const.MATERIAL_NOTE_FILE_DOWNLOAD;
        } else {
            fileNoticeDownLoadType = Const.FILE_DOWNLOAD;
            fileNoteDownLoadType = Const.FILE_DOWNLOAD;
        }
        CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
        if (ObjectUtil.notNull(cmsContent)) {
            Content content = contentService.get(cmsContent.getMid());
            if (ObjectUtil.notNull(content)) {
                contentText = content.getContent();
            }
        }
        if (CollectionUtil.isNotEmpty(materialNoticeAttachments)) {
            for (MaterialNoticeAttachment materialNoticeAttachment : materialNoticeAttachments) {
                String attachment = materialNoticeAttachment.getAttachment();
                // 拼接附件下载路径
                materialNoticeAttachment.setAttachment(fileNoticeDownLoadType + attachment);
            }
        }
        if (CollectionUtil.isNotEmpty(materialNoteAttachments)) {
            for (MaterialNoteAttachment materialNoteAttachment : materialNoteAttachments) {
                String attachment = materialNoteAttachment.getAttachment();
                // 拼接附件下载路径
                materialNoteAttachment.setAttachment(fileNoteDownLoadType + attachment);
            }
        }
    }
    // 教材
    resultMap.put("materialName", material);
    // 联系人
    resultMap.put("materialContacts", materialContacts);
    // 教材通知备注
    resultMap.put("materialExtra", materialExtra);
    // MongoDB中教材通知
    resultMap.put("content", contentText);
    // 教材通知附件
    resultMap.put("materialNoticeAttachments", materialNoticeAttachments);
    // 教材备注附件
    resultMap.put("materialNoteAttachments", materialNoteAttachments);
    return resultMap;
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) CmsContent(com.bc.pmpheep.back.po.CmsContent) HashMap(java.util.HashMap) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Aggregations

CmsContent (com.bc.pmpheep.back.po.CmsContent)22 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)16 Content (com.bc.pmpheep.general.po.Content)12 PmphUser (com.bc.pmpheep.back.po.PmphUser)8 ArrayList (java.util.ArrayList)7 Material (com.bc.pmpheep.back.po.Material)6 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)6 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)4 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)4 HashMap (java.util.HashMap)4 CmsExtra (com.bc.pmpheep.back.po.CmsExtra)3 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)3 BaseTest (com.bc.pmpheep.test.BaseTest)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 UserMessage (com.bc.pmpheep.back.po.UserMessage)2 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)2 Message (com.bc.pmpheep.general.po.Message)2 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)2