Search in sources :

Example 6 with Content

use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.

the class MaterialExtraServiceImpl method updateMaterialExtraAndNoticeFile.

/**
 * <pre>
 * 功能描述:编辑通知详情
 * 使用示范:
 *
 * &#64;param materialExtraVO MaterialExtraVO
 * &#64;return Map<String, Object>集合
 * &#64;throws CheckedServiceException
 * </pre>
 */
@Override
public Integer updateMaterialExtraAndNoticeFile(MaterialExtraVO materialExtraVO) throws CheckedServiceException, IOException {
    // 教材ID
    Long materialId = materialExtraVO.getMaterialId();
    if (ObjectUtil.isNull(materialId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
    }
    String materialName = materialExtraVO.getMaterialName();
    if (StringUtil.isEmpty(materialName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
    }
    String content = materialExtraVO.getContent();
    if (StringUtil.isEmpty(content)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知为空");
    }
    // MongoDB 内容插入
    Content contentObj = contentService.add(new Content(content));
    if (ObjectUtil.isNull(contentObj)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.OBJECT_NOT_FOUND, "教材通知保存失败");
    }
    Material material = materialService.getMaterialById(materialId);
    if (StringUtil.isEmpty(materialExtraVO.getContent())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
    }
    // 内容ID
    Long cmsContentId = null;
    CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
    if (ObjectUtil.notNull(cmsContent)) {
        cmsContentId = cmsContent.getId();
        String mid = null;
        if (StringUtil.notEmpty(cmsContent.getMid())) {
            mid = cmsContent.getMid();
        }
        // 存在就更新
        Integer count = cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), contentObj.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
        if (count > 0) {
            // 删除之前教材通知内容
            contentService.delete(mid);
        }
    } else {
        // 保存CMSContent内容
        CmsContent cmsContentObj = cmsContentService.addCmsContent(new CmsContent(0L, "0", contentObj.getId(), materialName, Const.CMS_AUTHOR_TYPE_0, false, true, material.getFounderId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()), materialId, Const.CMS_CATEGORY_ID_3, Const.TRUE, "DEFAULT"));
        if (ObjectUtil.isNull(cmsContentObj.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "创建教材通知公告失败");
        }
        cmsContentId = cmsContentObj.getId();
    }
    // 先删除教材通知附件
    List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(cmsContentId);
    if (CollectionUtil.isNotEmpty(cmsExtras)) {
        List<Long> cmsExtraIds = new ArrayList<Long>();
        for (CmsExtra cmsExtra : cmsExtras) {
            cmsExtraIds.add(cmsExtra.getId());
        }
        cmsExtraService.deleteCmsExtraByIds(cmsExtraIds);
    }
    // 教材通知附件
    List<MaterialNoticeAttachment> materialNoticeAttachments = null;
    // 教材备注附件
    List<MaterialNoteAttachment> materialNoteAttachments = null;
    // 教材通知备注
    MaterialExtra materialExtra = this.getMaterialExtraByMaterialId(materialId);
    if (ObjectUtil.notNull(materialExtra)) {
        Long materialExtraId = materialExtra.getId();
        if (ObjectUtil.notNull(materialExtraId)) {
            // 教材通知附件
            materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
            // 教材备注附件
            materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
            // 教材通知附件保存到CMS附件表中
            for (MaterialNoticeAttachment mna : materialNoticeAttachments) {
                cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, mna.getAttachment(), mna.getAttachmentName(), 0L));
            }
            for (MaterialNoteAttachment ma : materialNoteAttachments) {
                cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, ma.getAttachment(), ma.getAttachmentName(), 0L));
            }
        }
    }
    // 教材通知附件
    // String[] noticeFiles = materialExtraVO.getNoticeFiles();
    // if (ArrayUtil.isNotEmpty(noticeFiles)) {
    // this.saveFileToMongoDB(noticeFiles, materialExtraId, NOTICE);
    // }
    // 教材通知附件MongoDB对应ID
    String[] noticeAttachments = materialExtraVO.getNoticeAttachments();
    if (ArrayUtil.isNotEmpty(noticeAttachments)) {
        // 删除MaterialNoticeAttachment 表
        materialNoticeAttachmentService.deleteMaterialNoticeAttachmentByAttachments(noticeAttachments);
        // 删除MongoDB对应的文件
        for (int i = 0; i < noticeAttachments.length; i++) {
            fileService.remove(noticeAttachments[i]);
        }
    }
    // 教材备注附件
    // String[] noteFiles = materialExtraVO.getNoteFiles();
    // if (ArrayUtil.isNotEmpty(noteFiles)) {
    // this.saveFileToMongoDB(noteFiles, materialExtraId, NOTE);
    // }
    // 教材备注附件MongoDB对应ID
    String[] noteAttachments = materialExtraVO.getNoteAttachments();
    if (ArrayUtil.isNotEmpty(noteAttachments)) {
        // 删除MaterialNoteAttachment 表
        materialNoteAttachmentService.deleteMaterialNoteAttachmentByAttachments(noteAttachments);
        // 删除MongoDB对应的文件
        for (int i = 0; i < noteAttachments.length; i++) {
            fileService.remove(noteAttachments[i]);
        }
    }
    return 1;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) CmsExtra(com.bc.pmpheep.back.po.CmsExtra) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 7 with Content

use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.

the class WechatArticleService method synchroCmsContent.

public CmsContent synchroCmsContent(String guid, HttpServletRequest request) throws IOException {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser sessionPmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == sessionPmphUser) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    CmsContent cmsContent = new CmsContent();
    if (StringUtil.isEmpty(guid)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.NULL_PARAM, "文章唯一标识不能为空");
    }
    // 删除文件夹及以下文件
    // 获取路径
    String dir = new File("").getAbsolutePath() + "/" + guid;
    FileUtil.deleteDirectory(dir);
    if (Const.WACT_MAP.containsKey(guid)) {
        WechatArticle wechatArticle = Const.WACT_MAP.get(guid);
        String html = wechatArticle.getResult();
        String titleStart = "<h2 class=\"rich_media_title\" id=\"activity-name\">";
        String titleEnd = "</h2>";
        int titleS = html.indexOf(titleStart) + titleStart.length();
        String title = "";
        try {
            int titleE = html.indexOf(titleEnd);
            // 获取标题
            title = html.substring(titleS, titleE);
        } catch (Exception e) {
            throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
        }
        String contentStart = "<div class=\"rich_media_content \" id=\"js_content\">";
        String contentEnd = "</div>";
        int contentS = html.indexOf(contentStart) + contentStart.length();
        int contentE = html.lastIndexOf(contentEnd);
        // 获取内容
        String content = html.substring(contentS, contentE);
        // 替换内容
        String contents = content.replace("data-src", "src");
        // 获取图片标签
        List<String> imgUrl = download.getImageUrl(contents);
        // 获取图片src地址
        List<String> imgSrc = download.getImageSrc(imgUrl);
        // 下载图片
        List<String> mongoImgs = download.download(imgSrc);
        for (int i = 0; i < imgSrc.size(); i++) {
            if (StringUtil.notEmpty(mongoImgs.get(i))) {
                // 下载路径
                String imgsId = RouteUtil.MONGODB_FILE + mongoImgs.get(i);
                contents = contents.replace(imgSrc.get(i), imgsId);
            }
        }
        if (StringUtil.isEmpty(contents)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容参数为空");
        }
        // MongoDB内容插入
        Content contentObj = contentService.add(new Content(contents));
        if (StringUtil.isEmpty(contentObj.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
        }
        // 上级id(0为内容)
        cmsContent.setParentId(0L);
        // 根节点路径
        cmsContent.setPath("0");
        // 内容id
        cmsContent.setMid(contentObj.getId());
        // 内容类型(1=随笔文章)
        cmsContent.setCategoryId(Const.CMS_CATEGORY_ID_1);
        cmsContent.setTitle(title.trim());
        // 作者类型
        cmsContent.setAuthorType((short) 0);
        // 作者id
        cmsContent.setAuthorId(sessionPmphUser.getId());
        cmsContent = cmsContentService.addCmsContent(cmsContent);
    }
    // 防止map内存溢出,操作过后就移除
    Const.WACT_MAP.remove("guid");
    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) WechatArticle(com.bc.pmpheep.general.runnable.WechatArticle) File(java.io.File) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException)

Example 8 with Content

use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.

the class MigrationStageFour method addMaterialCommunity.

protected void addMaterialCommunity() {
    // 保存教材社区相关的信息
    for (Material material : materials) {
        MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
        if (null == materialExtra) {
            materialExtra = new MaterialExtra();
        }
        String detail = "<p>简介:驱蚊器</p>" + "<p><br/></p>" + "<p>邮寄地址:驱蚊器翁</p>" + "<p><br/></p>" + "<p>联&nbsp;系&nbsp;人:陈慧 (电话:18610032992,Emali:147258369@qq.com)</p>" + "<p><br/>/p>";
        detail = detail + "<p>简介:" + null == materialExtra.getNotice() ? "" : materialExtra.getNotice() + "</p>";
        detail = detail + "<p><br/></p><p>邮寄地址:" + material.getMailAddress() + "</p>";
        List<MaterialContact> materialContacts = materialContactService.listMaterialContactByMaterialId(material.getId());
        for (MaterialContact materialContact : materialContacts) {
            detail = detail + "<p><br/></p><p>联&nbsp;系&nbsp;人:" + materialContact.getContactUserName() + " (电话:" + materialContact.getContactPhone() + ",Emali:" + materialContact.getContactEmail() + ")</p>";
        }
        Content content = new Content(detail);
        content = contentService.add(content);
        CmsContent cmsContent = new CmsContent();
        cmsContent.setParentId(0L);
        cmsContent.setPath("0");
        cmsContent.setMid(content.getId());
        cmsContent.setCategoryId(3L);
        cmsContent.setTitle(material.getMaterialName());
        cmsContent.setAuthorType(new Short("0"));
        cmsContent.setAuthorId(material.getFounderId());
        cmsContent.setIsPublished(material.getIsPublished());
        cmsContent.setAuthStatus(material.getIsPublished() ? new Short("2") : new Short("0"));
        cmsContent.setAuthDate(DateUtil.date2Str(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate()));
        cmsContent.setAuthUserId(material.getFounderId());
        cmsContent.setGmtCreate(material.getGmtCreate());
        cmsContent.setGmtUpdate(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate());
        cmsContent.setIsMaterialEntry(true);
        cmsContent.setMaterialId(material.getId());
        cmsContentService.addCmsContent(cmsContent);
    }
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) Material(com.bc.pmpheep.back.po.Material) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 9 with Content

use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.

the class MigrationStageTen method materialNotice.

public void materialNotice() {
    List<Material> materials = materialService.getListMaterial("轮");
    List<CmsCategory> categorys = cmsCategoryService.getCmsCategoryListByCategoryName("公告");
    Long categoryId = categorys.get(0).getId();
    final String html = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$f</span></strong>$d</p>";
    final String htmlS1 = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$d</span></strong></p>";
    final String htmlS2 = "<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; padding: 0px;\">$d</p>";
    for (Material material : materials) {
        CmsContent cmsContent = new CmsContent();
        cmsContent.setParentId(0L);
        cmsContent.setCategoryId(categoryId);
        cmsContent.setPath("0");
        cmsContent.setTitle(material.getMaterialName());
        cmsContent.setAuthorType((short) 0);
        cmsContent.setMaterialId(material.getId());
        /* 生成通知内容 */
        StringBuilder sb = new StringBuilder();
        String str = html.replace("$f", "截止日期:");
        str = str.replace("$d", sdf.format(material.getDeadline()));
        sb.append(str);
        /* 获取教材联系人 */
        List<MaterialContact> contacts = materialContactService.listMaterialContactByMaterialId(categoryId);
        if (CollectionUtil.isNotEmpty(contacts)) {
            str = htmlS1.replace("$f", "联系人:");
            sb.append(str);
            for (MaterialContact contact : contacts) {
                /* 裴中惠&nbsp;(电话:010-59787110&nbsp;,&nbsp;Email:pzh@pmph.com) */
                StringBuilder builder = new StringBuilder(contact.getContactUserName());
                builder.append("&nbsp;(电话:");
                builder.append(contact.getContactPhone());
                builder.append("&nbsp;,&nbsp;Email:");
                builder.append(contact.getContactEmail());
                builder.append(")");
                str = htmlS2.replace("$d", builder.toString());
                sb.append(str);
            }
        }
        str = html.replace("$f", "邮寄地址:");
        str = str.replace("$d", material.getMailAddress());
        sb.append(str);
        /* 获取通知内容和备注 */
        MaterialExtra extra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
        str = htmlS1.replace("$d", "简&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;介:");
        sb.append(str);
        if (null != extra) {
        // str = htmlS2.replace("$d", extra.getNotice()) /* 存入MongoDB */
        }
        Content content = new Content(sb.toString());
        content = contentService.add(content);
        cmsContent.setMid(content.getId());
    }
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) Material(com.bc.pmpheep.back.po.Material) CmsCategory(com.bc.pmpheep.back.po.CmsCategory) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 10 with Content

use of com.bc.pmpheep.general.po.Content 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)

Aggregations

Content (com.bc.pmpheep.general.po.Content)17 CmsContent (com.bc.pmpheep.back.po.CmsContent)12 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)10 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)5 Material (com.bc.pmpheep.back.po.Material)4 PmphUser (com.bc.pmpheep.back.po.PmphUser)4 BaseTest (com.bc.pmpheep.test.BaseTest)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)3 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CmsExtra (com.bc.pmpheep.back.po.CmsExtra)2 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)2 Book (com.bc.pmpheep.back.po.Book)1 CmsCategory (com.bc.pmpheep.back.po.CmsCategory)1 UserMessage (com.bc.pmpheep.back.po.UserMessage)1 InfoWorking (com.bc.pmpheep.erp.service.InfoWorking)1 Message (com.bc.pmpheep.general.po.Message)1