Commit 35335d3a by Future

消息已读修改调整

parent 1859e55a
......@@ -15,52 +15,6 @@ import io.geekidea.springbootplus.framework.common.service.BaseService;
*/
public interface ImInboxService extends BaseService<ImInbox> {
// /**
// * 保存
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean saveImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 修改
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean updateImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 删除
// *
// * @param id
// * @return
// * @throws Exception
// */
// boolean deleteImInbox(Long id) throws Exception;
//
// /**
// * 根据ID获取查询对象
// *
// * @param id
// * @return
// * @throws Exception
// */
// ImInboxQueryVo getImInboxById(Long id) throws Exception;
//
// /**
// * 获取分页对象
// *
// * @param imInboxPageParam
// * @return
// * @throws Exception
// */
// Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception;
/**
* 消息修改为已接收状态
*
......
package com.wecloud.im.service.impl;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.entity.ImConversationMembers;
import com.wecloud.im.entity.ImInbox;
import com.wecloud.im.entity.ImMessage;
import com.wecloud.im.entity.ImMessageOnlineSend;
import com.wecloud.im.mapper.ImInboxMapper;
import com.wecloud.im.param.ImMsgReceivedStatusUpdate;
import com.wecloud.im.param.MsgReadStatusUpdateParam;
import com.wecloud.im.param.UpdateMsgReadStatusByConversationParam;
import com.wecloud.im.sdk.enums.ReadMsgStatusEnum;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.service.ImConversationMembersService;
import com.wecloud.im.service.ImInboxService;
import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.ws.enums.MsgTypeEnum;
import com.wecloud.im.ws.enums.WsResponseCmdEnum;
import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.sender.ChannelSender;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 消息收件箱表 服务实现类
......@@ -54,73 +30,10 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Autowired
private ImClientService imClientService;
@Autowired
private ImMessageService imMessageService;
@Autowired
private ImConversationMembersService imConversationMembersService;
@Autowired
private ChannelSender channelSender;
@Autowired
private ImApplicationService imApplicationService;
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean saveImInbox(ImInbox imInbox) throws Exception {
// return super.save(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean updateImInbox(ImInbox imInbox) throws Exception {
// return super.updateById(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean deleteImInbox(Long id) throws Exception {
// return super.removeById(id);
// }
//
// @Override
// public ImInboxQueryVo getImInboxById(Long id) throws Exception {
// return imInboxMapper.getImInboxById(id);
// }
//
// @Override
// public Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception {
// Page<ImInboxQueryVo> page = new PageInfo<>(imInboxPageParam, OrderItem.desc(getLambdaColumn(ImInbox::getCreateTime)));
// IPage<ImInboxQueryVo> iPage = imInboxMapper.getImInboxPageList(page, imInboxPageParam);
// return new Paging<ImInboxQueryVo>(iPage);
// }
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateImMsgReceived(ImMsgReceivedStatusUpdate imMsgReceivedUpdate) {
ImClient curentClient = imClientService.getCurrentClient();
// 修改已接收状态
Long aLong = imInboxMapper.updateImMsgReceivedByIds(curentClient.getId(), imMsgReceivedUpdate.getMsgIds());
// 根据appKey查询appid
ImApplication application = imApplicationService.getCacheById(curentClient.getFkAppid());
// 内容
HashMap<String, String> contentMap = new HashMap<>();
contentMap.put("receiverId", curentClient.getClientId());
// 推送给接收方
sendMsgStatus(curentClient, MsgTypeEnum.CLIENT_RECEIVED_MSG, contentMap, imMsgReceivedUpdate.getMsgIds());
// 是否同时修改为已读状态
if (imMsgReceivedUpdate.getReadStatus()) {
MsgReadStatusUpdateParam msgReadStatusUpdateParam = new MsgReadStatusUpdateParam();
msgReadStatusUpdateParam.setMsgIds(imMsgReceivedUpdate.getMsgIds());
this.updateImMsgRead(msgReadStatusUpdateParam);
}
// 不做接收事件处理
return true;
}
......@@ -138,19 +51,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateImMsgRead(MsgReadStatusUpdateParam msgReadStatusUpdateParam) {
ImClient curentClient = imClientService.getCurrentClient();
// 修改已读状态
Long aLong = imInboxMapper.updateImMsgReadByIds(curentClient.getId(), msgReadStatusUpdateParam.getMsgIds());
// 根据appKey查询appid
ImApplication application = imApplicationService.getCacheById(curentClient.getFkAppid());
// 内容
HashMap<String, String> contentMap = new HashMap<>();
contentMap.put("receiverId", curentClient.getClientId());
sendMsgStatus(curentClient, MsgTypeEnum.CLIENT_READ_MSG, contentMap, msgReadStatusUpdateParam.getMsgIds());
// 小虎豆不做单条消息修改已读
return true;
}
......@@ -158,93 +59,12 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Override
public Boolean updateMsgReadStatusByConversation(UpdateMsgReadStatusByConversationParam param) {
ImClient currentClient = imClientService.getCurrentClient();
// 获取该用户该会话所有未读消息 msgId 列表
List<ImInbox> imInboxList = this.list(new QueryWrapper<ImInbox>().lambda()
this.remove(new QueryWrapper<ImInbox>().lambda()
.eq(ImInbox::getFkConversationId, param.getConversationId())
.eq(ImInbox::getReadMsgStatus, ReadMsgStatusEnum.UNREAD.getCode())
.le(ImInbox::getFkMsgId, param.getMsgIdEnd())
.eq(ImInbox::getReceiver, currentClient.getId()));
if (CollectionUtils.isEmpty(imInboxList)) {
return true;
}
List<Long> msgIds = imInboxList.stream().map(i -> i.getFkMsgId()).collect(Collectors.toList());
// 修改已读状态
imInboxMapper.updateImMsgReadByIds(currentClient.getId(), msgIds);
// 内容
HashMap<String, String> contentMap = Maps.newHashMap();
contentMap.put("receiverId", currentClient.getClientId());
sendMsgStatus(currentClient, MsgTypeEnum.CLIENT_READ_MSG, contentMap, msgIds);
return true;
}
/**
* 下发状态类型消息
*
* @param currentClient 当前客户端
* @param msgTypeEnum 消息类型枚举
* @param contentMap 消息content内容
* @param msgIds 消息id集合
*/
private void sendMsgStatus(ImClient currentClient, MsgTypeEnum msgTypeEnum, HashMap<String, String> contentMap, List<Long> msgIds) {
// 遍历消息id集合
for (Long msgId : msgIds) {
// 查询该消息
ImMessage imMessageDb = imMessageService.getById(msgId);
if (imMessageDb == null) {
log.info("查无消息内容: {}", msgId);
continue;
}
// 根据会话id查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkConversationId, imMessageDb.getFkConversationId())
.notIn(ImConversationMembers::getFkClientId, currentClient.getId())
);
// 遍历发送给该会话的每个成员
for (ImConversationMembers conversationMember : membersList) {
// 消息实体
ImMessage imMessage = new ImMessage();
imMessage.setId(msgId);
imMessage.setMsgType(msgTypeEnum.getUriCode());
imMessage.setCreateTime(new Date());
imMessage.setFkAppid(currentClient.getFkAppid());
imMessage.setSender(currentClient.getId());
imMessage.setWithdraw(false);
imMessage.setEvent(true);
imMessage.setSystemFlag(false);
imMessage.setSendStatus(2);
imMessage.setFkConversationId(conversationMember.getFkConversationId());
// 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
BeanUtils.copyProperties(imMessage, imMessageOnlineSend);
imMessageOnlineSend.setType(msgTypeEnum.getUriCode());
imMessageOnlineSend.setMsgId(imMessage.getId());
imMessageOnlineSend.setCreateTime(new Date());
imMessageOnlineSend.setSender(currentClient.getClientId());
imMessageOnlineSend.setContent(contentMap);
imMessageOnlineSend.setConversationId(conversationMember.getFkConversationId());
// 查询接收方
ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, currentClient.getFkAppid())
.eq(ImClient::getId, conversationMember.getFkClientId()));
if (imClientReceiver == null) {
continue;
}
// 向接收方推送
WsResponse<ImMessageOnlineSend> responseModel = new WsResponse<>();
responseModel.setCmd(WsResponseCmdEnum.ONLINE_EVENT_MSG.getCmdCode());
ApiResult<Boolean> result = ApiResult.result(ApiCode.SUCCESS);
responseModel.setCode(result.getCode());
responseModel.setMsg(result.getMessage());
responseModel.setData(imMessageOnlineSend);
responseModel.setReqId(null);
channelSender.sendMsg(responseModel, imClientReceiver.getId());
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment