Commit adfd5e2f by giaogiao

查询会话的最后一条消息;获取加入的所有会话

parent 96cac575
package com.wecloud.im.constant;
/**
* @ClassName Constant
* @Descripteion 请写点注释吧!
* @Date 2020/10/13 14:08
* @Version 1.0
**/
public class Constant {
/**
* 卓美亚商家ID
*/
public static final Long MC_ID = 1L;
}
......@@ -45,4 +45,15 @@ public class ImApplication extends BaseEntity {
@ApiModelProperty("app名称")
private String appName;
@ApiModelProperty("ios推送证书")
private String iosPush;
@ApiModelProperty("安卓推送证书")
private String androidPush;
@ApiModelProperty("友盟推送key")
private String umengKey;
@ApiModelProperty("友盟推送密钥")
private String umengSecret;
}
......@@ -42,13 +42,12 @@ public class ImClient extends BaseEntity {
@ApiModelProperty("可选 自定义属性,供开发者扩展使用。")
private String attributes;
@ApiModelProperty("ios推送证书")
private String iosPushFile;
@ApiModelProperty("安卓推送证书")
private String androidPushFile;
@ApiModelProperty("客户方提供的唯一id")
private String clientId;
@ApiModelProperty("设备不想收到推送提醒, 1想, 0不想")
private Integer valid;
@ApiModelProperty("设备类型1:ios; 2:android")
private Integer deviceType;
}
......@@ -57,4 +57,22 @@ public interface ImMessageMapper extends BaseMapper<ImMessage> {
* @return
*/
List<OfflineMsgDto> getOfflineListByClientAndConversation(@Param("clientId") Long clientId, @Param("conversationId") Long conversationId);
/**
* 查询会话接收的的最后一条消息
*
* @param clientId
* @param conversationId
* @return
*/
OfflineMsgDto getReceivedLastMsgByConversationId(@Param("clientId") Long clientId, @Param("conversationId") Long conversationId);
/**
* 查询会话的最后一条消息
*
* @param conversationId
* @return
*/
OfflineMsgDto getLastMsgByConversationId(@Param("conversationId") Long conversationId);
}
......@@ -22,7 +22,7 @@ import java.util.List;
public class ImMsgReceivedUpdate extends BaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty("可选 邀请加入会话的客户端,如创建单聊,则填入对方的clientId")
@ApiModelProperty("消息id数组,可以传入单个或多个, 如接收离线消息列表时可以批量修改 则传入多个")
private List<Long> msgIds;
}
......@@ -77,6 +77,12 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/
List<MyConversationListVo> getMyImConversationListAndMsgCount() throws Exception;
/**
* 获取加入的所有会话
*
* @return
* @throws Exception
*/
List<ImConversation> getMyImConversationList() throws Exception;
......
......@@ -93,4 +93,23 @@ public interface ImMessageService extends BaseService<ImMessage> {
List<OfflineMsgDto> getOfflineListByClientAndConversation(Long clientId, Long conversationId);
/**
* 查询会话接收的最后一条消息
*
* @param clientId
* @param conversationId
* @return
*/
OfflineMsgDto getReceivedLastMsgByConversationId(Long clientId, Long conversationId);
/**
* 查询会话的最后一条消息
*
* @param conversationId
* @return
*/
OfflineMsgDto getLastMsgByConversationId(Long conversationId);
}
......@@ -18,8 +18,10 @@ import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.service.ImConversationMembersService;
import com.wecloud.im.service.ImConversationService;
import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.vo.ImConversationCreateVo;
import com.wecloud.im.vo.MyConversationListVo;
import com.wecloud.im.vo.OfflineMsgDto;
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;
......@@ -62,6 +64,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Autowired
private ImApplicationService imApplicationService;
@Autowired
private ImMessageService imMessageService;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveImConversation(ImConversation imConversation) throws Exception {
......@@ -74,6 +79,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
// 判断是否已经存在会话
// 两个用户如果已经创建过会话,不能重复创建会话
// 会话id
Long imConversationId = SnowflakeUtil.getId();
......@@ -169,15 +175,24 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
ImClient client = imClientService.getClient();
// 查询用户加入的所有会话 与每个会话的未读条数 成员
List<MyConversationListVo> myImConversationListAndMsgCount = imConversationMapper.getMyImConversationListAndMsgCount(client.getId());
JsonMapper jsonMapper = new JsonMapper();
// 返回的
List<MyConversationListVo> myImConversationListAndMsgCountNew = new ArrayList<>();
// 转换json格式
for (MyConversationListVo myconversationlistvo : myImConversationListAndMsgCount) {
HashMap attributess = jsonMapper.readValue(myconversationlistvo.getAttribute(), HashMap.class);
myconversationlistvo.setAttributes(attributess);
// 查询会话的最后一条消息
OfflineMsgDto lastMsg = imMessageService.getLastMsgByConversationId(myconversationlistvo.getId());
myconversationlistvo.setLastMsg(lastMsg);
myImConversationListAndMsgCountNew.add(myconversationlistvo);
}
return myImConversationListAndMsgCountNew;
......
......@@ -69,7 +69,6 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
public ApiResult<Boolean> updateImMsgReceived(ImMsgReceivedUpdate imMsgReceivedUpdate) {
ImClient client = imClientService.getClient();
Long aLong = imInboxMapper.updateImMsgReceivedByIds(client.getId(), imMsgReceivedUpdate.getMsgIds());
return ApiResult.ok();
......
......@@ -131,4 +131,15 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
}
@Override
public OfflineMsgDto getReceivedLastMsgByConversationId(Long clientId, Long conversationId) {
return imMessageMapper.getReceivedLastMsgByConversationId(clientId, conversationId);
}
@Override
public OfflineMsgDto getLastMsgByConversationId(Long conversationId) {
return imMessageMapper.getLastMsgByConversationId(conversationId);
}
}
......@@ -116,7 +116,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
);
if (membersList.isEmpty()) {
log.error("membersList为空");
log.error("membersList为空,toConversationId:" + toConversationId);
return;
}
......
......@@ -3,8 +3,6 @@ package com.wecloud.im.tillo.netty.handler;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.tillo.app_ws.WsHandler;
import com.wecloud.im.tillo.app_ws.model.WsConstants;
import com.wecloud.im.tillo.app_ws.service.MangerChannelService;
......@@ -21,7 +19,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -44,18 +41,9 @@ public class NettyApiRequest {
@Resource
private MangerChannelService appUserChannelsService;
@Autowired
private StringRedisTemplate redisTemplate;
@Resource
private WsHandler appImHandler;
@Autowired
private ImClientService imClientService;
@Autowired
private ImApplicationService imApplicationService;
/**
* http请求接收
*
......@@ -103,21 +91,6 @@ public class NettyApiRequest {
String appKey = (String) jsonObject.get("appKey");
String clientId = (String) jsonObject.get(CommonConstant.CLIENT_ID);
// 验签token
// ImApplication imApplication = imApplicationService.getOne(new QueryWrapper<ImApplication>().lambda()
// .eq(ImApplication::getAppKey, appKey));
// if (!JwtUtil.verifyToken(token, imApplication.getAppSecret())) {
// log.debug("验签token不通过");
// }
//
// String redisKey = "client:" + appKey + ":" + clientId;
// String redisToken = redisTemplate.opsForValue().get(redisKey);
//
// // 判断token和redis是否一致
// if (!token.equals(redisToken)) {
// log.debug("token和redis不一致");
// }
if (StringUtils.isBlank(token)) {
throw new AuthenticationException("token不能为空");
}
......@@ -129,7 +102,7 @@ public class NettyApiRequest {
JwtToken jwtToken = shiroLoginService.getTJwtTokenForRedis(token);
if (jwtToken == null) {
log.error("jwtToken == null ,token和redis不一致");
log.error("jwtToken == null ,token和redis不一致, clientId:" + clientId + ",token:" + token);
return;
}
......
......@@ -52,4 +52,7 @@ public class MyConversationListVo implements Serializable {
@ApiModelProperty("成员")
private String members;
@ApiModelProperty("会话最后一条消息")
private OfflineMsgDto lastMsg;
}
\ No newline at end of file
......@@ -25,9 +25,6 @@ public class OfflineMsgDto implements Serializable {
@ApiModelProperty("撤回时间")
private Date withdrawTime;
@ApiModelProperty("修改时间")
private Date updateDate;
@ApiModelProperty("发送者客户端id")
private String sender;
......@@ -45,5 +42,4 @@ public class OfflineMsgDto implements Serializable {
@ApiModelProperty("at他人,传入客户端id数组")
private String at;
}
......@@ -5,7 +5,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, create_time, update_time, app_key, app_secret, app_name
, create_time, update_time, app_key, app_secret, app_name, ios_push, android_push,umeng_key,umeng_secret
</sql>
<select id="getImApplicationById" resultType="com.wecloud.im.param.ImApplicationQueryVo">
......
......@@ -5,7 +5,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, create_time, update_time, fk_appid, attributes, ios_push_file, android_push_file
, create_time, update_time, fk_appid, attributes,device_type,valid
</sql>
<select id="getImClientById" resultType="com.wecloud.im.param.ImClientQueryVo">
......
......@@ -61,5 +61,44 @@
WHERE fk_conversation_id = #{param.conversationId}
ORDER BY `im_message`.`create_time` DESC
</select>
<select id="getReceivedLastMsgByConversationId" resultType="com.wecloud.im.vo.OfflineMsgDto">
SELECT im_message.id AS id,
im_message.create_time,
im_message.withdraw_time,
im_message.update_date,
`im_client`.client_id AS sender,
im_message.content,
im_message.withdraw,
im_message.`event`,
im_message.system,
im_message.`at`,
im_message.send_status,
im_message.fk_conversation_id
FROM im_inbox
INNER JOIN im_message ON im_message.id = im_inbox.fk_msg_id
INNER JOIN im_client AS im_client ON im_client.id = im_message.sender
WHERE im_inbox.receiver = #{clientId}
AND im_inbox.fk_conversation_id = #{conversationId}
ORDER BY create_time DESC LIMIT 1
</select>
<select id="getLastMsgByConversationId" resultType="com.wecloud.im.vo.OfflineMsgDto">
SELECT im_message.id AS id,
im_message.create_time,
im_message.withdraw_time,
im_message.update_date,
`im_client`.client_id AS sender,
im_message.content,
im_message.withdraw,
im_message.`event`,
im_message.system,
im_message.`at`,
im_message.send_status,
im_message.fk_conversation_id
FROM im_message
INNER JOIN im_client AS im_client ON im_client.id = im_message.sender
WHERE im_message.fk_conversation_id = #{conversationId}
ORDER BY create_time DESC LIMIT 1
</select>
</mapper>
......@@ -73,7 +73,9 @@ public class JwtFilter extends AuthenticatingFilter {
// 从redis 获取jwt数据
JwtToken jwtToken = shiroLoginService.getTJwtTokenForRedis(token);
if (jwtToken == null) {
throw new AuthenticationException("Redis Token不存在,token:" + token);
}
return JwtToken.build(token, jwtToken.getSalt(), jwtToken.getExpireSecond(), jwtToken.getClientId(), jwtToken.getAppKey());
}
......
......@@ -137,9 +137,6 @@ public class ShiroLoginServiceImpl implements ShiroLoginService {
String tokenMd5 = DigestUtils.md5Hex(token);
jwtTokenRedisVo = redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_TOKEN, tokenMd5));
// boolean redisExpired = sysLoginRedisService.exists(token); // 判断是否存在
if (jwtTokenRedisVo == null) {
throw new AuthenticationException("Redis Token不存在,token:" + token);
}
}
return (JwtToken) jwtTokenRedisVo;
}
......
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