Search in sources :

Example 11 with WebScocketMessage

use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.

the class SurveyTargetServiceImpl method batchSaveSurveyTargetByList.

@Override
public Integer batchSaveSurveyTargetByList(Message message, SurveyTargetVO surveyTargetVO, String sessionId) throws Exception {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(surveyTargetVO.getSurveyId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
    }
    if (CollectionUtil.isEmpty(surveyTargetVO.getOrgIds())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "学校Id为空");
    }
    if (StringUtil.isEmpty(surveyTargetVO.getStartTime())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间为空");
    }
    if (StringUtil.isEmpty(surveyTargetVO.getEndTime())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间为空");
    }
    Timestamp statTime = DateUtil.str2Timestam(surveyTargetVO.getStartTime());
    Timestamp endTime = DateUtil.str2Timestam(surveyTargetVO.getEndTime());
    if (statTime.getTime() > DateUtil.getCurrentTimeByYMD().getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间不能大于今天");
    }
    if (endTime.getTime() < DateUtil.getCurrentTimeByYMD().getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间不能小于今天");
    }
    if (statTime.getTime() > endTime.getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.ILLEGAL_PARAM, "开始日期不能大于结束日期");
    }
    List<Long> orgIds = this.listOrgIdBySurveyId(surveyTargetVO.getSurveyId());
    Integer count = 0;
    // 当前用户
    Long userId = pmphUser.getId();
    List<Long> listOrgId = new ArrayList<Long>();
    if (CollectionUtil.isEmpty(orgIds)) {
        // 第一次发布
        listOrgId.addAll(surveyTargetVO.getOrgIds());
        surveyService.updateSurvey(new Survey(surveyTargetVO.getSurveyId(), Const.SURVEY_STATUS_1, DateUtil.str2Timestam(surveyTargetVO.getStartTime()), DateUtil.str2Timestam(surveyTargetVO.getEndTime())));
    } else {
        // 第二次发布
        for (Long id : surveyTargetVO.getOrgIds()) {
            if (!orgIds.contains(id)) {
                listOrgId.add(id);
            }
        }
    }
    List<SurveyTarget> list = new ArrayList<SurveyTarget>(listOrgId.size());
    for (Long orgId : listOrgId) {
        list.add(new SurveyTarget(userId, surveyTargetVO.getSurveyId(), orgId));
    }
    if (CollectionUtil.isNotEmpty(list)) {
        // 保存发起问卷中间表
        count = surveyTargetDao.batchSaveSurveyTargetByList(list);
    }
    if (count > 0) {
        // MongoDB 消息插入
        message = messageService.add(message);
        if (StringUtil.isEmpty(message.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
        }
        // 发送消息
        List<WriterUser> writerUserList = // 作家用户
        writerUserService.getWriterUserListByOrgIds(listOrgId);
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
        for (WriterUser writerUser : writerUserList) {
            userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
        }
        // 获取学校管理员集合
        List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(listOrgId);
        // 收件人邮箱
        List<String> orgUserEmail = new ArrayList<String>(orgUserList.size());
        for (OrgUser orgUser : orgUserList) {
            userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, orgUser.getId(), Const.RECEIVER_TYPE_3, 0L));
            if (!"-".equals(orgUser.getEmail()) && !"null".equals(orgUser.getEmail())) {
            // orgUserEmail.add(orgUser.getEmail());// 获取学校管理员邮箱地址
            }
        }
        // Integer size = orgUserEmail.size();
        String[] emails = new String[] { "515944204@qq.com", "2310870657@qq.com", "501331000@qq.com" };
        // String[] toEmail = (String[]) orgUserEmail.toArray(new String[size]);
        if (ArrayUtil.isEmpty(emails)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "收件人邮箱为空");
        }
        // 发送邮件
        JavaMailSenderUtil javaMailSenderUtil = new JavaMailSenderUtil();
        String serverUrl = getLogin2frontUrl().substring(0, getLogin2frontUrl().lastIndexOf("/"));
        // 给学校管理员发送邮件
        javaMailSenderUtil.sendMail(surveyTargetVO.getTitle(), // message.getContent(),
        "<p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>您好:</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>&nbsp; &nbsp; 现有一份《" + surveyTargetVO.getTitle() + "》需要您登陆下面地址,填写您宝贵意见。</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>&nbsp;&nbsp;&nbsp;&nbsp;登陆地址:<a href='" + serverUrl + "/survey/writeSurvey.action?surveyId=" + surveyTargetVO.getSurveyId() + "'>人卫E教平台</a><br/></span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;'><br/></p>", emails);
        // 发送消息
        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, userId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, surveyTargetVO.getTitle(), message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    return count;
}
Also used : SurveyTarget(com.bc.pmpheep.back.po.SurveyTarget) PmphUser(com.bc.pmpheep.back.po.PmphUser) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Timestamp(java.sql.Timestamp) Survey(com.bc.pmpheep.back.po.Survey) JavaMailSenderUtil(com.bc.pmpheep.back.util.mail.JavaMailSenderUtil) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 12 with WebScocketMessage

use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.

the class SurveyTargetServiceImpl method reissueSurveyMessage.

@Override
public Integer reissueSurveyMessage(Message message, String title, Long surveyId, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(surveyId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
    }
    if (StringUtil.isEmpty(title)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷名称为空");
    }
    // MongoDB 消息插入
    message = messageService.add(message);
    if (StringUtil.isEmpty(message.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
    }
    List<Long> listUserId = surveyQuestionAnswerService.getUserIdBySurveyId(surveyId);
    Integer count = 0;
    List<Long> orgIds = this.listOrgIdBySurveyId(surveyId);
    if (CollectionUtil.isNotEmpty(orgIds)) {
        count = orgIds.size();
        Long userId = pmphUser.getId();
        String surveyTitle = title + "-(问卷催办)";
        // 发送消息
        // 作家用户
        List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(orgIds);
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
        for (WriterUser writerUser : writerUserList) {
            if (!listUserId.contains(writerUser.getId())) {
                userMessageList.add(new UserMessage(message.getId(), surveyTitle, Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 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, userId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, surveyTitle, message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    return count;
}
Also used : 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) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 13 with WebScocketMessage

use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.

the class SystemMessageService method sendWhenSubmitDeclarationForm.

/**
 * 作家教材申报表 给学校管理员发送或者人卫教材相关人员发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午4:31:19
 * @param declarationId
 *            申报id
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenSubmitDeclarationForm(Long declarationId) throws CheckedServiceException, IOException {
    // 获取申报表
    Declaration declaration = declarationService.getDeclarationById(declarationId);
    if (null == declaration) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "申报表不存在");
    }
    if (null == declaration.getOrgId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "认证的管理员为空");
    }
    Material material = materialService.getMaterialById(declaration.getMaterialId());
    if (declaration.getOrgId() == 0) {
        // 提交的人卫社
        // 项目编辑 策划编辑 主任 id
        String msgContent = "[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核";
        // 存入消息主体
        Message message = new Message(msgContent);
        message = messageService.add(message);
        String msg_id = message.getId();
        // 主任id
        Long directorId = material.getDirector();
        // 项目编辑列表
        List<MaterialProjectEditorVO> materialProjectEditorList = materialProjectEditorService.listMaterialProjectEditors(material.getId());
        // 批量保存的消息集合
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(materialProjectEditorList.size() + 1);
        List<String> userIds = new ArrayList<String>(materialProjectEditorList.size() + 1);
        userMessageList.add(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), directorId, new Short("1"), null));
        userIds.add("1_" + directorId);
        for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditorList) {
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), materialProjectEditor.getEditorId(), new Short("1"), null);
            userMessageList.add(userMessage);
            userIds.add("1_" + materialProjectEditor.getEditorId());
        }
        // 策划编辑
        // 我申报的书籍
        List<DecPosition> decPositionList = decPositionService.listDecPositions(declarationId);
        for (DecPosition decPosition : decPositionList) {
            Textbook textbook = textbookService.getTextbookById(decPosition.getTextbookId());
            if (null != textbook && null != textbook.getPlanningEditor()) {
                UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), textbook.getPlanningEditor(), new Short("1"), null);
                userMessageList.add(userMessage);
                userIds.add("1_" + textbook.getPlanningEditor());
            }
        }
        // 发送消息
        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);
    } else {
        // 提交的机构
        String msgContent = "贵校老师[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核、打印并快递申报纸质表";
        // 存入消息主体
        Message message = new Message(msgContent);
        message = messageService.add(message);
        String msg_id = message.getId();
        // 获取机构用户
        List<Long> orgIds = new ArrayList<Long>(1);
        orgIds.add(declaration.getOrgId());
        List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(orgIds);
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(orgUserList.size());
        List<String> userIds = new ArrayList<String>(orgUserList.size());
        for (OrgUser orgUser : orgUserList) {
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null);
            userMessageList.add(userMessage);
            userIds.add("3_" + orgUser.getId());
        }
        // 发送消息
        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) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook) Declaration(com.bc.pmpheep.back.po.Declaration)

Example 14 with WebScocketMessage

use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.

the class SystemMessageService method sendWhenConfirmFirstEditor.

/**
 * 遴选主编副主编时点击发布按钮之后向主编、副主编发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午1:57:04
 * @param bookId
 *            教材书籍id
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenConfirmFirstEditor(Long bookId, List<DecPositionPublished> newMessage) throws CheckedServiceException, IOException {
    // 获取教材书籍
    Textbook textbook = textbookService.getTextbookById(bookId);
    if (textbook.getIsPublished()) {
        sendWhenPubfinalResult(bookId, newMessage);
        return;
    }
    // 获取教材
    Material material = materialService.getMaterialById(textbook.getMaterialId());
    if (null == material) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "该书籍没有找到对应的教材");
    }
    // 获取这本书的申报遴选列表
    for (DecPositionPublished decPosition : newMessage) {
        if (null != decPosition && null != decPosition.getChosenPosition() && null != decPosition.getRank()) {
            // 筛选出主编、副主编
            Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
            // 消息内容
            String msgContent = "";
            if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                if (decPosition.getRank() == 1) {
                    if (decPosition.getChosenPosition() == 12) {
                        msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的第一主编和数字编委,您现在可以开始遴选编委了,最终结果以遴选结果公告为准";
                    } else {
                        msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的第一主编,您现在可以开始遴选编委了,最终结果以遴选结果公告为准";
                    }
                } else {
                    if (decPosition.getChosenPosition() == 12) {
                        msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的主编与数字编委,最终结果以遴选结果公告为准";
                    } else {
                        msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的主编,最终结果以遴选结果公告为准";
                    }
                }
            }
            if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                if (decPosition.getChosenPosition() == 10) {
                    msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的副主编和数字编委,最终结果以遴选结果公告为准";
                } else {
                    msgContent = "恭喜您被选为《<font color='red'>" + material.getMaterialName() + "</font>》<font color='red'>[" + textbook.getTextbookName() + "</font>]的副主编,最终结果以遴选结果公告为准";
                }
            }
            Message message = new Message(msgContent);
            message = messageService.add(message);
            String msg_id = message.getId();
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), declaration.getUserId(), new Short("2"), null);
            userMessageService.addUserMessage(userMessage);
            // 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_" + declaration.getUserId());
            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) Textbook(com.bc.pmpheep.back.po.Textbook) ArrayList(java.util.ArrayList) Material(com.bc.pmpheep.back.po.Material) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) Declaration(com.bc.pmpheep.back.po.Declaration)

Example 15 with WebScocketMessage

use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.

the class SystemMessageService method materialSend.

/**
 * 遴选公告发布时,给学校管理员和学校教师发送消息,通知他们留意报名情况或者是参加报名
 *
 * @author Mryang
 * @createDate 2017年11月17日 上午9:28:13
 * @param materialName
 *            教材名称
 * @param ids
 *            发送的机构id集合(新增或者增加的机构)
 * @param msgId
 *            消息id,没有发布过 则为null
 * @param isOnlyManager
 *            是否只发给管理员
 * @throws CheckedServiceException
 * @throws IOException
 * @return
 */
public void materialSend(Long materialId, List<Long> ids, boolean isOnlyManager) throws CheckedServiceException, IOException {
    String materialName = materialService.getMaterialNameById(materialId);
    if (StringUtils.isEmpty(materialName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息体为空");
    }
    if (null == ids || ids.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息接收对象为空");
    }
    // 向教师发送消息
    if (!isOnlyManager) {
        String tercherMsg = "《<font color='red'>" + materialName + "</font>》已经开始申报,请您留意";
        String msg_id = null;
        // mogodb保存消息体
        Message message = new Message(tercherMsg);
        message = messageService.add(message);
        msg_id = message.getId();
        // 获取这些机构启用的作家用户
        List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(ids);
        if (null != writerUserList && writerUserList.size() > 0) {
            List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
            List<String> userIds = new ArrayList<String>(writerUserList.size());
            for (WriterUser writerUser : writerUserList) {
                // 信息是由系统发出
                UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), writerUser.getId(), new Short("2"), materialId);
                userMessageList.add(userMessage);
                userIds.add("2_" + writerUser.getId());
            }
            // 批量插入消息
            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, tercherMsg, DateUtil.getCurrentTime());
            myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
        }
    }
    // 向管理员发送消息
    String managerMsg = "《<font color='red'>" + materialName + "</font>》已经开始申报,请您留意教职工的报名情况";
    Message message = new Message(managerMsg);
    message = messageService.add(message);
    String msg_id = message.getId();
    // 获取这些机构的管理员
    List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(ids);
    if (null != orgUserList && orgUserList.size() > 0) {
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(orgUserList.size());
        List<String> userIds = new ArrayList<String>(orgUserList.size());
        for (OrgUser orgUser : orgUserList) {
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), materialId);
            userMessageList.add(userMessage);
            userIds.add("3_" + orgUser.getId());
        }
        // 批量插入消息
        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, managerMsg, DateUtil.getCurrentTime());
        myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
    }
    return;
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Aggregations

WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)21 ArrayList (java.util.ArrayList)21 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)20 UserMessage (com.bc.pmpheep.back.po.UserMessage)19 Message (com.bc.pmpheep.general.po.Message)16 Declaration (com.bc.pmpheep.back.po.Declaration)7 Material (com.bc.pmpheep.back.po.Material)7 OrgUser (com.bc.pmpheep.back.po.OrgUser)7 PmphUser (com.bc.pmpheep.back.po.PmphUser)6 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)4 WriterUser (com.bc.pmpheep.back.po.WriterUser)4 Textbook (com.bc.pmpheep.back.po.Textbook)3 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)3 CmsContent (com.bc.pmpheep.back.po.CmsContent)2 DecPosition (com.bc.pmpheep.back.po.DecPosition)2 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)2 PmphGroupMessage (com.bc.pmpheep.back.po.PmphGroupMessage)2 Org (com.bc.pmpheep.back.po.Org)1 Survey (com.bc.pmpheep.back.po.Survey)1 SurveyTarget (com.bc.pmpheep.back.po.SurveyTarget)1