ceshi
This commit is contained in:
parent
a4adf0e6da
commit
2d09617185
|
@ -11,13 +11,13 @@ spring:
|
||||||
type: redis
|
type: redis
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: localhost
|
host: 192.168.244.129
|
||||||
# 数据库相关配置
|
# 数据库相关配置
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
url: jdbc:mysql://localhost:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://192.168.244.129:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||||
# 定时任务属性配置
|
# 定时任务属性配置
|
||||||
quartz:
|
quartz:
|
||||||
properties:
|
properties:
|
||||||
|
@ -101,10 +101,10 @@ mybatis-plus:
|
||||||
|
|
||||||
vital-sign:
|
vital-sign:
|
||||||
mongodb:
|
mongodb:
|
||||||
host: localhost:27017
|
host: 192.168.244.129:27017
|
||||||
password: root
|
password: root
|
||||||
username: root
|
username: root
|
||||||
mysql:
|
mysql:
|
||||||
host: localhost:3306
|
host: 192.168.244.129:3306
|
||||||
password: root
|
password: root
|
||||||
username: root
|
username: root
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.rax.vital.config;
|
||||||
import com.rax.vital.handler.ChatHandler;
|
import com.rax.vital.handler.ChatHandler;
|
||||||
import com.rax.vital.handler.MedicineHandler;
|
import com.rax.vital.handler.MedicineHandler;
|
||||||
import com.rax.vital.interceptor.WebSocketInterceptors;
|
import com.rax.vital.interceptor.WebSocketInterceptors;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
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.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
@ -10,15 +11,16 @@ import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||||
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
|
|
||||||
|
|
||||||
@EnableWebSocket
|
@EnableWebSocket
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebSocketConfig implements WebSocketConfigurer {
|
public class WebSocketConfig implements WebSocketConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(medicineHandler(), "/vitalSignsMedicine")
|
registry.addHandler(medicineHandler(), "/rax/vitalSignsMedicine")
|
||||||
.addHandler(chatHandler(), "/chatRoom")
|
.addHandler(chatHandler(), "/rax/chatRoom")
|
||||||
|
// .addInterceptors(new HttpSessionHandshakeInterceptor())
|
||||||
.addInterceptors(webSocketHandshakeInterceptor())
|
.addInterceptors(webSocketHandshakeInterceptor())
|
||||||
.setAllowedOrigins("*");
|
.setAllowedOrigins("*");
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
|
||||||
return new ChatHandler();
|
return new ChatHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
public HandshakeInterceptor webSocketHandshakeInterceptor() {
|
public HandshakeInterceptor webSocketHandshakeInterceptor() {
|
||||||
return new WebSocketInterceptors();
|
return new WebSocketInterceptors();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rax.vital.handler;
|
package com.rax.vital.handler;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
import org.springframework.web.socket.WebSocketMessage;
|
import org.springframework.web.socket.WebSocketMessage;
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
package com.rax.vital.handler;
|
package com.rax.vital.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.rax.vital.timer.VitalSignTimer;
|
||||||
|
import com.rax.vital.util.DatabaseNameUtil;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
import org.springframework.web.socket.WebSocketMessage;
|
import org.springframework.web.socket.WebSocketMessage;
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
public class MedicineHandler implements WebSocketHandler {
|
public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private VitalSignTimer vitalSignTimer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
session.getPrincipal();
|
session.getPrincipal();
|
||||||
|
@ -13,7 +22,13 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||||
|
String payload = (String) message.getPayload();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
|
String patientName = jsonObject.getString("patientName");
|
||||||
|
String idNum = jsonObject.getString("idNum");
|
||||||
|
String date = jsonObject.getString("date");
|
||||||
|
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||||
|
// vitalSignTimer.createAndSendMessageMongo(databaseName, username, simpSessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,27 +1,31 @@
|
||||||
package com.rax.vital.interceptor;
|
package com.rax.vital.interceptor;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
import org.springframework.http.server.ServletServerHttpRequest;
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
|
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WebSocketInterceptors implements HandshakeInterceptor {
|
public class WebSocketInterceptors implements HandshakeInterceptor {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||||
if (request instanceof ServletServerHttpRequest) {
|
|
||||||
ServletServerHttpRequest servletServerHttpRequest = (ServletServerHttpRequest) request;
|
String token = (String) attributes.get("token");
|
||||||
HttpSession session = servletServerHttpRequest.getServletRequest().getSession(false);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
if (session != null) {
|
if (authorization == null ) {
|
||||||
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user