【message】整理消息模块

pull/3/head
fengshuonan 2021-02-08 17:08:26 +08:00
parent 7670753007
commit 6d6e70b126
7 changed files with 25 additions and 18 deletions

View File

@ -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.rule.pojo.response.ResponseData;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -33,7 +33,7 @@ public class SysMessageController {
/**
* api
*/
@Autowired
@Resource
private MessageApi messageApi;
/**
@ -86,7 +86,6 @@ public class SysMessageController {
return new SuccessResponseData();
}
/**
*
*
@ -98,7 +97,6 @@ public class SysMessageController {
return new SuccessResponseData(messageApi.messageDetail(messageRequest));
}
/**
*
*
@ -121,7 +119,6 @@ public class SysMessageController {
return new SuccessResponseData(messageApi.queryListCurrentUser(messageRequest));
}
/**
*
*

View File

@ -77,4 +77,5 @@ public interface SysMessageService extends IService<SysMessage> {
* @date 2021/1/11 19:21
*/
Integer findCount(MessageRequest messageRequest);
}

View File

@ -98,6 +98,16 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
private LambdaQueryWrapper<SysMessage> createWrapper(MessageRequest messageRequest) {
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();
@ -116,12 +126,6 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
queryWrapper.eq(ObjectUtil.isNotEmpty(messageType), SysMessage::getMessageType, messageType);
queryWrapper.eq(ObjectUtil.isNotEmpty(readFlag), SysMessage::getReadFlag, readFlag);
// 查询未删除的
queryWrapper.ne(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
// 按发送事件倒序
queryWrapper.orderByDesc(SysMessage::getMessageSendTime);
return queryWrapper;
}
}

View File

@ -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.message.api.WebsocketApi;
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.response.MessageResponse;
import cn.stylefeng.roses.kernel.message.websocket.manager.WebSocketManager;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -51,4 +51,5 @@ public class WebSocketServiceImpl implements WebsocketApi {
log.error("发送websocket异常", e);
}
}
}

View File

@ -9,9 +9,13 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author liuhq
* websocket
*
* @author liuhanqing
* @date 2021/1/24 22:08
*/
public class WebSocketManager {
private static final ConcurrentHashMap<Long, List<Session>> userIdSessionMap = new ConcurrentHashMap<>();
/**
@ -97,4 +101,5 @@ public class WebSocketManager {
sendMessage(userId, message);
}
}
}

View File

@ -19,7 +19,6 @@ import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/message/websocket/{userId}")
public class WebSocketEndpoint {
/**
*
*
@ -30,10 +29,12 @@ public class WebSocketEndpoint {
*/
@OnOpen
public void onOpen(@PathParam(value = "userId") Long userId, Session session) {
// 添加到链接管理
WebSocketManager.add(userId, session);
// 返回消息
// session.getAsyncRemote().sendText("WebSocket连接成功");
session.getAsyncRemote().sendText("WebSocket连接成功");
}
/**

View File

@ -24,7 +24,6 @@
<version>7.0.0</version>
</dependency>
<!--websocket管理-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
@ -32,7 +31,6 @@
<version>7.0.0</version>
</dependency>
<!--消息默认记录到库中-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>