Search in sources :

Example 21 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class CmsContentServiceImpl method getHelpDetail.

@Override
public Map<String, Object> getHelpDetail(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);
    resultMap.put("cmsContent", cmsContent);
    // 按mid 获取Content对象
    Content content = contentService.get(cmsContent.getMid());
    resultMap.put("content", content);
    return resultMap;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) HashMap(java.util.HashMap) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 22 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 23 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class CmsContentServiceImpl method deleteCmsContentById.

@Override
public Integer deleteCmsContentById(Long id) throws CheckedServiceException {
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    List<CmsContent> list = this.getCmsContentByParentId(id);
    List<Long> ids = new ArrayList<Long>(list.size());
    for (CmsContent cmsContent : list) {
        ids.add(cmsContent.getId());
    }
    Integer count = 0;
    count = cmsContentDao.deleteCmsContentById(id);
    if (CollectionUtil.isNotEmpty(ids)) {
        count = this.deleteCmsContentByIds(ids);
    }
    return count;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 24 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 25 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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)

Aggregations

CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)208 PmphUser (com.bc.pmpheep.back.po.PmphUser)81 ArrayList (java.util.ArrayList)73 PageResult (com.bc.pmpheep.back.plugin.PageResult)33 Material (com.bc.pmpheep.back.po.Material)30 IOException (java.io.IOException)30 HashMap (java.util.HashMap)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)24 Workbook (org.apache.poi.ss.usermodel.Workbook)23 UserMessage (com.bc.pmpheep.back.po.UserMessage)22 LogDetail (com.bc.pmpheep.annotation.LogDetail)20 Message (com.bc.pmpheep.general.po.Message)20 Textbook (com.bc.pmpheep.back.po.Textbook)18 WriterUser (com.bc.pmpheep.back.po.WriterUser)17 OutputStream (java.io.OutputStream)17 CmsContent (com.bc.pmpheep.back.po.CmsContent)16 BufferedOutputStream (java.io.BufferedOutputStream)16 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14