mirror of https://gitee.com/stylefeng/roses
【message】整理消息模块
parent
7670753007
commit
6d6e70b126
|
@ -10,11 +10,11 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
||||||
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,7 +33,7 @@ public class SysMessageController {
|
||||||
/**
|
/**
|
||||||
* 系统消息api
|
* 系统消息api
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Resource
|
||||||
private MessageApi messageApi;
|
private MessageApi messageApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +86,6 @@ public class SysMessageController {
|
||||||
return new SuccessResponseData();
|
return new SuccessResponseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查看系统消息
|
* 查看系统消息
|
||||||
*
|
*
|
||||||
|
@ -98,7 +97,6 @@ public class SysMessageController {
|
||||||
return new SuccessResponseData(messageApi.messageDetail(messageRequest));
|
return new SuccessResponseData(messageApi.messageDetail(messageRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询系统消息列表
|
* 分页查询系统消息列表
|
||||||
*
|
*
|
||||||
|
@ -121,7 +119,6 @@ public class SysMessageController {
|
||||||
return new SuccessResponseData(messageApi.queryListCurrentUser(messageRequest));
|
return new SuccessResponseData(messageApi.queryListCurrentUser(messageRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统消息未读数量
|
* 系统消息未读数量
|
||||||
*
|
*
|
||||||
|
|
|
@ -77,4 +77,5 @@ public interface SysMessageService extends IService<SysMessage> {
|
||||||
* @date 2021/1/11 19:21
|
* @date 2021/1/11 19:21
|
||||||
*/
|
*/
|
||||||
Integer findCount(MessageRequest messageRequest);
|
Integer findCount(MessageRequest messageRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,16 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||||
private LambdaQueryWrapper<SysMessage> createWrapper(MessageRequest messageRequest) {
|
private LambdaQueryWrapper<SysMessage> createWrapper(MessageRequest messageRequest) {
|
||||||
LambdaQueryWrapper<SysMessage> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
// 查询未删除的
|
||||||
|
queryWrapper.ne(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
|
||||||
|
// 按发送事件倒序
|
||||||
|
queryWrapper.orderByDesc(SysMessage::getMessageSendTime);
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(messageRequest)) {
|
||||||
|
return queryWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
// 消息标题
|
// 消息标题
|
||||||
String messageTitle = messageRequest.getMessageTitle();
|
String messageTitle = messageRequest.getMessageTitle();
|
||||||
|
|
||||||
|
@ -116,12 +126,6 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||||
queryWrapper.eq(ObjectUtil.isNotEmpty(messageType), SysMessage::getMessageType, messageType);
|
queryWrapper.eq(ObjectUtil.isNotEmpty(messageType), SysMessage::getMessageType, messageType);
|
||||||
queryWrapper.eq(ObjectUtil.isNotEmpty(readFlag), SysMessage::getReadFlag, readFlag);
|
queryWrapper.eq(ObjectUtil.isNotEmpty(readFlag), SysMessage::getReadFlag, readFlag);
|
||||||
|
|
||||||
// 查询未删除的
|
|
||||||
queryWrapper.ne(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
|
||||||
|
|
||||||
// 按发送事件倒序
|
|
||||||
queryWrapper.orderByDesc(SysMessage::getMessageSendTime);
|
|
||||||
|
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||||
import cn.stylefeng.roses.kernel.message.api.WebsocketApi;
|
import cn.stylefeng.roses.kernel.message.api.WebsocketApi;
|
||||||
import cn.stylefeng.roses.kernel.message.api.enums.MessageReadFlagEnum;
|
import cn.stylefeng.roses.kernel.message.api.enums.MessageReadFlagEnum;
|
||||||
import cn.stylefeng.roses.kernel.message.api.pojo.response.MessageResponse;
|
|
||||||
import cn.stylefeng.roses.kernel.message.api.pojo.request.MessageSendRequest;
|
import cn.stylefeng.roses.kernel.message.api.pojo.request.MessageSendRequest;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.pojo.response.MessageResponse;
|
||||||
import cn.stylefeng.roses.kernel.message.websocket.manager.WebSocketManager;
|
import cn.stylefeng.roses.kernel.message.websocket.manager.WebSocketManager;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
@ -51,4 +51,5 @@ public class WebSocketServiceImpl implements WebsocketApi {
|
||||||
log.error("发送websocket异常", e);
|
log.error("发送websocket异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,13 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author liuhq
|
* websocket客户端连接管理
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/24 22:08
|
||||||
*/
|
*/
|
||||||
public class WebSocketManager {
|
public class WebSocketManager {
|
||||||
|
|
||||||
private static final ConcurrentHashMap<Long, List<Session>> userIdSessionMap = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<Long, List<Session>> userIdSessionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,4 +101,5 @@ public class WebSocketManager {
|
||||||
sendMessage(userId, message);
|
sendMessage(userId, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import javax.websocket.server.ServerEndpoint;
|
||||||
@ServerEndpoint("/message/websocket/{userId}")
|
@ServerEndpoint("/message/websocket/{userId}")
|
||||||
public class WebSocketEndpoint {
|
public class WebSocketEndpoint {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接建立成功后调用
|
* 连接建立成功后调用
|
||||||
*
|
*
|
||||||
|
@ -30,10 +29,12 @@ public class WebSocketEndpoint {
|
||||||
*/
|
*/
|
||||||
@OnOpen
|
@OnOpen
|
||||||
public void onOpen(@PathParam(value = "userId") Long userId, Session session) {
|
public void onOpen(@PathParam(value = "userId") Long userId, Session session) {
|
||||||
|
|
||||||
// 添加到链接管理
|
// 添加到链接管理
|
||||||
WebSocketManager.add(userId, session);
|
WebSocketManager.add(userId, session);
|
||||||
|
|
||||||
// 返回消息
|
// 返回消息
|
||||||
// session.getAsyncRemote().sendText("WebSocket连接成功");
|
session.getAsyncRemote().sendText("WebSocket连接成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,4 +78,4 @@ public class WebSocketEndpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<version>7.0.0</version>
|
<version>7.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!--websocket管理-->
|
<!--websocket管理-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.stylefeng.roses</groupId>
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
@ -32,7 +31,6 @@
|
||||||
<version>7.0.0</version>
|
<version>7.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!--消息默认记录到库中-->
|
<!--消息默认记录到库中-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.stylefeng.roses</groupId>
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
|
Loading…
Reference in New Issue