Search in sources :

Example 11 with PmphUser

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

the class CmsContentServiceImpl method addCmsContent.

@Override
public CmsContent addCmsContent(CmsContent cmsContent, String[] files, String content, String scheduledTime, 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, "内容参数为空");
    }
    if (ObjectUtil.isNull(cmsContent.getCategoryId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "所属栏目不能为空");
    }
    if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID不能为空");
    }
    // MongoDB 内容插入
    Content contentObj = contentService.add(new Content(content));
    if (StringUtil.isEmpty(contentObj.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
    }
    // 内容保存
    // 上级id
    cmsContent.setParentId(cmsContent.getCategoryId());
    // cmsContent.setPath(cmsContent.getPath());// 根节点路径
    // 内容id
    cmsContent.setMid(contentObj.getId());
    // 作者类型
    cmsContent.setAuthorType(Const.CMS_AUTHOR_TYPE_1);
    // 作者id
    cmsContent.setAuthorId(pmphUser.getId());
    // cmsContent.setMaterialId(cmsContent.getMaterialId());// 教材ID,为0表示未选择教材
    String summary = SummaryUtil.htmlToText(content);
    summary = summary.substring(0, Math.min(summary.length(), 60));
    cmsContent.setSummary(summary);
    if (Const.TRUE == cmsContent.getIsPublished()) {
        cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
    }
    // 信息快报/公告管理(发布),审核时间就为当前时间
    if (ObjectUtil.notNull(cmsContent.getAuthStatus())) {
        if (Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus()) {
            cmsContent.setAuthUserId(pmphUser.getId());
            cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
            cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
            cmsContent.setIsPublished(true);
        }
    }
    if (ObjectUtil.notNull(cmsContent.getIsStaging())) {
        if (Const.TRUE.booleanValue() == cmsContent.getIsStaging().booleanValue()) {
            // 信息快报/公告管理(暂存)
            cmsContent.setAuthUserId(pmphUser.getId());
            cmsContent.setAuthStatus(null);
            cmsContent.setAuthDate(null);
            cmsContent.setIsPublished(false);
        }
    }
    // 获取新增后的主键ID
    Long contentId = this.addCmsContent(cmsContent).getId();
    if (ObjectUtil.isNull(contentId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsContent添加内容失败");
    }
    // 定时发布
    // if (Const.TRUE.booleanValue() == cmsContent.getIsScheduled().booleanValue())
    // {
    // if (StringUtil.isEmpty(scheduledTime)) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.CMS,
    // CheckedExceptionResult.NULL_PARAM, "定时发布时间参数为空");
    // }
    // cmsScheduleService.addCmsSchedule(new CmsSchedule(contentId,
    // DateUtil.str2Timestam(scheduledTime)));
    // }
    // 保存附件到MongoDB
    this.saveFileToMongoDB(request, files, null, contentId);
    return cmsContent;
}
Also used : 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 12 with PmphUser

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

the class CmsContentServiceImpl method listCmsContent.

@Override
public PageResult<CmsContentVO> listCmsContent(PageParameter<CmsContentVO> pageParameter, 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 (Const.CMS_CATEGORY_ID_1.longValue() == pageParameter.getParameter().getCategoryId()) {
        pageParameter.getParameter().setIsAdmin(true);
    } else {
        pageParameter.getParameter().setIsAdmin(pmphUser.getIsAdmin());
    }
    pageParameter.getParameter().setAuthorId(pmphUser.getId());
    PageResult<CmsContentVO> pageResult = new PageResult<CmsContentVO>();
    // 将页面大小和页面页码拷贝
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // if(cmsContentDao.getCmsContentByAuthorId(pageParameter.getParameter().getAuthorId()).size()>0){
    // 包含数据总条数的数据集
    List<CmsContentVO> cmsContentList = cmsContentDao.listCmsContent(pageParameter);
    if (CollectionUtil.isNotEmpty(cmsContentList)) {
        Integer count = cmsContentList.get(0).getCount();
        pageResult.setTotal(count);
        pageResult.setRows(cmsContentList);
    }
    // }
    return pageResult;
}
Also used : CmsContentVO(com.bc.pmpheep.back.vo.CmsContentVO) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult)

Example 13 with PmphUser

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

the class CmsContentServiceImpl method updateCmsContent.

@Override
public Integer updateCmsContent(CmsContent cmsContent, String[] files, String[] imgFile, String content, String[] attachment, String[] imgAttachment, String scheduledTime, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
    Integer count = 0;
    // 获取当前登陆用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (StringUtil.notEmpty(content)) {
        // 更新MongoDB 内容
        contentService.update(new Content(cmsContent.getMid(), content));
    }
    if (ObjectUtil.isNull(cmsContent)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
    }
    // 信息快报/公告管理(发布),审核时间就为当前时间
    if (Const.CMS_AUTHOR_STATUS_2 == cmsContent.getAuthStatus().shortValue()) {
        cmsContent.setAuthUserId(pmphUser.getId());
        cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
        cmsContent.setIsStaging(Const.FALSE);
        cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
        cmsContent.setIsPublished(true);
    } else if (Const.CMS_AUTHOR_STATUS_0 == cmsContent.getAuthStatus().shortValue()) {
        if (cmsContent.getIsStaging()) {
            // 信息快报/公告管理(暂存)
            cmsContent.setAuthUserId(pmphUser.getId());
            cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_0);
            cmsContent.setAuthDate(null);
            cmsContent.setIsPublished(false);
        }
    } else if (Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
        // 文章管理,退回
        cmsContent.setAuthUserId(pmphUser.getId());
        cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_1);
        cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
        cmsContent.setIsDeleted(false);
        cmsContent.setIsPublished(false);
    }
    if (cmsContent.getCategoryId() == Const.CMS_CATEGORY_ID_1 && cmsContent.getAuthorType() == Const.CMS_AUTHOR_TYPE_2 && cmsContent.getAuthStatus() == Const.CMS_AUTHOR_STATUS_0 && Const.TRUE == cmsContent.getIsStaging()) {
        cmsContent.setIsStaging(false);
    }
    // 再次编辑时间
    cmsContent.setGmtReedit(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
    // 撤销
    if (null != cmsContent.getIsPublished()) {
        cmsContent.setIsStaging(cmsContent.getIsPublished());
    } else {
        cmsContent.setIsStaging(false);
    }
    count = cmsContentDao.updateCmsContent(cmsContent);
    if (// 内容管理,退回发送消息
    count > 0 && Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
        // MongoDB 消息插入
        String categoryName = "文章管理";
        if (Const.CMS_CATEGORY_ID_2.longValue() == cmsContent.getCategoryId().longValue()) {
            categoryName = "信息快报管理";
        } else if (Const.CMS_CATEGORY_ID_3.longValue() == cmsContent.getCategoryId().longValue()) {
            categoryName = "公告管理";
        }
        // 退回时发送消息内容
        StringBuilder sb = new StringBuilder();
        sb.append(categoryName);
        sb.append("中您添加的《 ");
        sb.append(cmsContent.getTitle());
        sb.append(" 》已被退回 !");
        if (StringUtil.notEmpty(cmsContent.getReturnReason())) {
            sb.append("<br/><br/>退回理由为:");
            sb.append(cmsContent.getReturnReason());
        }
        Message message = messageService.add(new Message(sb.toString()));
        if (StringUtil.isEmpty(message.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
        }
        String returnContentTitle = "内容管理审核退回";
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(4);
        userMessageList.add(new UserMessage(message.getId(), returnContentTitle, Const.MSG_TYPE_1, pmphUser.getId(), Const.SENDER_TYPE_1, cmsContent.getAuthorId(), cmsContent.getAuthorType(), 0L));
        // 发送消息
        if (CollectionUtil.isNotEmpty(userMessageList)) {
            // 插入消息发送对象数据
            userMessageService.addUserMessageBatch(userMessageList);
            // websocket发送的id集合
            List<String> websocketUserIds = new ArrayList<String>();
            for (UserMessage userMessage : userMessageList) {
                websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
            }
            // webscokt发送消息
            if (CollectionUtil.isNotEmpty(websocketUserIds)) {
                WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, pmphUser.getId(), pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, returnContentTitle, message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    // 当文章通过的时候给用户增加积分
    if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue() && Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue() && Const.CMS_AUTHOR_TYPE_2 == cmsContent.getAuthorType()) {
        String ruleName = "发表文章";
        writerPointLogService.addWriterPointLogByRuleName(ruleName, cmsContent.getAuthorId());
    }
    // 删除附件
    if (ArrayUtil.isNotEmpty(attachment)) {
        // 删除CmsExtra 表
        cmsExtraService.deleteCmsExtraByAttachment(attachment);
        // 删除MongoDB对应的文件
        for (int i = 0; i < attachment.length; i++) {
            fileService.remove(attachment[i]);
        }
    }
    // 文章封面
    if (ArrayUtil.isNotEmpty(imgAttachment)) {
        // 删除CmsExtra 表
        cmsExtraService.deleteCmsExtraByAttachment(imgAttachment);
        // 删除MongoDB对应的文件
        for (int i = 0; i < imgAttachment.length; i++) {
            fileService.remove(imgAttachment[i]);
        }
        if (ArrayUtil.isEmpty(imgFile)) {
            // 如果删除了封面没上传,就使用默认封面
            this.updateCmsContent(new CmsContent(cmsContent.getId(), "DEFAULT"));
        }
    }
    // 保存附件到MongoDB
    this.saveFileToMongoDB(request, files, imgFile, cmsContent.getId());
    return count;
}
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) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content)

Example 14 with PmphUser

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

the class CmsManualServiceImpl method addCmsManual.

@Override
public CmsManual addCmsManual(CmsManual cmsManual, 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, "用户为空");
    }
    cmsManual.setUserId(pmphUser.getId());
    this.addCmsManual(cmsManual);
    return cmsManual;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 15 with PmphUser

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

the class CmsManualServiceImpl method listCmsManual.

@Override
public PageResult<CmsManualVO> listCmsManual(PageParameter<CmsManualVO> pageParameter, 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, "用户为空");
    }
    PageResult<CmsManualVO> pageResult = new PageResult<CmsManualVO>();
    // 将页面大小和页面页码拷贝
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // 包含数据总条数的数据集
    List<CmsManualVO> cmsManualVOs = cmsManualDao.listCmsManual(pageParameter);
    if (CollectionUtil.isNotEmpty(cmsManualVOs)) {
        Integer count = cmsManualVOs.get(0).getCount();
        pageResult.setTotal(count);
        pageResult.setRows(cmsManualVOs);
    }
    return pageResult;
}
Also used : CmsManualVO(com.bc.pmpheep.back.vo.CmsManualVO) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult)

Aggregations

PmphUser (com.bc.pmpheep.back.po.PmphUser)102 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)81 ArrayList (java.util.ArrayList)33 PageResult (com.bc.pmpheep.back.plugin.PageResult)17 HashMap (java.util.HashMap)13 Material (com.bc.pmpheep.back.po.Material)11 WriterUser (com.bc.pmpheep.back.po.WriterUser)11 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)10 PmphRole (com.bc.pmpheep.back.po.PmphRole)9 UserMessage (com.bc.pmpheep.back.po.UserMessage)9 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)9 BaseTest (com.bc.pmpheep.test.BaseTest)9 Test (org.junit.Test)9 CmsContent (com.bc.pmpheep.back.po.CmsContent)8 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)8 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)7 Textbook (com.bc.pmpheep.back.po.Textbook)7 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)6 Gson (com.google.gson.Gson)6 OrgUser (com.bc.pmpheep.back.po.OrgUser)5