新增登录推送历史为推送消息
This commit is contained in:
parent
2453cda0a7
commit
f0e181a9bd
@ -41,6 +41,14 @@ public interface INoticeDao extends IInitBaseTable {
|
|||||||
*/
|
*/
|
||||||
void updateHandle(Map<String, Object> params) throws UpdateException;
|
void updateHandle(Map<String, Object> params) throws UpdateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改已发送
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @throws UpdateException
|
||||||
|
*/
|
||||||
|
void updateSend(Map<String, Object> params) throws UpdateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 详情
|
* 详情
|
||||||
*
|
*
|
||||||
@ -119,4 +127,5 @@ public interface INoticeDao extends IInitBaseTable {
|
|||||||
* @throws SearchException
|
* @throws SearchException
|
||||||
*/
|
*/
|
||||||
List<NoticeDTO> list(Map<String, Object> params) throws SearchException;
|
List<NoticeDTO> list(Map<String, Object> params) throws SearchException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import ink.wgink.module.instantmessage.pojo.bos.NoticeBO;
|
|||||||
import ink.wgink.module.instantmessage.pojo.bos.NoticeTargetBO;
|
import ink.wgink.module.instantmessage.pojo.bos.NoticeTargetBO;
|
||||||
import ink.wgink.module.instantmessage.pojo.vos.NoticeSendVO;
|
import ink.wgink.module.instantmessage.pojo.vos.NoticeSendVO;
|
||||||
import ink.wgink.module.instantmessage.pojo.vos.NoticeVO;
|
import ink.wgink.module.instantmessage.pojo.vos.NoticeVO;
|
||||||
|
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketSession;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -70,4 +71,11 @@ public interface IMessageService {
|
|||||||
*/
|
*/
|
||||||
void delete(List<String> serviceIds);
|
void delete(List<String> serviceIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知未发送消息的用户
|
||||||
|
*
|
||||||
|
* @param 当前会话
|
||||||
|
*/
|
||||||
|
void noticeUnSendByUserId(WebSocketSession webSocketSession);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,14 @@ public interface INoticeService {
|
|||||||
*/
|
*/
|
||||||
void updateHandleStatus(String userId, CountNeedToDealWithBody countNeedToDealWithBody);
|
void updateHandleStatus(String userId, CountNeedToDealWithBody countNeedToDealWithBody);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新发送状态
|
||||||
|
*
|
||||||
|
* @param noticeId
|
||||||
|
* @param isSend
|
||||||
|
*/
|
||||||
|
void updateSendStatus(String noticeId, int isSend);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知详情
|
* 通知详情
|
||||||
*
|
*
|
||||||
@ -220,4 +228,14 @@ public interface INoticeService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<NoticePO> listPOByStartTimeAndEndTime(String startTime, String endTime);
|
List<NoticePO> listPOByStartTimeAndEndTime(String startTime, String endTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送通知列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param isSend 是否发送
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<NoticePO> listPOByUserIdAndIsSend(String userId, int isSend);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -224,4 +224,29 @@ public class MessageServiceImpl extends DefaultBaseService implements IMessageSe
|
|||||||
}
|
}
|
||||||
}, 3, TimeUnit.SECONDS);
|
}, 3, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noticeUnSendByUserId(WebSocketSession webSocketSession) {
|
||||||
|
List<NoticePO> noticePOs = noticeService.listPOByUserIdAndIsSend(webSocketSession.getUserId(), 0);
|
||||||
|
if (noticePOs.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3s后发送通知
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
if (webSocketSession.getChannel() == null || !webSocketSession.getChannel().isOpen() || !webSocketSession.getChannel().isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
noticePOs.forEach(noticePO -> {
|
||||||
|
NoticeBody noticeBody = new NoticeBody(noticePO.getNoticeTitle(), noticePO.getNoticeMsg());
|
||||||
|
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(MessageTypeEnum.NOTICE.getValue(),
|
||||||
|
true,
|
||||||
|
WebSocketChannelManager.FORM_SYSTEM,
|
||||||
|
webSocketSession.getUserId(),
|
||||||
|
JSONObject.toJSONString(noticeBody));
|
||||||
|
WebSocketChannelManager.getInstance().sendText(webSocketSession.getChannel(), webSocketClientMessage);
|
||||||
|
// 更新发送状态
|
||||||
|
noticeService.updateSendStatus(noticePO.getNoticeId(), 1);
|
||||||
|
});
|
||||||
|
}, 3, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,15 @@ public class NoticeServiceImpl extends DefaultBaseService implements INoticeServ
|
|||||||
noticeDao.updateHandle(params);
|
noticeDao.updateHandle(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSendStatus(String noticeId, int isSend) {
|
||||||
|
Map<String, Object> params = getHashMap(4);
|
||||||
|
params.put("noticeId", noticeId);
|
||||||
|
params.put("isSend", isSend);
|
||||||
|
setUpdateInfoByUserId(params, "1");
|
||||||
|
noticeDao.updateSend(params);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NoticePO getPO(Map<String, Object> params) {
|
public NoticePO getPO(Map<String, Object> params) {
|
||||||
return noticeDao.getPO(params);
|
return noticeDao.getPO(params);
|
||||||
@ -298,6 +307,14 @@ public class NoticeServiceImpl extends DefaultBaseService implements INoticeServ
|
|||||||
return listPO(params);
|
return listPO(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NoticePO> listPOByUserIdAndIsSend(String userId, int isSend) {
|
||||||
|
Map<String, Object> params = getHashMap(4);
|
||||||
|
params.put("userId", userId);
|
||||||
|
params.put("isSend", isSend);
|
||||||
|
return listPO(params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统列表
|
* 系统列表
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ink.wgink.module.instantmessage.websocket.channel;
|
package ink.wgink.module.instantmessage.websocket.channel;
|
||||||
|
|
||||||
|
import ink.wgink.module.instantmessage.service.IMessageService;
|
||||||
import ink.wgink.module.instantmessage.websocket.handler.WebSocketHandler;
|
import ink.wgink.module.instantmessage.websocket.handler.WebSocketHandler;
|
||||||
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
||||||
import ink.wgink.properties.websocket.WebSocketProperties;
|
import ink.wgink.properties.websocket.WebSocketProperties;
|
||||||
@ -22,6 +23,7 @@ public class WebSocketChannelInitializer extends ChannelInitializer<SocketChanne
|
|||||||
|
|
||||||
private WebSocketProperties webSocketProperties;
|
private WebSocketProperties webSocketProperties;
|
||||||
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel socketChannel) throws Exception {
|
protected void initChannel(SocketChannel socketChannel) throws Exception {
|
||||||
@ -37,6 +39,7 @@ public class WebSocketChannelInitializer extends ChannelInitializer<SocketChanne
|
|||||||
WebSocketHandler webSocketHandler = new WebSocketHandler();
|
WebSocketHandler webSocketHandler = new WebSocketHandler();
|
||||||
webSocketHandler.setWebSocketProperties(webSocketProperties);
|
webSocketHandler.setWebSocketProperties(webSocketProperties);
|
||||||
webSocketHandler.setWebSocketTextCustomHandler(IWebSocketTextCustomService);
|
webSocketHandler.setWebSocketTextCustomHandler(IWebSocketTextCustomService);
|
||||||
|
webSocketHandler.setMessageService(messageService);
|
||||||
socketChannel.pipeline().addLast("handler", webSocketHandler);
|
socketChannel.pipeline().addLast("handler", webSocketHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,4 +50,8 @@ public class WebSocketChannelInitializer extends ChannelInitializer<SocketChanne
|
|||||||
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
||||||
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMessageService(IMessageService messageService) {
|
||||||
|
this.messageService = messageService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ink.wgink.module.instantmessage.websocket.handler;
|
package ink.wgink.module.instantmessage.websocket.handler;
|
||||||
|
|
||||||
|
import ink.wgink.module.instantmessage.service.IMessageService;
|
||||||
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
||||||
import ink.wgink.module.instantmessage.websocket.handler.text.WebSocketTextHandler;
|
import ink.wgink.module.instantmessage.websocket.handler.text.WebSocketTextHandler;
|
||||||
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
||||||
@ -36,6 +37,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<Object> {
|
|||||||
private WebSocketProperties webSocketProperties;
|
private WebSocketProperties webSocketProperties;
|
||||||
private WebSocketServerHandshaker webSocketServerHandshaker;
|
private WebSocketServerHandshaker webSocketServerHandshaker;
|
||||||
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
@ -81,6 +83,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<Object> {
|
|||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
WebSocketTextHandler webSocketTextHandler = new WebSocketTextHandler();
|
WebSocketTextHandler webSocketTextHandler = new WebSocketTextHandler();
|
||||||
webSocketTextHandler.setWebSocketTextCustomHandler(IWebSocketTextCustomService);
|
webSocketTextHandler.setWebSocketTextCustomHandler(IWebSocketTextCustomService);
|
||||||
|
webSocketTextHandler.setMessageService(messageService);
|
||||||
webSocketTextHandler.handler(ctx, (TextWebSocketFrame) frame);
|
webSocketTextHandler.handler(ctx, (TextWebSocketFrame) frame);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -150,4 +153,8 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<Object> {
|
|||||||
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
||||||
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMessageService(IMessageService messageService) {
|
||||||
|
this.messageService = messageService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ink.wgink.module.instantmessage.websocket.handler.text;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONException;
|
import com.alibaba.fastjson.JSONException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import ink.wgink.module.instantmessage.service.IMessageService;
|
||||||
import ink.wgink.module.instantmessage.websocket.enums.MessageTypeEnum;
|
import ink.wgink.module.instantmessage.websocket.enums.MessageTypeEnum;
|
||||||
import ink.wgink.module.instantmessage.websocket.enums.StatusEnum;
|
import ink.wgink.module.instantmessage.websocket.enums.StatusEnum;
|
||||||
import ink.wgink.module.instantmessage.websocket.exception.*;
|
import ink.wgink.module.instantmessage.websocket.exception.*;
|
||||||
@ -33,6 +34,7 @@ import java.util.Set;
|
|||||||
public class WebSocketTextHandler {
|
public class WebSocketTextHandler {
|
||||||
|
|
||||||
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
private IWebSocketTextCustomService IWebSocketTextCustomService;
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
public void handler(ChannelHandlerContext ctx, TextWebSocketFrame textWebSocketFrame) {
|
public void handler(ChannelHandlerContext ctx, TextWebSocketFrame textWebSocketFrame) {
|
||||||
WebSocketClientMessage clientSocketMessage = null;
|
WebSocketClientMessage clientSocketMessage = null;
|
||||||
@ -139,7 +141,8 @@ public class WebSocketTextHandler {
|
|||||||
private StatusBody clientRegisterSession(Channel channel, WebSocketClientMessage clientSocketMessage) throws SessionException {
|
private StatusBody clientRegisterSession(Channel channel, WebSocketClientMessage clientSocketMessage) throws SessionException {
|
||||||
RegisterBody registerBody = JSONObject.parseObject(clientSocketMessage.getBody(), RegisterBody.class);
|
RegisterBody registerBody = JSONObject.parseObject(clientSocketMessage.getBody(), RegisterBody.class);
|
||||||
// 更新通道
|
// 更新通道
|
||||||
WebSocketChannelManager.getInstance().addChannel(registerBody.getSessionId(), clientSocketMessage.getFrom(), channel);
|
WebSocketSession webSocketSession = WebSocketChannelManager.getInstance().addChannel(registerBody.getSessionId(), clientSocketMessage.getFrom(), channel);
|
||||||
|
sendHistory(webSocketSession);
|
||||||
return new StatusBody(StatusEnum.SUCCESS.getValue(), StatusEnum.SUCCESS, "OK");
|
return new StatusBody(StatusEnum.SUCCESS.getValue(), StatusEnum.SUCCESS, "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +222,16 @@ public class WebSocketTextHandler {
|
|||||||
sendText(fromChannel, webSocketClientMessage);
|
sendText(fromChannel, webSocketClientMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送历史
|
||||||
|
*
|
||||||
|
* @param webSocketSession
|
||||||
|
*/
|
||||||
|
private void sendHistory(WebSocketSession webSocketSession) {
|
||||||
|
// 3s之后更新,更新历史通知
|
||||||
|
messageService.noticeUnSendByUserId(webSocketSession);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送失败内容
|
* 发送失败内容
|
||||||
*
|
*
|
||||||
@ -235,4 +248,8 @@ public class WebSocketTextHandler {
|
|||||||
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
public void setWebSocketTextCustomHandler(IWebSocketTextCustomService IWebSocketTextCustomService) {
|
||||||
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
this.IWebSocketTextCustomService = IWebSocketTextCustomService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMessageService(IMessageService messageService) {
|
||||||
|
this.messageService = messageService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,13 @@ public class WebSocketChannelManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加通道,绑定通道与会话
|
* 添加通道,绑定通道与会话
|
||||||
*
|
|
||||||
* @param sessionId
|
* @param sessionId
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param channel
|
* @param channel
|
||||||
|
* @return 返回创建的会话
|
||||||
* @throws SessionException
|
* @throws SessionException
|
||||||
*/
|
*/
|
||||||
public void addChannel(String sessionId, String userId, Channel channel) throws SessionException {
|
public WebSocketSession addChannel(String sessionId, String userId, Channel channel) throws SessionException {
|
||||||
WebSocketSession onlineUser = getOnlineUserBySessionId(sessionId);
|
WebSocketSession onlineUser = getOnlineUserBySessionId(sessionId);
|
||||||
if (onlineUser == null) {
|
if (onlineUser == null) {
|
||||||
throw new SessionException("无效会话,请登录");
|
throw new SessionException("无效会话,请登录");
|
||||||
@ -80,6 +80,7 @@ public class WebSocketChannelManager {
|
|||||||
onlineUser.setChannel(channel);
|
onlineUser.setChannel(channel);
|
||||||
onlineUser.setChannelId(channel.id().asLongText());
|
onlineUser.setChannelId(channel.id().asLongText());
|
||||||
globalGroup.add(channel);
|
globalGroup.add(channel);
|
||||||
|
return onlineUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeChannel(Channel channel) {
|
public void removeChannel(Channel channel) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ink.wgink.module.instantmessage.websocket.server;
|
package ink.wgink.module.instantmessage.websocket.server;
|
||||||
|
|
||||||
|
import ink.wgink.module.instantmessage.service.IMessageService;
|
||||||
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
|
||||||
import ink.wgink.module.instantmessage.websocket.channel.WebSocketChannelInitializer;
|
import ink.wgink.module.instantmessage.websocket.channel.WebSocketChannelInitializer;
|
||||||
import ink.wgink.properties.websocket.WebSocketProperties;
|
import ink.wgink.properties.websocket.WebSocketProperties;
|
||||||
@ -26,6 +27,8 @@ public class WebSocketServer implements Runnable {
|
|||||||
private static final Logger LOG = LoggerFactory.getLogger(WebSocketServer.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WebSocketServer.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
private WebSocketProperties webSocketProperties;
|
private WebSocketProperties webSocketProperties;
|
||||||
|
@Autowired
|
||||||
|
private IMessageService messageService;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private IWebSocketTextCustomService webSocketTextCustomService;
|
private IWebSocketTextCustomService webSocketTextCustomService;
|
||||||
|
|
||||||
@ -35,6 +38,8 @@ public class WebSocketServer implements Runnable {
|
|||||||
WebSocketChannelInitializer webSocketChannelInitializer = new WebSocketChannelInitializer();
|
WebSocketChannelInitializer webSocketChannelInitializer = new WebSocketChannelInitializer();
|
||||||
webSocketChannelInitializer.setWebSocketProperties(webSocketProperties);
|
webSocketChannelInitializer.setWebSocketProperties(webSocketProperties);
|
||||||
webSocketChannelInitializer.setWebSocketTextCustomHandler(webSocketTextCustomService);
|
webSocketChannelInitializer.setWebSocketTextCustomHandler(webSocketTextCustomService);
|
||||||
|
webSocketChannelInitializer.setMessageService(messageService);
|
||||||
|
|
||||||
// server
|
// server
|
||||||
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||||
|
@ -136,6 +136,18 @@
|
|||||||
notice_service_id = #{noticeServiceId}
|
notice_service_id = #{noticeServiceId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 修改发送状态 -->
|
||||||
|
<update id="updateSend" parameterType="map" flushCache="true">
|
||||||
|
UPDATE
|
||||||
|
im_notice
|
||||||
|
SET
|
||||||
|
is_send = #{isSend},
|
||||||
|
gmt_modified = #{gmtModified},
|
||||||
|
modifier = #{modifier}
|
||||||
|
WHERE
|
||||||
|
notice_id = #{noticeId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 删除 -->
|
<!-- 删除 -->
|
||||||
<delete id="delete" parameterType="map" flushCache="true">
|
<delete id="delete" parameterType="map" flushCache="true">
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
@ -260,6 +272,10 @@
|
|||||||
AND
|
AND
|
||||||
user_id = #{userId}
|
user_id = #{userId}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="isSend != null">
|
||||||
|
AND
|
||||||
|
is_send = #{isSend}
|
||||||
|
</if>
|
||||||
<if test="isHandle != null">
|
<if test="isHandle != null">
|
||||||
AND
|
AND
|
||||||
is_handle = #{isHandle}
|
is_handle = #{isHandle}
|
||||||
|
Loading…
Reference in New Issue
Block a user