Search in sources :

Example 61 with CheckedServiceException

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

the class SystemMessageService method sendWhenKickingOutGroup.

/**
 * 任意用户被踢出进入小组 向被踢出人发出
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午2:16:36
 * @param inviterName
 *            踢出人名字
 * @param groupId
 *            小组id
 * @param invitedPersonIds
 *            被踢出人ids
 * @param invitedPersonType
 *            被踢出人类型: 1=社内用户/2=作家/3=机构用户
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenKickingOutGroup(String inviterName, Long groupId, List<Long> invitedPersonIds, short invitedPersonType) throws CheckedServiceException, IOException {
    if (StringUtils.isEmpty(inviterName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "邀请人为空");
    }
    if (null == invitedPersonIds || invitedPersonIds.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "被邀请人为空");
    }
    // 获取小组
    PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
    if (null == pmphGroup) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组不存在");
    }
    String msgContent = "您被[<font color='red'>" + inviterName + "</font>]移出群组[<font color='red'>" + pmphGroup.getGroupName() + "]</font>";
    // 存入消息主体
    Message message = new Message(msgContent);
    message = messageService.add(message);
    String msg_id = message.getId();
    // 组装消息和消息对象
    List<UserMessage> userMessageList = new ArrayList<UserMessage>(invitedPersonIds.size());
    List<String> userIds = new ArrayList<String>(invitedPersonIds.size());
    for (Long id : invitedPersonIds) {
        UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, invitedPersonType, null);
        userMessageList.add(userMessage);
        userIds.add(invitedPersonType + "_" + id);
    }
    // 发送消息
    userMessageService.addUserMessageBatch(userMessageList);
    // 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());
    myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) 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 62 with CheckedServiceException

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

the class SystemMessageService method sendWhenManagerCertificationAudit.

/**
 * 学校管理员认证 向机构用户发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午3:01:42
 * @param orguserIds
 *            机构用户ids
 * @param isPass
 *            true 通过/false 退回
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenManagerCertificationAudit(List<Long> orguserIds, boolean isPass) throws CheckedServiceException, IOException {
    if (null == orguserIds || orguserIds.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.SCHOOL_ADMIN_CHECK, CheckedExceptionResult.NULL_PARAM, "认证的管理员为空");
    }
    // 存入消息主体
    // 退回
    String msgContent = "抱歉,您提交的管理员认证资料已被退回,请您修改后重试";
    if (isPass) {
        // 通过
        msgContent = "恭喜!您提交的管理员认证资料已通过审核";
    }
    // 存入消息主体
    Message message = new Message(msgContent);
    message = messageService.add(message);
    String msg_id = message.getId();
    // 组装消息和消息对象
    List<UserMessage> userMessageList = new ArrayList<UserMessage>(orguserIds.size());
    List<String> userIds = new ArrayList<String>(orguserIds.size());
    // 发送消息
    for (Long id : orguserIds) {
        UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, new Short("3"), null);
        userMessageList.add(userMessage);
        userIds.add("3_" + id);
    }
    userMessageService.addUserMessageBatch(userMessageList);
    // 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());
    myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
Also used : 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 63 with CheckedServiceException

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

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

the class WechatArticleService method runCrawler.

public String runCrawler(String url) throws CheckedServiceException {
    if (StringUtil.isEmpty(url)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.NULL_PARAM, "给定链接不能为空");
    }
    if (url.length() < 25) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
    } else {
        String httpStr = url.substring(0, 23);
        String httpsStr = url.substring(0, 24);
        if (!"http://mp.weixin.qq.com".equals(httpStr) && !"https://mp.weixin.qq.com".equals(httpsStr)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
        }
    }
    String guid = String.valueOf(System.currentTimeMillis()).concat(String.valueOf(RandomUtil.getRandomNum()));
    taskExecutor.execute(new WechatArticleCrawlerTask(new WechatArticle(guid, url)));
    return guid;
}
Also used : CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WechatArticle(com.bc.pmpheep.general.runnable.WechatArticle) WechatArticleCrawlerTask(com.bc.pmpheep.general.runnable.WechatArticleCrawlerTask)

Example 65 with CheckedServiceException

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

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