mirror of https://gitee.com/stylefeng/roses
【message】消息模块增加websocket
parent
6f1262cf75
commit
c7d5392fbd
|
@ -1,15 +1,15 @@
|
||||||
package cn.stylefeng.roses.kernel.auth.api.pojo.login;
|
package cn.stylefeng.roses.kernel.auth.api.pojo.login;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录用户信息
|
* 登录用户信息
|
||||||
|
@ -89,4 +89,20 @@ public class LoginUser implements Serializable {
|
||||||
*/
|
*/
|
||||||
private Dict otherInfos;
|
private Dict otherInfos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的ws-url
|
||||||
|
*/
|
||||||
|
private String wsUrl;
|
||||||
|
|
||||||
|
|
||||||
|
public String getWsUrl(){
|
||||||
|
AtomicReference<String> returnUrl = new AtomicReference<>(StrUtil.EMPTY);
|
||||||
|
Optional.ofNullable(this.wsUrl).ifPresent(url -> {
|
||||||
|
Map<String, Long> user = new HashMap<>(1);
|
||||||
|
user.put("userId", this.userId);
|
||||||
|
returnUrl.set(StrUtil.format(url, user));
|
||||||
|
});
|
||||||
|
return returnUrl.get();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,14 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--系统消息业务模块的api-->
|
||||||
|
<!--获取当前登录用户的ws-url-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>message-api</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -16,6 +16,7 @@ import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext;
|
||||||
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
||||||
import cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum;
|
import cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum;
|
||||||
import cn.stylefeng.roses.kernel.jwt.api.pojo.payload.DefaultJwtPayload;
|
import cn.stylefeng.roses.kernel.jwt.api.pojo.payload.DefaultJwtPayload;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.expander.WebSocketConfigExpander;
|
||||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||||
import cn.stylefeng.roses.kernel.system.LoginLogServiceApi;
|
import cn.stylefeng.roses.kernel.system.LoginLogServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||||
|
@ -213,6 +214,9 @@ public class AuthServiceImpl implements AuthServiceApi {
|
||||||
|
|
||||||
synchronized (SESSION_OPERATE_LOCK) {
|
synchronized (SESSION_OPERATE_LOCK) {
|
||||||
|
|
||||||
|
// 8.1 获取ws-url 保存到用户信息中
|
||||||
|
loginUser.setWsUrl(WebSocketConfigExpander.getWebSocketWsUrl());
|
||||||
|
|
||||||
// 9. 缓存用户信息,创建会话
|
// 9. 缓存用户信息,创建会话
|
||||||
sessionManagerApi.createSession(jwtToken, loginUser);
|
sessionManagerApi.createSession(jwtToken, loginUser);
|
||||||
|
|
||||||
|
|
|
@ -37,26 +37,38 @@ public class FlywayInitListener implements ApplicationListener<ApplicationContex
|
||||||
String dataSourcePassword = environment.getProperty("spring.datasource.password");
|
String dataSourcePassword = environment.getProperty("spring.datasource.password");
|
||||||
|
|
||||||
// flyway的配置
|
// flyway的配置
|
||||||
|
String enabledStr = environment.getProperty("spring.flyway.enabled");
|
||||||
String locations = environment.getProperty("spring.flyway.locations");
|
String locations = environment.getProperty("spring.flyway.locations");
|
||||||
String baselineOnMigrateStr = environment.getProperty("spring.flyway.baseline-on-migrate");
|
String baselineOnMigrateStr = environment.getProperty("spring.flyway.baseline-on-migrate");
|
||||||
String outOfOrderStr = environment.getProperty("spring.flyway.out-of-order");
|
String outOfOrderStr = environment.getProperty("spring.flyway.out-of-order");
|
||||||
|
|
||||||
|
// 是否开启flyway,默认false.
|
||||||
|
boolean enabled = false;
|
||||||
|
if (StrUtil.isNotBlank(enabledStr)) {
|
||||||
|
enabled = Boolean.parseBoolean(enabledStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果未开启flyway 直接return
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 如果有为空的配置,终止执行
|
// 如果有为空的配置,终止执行
|
||||||
if (ObjectUtil.hasEmpty(dataSourceUrl, dataSourceUsername, dataSourcePassword)) {
|
if (ObjectUtil.hasEmpty(dataSourceUrl, dataSourceUsername, dataSourcePassword)) {
|
||||||
throw new DaoException(FlywayExceptionEnum.DB_CONFIG_ERROR);
|
throw new DaoException(FlywayExceptionEnum.DB_CONFIG_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果未设置flyway路径,则设置为默认flyway路径
|
|
||||||
if (StrUtil.isBlank(locations)) {
|
|
||||||
locations = FLYWAY_LOCATIONS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当迁移时发现目标schema非空,而且带有没有元数据的表时,是否自动执行基准迁移,默认false.
|
// 当迁移时发现目标schema非空,而且带有没有元数据的表时,是否自动执行基准迁移,默认false.
|
||||||
boolean baselineOnMigrate = false;
|
boolean baselineOnMigrate = false;
|
||||||
if (StrUtil.isNotBlank(baselineOnMigrateStr)) {
|
if (StrUtil.isNotBlank(baselineOnMigrateStr)) {
|
||||||
baselineOnMigrate = Boolean.parseBoolean(baselineOnMigrateStr);
|
baselineOnMigrate = Boolean.parseBoolean(baselineOnMigrateStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果未设置flyway路径,则设置为默认flyway路径
|
||||||
|
if (StrUtil.isBlank(locations)) {
|
||||||
|
locations = FLYWAY_LOCATIONS;
|
||||||
|
}
|
||||||
|
|
||||||
// 是否允许无序的迁移 开发环境最好开启, 生产环境关闭
|
// 是否允许无序的迁移 开发环境最好开启, 生产环境关闭
|
||||||
boolean outOfOrder = false;
|
boolean outOfOrder = false;
|
||||||
if (StrUtil.isNotBlank(outOfOrderStr)) {
|
if (StrUtil.isNotBlank(outOfOrderStr)) {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket相关配置快速获取
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/25 20:05
|
||||||
|
*/
|
||||||
|
public class WebSocketConfigExpander {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取websocket的ws-url
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/25 20:34
|
||||||
|
*/
|
||||||
|
public static String getWebSocketWsUrl() {
|
||||||
|
String webSocketWsUr = ConfigContext.me().getConfigValueNullable("WEB_SOCKET_WS_URL", String.class);
|
||||||
|
|
||||||
|
if (webSocketWsUr == null) {
|
||||||
|
// 没配置就查询配置文件
|
||||||
|
String propertiesUrl = SpringUtil.getProperty("web-socket.ws-url");
|
||||||
|
if(StrUtil.isNotEmpty(propertiesUrl)){
|
||||||
|
return propertiesUrl;
|
||||||
|
}
|
||||||
|
// 没配置就返回一个空串
|
||||||
|
return StrUtil.EMPTY;
|
||||||
|
}
|
||||||
|
return webSocketWsUr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
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 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;
|
||||||
|
@ -28,8 +29,10 @@ public class GunsMessageAutoConfiguration {
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = WEB_SOCKET_PREFIX)
|
@ConfigurationProperties(prefix = WEB_SOCKET_PREFIX)
|
||||||
public MessageWebSocketProperties sysLogProperties() {
|
public MessageWebSocketProperties messageWebSocketProperties() {
|
||||||
return new MessageWebSocketProperties();
|
MessageWebSocketProperties properties = new MessageWebSocketProperties();
|
||||||
|
properties.setWsUrl(WebSocketConfigExpander.getWebSocketWsUrl());
|
||||||
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue