diff --git a/upms/upms-biz/src/main/resources/application.yml b/upms/upms-biz/src/main/resources/application.yml index bcf3619..4144057 100644 --- a/upms/upms-biz/src/main/resources/application.yml +++ b/upms/upms-biz/src/main/resources/application.yml @@ -11,13 +11,13 @@ spring: type: redis data: redis: - host: localhost + host: 192.168.244.129 # 数据库相关配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: 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: properties: @@ -101,10 +101,10 @@ mybatis-plus: vital-sign: mongodb: - host: localhost:27017 + host: 192.168.244.129:27017 password: root username: root mysql: - host: localhost:3306 + host: 192.168.244.129:3306 password: root username: root diff --git a/vital-signs/src/main/java/com/rax/vital/config/WebSocketConfig.java b/vital-signs/src/main/java/com/rax/vital/config/WebSocketConfig.java index 03a0d42..fd48280 100644 --- a/vital-signs/src/main/java/com/rax/vital/config/WebSocketConfig.java +++ b/vital-signs/src/main/java/com/rax/vital/config/WebSocketConfig.java @@ -3,6 +3,7 @@ package com.rax.vital.config; import com.rax.vital.handler.ChatHandler; import com.rax.vital.handler.MedicineHandler; import com.rax.vital.interceptor.WebSocketInterceptors; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; 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.WebSocketHandlerRegistry; import org.springframework.web.socket.server.HandshakeInterceptor; -import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; @EnableWebSocket @Configuration public class WebSocketConfig implements WebSocketConfigurer { + @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(medicineHandler(), "/vitalSignsMedicine") - .addHandler(chatHandler(), "/chatRoom") + registry.addHandler(medicineHandler(), "/rax/vitalSignsMedicine") + .addHandler(chatHandler(), "/rax/chatRoom") +// .addInterceptors(new HttpSessionHandshakeInterceptor()) .addInterceptors(webSocketHandshakeInterceptor()) .setAllowedOrigins("*"); } @@ -33,6 +35,7 @@ public class WebSocketConfig implements WebSocketConfigurer { return new ChatHandler(); } + @Bean public HandshakeInterceptor webSocketHandshakeInterceptor() { return new WebSocketInterceptors(); } diff --git a/vital-signs/src/main/java/com/rax/vital/handler/ChatHandler.java b/vital-signs/src/main/java/com/rax/vital/handler/ChatHandler.java index e237168..d65ed5e 100644 --- a/vital-signs/src/main/java/com/rax/vital/handler/ChatHandler.java +++ b/vital-signs/src/main/java/com/rax/vital/handler/ChatHandler.java @@ -1,5 +1,6 @@ package com.rax.vital.handler; +import org.springframework.stereotype.Component; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketMessage; diff --git a/vital-signs/src/main/java/com/rax/vital/handler/MedicineHandler.java b/vital-signs/src/main/java/com/rax/vital/handler/MedicineHandler.java index 59ac123..e837c29 100644 --- a/vital-signs/src/main/java/com/rax/vital/handler/MedicineHandler.java +++ b/vital-signs/src/main/java/com/rax/vital/handler/MedicineHandler.java @@ -1,11 +1,20 @@ 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.WebSocketHandler; import org.springframework.web.socket.WebSocketMessage; import org.springframework.web.socket.WebSocketSession; public class MedicineHandler implements WebSocketHandler { + + @Resource + private VitalSignTimer vitalSignTimer; + @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { session.getPrincipal(); @@ -13,7 +22,13 @@ public class MedicineHandler implements WebSocketHandler { @Override 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 diff --git a/vital-signs/src/main/java/com/rax/vital/interceptor/WebSocketInterceptors.java b/vital-signs/src/main/java/com/rax/vital/interceptor/WebSocketInterceptors.java index 6c28b7a..cc73618 100644 --- a/vital-signs/src/main/java/com/rax/vital/interceptor/WebSocketInterceptors.java +++ b/vital-signs/src/main/java/com/rax/vital/interceptor/WebSocketInterceptors.java @@ -1,26 +1,30 @@ 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.ServerHttpResponse; -import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; +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.server.HandshakeInterceptor; import java.util.Map; -public class WebSocketInterceptors implements HandshakeInterceptor { +public class WebSocketInterceptors implements HandshakeInterceptor { + + @Resource + private OAuth2AuthorizationService authorizationService; + @Override public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map attributes) throws Exception { - if (request instanceof ServletServerHttpRequest) { - ServletServerHttpRequest servletServerHttpRequest = (ServletServerHttpRequest) request; - HttpSession session = servletServerHttpRequest.getServletRequest().getSession(false); - if (session != null) { - SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - } + + String token = (String) attributes.get("token"); + OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); + if (authorization == null ) { + return false; } - return false; + return true; } @Override