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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
* @param roomId
* @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
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);
}

View File

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

View File

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

View File

@ -1,6 +1,8 @@
package com.m2pool.chat.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -13,8 +15,10 @@ import java.time.LocalDateTime;
* @Date 2025/4/22 17:09
*/
@Data
@ApiModel(description = "请求对象")
public class RoomPageVo {
@JsonFormat(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;
}

View File

@ -13,7 +13,12 @@
content,
create_time as createTime
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
LIMIT #{pageNum}
</select>

View File

@ -8,9 +8,19 @@
type,
send_email as sendEmail,
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
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
LIMIT #{pageNum}
</select>