Commit 0b0eb39a by giaogiao

下发状态类型消息: 已读 未读

parent 8bd38a6d
......@@ -70,10 +70,10 @@ public interface ImClientService extends BaseService<ImClient> {
/**
* 获取当前请求的client
* 获取当前请求的client对象
*
* @return
*/
ImClient getClient();
ImClient getCurentClient();
}
......@@ -58,5 +58,4 @@ public interface ImConversationMembersService extends BaseService<ImConversation
* @throws Exception
*/
Paging<ImConversationMembersQueryVo> getImConversationMembersPageList(ImConversationMembersPageParam imConversationMembersPageParam) throws Exception;
}
package com.wecloud.im.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.im.entity.ImInbox;
import com.wecloud.im.param.ImInboxPageParam;
import com.wecloud.im.param.ImInboxQueryVo;
......@@ -71,6 +72,11 @@ public interface ImInboxService extends BaseService<ImInbox> {
*/
ApiResult<Boolean> updateImMsgReceived(ImMsgReceivedStatusUpdate imMsgReceivedUpdate);
ApiResult<Boolean> updateImMsgRead(ImMsgReadStatusUpdate imMsgReadStatusUpdate);
/**
* 消息修改为已读状态
*
* @return
*/
ApiResult<Boolean> updateImMsgRead(ImMsgReadStatusUpdate imMsgReadStatusUpdate) throws JsonProcessingException;
}
......@@ -52,7 +52,7 @@ public class ImClientBlacklistServiceImpl extends BaseServiceImpl<ImClientBlackl
@Override
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> addImClientBlacklist(ImClientBlacklistUpdate imClientBlacklistUpdate) throws Exception {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
ImClient client1 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, client.getFkAppid())
......@@ -74,7 +74,7 @@ public class ImClientBlacklistServiceImpl extends BaseServiceImpl<ImClientBlackl
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> removeImClientBlacklist(ImClientBlacklistUpdate imClientBlacklistUpdate) throws Exception {
// 操作者
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
// 被拉黑者
ImClient client1 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
......@@ -124,7 +124,7 @@ public class ImClientBlacklistServiceImpl extends BaseServiceImpl<ImClientBlackl
Page<ImClientBlacklistQueryVo> page = new PageInfo<>(imClientBlacklistPageParam, OrderItem.desc(getLambdaColumn(ImClientBlacklist::getCreateTime)));
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
IPage<ImClientBlacklistQueryVo> imClientBlacklistPageList = imClientBlacklistMapper.getImClientBlacklistPageList(page, client.getId());
......
......@@ -47,7 +47,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addDeviceInfo(ImClientDeviceInfoAdd imClientDevice) {
ImClient client = getClient();
ImClient client = getCurentClient();
ImClient clientNew = new ImClient();
BeanUtils.copyProperties(imClientDevice, clientNew);
......@@ -80,7 +80,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
}
@Override
public ImClient getClient() {
public ImClient getCurentClient() {
// shiro线程中获取当前token
JwtToken curentJwtToken = JwtUtil.getCurentJwtToken();
......
......@@ -75,7 +75,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Transactional(rollbackFor = Exception.class)
public ApiResult<ImConversationCreateVo> createImConversation(ImConversationCreate imConversationCreate) {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
// 成员不存在,不能创建会话
for (String id : imConversationCreate.getClientIds()) {
......@@ -194,7 +194,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
public List<MyConversationListVo> getMyImConversationListAndMsgCount() throws Exception {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
// 查询用户加入的所有会话 与每个会话的未读条数 成员
List<MyConversationListVo> myImConversationListAndMsgCount = imConversationMapper.getMyImConversationListAndMsgCount(client.getId());
......@@ -222,7 +222,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
public List<ImConversation> getMyImConversationList() throws Exception {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
return imConversationMapper.getMyImConversationList(client.getId());
}
......
package com.wecloud.im.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.ImInboxPageParam;
import com.wecloud.im.param.ImInboxQueryVo;
import com.wecloud.im.param.ImMsgReadStatusUpdate;
import com.wecloud.im.param.ImMsgReceivedStatusUpdate;
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.model.ResponseModel;
import com.wecloud.im.ws.service.WriteDataService;
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 io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/**
* 消息收件箱表 服务实现类
*
......@@ -36,6 +51,18 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Autowired
private ImClientService imClientService;
@Autowired
private ImMessageService imMessageService;
@Autowired
private ImConversationMembersService imConversationMembersService;
@Autowired
private WriteDataService writeDataService;
@Autowired
private ImApplicationService imApplicationService;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveImInbox(ImInbox imInbox) throws Exception {
......@@ -69,27 +96,117 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Override
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> updateImMsgReceived(ImMsgReceivedStatusUpdate imMsgReceivedUpdate) {
ImClient client = imClientService.getClient();
ImClient curentClient = imClientService.getCurentClient();
// 修改已接收状态
Long aLong = imInboxMapper.updateImMsgReceivedByIds(curentClient.getId(), imMsgReceivedUpdate.getMsgIds());
Long aLong = imInboxMapper.updateImMsgReceivedByIds(client.getId(), imMsgReceivedUpdate.getMsgIds());
// 根据appKey查询appid
ImApplication application = imApplicationService.getById(curentClient.getFkAppid());
// 内容
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("type", "-1009");
stringStringHashMap.put("receiverId", curentClient.getClientId());
// 推送给接收方
sendMsgStatus(curentClient, application, stringStringHashMap, imMsgReceivedUpdate.getMsgIds());
// 是否同时修改为已读状态
if (imMsgReceivedUpdate.getReadStatus()) {
imInboxMapper.updateImMsgReadByIds(client.getId(), imMsgReceivedUpdate.getMsgIds());
}
ImMsgReadStatusUpdate imMsgReadStatusUpdate = new ImMsgReadStatusUpdate();
imMsgReadStatusUpdate.setMsgIds(imMsgReceivedUpdate.getMsgIds());
this.updateImMsgRead(imMsgReadStatusUpdate);
}
return ApiResult.ok();
}
@Override
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> updateImMsgRead(ImMsgReadStatusUpdate imMsgReadStatusUpdate) {
ImClient client = imClientService.getClient();
Long aLong = imInboxMapper.updateImMsgReadByIds(client.getId(), imMsgReadStatusUpdate.getMsgIds());
ImClient curentClient = imClientService.getCurentClient();
// 修改已读状态
Long aLong = imInboxMapper.updateImMsgReadByIds(curentClient.getId(), imMsgReadStatusUpdate.getMsgIds());
// 根据appKey查询appid
ImApplication application = imApplicationService.getById(curentClient.getFkAppid());
// 内容
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("type", "-1010");
stringStringHashMap.put("receiverId", curentClient.getClientId());
sendMsgStatus(curentClient, application, stringStringHashMap, imMsgReadStatusUpdate.getMsgIds());
return ApiResult.ok();
}
/**
* 下发状态类型消息
*
* @param curentClient 当前客户端
* @param application 当前应用
* @param stringStringHashMap 消息content内容
* @param msgIds 消息id集合
*/
private void sendMsgStatus(ImClient curentClient, ImApplication application, HashMap<String, String> stringStringHashMap, List<Long> msgIds) {
// 遍历消息id集合
for (Long MsgId : msgIds) {
// 查询该消息
ImMessage imMessageDb = imMessageService.getById(MsgId);
// 根据消息id查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkConversationId, imMessageDb.getFkConversationId())
.notIn(ImConversationMembers::getFkClientId, curentClient.getId())
);
// 遍历发送给该会话的每个成员
for (ImConversationMembers conversationMember : membersList) {
// 消息实体
ImMessage imMessage = new ImMessage();
imMessage.setId(MsgId);
imMessage.setCreateTime(new Date());
imMessage.setFkAppid(curentClient.getFkAppid());
imMessage.setSender(curentClient.getId());
imMessage.setWithdraw(false);
imMessage.setEvent(true);
imMessage.setSystem(false);
imMessage.setSendStatus(2);
imMessage.setFkConversationId(conversationMember.getFkConversationId());
// 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
BeanUtils.copyProperties(imMessage, imMessageOnlineSend);
imMessageOnlineSend.setMsgId(imMessage.getId());
imMessageOnlineSend.setSender(curentClient.getClientId());
imMessageOnlineSend.setContent(stringStringHashMap);
imMessageOnlineSend.setConversationId(conversationMember.getFkConversationId());
// 查询接收方
ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, curentClient.getId())
.eq(ImClient::getId, conversationMember.getFkClientId()));
if (imClientReceiver == null) {
continue;
}
// 向接收方推送
ResponseModel<ImMessageOnlineSend> responseModel = new ResponseModel<>();
responseModel.setCmd(ResponseModel.ONLINE_MSG);
ApiResult<Boolean> result = ApiResult.result(ApiCode.SUCCESS);
responseModel.setCode(result.getCode());
responseModel.setMsg(result.getMessage());
responseModel.setData(imMessageOnlineSend);
responseModel.setReqId(null);
writeDataService.write(responseModel, application.getAppKey(), imClientReceiver.getClientId());
}
}
}
}
......@@ -51,7 +51,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
@Override
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> updateMsgWithdrawById(Long msgId) {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
// 判断该消息是否是该客户端发送
ImMessage messageById = this.getById(msgId);
......@@ -81,7 +81,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
@Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> updateMsgById(ImMsgUpdate imMsgUpdate) {
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
/* // 判断该消息是否是该客户端发送
ImMessage messageById = this.getById(imMsgUpdate.getId());
......@@ -163,7 +163,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
// 返回数据
List<ImMessageOfflineListVo> imMessageOfflineListVoList = new ArrayList<>();
ImClient client = imClientService.getClient();
ImClient client = imClientService.getCurentClient();
// 获取加入的所有会话
List<ImConversation> myImConversationList = imConversationService.getMyImConversationList();
......
......@@ -175,11 +175,6 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
// 遍历发送
for (ImConversationMembers conversationMembers : membersList) {
// // 排除发送者自己
// if (conversationMembers.getFkClientId().equals(imClientSender.getId())) {
// membersList.remove(conversationMembers);
// continue;
// }
// 保存收件箱
long imInboxId = SnowflakeUtil.getId();
ImInbox imInbox = new ImInbox();
......@@ -211,7 +206,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
responseModel.setReqId(null);
writeDataService.write(responseModel, appKey, imClientReceiver.getClientId());
// 异步推送
// 异步推送系统通知消息
pushTask.push(imClientReceiver, imClientSender, imMessage, imApplication);
}
......
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