update bug 修改
This commit is contained in:
parent
798bec4812
commit
c0fea6a787
|
@ -8,6 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||||
import springfox.documentation.service.*;
|
import springfox.documentation.service.*;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||||
|
@ -28,6 +29,7 @@ import java.util.function.Predicate;
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
|
@EnableOpenApi
|
||||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||||
public class SwaggerAutoConfiguration {
|
public class SwaggerAutoConfiguration {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.m2pool.chat.controller;
|
package com.m2pool.chat.controller;
|
||||||
|
|
||||||
import com.m2pool.chat.service.ChatMessageService;
|
import com.m2pool.chat.service.ChatMessageService;
|
||||||
|
import com.m2pool.chat.vo.MessagePageVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
import com.m2pool.common.security.annotation.RequiresLogin;
|
import com.m2pool.common.security.annotation.RequiresLogin;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
@ -21,32 +22,18 @@ public class ChatMessageController {
|
||||||
* 查询7天前的历史记录
|
* 查询7天前的历史记录
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/find/history/message")
|
@PostMapping("/find/history/message")
|
||||||
@ApiOperation(value = "查询7天前的历史记录", notes = "根据ID查询7天前的历史记录")
|
@ApiOperation(value = "查询7天前的历史记录", notes = "根据ID查询7天前的历史记录")
|
||||||
@RequiresLogin
|
@RequiresLogin
|
||||||
public AjaxResult findHistoryMessage(
|
public AjaxResult findHistoryMessage(@RequestBody MessagePageVo pageVo) {
|
||||||
@ApiParam(value = "游标:最后一条消息id", required = true, example = "1")
|
return chatMessageService.findHistoryMessage(pageVo.getId(), pageVo.getPageNum(), pageVo.getRoomId());
|
||||||
@RequestParam(defaultValue = "1") Long id,
|
|
||||||
@ApiParam(value = "分页页码,默认为10条/页", example = "10")
|
|
||||||
@RequestParam(required = false,defaultValue = "10")Integer pageNum,
|
|
||||||
@ApiParam(value = "聊天室id", required = true, example = "1")
|
|
||||||
@RequestParam Long roomId
|
|
||||||
) {
|
|
||||||
return chatMessageService.findHistoryMessage(id,pageNum,roomId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/find/recently/message")
|
@PostMapping("/find/recently/message")
|
||||||
@ApiOperation(value = "查询七天内的记录", notes = "根据ID查询七天内的记录")
|
@ApiOperation(value = "查询七天内的记录", notes = "根据ID查询七天内的记录")
|
||||||
@RequiresLogin
|
@RequiresLogin
|
||||||
public AjaxResult findRecentlyMessage(
|
public AjaxResult findRecentlyMessage(@RequestBody MessagePageVo pageVo) {
|
||||||
@ApiParam(value = "游标:最后一条消息id", required = true, example = "1")
|
return chatMessageService.findRecentlyMessage(pageVo.getId(), pageVo.getPageNum(), pageVo.getRoomId());
|
||||||
@RequestParam(defaultValue = "1") Long id,
|
|
||||||
@ApiParam(value = "分页页码,默认为10条/页", example = "10")
|
|
||||||
@RequestParam(required = false,defaultValue = "10")Integer pageNum,
|
|
||||||
@ApiParam(value = "聊天室id", required = true, example = "1")
|
|
||||||
@RequestParam Long roomId
|
|
||||||
) {
|
|
||||||
return chatMessageService.findRecentlyMessage(id,pageNum,roomId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/delete/message")
|
@GetMapping("/delete/message")
|
||||||
|
@ -64,10 +51,8 @@ public class ChatMessageController {
|
||||||
@PostMapping("/read/message")
|
@PostMapping("/read/message")
|
||||||
@ApiOperation(value = "聊天室消息改已读")
|
@ApiOperation(value = "聊天室消息改已读")
|
||||||
@RequiresLogin
|
@RequiresLogin
|
||||||
public AjaxResult readMessage(
|
public AjaxResult readMessage(@RequestBody MessagePageVo pageVo) {
|
||||||
@ApiParam(value = "聊天室id", required = true, example = "1")
|
return chatMessageService.readMessage(pageVo.getRoomId());
|
||||||
@RequestParam Long roomId) {
|
|
||||||
return chatMessageService.readMessage(roomId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.m2pool.chat.controller;
|
||||||
|
|
||||||
import com.m2pool.chat.service.ChatRoomService;
|
import com.m2pool.chat.service.ChatRoomService;
|
||||||
import com.m2pool.chat.vo.CharRoomVo;
|
import com.m2pool.chat.vo.CharRoomVo;
|
||||||
|
import com.m2pool.chat.vo.MessagePageVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
import com.m2pool.common.core.web.page.TableDataInfo;
|
import com.m2pool.common.core.web.page.TableDataInfo;
|
||||||
import com.m2pool.common.security.annotation.RequiresLogin;
|
import com.m2pool.common.security.annotation.RequiresLogin;
|
||||||
|
@ -19,11 +20,11 @@ public class ChatRoomController {
|
||||||
private ChatRoomService chatRoomService;
|
private ChatRoomService chatRoomService;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/find/room/list")
|
@PostMapping("/find/room/list")
|
||||||
@ApiOperation(value = "查询客服人员的聊天室列表")
|
@ApiOperation(value = "查询客服人员的聊天室列表")
|
||||||
@RequiresLogin
|
@RequiresLogin
|
||||||
public TableDataInfo findRoomList() {
|
public TableDataInfo findRoomList(@RequestBody MessagePageVo messagePageVo) {
|
||||||
return chatRoomService.findRoomList();
|
return chatRoomService.findRoomList(messagePageVo.getSendDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/find/room/by/userid")
|
@GetMapping("/find/room/by/userid")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.m2pool.chat.controller;
|
package com.m2pool.chat.controller;
|
||||||
|
|
||||||
|
import com.m2pool.chat.entity.StompPrincipal;
|
||||||
import com.m2pool.chat.service.StompService;
|
import com.m2pool.chat.service.StompService;
|
||||||
import com.m2pool.chat.vo.UserMessageVo;
|
import com.m2pool.chat.vo.UserMessageVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
|
@ -32,7 +33,7 @@ public class StompController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@MessageMapping("/send/message")
|
@MessageMapping("/send/message")
|
||||||
@SendToUser("/queue")
|
@SendToUser("/queue")
|
||||||
public AjaxResult sendMessageToUser(@Payload UserMessageVo userMessageVo) {
|
public AjaxResult sendMessageToUser(StompPrincipal principal, @Payload UserMessageVo userMessageVo) {
|
||||||
return stompService.sendMessageToUser(userMessageVo);
|
return stompService.sendMessageToUser(principal,userMessageVo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName WebsocketMessageDto
|
* @ClassName WebsocketMessageDto
|
||||||
* @Description 消息返回对象
|
* @Description 消息返回对象
|
||||||
|
@ -35,4 +37,21 @@ public class WebsocketMessageDto {
|
||||||
* 发送者类型 0 游客 1 登录用户 2 客服人员
|
* 发送者类型 0 游客 1 登录用户 2 客服人员
|
||||||
*/
|
*/
|
||||||
private Integer sendUserType;
|
private Integer sendUserType;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送者邮箱
|
||||||
|
*/
|
||||||
|
private String sendEmail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送时间
|
||||||
|
*/
|
||||||
|
private Date sendTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天室id
|
||||||
|
*/
|
||||||
|
private Long roomId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.m2pool.chat.entity;
|
package com.m2pool.chat.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -12,6 +14,7 @@ import java.time.LocalDateTime;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ChatMessage {
|
public class ChatMessage {
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
private Integer type;
|
private Integer type;
|
||||||
private Integer read;
|
private Integer read;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.m2pool.chat.entity;
|
package com.m2pool.chat.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -10,6 +12,7 @@ import java.time.LocalDateTime;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ChatMessageHistory {
|
public class ChatMessageHistory {
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
private Integer type;
|
private Integer type;
|
||||||
private String sendEmail;
|
private String sendEmail;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.m2pool.chat.entity;
|
package com.m2pool.chat.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -12,6 +14,7 @@ import java.time.LocalDateTime;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ChatRoom {
|
public class ChatRoom {
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
private String userOneEmail;
|
private String userOneEmail;
|
||||||
private String userTwoEmail;
|
private String userTwoEmail;
|
||||||
|
|
|
@ -17,9 +17,11 @@ public class StompPrincipal implements Principal {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import com.m2pool.chat.entity.ChatRoom;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
@ -18,7 +19,7 @@ public interface ChatRoomMapper extends BaseMapper<ChatRoom> {
|
||||||
* @param userEmail 客服邮箱
|
* @param userEmail 客服邮箱
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ChatRoomDto> findRoomList(@Param("userEmail") String userEmail);
|
List<ChatRoomDto> findRoomList(@Param("userEmail") String userEmail, @Param("sendDateTime") LocalDateTime sendDateTime);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,16 @@ import com.m2pool.chat.vo.CharRoomVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
import com.m2pool.common.core.web.page.TableDataInfo;
|
import com.m2pool.common.core.web.page.TableDataInfo;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public interface ChatRoomService extends IService<ChatRoom> {
|
public interface ChatRoomService extends IService<ChatRoom> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询客服的聊天室列表
|
* 查询客服的聊天室列表
|
||||||
|
* @param sendDateTime 最后一个发送者发送时间
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
TableDataInfo findRoomList();
|
TableDataInfo findRoomList(LocalDateTime sendDateTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据当前用户邮箱查询聊天室
|
* 根据当前用户邮箱查询聊天室
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.m2pool.chat.service;
|
package com.m2pool.chat.service;
|
||||||
|
|
||||||
|
import com.m2pool.chat.entity.StompPrincipal;
|
||||||
import com.m2pool.chat.vo.UserMessageVo;
|
import com.m2pool.chat.vo.UserMessageVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
|
|
||||||
|
@ -10,6 +11,6 @@ public interface StompService {
|
||||||
* @param userMessageVo
|
* @param userMessageVo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AjaxResult sendMessageToUser(UserMessageVo userMessageVo);
|
AjaxResult sendMessageToUser(StompPrincipal principal, UserMessageVo userMessageVo);
|
||||||
|
|
||||||
}
|
}
|
|
@ -55,7 +55,6 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
||||||
public AjaxResult readMessage(Long roomId) {
|
public AjaxResult readMessage(Long roomId) {
|
||||||
ChatRoom chatRoom = chatRoomMapper.selectById(roomId);
|
ChatRoom chatRoom = chatRoomMapper.selectById(roomId);
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
|
|
||||||
if (chatRoom != null){
|
if (chatRoom != null){
|
||||||
String updateUserEmail = "";
|
String updateUserEmail = "";
|
||||||
if( username.equals(chatRoom.getUserOneEmail())){
|
if( username.equals(chatRoom.getUserOneEmail())){
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -39,12 +40,11 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo findRoomList() {
|
public TableDataInfo findRoomList(LocalDateTime sendDateTime) {
|
||||||
PageUtils.clearPage();
|
|
||||||
PageUtils.startPage();
|
|
||||||
String userEmail = SecurityUtils.getUsername();
|
String userEmail = SecurityUtils.getUsername();
|
||||||
|
PageUtils.startPage();
|
||||||
//1.查找当前客服对应的聊天室
|
//1.查找当前客服对应的聊天室
|
||||||
List<ChatRoomDto> roomList = chatRoomMapper.findRoomList(userEmail);
|
List<ChatRoomDto> roomList = chatRoomMapper.findRoomList(userEmail,sendDateTime);
|
||||||
List<String> userEmails = roomList.stream().map(ChatRoomDto::getUserEmail).collect(Collectors.toList());
|
List<String> userEmails = roomList.stream().map(ChatRoomDto::getUserEmail).collect(Collectors.toList());
|
||||||
//2.查询未读数量
|
//2.查询未读数量
|
||||||
if (!userEmails.isEmpty()){
|
if (!userEmails.isEmpty()){
|
||||||
|
@ -55,6 +55,7 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
PageUtils.clearPage();
|
||||||
return getDataTable(roomList);
|
return getDataTable(roomList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ import com.m2pool.chat.constant.Destination;
|
||||||
import com.m2pool.chat.dto.WebsocketMessageDto;
|
import com.m2pool.chat.dto.WebsocketMessageDto;
|
||||||
import com.m2pool.chat.entity.ChatMessage;
|
import com.m2pool.chat.entity.ChatMessage;
|
||||||
import com.m2pool.chat.entity.ChatRoom;
|
import com.m2pool.chat.entity.ChatRoom;
|
||||||
|
import com.m2pool.chat.entity.StompPrincipal;
|
||||||
import com.m2pool.chat.mapper.ChatMessageMapper;
|
import com.m2pool.chat.mapper.ChatMessageMapper;
|
||||||
import com.m2pool.chat.mapper.ChatRoomMapper;
|
import com.m2pool.chat.mapper.ChatRoomMapper;
|
||||||
import com.m2pool.chat.service.StompService;
|
import com.m2pool.chat.service.StompService;
|
||||||
import com.m2pool.chat.vo.UserMessageVo;
|
import com.m2pool.chat.vo.UserMessageVo;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
import com.m2pool.common.core.web.Result.AjaxResult;
|
||||||
import com.m2pool.common.security.utils.SecurityUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.messaging.simp.user.SimpUserRegistry;
|
import org.springframework.messaging.simp.user.SimpUserRegistry;
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static com.m2pool.chat.constant.UserType.CUSTOMER;
|
import static com.m2pool.chat.constant.UserType.CUSTOMER;
|
||||||
import static com.m2pool.chat.constant.UserType.TOURIST;
|
import static com.m2pool.chat.constant.UserType.TOURIST;
|
||||||
|
@ -43,24 +44,35 @@ public class StompServiceImpl implements StompService {
|
||||||
private TransactionTemplate transactionTemplate;
|
private TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult sendMessageToUser(UserMessageVo userMessageVo) {
|
public AjaxResult sendMessageToUser(StompPrincipal principal, UserMessageVo userMessageVo) {
|
||||||
// 检查目标用户是否在线
|
// 检查目标用户是否在线
|
||||||
if (!checkOnline(userMessageVo)) {
|
if (!checkOnline(userMessageVo)) {
|
||||||
return AjaxResult.error("目标用户不在线");
|
return AjaxResult.error("目标用户不在线");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebsocketMessageDto build = WebsocketMessageDto.builder()
|
||||||
|
.type(userMessageVo.getType())
|
||||||
|
.content(userMessageVo.getContent())
|
||||||
|
.sendEmail(principal.getName())
|
||||||
|
.sendUserType(principal.getType())
|
||||||
|
.sendTime(new Date())
|
||||||
|
.build();
|
||||||
|
if(!TOURIST.equals(userMessageVo.getReceiveUserType())){
|
||||||
|
build.setRoomId(userMessageVo.getRoomId());
|
||||||
|
}
|
||||||
//当前用户发送其他人, 发送给指定用户. 否则默认发送给当前发送者
|
//当前用户发送其他人, 发送给指定用户. 否则默认发送给当前发送者
|
||||||
messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE + "/" + userMessageVo.getEmail(),
|
messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE + "/" + userMessageVo.getEmail(),build);
|
||||||
WebsocketMessageDto.builder().type(userMessageVo.getType()).content(userMessageVo.getContent()).sendUserType(userMessageVo.getSendUserType()).build());
|
|
||||||
// 接收者和发送者 都不是游客才能存储消息 和修改聊天室信息。后续可改为消息中间件解耦形式。
|
// 接收者和发送者 都不是游客才能存储消息 和修改聊天室信息。后续可改为消息中间件解耦形式。
|
||||||
if (!TOURIST.equals(userMessageVo.getReceiveUserType()) && !TOURIST.equals(userMessageVo.getSendUserType())){
|
if (!TOURIST.equals(userMessageVo.getReceiveUserType()) && !TOURIST.equals(principal.getType())){
|
||||||
|
|
||||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||||
@Override
|
@Override
|
||||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
try {
|
try {
|
||||||
// 插入消息并获取 ID
|
// 插入消息并获取 ID
|
||||||
insertMessage(userMessageVo);
|
insertMessage(principal,userMessageVo);
|
||||||
// 更新房间信息
|
// 更新房间信息
|
||||||
updateRoom(userMessageVo);
|
updateRoom(userMessageVo.getRoomId(),principal.getType());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 回滚事务
|
// 回滚事务
|
||||||
status.setRollbackOnly();
|
status.setRollbackOnly();
|
||||||
|
@ -87,9 +99,9 @@ public class StompServiceImpl implements StompService {
|
||||||
* @param userMessageVo
|
* @param userMessageVo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Long insertMessage(UserMessageVo userMessageVo){
|
private Long insertMessage(StompPrincipal principal,UserMessageVo userMessageVo){
|
||||||
ChatMessage message = ChatMessage.builder()
|
ChatMessage message = ChatMessage.builder()
|
||||||
.sendEmail(SecurityUtils.getUsername())
|
.sendEmail(principal.getName())
|
||||||
.content(userMessageVo.getContent())
|
.content(userMessageVo.getContent())
|
||||||
.type(userMessageVo.getType())
|
.type(userMessageVo.getType())
|
||||||
.roomId(userMessageVo.getRoomId())
|
.roomId(userMessageVo.getRoomId())
|
||||||
|
@ -100,15 +112,16 @@ public class StompServiceImpl implements StompService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改聊天信息
|
* 修改聊天信息
|
||||||
* @param userMessageVo
|
* @param roomId
|
||||||
|
* @param sendUserType
|
||||||
*/
|
*/
|
||||||
private void updateRoom(UserMessageVo userMessageVo){
|
private void updateRoom(Long roomId,Integer sendUserType){
|
||||||
ChatRoom room = ChatRoom.builder().id(userMessageVo.getRoomId()).build();
|
ChatRoom room = ChatRoom.builder().id(roomId).build();
|
||||||
if (CUSTOMER.equals(userMessageVo.getSendUserType())) {
|
if (CUSTOMER.equals(sendUserType)) {
|
||||||
room.setLastCustomerSendTime(LocalDateTime.now());
|
room.setLastCustomerSendTime(LocalDateTime.now());
|
||||||
} else {
|
} else {
|
||||||
room.setLastUserSendTime(LocalDateTime.now());
|
room.setLastUserSendTime(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
chatRoomMapper.insert(room);
|
chatRoomMapper.updateById(room);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.m2pool.chat.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName MessagePageVo
|
||||||
|
* @Description TODO
|
||||||
|
* @Author yyb
|
||||||
|
* @Date 2025/4/22 17:09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MessagePageVo {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Integer pageNum;
|
||||||
|
private Long roomId;
|
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime sendDateTime;
|
||||||
|
|
||||||
|
public MessagePageVo() {
|
||||||
|
this.id = 1L;
|
||||||
|
this.pageNum = 20;
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,15 +31,11 @@ public class UserMessageVo {
|
||||||
*/
|
*/
|
||||||
private Integer receiveUserType;
|
private Integer receiveUserType;
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送者类型 0 游客 1 登录用户 2 客服人员
|
|
||||||
*/
|
|
||||||
private Integer sendUserType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天室id
|
* 聊天室id
|
||||||
*/
|
*/
|
||||||
private Long roomId;
|
private Long roomId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@ server:
|
||||||
mime-types: application/json
|
mime-types: application/json
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant-path-matcher
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: m2pool-chat
|
name: m2pool-chat
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
create_time as createTime
|
create_time as createTime
|
||||||
FROM chat_message_history
|
FROM chat_message_history
|
||||||
WHERE id <![CDATA[ <= ]]> #{id} AND room_id = #{roomId}
|
WHERE id <![CDATA[ <= ]]> #{id} AND room_id = #{roomId}
|
||||||
ORDER BY create_time DESC
|
ORDER BY id DESC
|
||||||
LIMIT #{pageNum}
|
LIMIT #{pageNum}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -11,7 +11,7 @@
|
||||||
create_time as createTime
|
create_time as createTime
|
||||||
FROM chat_message
|
FROM chat_message
|
||||||
WHERE id <![CDATA[ <= ]]> #{id} AND room_id = #{roomId}
|
WHERE id <![CDATA[ <= ]]> #{id} AND room_id = #{roomId}
|
||||||
ORDER BY create_time DESC
|
ORDER BY id DESC
|
||||||
LIMIT #{pageNum}
|
LIMIT #{pageNum}
|
||||||
</select>
|
</select>
|
||||||
<select id="findUnReadNums" resultType="java.util.Map">
|
<select id="findUnReadNums" resultType="java.util.Map">
|
||||||
|
|
|
@ -12,12 +12,11 @@
|
||||||
FROM
|
FROM
|
||||||
chat_room
|
chat_room
|
||||||
WHERE
|
WHERE
|
||||||
user_two_email = #{userEmail}
|
user_two_email = #{userEmail} AND last_user_send_time <![CDATA[ <= ]]> #{sendDateTime}
|
||||||
AND del = FALSE
|
AND del = FALSE
|
||||||
ORDER BY
|
ORDER BY
|
||||||
flag DESC,
|
flag DESC,
|
||||||
last_user_send_time DESC,
|
last_user_send_time DESC
|
||||||
last_customer_send_time DESC
|
|
||||||
</select>
|
</select>
|
||||||
<select id="findRoomByUserEmail" resultType="com.m2pool.chat.dto.ChatRoomDto">
|
<select id="findRoomByUserEmail" resultType="com.m2pool.chat.dto.ChatRoomDto">
|
||||||
SELECT
|
SELECT
|
||||||
|
|
Loading…
Reference in New Issue