update 聊天室根据用户邮箱查找聊天室接口修改
This commit is contained in:
parent
c47c321b76
commit
476cb6711e
|
@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/chat/message")
|
||||
@RequestMapping("/message")
|
||||
@Api(tags = "聊天消息相关接口")
|
||||
public class ChatMessageController {
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class ChatMessageController {
|
|||
public AjaxResult readMessage(
|
||||
@ApiParam(value = "聊天室id", required = true, example = "1")
|
||||
@RequestParam Long roomId) {
|
||||
return null;
|
||||
return chatMessageService.readMessage(roomId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
@Api(tags = "聊天室相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/chat/rooms")
|
||||
@RequestMapping("/rooms")
|
||||
public class ChatRoomController {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.m2pool.chat.interceptor;
|
|||
|
||||
|
||||
import com.m2pool.chat.entity.StompPrincipal;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
|
@ -16,8 +16,6 @@ import org.springframework.messaging.support.MessageHeaderAccessor;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.m2pool.chat.constant.Destination.VISITOR_PREFIX;
|
||||
|
||||
/**
|
||||
* @ClassName WebsocketChannelInterceptor
|
||||
* @Description websocket channel 通道拦截器 适用于前端@stomp/stompjs 实现.
|
||||
|
@ -38,21 +36,16 @@ public class WebsocketChannelInterceptor implements ChannelInterceptor {
|
|||
//获取链接建立时的请求头信息
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
|
||||
if (accessor.getCommand() == StompCommand.CONNECT) {
|
||||
String visitor = (String) accessor.getSessionAttributes().get(VISITOR_PREFIX);
|
||||
LOGGER.info("------------收到websocket的连接消息");
|
||||
//获取channel 中的请求头信息
|
||||
StompHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
Object raw = message.getHeaders().get(SimpMessageHeaderAccessor.NATIVE_HEADERS);
|
||||
System.out.println("raw:"+raw);
|
||||
if (raw instanceof Map) {
|
||||
Object userInfo = ((Map) raw).get("userId");
|
||||
// 游客或登录用户
|
||||
if (userInfo == null){
|
||||
mha.setUser(new StompPrincipal(visitor));
|
||||
}else if(userInfo instanceof ArrayList) {
|
||||
Object userInfo = ((Map) raw).get("email");
|
||||
if(userInfo instanceof ArrayList){
|
||||
mha.setUser(new StompPrincipal((String) ((ArrayList) userInfo).get(0)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (accessor.getCommand() == StompCommand.SEND) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public interface ChatRoomMapper extends BaseMapper<ChatRoom> {
|
|||
* @param email 客服邮箱
|
||||
* @return
|
||||
*/
|
||||
String findRoomByUserEmail(@Param("userEmail") String userEmail,@Param("email") String email);
|
||||
Long findRoomByUserEmail(@Param("userEmail") String userEmail,@Param("email") String email);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.m2pool.chat.service.ChatRoomService;
|
|||
import com.m2pool.chat.vo.CharRoomVo;
|
||||
import com.m2pool.common.core.constant.HttpStatus;
|
||||
import com.m2pool.common.core.utils.PageUtils;
|
||||
import com.m2pool.common.core.utils.StringUtils;
|
||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||
import com.m2pool.common.core.web.page.TableDataInfo;
|
||||
import com.m2pool.common.security.utils.SecurityUtils;
|
||||
|
@ -66,14 +65,16 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
|||
public AjaxResult findRoomByUserid(String email) {
|
||||
//1.查询当前用户与对应用户是否已存在创建的聊天室
|
||||
String userEmail = SecurityUtils.getUsername();
|
||||
String roomByUserEmail = chatRoomMapper.findRoomByUserEmail(userEmail, email);
|
||||
if(StringUtils.isNotEmpty(roomByUserEmail)){
|
||||
return AjaxResult.success(roomByUserEmail);
|
||||
Long roomId = chatRoomMapper.findRoomByUserEmail(userEmail, email);
|
||||
if(roomId != null){
|
||||
return AjaxResult.success(roomId);
|
||||
}
|
||||
ChatRoom build = ChatRoom.builder().userOneEmail(userEmail).userTwoEmail(email).build();
|
||||
//2.不存在创建一个聊天室
|
||||
int insert = chatRoomMapper.insert(ChatRoom.builder().userOneEmail(userEmail).userTwoEmail(email).build());
|
||||
int insert = chatRoomMapper.insert(build);
|
||||
if (insert > 0){
|
||||
return AjaxResult.success(roomByUserEmail);
|
||||
roomId = build.getId();
|
||||
return AjaxResult.success(roomId);
|
||||
}
|
||||
return AjaxResult.error("聊天室不存在,并且创建聊天室失败");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.m2pool.chat.mapper.ChatRoomMapper">
|
||||
|
||||
<select id="findRoomByUserEmail" resultType="java.lang.String">
|
||||
<select id="findRoomByUserEmail" resultType="java.lang.Long">
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
|
|
Loading…
Reference in New Issue