update 聊天室列表新增返回对象,新增部分swagger注解

This commit is contained in:
yyb 2025-04-27 14:27:09 +08:00
parent 4dc7964ef4
commit d941b161f9
13 changed files with 69 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package com.m2pool.common.core.web.page; package com.m2pool.common.core.web.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@ -11,23 +13,29 @@ import java.util.List;
* @Author dy * @Author dy
*/ */
@Data @Data
public class TableDataInfo implements Serializable @ApiModel(description = "分页返回对象")
public class TableDataInfo<T> implements Serializable
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 总记录数 */ /** 总记录数 */
@ApiModelProperty(value = "总记录数", example = "1")
private long total; private long total;
/** 总页数 */ /** 总页数 */
@ApiModelProperty(value = "总页数", example = "1")
private long totalPage; private long totalPage;
/** 列表数据 */ /** 列表数据 */
private List<?> rows; @ApiModelProperty(value = "查询结果集合")
private List<T> rows;
/** 消息状态码 */ /** 消息状态码 */
@ApiModelProperty(value = "消息状态码", example = "200")
private int code; private int code;
/** 消息内容 */ /** 消息内容 */
@ApiModelProperty(value = "查询结果描述", example = "成功")
private String msg; private String msg;
/** /**
@ -43,7 +51,7 @@ public class TableDataInfo implements Serializable
* @param list 列表数据 * @param list 列表数据
* @param total 总记录数 * @param total 总记录数
*/ */
public TableDataInfo(List<?> list, int total) public TableDataInfo(List<T> list, int total)
{ {
this.rows = list; this.rows = list;
this.total = total; this.total = total;

View File

@ -18,6 +18,8 @@ public class SwaggerWebConfiguration implements WebMvcConfigurer {
/** swagger-ui 地址 */ /** swagger-ui 地址 */
registry.addResourceHandler("/swagger-ui/**") registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
} }
} }

View File

@ -1,5 +1,6 @@
package com.m2pool.chat.controller; package com.m2pool.chat.controller;
import com.m2pool.chat.dto.ChatRoomDto;
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.RoomPageVo; import com.m2pool.chat.vo.RoomPageVo;
@ -25,7 +26,7 @@ public class ChatRoomController {
@PostMapping("/find/room/list") @PostMapping("/find/room/list")
@ApiOperation(value = "查询客服人员的聊天室列表") @ApiOperation(value = "查询客服人员的聊天室列表")
@RequiresLogin @RequiresLogin
public TableDataInfo findRoomList(@RequestBody(required = false) RoomPageVo roomPageVo) { public TableDataInfo<ChatRoomDto> findRoomList(@RequestBody(required = false) RoomPageVo roomPageVo) {
// 如果请求体为空初始化一个默认的 RoomPageVo 对象 // 如果请求体为空初始化一个默认的 RoomPageVo 对象
if (roomPageVo == null) { if (roomPageVo == null) {
roomPageVo = new RoomPageVo(); roomPageVo = new RoomPageVo();

View File

@ -35,4 +35,15 @@ public class ChatMessageDto {
@ApiModelProperty(value = "发送时间", example = "") @ApiModelProperty(value = "发送时间", example = "")
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty(value = "聊天室id", example = "")
private Long roomId;
@ApiModelProperty(value = "消息是否已读", example = "")
private Integer isRead;
@ApiModelProperty(value = "是否是自己发送的消息", example = "")
private Integer isSelf;
} }

View File

@ -1,5 +1,7 @@
package com.m2pool.chat.dto; package com.m2pool.chat.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -17,34 +19,41 @@ import java.time.LocalDateTime;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ApiModel(description = "客服 聊天室列表返回对象")
public class ChatRoomDto { public class ChatRoomDto {
/** /**
* 聊天室id * 聊天室id
*/ */
@ApiModelProperty(value = "聊天室id", example = "1")
private Long id; private Long id;
/** /**
* 聊天对象id * 聊天对象id
*/ */
@ApiModelProperty(value = "聊天对象id", example = "1")
private String userEmail; private String userEmail;
/** /**
* 聊天室重要程度 * 聊天室重要程度
*/ */
@ApiModelProperty(value = "聊天室重要程度 0不重要 1重要", example = "1")
private Integer flag; private Integer flag;
/** /**
* 未读消息条数 * 未读消息条数
*/ */
@ApiModelProperty(value = "未读消息条数", example = "1")
private Integer unReadNumber; private Integer unReadNumber;
/** /**
* 用户回复时间 * 用户回复时间
*/ */
@ApiModelProperty(value = "用户回复时间", example = "2025-10-01 12:32:01")
private LocalDateTime lastUserSendTime; private LocalDateTime lastUserSendTime;
/** /**
* 客服回复时间 * 客服回复时间
*/ */
@ApiModelProperty(value = "客服回复时间", example = "2025-10-01 12:32:01")
private LocalDateTime lastCustomerSendTime; private LocalDateTime lastCustomerSendTime;
} }

View File

@ -130,9 +130,11 @@ public class WebsocketChannelInterceptor implements ChannelInterceptor {
throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.IP_LIMIT_CONNECT)); throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.IP_LIMIT_CONNECT));
} }
//本次链接为登录用户,并且已经链接.直接拒绝本次链接(多用户登录) //本次链接为登录用户,并且已经链接.直接拒绝本次链接(多用户登录)
if ( type == LOGIN_USER && email.equals(hasConnectionEmail)) { if ( type == LOGIN_USER ) {
if(email.equals(hasConnectionEmail) || ipConnectionCountMap.containsValue(email)){
throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.IP_LIMIT_CONNECT)); throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.IP_LIMIT_CONNECT));
} }
}
ipConnectionCountMap.put(ipAddr,email); ipConnectionCountMap.put(ipAddr,email);
}else{ }else{

View File

@ -20,7 +20,7 @@ public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
* @param roomId * @param roomId
* @return * @return
*/ */
List<ChatMessageDto> findRecentlyMessage(@Param("id") Long id,@Param("pageNum") Integer pageNum,@Param("roomId") Long roomId); List<ChatMessageDto> findRecentlyMessage(@Param("email")String email,@Param("id") Long id,@Param("pageNum") Integer pageNum,@Param("roomId") Long roomId);
/** /**

View File

@ -36,7 +36,8 @@ public class ChatMessageServiceImpl implements ChatMessageService {
@Override @Override
public AjaxResult findRecentlyMessage(Long id,Integer pageNum,Long roomId) { public AjaxResult findRecentlyMessage(Long id,Integer pageNum,Long roomId) {
List<ChatMessageDto> recentlyMessage = chatMessageMapper.findRecentlyMessage(id, pageNum, roomId); String email = SecurityUtils.getUsername();
List<ChatMessageDto> recentlyMessage = chatMessageMapper.findRecentlyMessage(email,id, pageNum, roomId);
return AjaxResult.success(recentlyMessage); return AjaxResult.success(recentlyMessage);
} }

View File

@ -45,11 +45,6 @@ public class StompServiceImpl implements StompService {
@Override @Override
public AjaxResult sendMessageToUser(StompPrincipal principal, UserMessageVo userMessageVo) { public AjaxResult sendMessageToUser(StompPrincipal principal, UserMessageVo userMessageVo) {
// 检查目标用户是否在线
if (!checkOnline(userMessageVo)) {
return AjaxResult.error("目标用户不在线");
}
WebsocketMessageDto build = WebsocketMessageDto.builder() WebsocketMessageDto build = WebsocketMessageDto.builder()
.type(userMessageVo.getType()) .type(userMessageVo.getType())
.content(userMessageVo.getContent()) .content(userMessageVo.getContent())
@ -60,11 +55,12 @@ public class StompServiceImpl implements StompService {
if(!TOURIST.equals(userMessageVo.getReceiveUserType())){ if(!TOURIST.equals(userMessageVo.getReceiveUserType())){
build.setRoomId(userMessageVo.getRoomId()); build.setRoomId(userMessageVo.getRoomId());
} }
if (checkOnline(userMessageVo)){
//当前用户发送其他人, 发送给指定用户. 否则默认发送给当前发送者 //当前用户发送其他人, 发送给指定用户. 否则默认发送给当前发送者
messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE + "/" + userMessageVo.getEmail(),build); messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE + "/" + userMessageVo.getEmail(),build);
}
// 接收者和发送者 都不是游客才能存储消息 和修改聊天室信息后续可改为消息中间件解耦形式 // 接收者和发送者 都不是游客才能存储消息 和修改聊天室信息后续可改为消息中间件解耦形式
if (!TOURIST.equals(userMessageVo.getReceiveUserType()) && !TOURIST.equals(principal.getType())){ 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) {

View File

@ -15,7 +15,6 @@ public class MessagePageVo {
private Integer pageNum; private Integer pageNum;
private Long roomId; private Long roomId;
public MessagePageVo() { public MessagePageVo() {
this.id = 1L;
this.pageNum = 20; this.pageNum = 20;
} }
} }

View File

@ -1,6 +1,8 @@
package com.m2pool.chat.vo; package com.m2pool.chat.vo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@ -13,8 +15,10 @@ import java.time.LocalDateTime;
* @Date 2025/4/22 17:09 * @Date 2025/4/22 17:09
*/ */
@Data @Data
@ApiModel(description = "请求对象")
public class RoomPageVo { public class RoomPageVo {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "上一页最后一个聊天室发送时间", example = "2025-10-01 12:32:01")
private LocalDateTime sendDateTime; private LocalDateTime sendDateTime;
} }

View File

@ -13,7 +13,12 @@
content, content,
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>
room_id = #{roomId}
<if test="id != null">
AND id <![CDATA[ <= ]]> #{id}
</if>
</where>
ORDER BY id DESC ORDER BY id DESC
LIMIT #{pageNum} LIMIT #{pageNum}
</select> </select>

View File

@ -8,9 +8,19 @@
type, type,
send_email as sendEmail, send_email as sendEmail,
content, content,
create_time as createTime create_time as createTime,
room_id as roomId,
is_read as isRead,
case when send_email = #{email} then 1
else 0
end as isSelf
FROM chat_message FROM chat_message
WHERE id <![CDATA[ <= ]]> #{id} AND room_id = #{roomId} <where>
room_id = #{roomId}
<if test="id != null">
AND id <![CDATA[ <= ]]> #{id}
</if>
</where>
ORDER BY id DESC ORDER BY id DESC
LIMIT #{pageNum} LIMIT #{pageNum}
</select> </select>