mirror of https://gitee.com/stylefeng/roses
【websocket】更新websocket配置
parent
3103083eac
commit
36b7ac11e2
|
@ -94,8 +94,7 @@ public class LoginUser implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String wsUrl;
|
private String wsUrl;
|
||||||
|
|
||||||
|
public String getWsUrl() {
|
||||||
public String getWsUrl(){
|
|
||||||
AtomicReference<String> returnUrl = new AtomicReference<>(StrUtil.EMPTY);
|
AtomicReference<String> returnUrl = new AtomicReference<>(StrUtil.EMPTY);
|
||||||
Optional.ofNullable(this.wsUrl).ifPresent(url -> {
|
Optional.ofNullable(this.wsUrl).ifPresent(url -> {
|
||||||
Map<String, Long> user = new HashMap<>(1);
|
Map<String, Long> user = new HashMap<>(1);
|
||||||
|
|
|
@ -24,13 +24,8 @@ public interface MessageConstants {
|
||||||
String RECEIVE_ALL_USER_FLAG = "all";
|
String RECEIVE_ALL_USER_FLAG = "all";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认查询日志分页
|
* 默认websocket-url
|
||||||
*/
|
*/
|
||||||
Integer DEFAULT_BEGIN_PAGE_NO = 1;
|
String DEFAULT_WS_URL = "ws://localhost:8080/message/websocket/{userId}";
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认查询日志分页大小
|
|
||||||
*/
|
|
||||||
Integer DEFAULT_PAGE_SIZE = 10;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package cn.stylefeng.roses.kernel.message.api.expander;
|
package cn.stylefeng.roses.kernel.message.api.expander;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.constants.MessageConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* websocket相关配置快速获取
|
* websocket相关配置快速获取
|
||||||
|
@ -19,19 +18,7 @@ public class WebSocketConfigExpander {
|
||||||
* @date 2021/1/25 20:34
|
* @date 2021/1/25 20:34
|
||||||
*/
|
*/
|
||||||
public static String getWebSocketWsUrl() {
|
public static String getWebSocketWsUrl() {
|
||||||
String webSocketWsUr = ConfigContext.me().getConfigValueNullable("WEB_SOCKET_WS_URL", String.class);
|
return ConfigContext.me().getSysConfigValueWithDefault("WEB_SOCKET_WS_URL", String.class, MessageConstants.DEFAULT_WS_URL);
|
||||||
|
|
||||||
if (webSocketWsUr == null) {
|
|
||||||
// 没配置就查询配置文件
|
|
||||||
String propertiesUrl = SpringUtil.getProperty("web-socket.ws-url");
|
|
||||||
if(StrUtil.isNotEmpty(propertiesUrl)){
|
|
||||||
return propertiesUrl;
|
|
||||||
}
|
|
||||||
// 没配置就返回一个空串
|
|
||||||
return StrUtil.EMPTY;
|
|
||||||
}
|
|
||||||
return webSocketWsUr;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package cn.stylefeng.roses.kernel.message.api.pojo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日志配置信息
|
|
||||||
*
|
|
||||||
* @author liuhanqing
|
|
||||||
* @date 2021/1/25 9:25
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class MessageWebSocketProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* websocket开关
|
|
||||||
*/
|
|
||||||
private Boolean open = true ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* websocket地址
|
|
||||||
*/
|
|
||||||
private String wsUrl = "";
|
|
||||||
|
|
||||||
}
|
|
|
@ -40,7 +40,6 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
public class MessageDbServiceImpl implements MessageApi {
|
public class MessageDbServiceImpl implements MessageApi {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private WebsocketApi websocketApi;
|
private WebsocketApi websocketApi;
|
||||||
|
|
||||||
|
@ -132,7 +131,6 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
updateWrapper.eq(SysMessage::getMessageId, messageId)
|
updateWrapper.eq(SysMessage::getMessageId, messageId)
|
||||||
.set(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
.set(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
sysMessageService.update(updateWrapper);
|
sysMessageService.update(updateWrapper);
|
||||||
// sysMessageService.remove(updateWrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +147,7 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
SysMessage sysMessage = sysMessageService.getById(messageParam.getMessageId());
|
SysMessage sysMessage = sysMessageService.getById(messageParam.getMessageId());
|
||||||
// 判断消息为未读状态更新为已读
|
// 判断消息为未读状态更新为已读
|
||||||
Optional.ofNullable(sysMessage).ifPresent(msg -> {
|
Optional.ofNullable(sysMessage).ifPresent(msg -> {
|
||||||
if(MessageReadFlagEnum.UNREAD.getCode().equals(sysMessage.getReadFlag())){
|
if (MessageReadFlagEnum.UNREAD.getCode().equals(sysMessage.getReadFlag())) {
|
||||||
msg.setReadFlag(MessageReadFlagEnum.READ.getCode());
|
msg.setReadFlag(MessageReadFlagEnum.READ.getCode());
|
||||||
sysMessageService.updateById(msg);
|
sysMessageService.updateById(msg);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +163,7 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
PageResult<MessageResponse> result = new PageResult<>();
|
PageResult<MessageResponse> result = new PageResult<>();
|
||||||
List<SysMessage> messageList = pageResult.getRows();
|
List<SysMessage> messageList = pageResult.getRows();
|
||||||
List<MessageResponse> resultList = messageList.stream().map(msg -> {
|
List<MessageResponse> resultList = messageList.stream().map(msg -> {
|
||||||
MessageResponse response = new MessageResponse();
|
MessageResponse response = new MessageResponse();
|
||||||
BeanUtil.copyProperties(msg, response);
|
BeanUtil.copyProperties(msg, response);
|
||||||
return response;
|
return response;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
@ -178,7 +176,7 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
public List<MessageResponse> queryList(MessageParam messageParam) {
|
public List<MessageResponse> queryList(MessageParam messageParam) {
|
||||||
List<SysMessage> messageList = sysMessageService.list(messageParam);
|
List<SysMessage> messageList = sysMessageService.list(messageParam);
|
||||||
List<MessageResponse> resultList = messageList.stream().map(msg -> {
|
List<MessageResponse> resultList = messageList.stream().map(msg -> {
|
||||||
MessageResponse response = new MessageResponse();
|
MessageResponse response = new MessageResponse();
|
||||||
BeanUtil.copyProperties(msg, response);
|
BeanUtil.copyProperties(msg, response);
|
||||||
return response;
|
return response;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
@ -211,6 +209,7 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
public Integer queryCount(MessageParam messageParam) {
|
public Integer queryCount(MessageParam messageParam) {
|
||||||
return sysMessageService.count(messageParam);
|
return sysMessageService.count(messageParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer queryCountCurrentUser(MessageParam messageParam) {
|
public Integer queryCountCurrentUser(MessageParam messageParam) {
|
||||||
if (ObjectUtil.isEmpty(messageParam)) {
|
if (ObjectUtil.isEmpty(messageParam)) {
|
||||||
|
@ -221,4 +220,5 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
messageParam.setReceiveUserId(loginUser.getUserId());
|
messageParam.setReceiveUserId(loginUser.getUserId());
|
||||||
return this.queryCount(messageParam);
|
return this.queryCount(messageParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package cn.stylefeng.roses.kernel.message.starter;
|
package cn.stylefeng.roses.kernel.message.starter;
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.message.api.expander.WebSocketConfigExpander;
|
|
||||||
import cn.stylefeng.roses.kernel.message.api.pojo.MessageWebSocketProperties;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
@ -20,22 +17,6 @@ public class GunsMessageAutoConfiguration {
|
||||||
|
|
||||||
public static final String WEB_SOCKET_PREFIX = "web-socket";
|
public static final String WEB_SOCKET_PREFIX = "web-socket";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* websocket的配置
|
|
||||||
*
|
|
||||||
* @author liuhanqing
|
|
||||||
* @date 2021/1/25 9:29
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties(prefix = WEB_SOCKET_PREFIX)
|
|
||||||
public MessageWebSocketProperties messageWebSocketProperties() {
|
|
||||||
MessageWebSocketProperties properties = new MessageWebSocketProperties();
|
|
||||||
properties.setWsUrl(WebSocketConfigExpander.getWebSocketWsUrl());
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开启WebSocket功能
|
* 开启WebSocket功能
|
||||||
*
|
*
|
||||||
|
@ -50,4 +31,4 @@ public class GunsMessageAutoConfiguration {
|
||||||
return new ServerEndpointExporter();
|
return new ServerEndpointExporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue