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";
}
Aggregations