Search in sources :

Example 6 with UserMessage

use of com.bc.pmpheep.back.po.UserMessage in project pmph by BCSquad.

the class UserMessageServiceImpl method addOneUserMessage.

@Override
public Integer addOneUserMessage(Message message, Long receiverId, String sessionId) throws CheckedServiceException, IOException {
    // 发送者id
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "发送人为空!");
    }
    // MongoDB 消息插入
    message = messageService.add(message);
    if (StringUtil.isEmpty(message.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
    }
    // 新发消息,发送者Id为登陆用户ID
    Long senderUserId = pmphUser.getId();
    // 装储存数据
    UserMessage userMessage = new UserMessage();
    // 私信发送
    if (null == receiverId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "接收人为空!");
    } else {
        userMessage = new UserMessage(message.getId(), "系统消息", Const.MSG_TYPE_0, senderUserId, Const.SENDER_TYPE_1, receiverId, Const.RECEIVER_TYPE_2);
    }
    // 插入消息发送对象数据
    Integer res = userMessageDao.addUserMessage(userMessage);
    // websocket发送的id
    List<String> websocketUserId = new ArrayList<String>();
    websocketUserId.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
    // webscokt发送消息
    if (CollectionUtil.isNotEmpty(websocketUserId)) {
        WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_0, senderUserId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, message.getContent(), DateUtil.getCurrentTime());
        myWebSocketHandler.sendWebSocketMessageToUser(websocketUserId, webScocketMessage);
    }
    return res;
}
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)

Example 7 with UserMessage

use of com.bc.pmpheep.back.po.UserMessage in project pmph by BCSquad.

the class SystemMessageService method sendWhenInviteJoinGroup.

/**
 * 任意用户被邀请进入小组 向被邀请人发出
 *
 * @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 sendWhenInviteJoinGroup(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 8 with UserMessage

use of com.bc.pmpheep.back.po.UserMessage in project pmph by BCSquad.

the class SystemMessageService method sendWhenTeacherCertificationAudit.

/**
 * 教师认证审 向教师用户发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午2:52:53
 * @param auditorOrgName
 *            认证机构名称,如:首都医科大学,如是人卫社认证的审核,则为:人民卫生出版社
 * @param teacherIds
 *            教师ids
 * @param isPass
 *            true 通过/false 退回
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenTeacherCertificationAudit(String auditorOrgName, List<Long> teacherIds, boolean isPass) throws CheckedServiceException, IOException {
    if (StringUtils.isEmpty(auditorOrgName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "审核机构为空");
    }
    if (null == teacherIds || teacherIds.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "认证的教师为空");
    }
    // 存入消息主体
    // 退回
    String msgContent = "抱歉,您提交的教师认证资料已被[<font color='red'>" + auditorOrgName + "</font>]管理员退回,请您核对后重试";
    if (isPass) {
        // 通过
        msgContent = "恭喜!您提交的教师认证资料已通过[<font color='red'>" + auditorOrgName + "</font>]管理员审核";
    }
    // 存入消息主体
    Message message = new Message(msgContent);
    message = messageService.add(message);
    String msg_id = message.getId();
    // 组装消息和消息对象
    List<UserMessage> userMessageList = new ArrayList<UserMessage>(teacherIds.size());
    List<String> userIds = new ArrayList<String>(teacherIds.size());
    // 发送消息
    for (Long id : teacherIds) {
        UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, new Short("2"), null);
        userMessageList.add(userMessage);
        userIds.add("2_" + 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 9 with UserMessage

use of com.bc.pmpheep.back.po.UserMessage 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 10 with UserMessage

use of com.bc.pmpheep.back.po.UserMessage 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)

Aggregations

UserMessage (com.bc.pmpheep.back.po.UserMessage)25 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)21 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)20 ArrayList (java.util.ArrayList)20 Message (com.bc.pmpheep.general.po.Message)19 OrgUser (com.bc.pmpheep.back.po.OrgUser)8 Declaration (com.bc.pmpheep.back.po.Declaration)7 Material (com.bc.pmpheep.back.po.Material)7 PmphUser (com.bc.pmpheep.back.po.PmphUser)7 WriterUser (com.bc.pmpheep.back.po.WriterUser)6 MessageAttachment (com.bc.pmpheep.back.po.MessageAttachment)3 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)3 Textbook (com.bc.pmpheep.back.po.Textbook)3 BaseTest (com.bc.pmpheep.test.BaseTest)3 Random (java.util.Random)3 Test (org.junit.Test)3 Rollback (org.springframework.test.annotation.Rollback)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