Search in sources :

Example 21 with WebScocketMessage

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

the class PmphGroupMessageServiceImpl method addGroupMessage.

@Override
public String addGroupMessage(String msgConrent, Long groupId, String sessionId, Short senderType) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Long userId = pmphUser.getId();
    PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(groupId, userId, // 获取后台用户
    false);
    if (ObjectUtil.isNull(pmphGroupMemberVO)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "您不是该小组成员,无法与其他成员对话或上传小组文件。");
    }
    PmphGroupMessage pmphGroupMessage;
    if (senderType == 0) {
        pmphGroupMessage = new PmphGroupMessage(groupId, 0L, msgConrent);
    } else {
        pmphGroupMessage = new PmphGroupMessage(groupId, pmphGroupMemberVO.getId(), msgConrent);
    }
    pmphGroupMessageDao.addPmphGroupMessage(pmphGroupMessage);
    pmphGroupMessage = pmphGroupMessageDao.getPmphGroupMessageById(pmphGroupMessage.getId());
    // 将该条消息创建时间作为最后一条消息时间放入该小组中
    PmphGroup pmphGroup = new PmphGroup();
    pmphGroup.setId(groupId);
    pmphGroup.setGmtLastMessage(pmphGroupMessage.getGmtCreate());
    pmphGroupDao.updatePmphGroup(pmphGroup);
    // 进行推送消息步骤1.查询接收人的id 2.进行推送
    List<PmphGroupMemberVO> list = pmphGroupMemberService.listPmphGroupMember(groupId, sessionId);
    List<String> ids = new ArrayList<String>();
    for (PmphGroupMemberVO groupMemberVO : list) {
        String tempId = (groupMemberVO.getIsWriter() ? "2" : "1") + "_" + groupMemberVO.getUserId();
        ids.add(tempId);
    }
    WebScocketMessage webScocketMessage = new WebScocketMessage(String.valueOf(pmphGroupMessage.getId()), Const.MSG_TYPE_3, userId, pmphGroupMemberVO.getDisplayName(), senderType, Const.SEND_MSG_TYPE_0, null, null, msgConrent, pmphGroupMessage.getGmtCreate());
    webScocketMessage.setGroupId(groupId);
    webScocketMessage.setSenderIcon(pmphGroupMemberVO.getAvatar());
    handler.sendWebSocketMessageToUser(ids, webScocketMessage);
    return "SUCCESS";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) PmphGroupMessage(com.bc.pmpheep.back.po.PmphGroupMessage)

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