Search in sources :

Example 11 with CmsContent

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

the class SystemMessageService method sendWhenInformalEssayAudit.

/**
 * 随笔文章审核 向作家用户发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午5:23:16
 * @param cmsContentId
 * @param isPass
 *            true通过/false 不通过
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenInformalEssayAudit(Long cmsContentId, boolean isPass) throws CheckedServiceException, IOException {
    CmsContent cmsContent = cmsContentService.getCmsContentById(cmsContentId);
    if (null == cmsContent) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "文章不存在");
    }
    String msgContent = "抱歉,您的文章《<font color='red'>" + cmsContent.getTitle() + "</font>》没有通过审核,请您修改后重试 ";
    if (isPass) {
        msgContent = "恭喜!您的文章《<font color='red'>" + cmsContent.getTitle() + "</font>》已通过审核 ";
    }
    // 存入消息主体
    Message message = new Message(msgContent);
    message = messageService.add(message);
    String msg_id = message.getId();
    // 发送消息给申报者
    userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), cmsContent.getAuthorId(), new Short("2"), null));
    // websocket推送页面消息
    WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
    List<String> userIds = new ArrayList<String>(1);
    userIds.add("2_" + cmsContent.getAuthorId());
    myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage)

Example 12 with CmsContent

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

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

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

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

the class CmsContentServiceImpl method checkContentById.

@Override
public Integer checkContentById(Long id, Short authStatus, Long categoryId, 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) || ObjectUtil.isNull(authStatus)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    Boolean isPublished = false;
    Boolean isStaging = false;
    if (Const.CMS_AUTHOR_STATUS_2 == authStatus) {
        // 发布
        isPublished = true;
        isStaging = true;
    }
    Integer count = 0;
    count = cmsContentDao.checkContentById(new CmsContent(id, authStatus, pmphUser.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()), isPublished, isStaging, Const.MATERIAL_TYPE_ID));
    CmsContent cmsContent = this.getCmsContentById(id);
    if (ObjectUtil.isNull(cmsContent)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.OBJECT_NOT_FOUND, "获取对象为空");
    }
    // 评论审核通过,评论数加1
    if (Const.CMS_CATEGORY_ID_0.longValue() == categoryId.longValue() && isPublished) {
        this.updatCmsContentCommentsById(id, 1);
        this.updateCmsContentByParentId(cmsContent.getParentId(), 1);
    }
    Integer type = 0;
    if (Const.CMS_CATEGORY_ID_0.longValue() == categoryId.longValue()) {
        type = Const.WRITER_USER_TRENDST_TYPE_2;
    } else if (Const.CMS_CATEGORY_ID_1.longValue() == categoryId.longValue()) {
        type = Const.WRITER_USER_TRENDST_TYPE_1;
    }
    if (isPublished) {
        writerUserTrendstService.addWriterUserTrendst(new WriterUserTrendst(cmsContent.getAuthorId(), type, id));
    }
    // 当文章通过的时候 给用户增加积分
    if (Const.CMS_CATEGORY_ID_1.longValue() == categoryId.longValue() && isPublished && Const.CMS_AUTHOR_TYPE_2 == cmsContent.getAuthorType()) {
        String ruleName = "发表文章";
        writerPointLogService.addWriterPointLogByRuleName(ruleName, cmsContent.getAuthorId());
    }
    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)

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