This commit is contained in:
parent
49df6cd03e
commit
f5ef4fd0b7
|
@ -105,6 +105,13 @@
|
|||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 加密模块-->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.68</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.rax.vital.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.vital.timer.AIMedicineTimer;
|
||||
import com.rax.vital.timer.VitalSignTimerWS;
|
||||
import com.rax.vital.util.DatabaseNameUtil;
|
||||
import com.rax.vital.util.GetHttpParamUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||
|
@ -27,6 +29,10 @@ public class AddMedicineHandler implements WebSocketHandler {
|
|||
@Resource
|
||||
private OAuth2AuthorizationService authorizationService;
|
||||
|
||||
// @Autowired
|
||||
// private AIMedicineTimer aiMedicineTimer;
|
||||
|
||||
// 发送心跳任务的定时任务容器
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rax.vital.handler;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.vital.medicine.service.ChatService;
|
||||
import com.rax.vital.util.DatabaseNameUtil;
|
||||
import com.rax.vital.util.GetHttpParamUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||
|
@ -47,7 +48,9 @@ public class ChatHandler implements WebSocketHandler {
|
|||
String date = jsonObject.getString("date");
|
||||
// 消息内容
|
||||
String msg = jsonObject.getString("msg");
|
||||
chatService.sendMessage(username, patientName, idNum, date, session, msg);
|
||||
System.out.println("chatHandler-jsonObject = " + jsonObject.toJSONString());
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
chatService.sendMessage(databaseName,username,session, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.rax.vital.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.vital.timer.AIMedicineTimer;
|
||||
import com.rax.vital.timer.VitalSignTimerWS;
|
||||
import com.rax.vital.util.DatabaseNameUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
|
@ -23,8 +26,13 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
|||
@Resource
|
||||
private VitalSignTimerWS vitalSignTimerWS;
|
||||
|
||||
|
||||
// @Autowired
|
||||
// private AIMedicineTimer aiMedicineTimer;
|
||||
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) {
|
||||
vitalSignTimerWS.setMachineSessionMap(session);
|
||||
|
@ -33,6 +41,7 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
|||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||
|
||||
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||
|
@ -44,8 +53,16 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
|||
String date = jsonObject.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
String code = jsonObject.getString("code");
|
||||
|
||||
// aiMedicineTimer.addU3DSession(databaseName,session);
|
||||
// aiMedicineTimer.addU3DStatusMap(databaseName, false); // 初始状态为false
|
||||
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
||||
|
||||
String connection = jsonObject.getString("connection");
|
||||
if ("true".equals(connection)) {
|
||||
// 设备端口请求连接
|
||||
// 广播到网站段端
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.security.oauth2.server.authorization.OAuth2Authorizat
|
|||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
@ -48,7 +48,10 @@ public class MedicineHandler implements WebSocketHandler {
|
|||
String patientName = jsonObject.getString("patientName");
|
||||
String idNum = jsonObject.getString("idNum");
|
||||
String date = jsonObject.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
System.out.println("medicineHandler-jsonObject = " + jsonObject.toJSONString());
|
||||
String databaseName = null;
|
||||
databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
System.out.println("medicineHandler-databaseName = " + databaseName);
|
||||
vitalSignTimerWS.createAndSendWSMessageMongo(databaseName, username, session);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.rax.vital.handler;
|
||||
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
|
||||
public class MedicineHandlerV2 extends AbstractWebSocketHandler {
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||
super.afterConnectionEstablished(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
super.handleMessage(session, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||
super.handleTransportError(session, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
||||
super.afterConnectionClosed(session, status);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import jakarta.annotation.Resource;
|
|||
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.stereotype.Component;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
|||
public interface ChatService {
|
||||
void sendMessage(String username, String patientName, String idNum, String date, String simpSessionId, String msg);
|
||||
|
||||
void sendMessage(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) throws IOException;
|
||||
void sendMessage(String dbName, String username, WebSocketSession session, String msg) throws IOException;
|
||||
|
||||
void sendMessageMysql(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) throws Exception;
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ public class ChatServiceImpl implements ChatService {
|
|||
@Override
|
||||
public void sendMessage(String username, String patientName, String idNum, String date, String simpSessionId, String msg) {
|
||||
CustomDataSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
|
||||
if (mongoDBSource == null) {
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
|
@ -78,7 +79,6 @@ public class ChatServiceImpl implements ChatService {
|
|||
mongoDBSource.open();
|
||||
}
|
||||
|
||||
|
||||
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
|
||||
Map param = new HashMap();
|
||||
|
@ -102,31 +102,31 @@ public class ChatServiceImpl implements ChatService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) throws IOException {
|
||||
public void sendMessage(String databaseName,String username, WebSocketSession session, String msg) throws IOException {
|
||||
CustomDataSource mongoDBSource = datasourceMap.get(session.getId());
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
synchronized (username) {
|
||||
if (mongoDBSource == null) {
|
||||
mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
mongoDBSource.open();
|
||||
datasourceMap.put(session.getId(), mongoDBSource);
|
||||
sessionDatabaseMap.put(session.getId(), databaseName);
|
||||
Map<String, WebSocketSession> sessionMap = databaseSessionMap.get(databaseName);
|
||||
if (sessionMap == null) {
|
||||
sessionMap = new HashMap();
|
||||
// synchronized (username) {
|
||||
if (mongoDBSource == null) {
|
||||
mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
mongoDBSource.open();
|
||||
datasourceMap.put(session.getId(), mongoDBSource);
|
||||
sessionDatabaseMap.put(session.getId(), databaseName);
|
||||
Map<String, WebSocketSession> sessionMap = databaseSessionMap.get(databaseName);
|
||||
if (sessionMap == null) {
|
||||
sessionMap = new HashMap();
|
||||
sessionMap.put(session.getId(), session);
|
||||
databaseSessionMap.put(databaseName, sessionMap);
|
||||
} else {
|
||||
if (!sessionMap.containsKey(session.getId())) {
|
||||
sessionMap.put(session.getId(), session);
|
||||
databaseSessionMap.put(databaseName, sessionMap);
|
||||
} else {
|
||||
if (!sessionMap.containsKey(session.getId())) {
|
||||
sessionMap.put(session.getId(), session);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
|
||||
|
||||
// 将聊天消息保存在mongo中
|
||||
if (StringUtils.hasText(msg)) {
|
||||
JSONObject param = new JSONObject();
|
||||
MongoTemplate template = mongoDBSource.getConnection();
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package com.rax.vital.timer;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@RefreshScope
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AIMedicineTimer {
|
||||
// MongoDB的地址
|
||||
@Value("${vital-sign.mongodb.host}")
|
||||
private String mongoDBHost;
|
||||
|
||||
// MongoDB的用户名
|
||||
@Value("${vital-sign.mongodb.username}")
|
||||
private String mongoUsername;
|
||||
|
||||
// MongoDB的用户的密码
|
||||
@Value("${vital-sign.mongodb.password}")
|
||||
private String mongoPassword;
|
||||
|
||||
// mysql地址
|
||||
@Value("${vital-sign.mysql.host}")
|
||||
private String mysqlHost;
|
||||
|
||||
// mysql用户名
|
||||
@Value("${vital-sign.mysql.username}")
|
||||
private String mysqlUsername;
|
||||
|
||||
// mysql用户密码
|
||||
@Value("${vital-sign.mysql.password}")
|
||||
private String mysqlPassword;
|
||||
|
||||
// 定时任务容器
|
||||
private static final Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
// web端状态容器 key:sessionId value:boolean
|
||||
private static final Map<String, Boolean> webStatusMap = new ConcurrentHashMap<>();
|
||||
|
||||
// u3D端状态容器 key:sessionId value:boolean
|
||||
private static final Map<String, Boolean> u3DStatusMap = new ConcurrentHashMap<>();
|
||||
|
||||
// key: dbName value: sessionId
|
||||
private static final Map<String, String> webSession = new ConcurrentHashMap<>();
|
||||
// key: dbName value: sessionId
|
||||
private static final Map<String, String> u3DSession = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public void addWebSession(String dbName, WebSocketSession session) {
|
||||
webSession.put(dbName, session.getId());
|
||||
}
|
||||
public void addU3DSession(String dbName, WebSocketSession session) {
|
||||
u3DSession.put(dbName, session.getId());
|
||||
}
|
||||
|
||||
public void addWebStatus(String sessionId, boolean status) {
|
||||
webStatusMap.put(sessionId, status);
|
||||
}
|
||||
|
||||
public void addU3DStatusMap(String sessionId, boolean status) {
|
||||
webStatusMap.put(sessionId, status);
|
||||
}
|
||||
}
|
|
@ -54,22 +54,22 @@ public class VitalSignTimerWS {
|
|||
// 定时任务容器
|
||||
private static final Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 链接工具类容器
|
||||
// 链接工具类容器 ket
|
||||
private static final Map<String, CustomDataSource> dataSourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 主控人员容器
|
||||
// 主控人员容器, 建立连接放入存值,生命体征信息 key:数据库名 value:网页解析的token用户名
|
||||
private static final Map<String, String> masterControlMap = new ConcurrentHashMap<>();
|
||||
|
||||
// session容器
|
||||
// session容器,网站端操作员
|
||||
private static final Map<String, WebSocketSession> userSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// sessionId容器,(数据库名, sessionId)
|
||||
private static final Map<String, String> userDatabaseSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 设备端session容器
|
||||
// 设备端session容器,U3D
|
||||
private static final Map<String, WebSocketSession> machineSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// sessionId容器,(数据库名, sessionId)
|
||||
// sessionId容器,(数据库名, sessionId) 数据库名称, u3d获取药物的sessionId
|
||||
private static final Map<String, String> machineDatabaseSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final VitalSignsService vitalSignsService;
|
||||
|
@ -84,11 +84,14 @@ public class VitalSignTimerWS {
|
|||
|
||||
public void createAndSendWSMessageMongo(String database, String username, WebSocketSession session) {
|
||||
|
||||
synchronized (this) {
|
||||
if (!masterControlMap.containsKey(database)) {
|
||||
masterControlMap.put(database, username);
|
||||
}
|
||||
for (String s : masterControlMap.keySet()) {
|
||||
System.out.println("s = " + s + " masterControlMap.get(s) = " + masterControlMap.get(s));
|
||||
}
|
||||
// synchronized (this) {
|
||||
if (!masterControlMap.containsKey(database)) {
|
||||
masterControlMap.put(database, username);
|
||||
}
|
||||
// }
|
||||
|
||||
String sessionId = session.getId();
|
||||
|
||||
|
@ -301,7 +304,7 @@ public class VitalSignTimerWS {
|
|||
String userSessionId = userDatabaseSessionMap.get(database);
|
||||
WebSocketSession webSocketSession = userSessionMap.get(userSessionId);
|
||||
result.put("status", code);
|
||||
result.put("msg", "");
|
||||
result.put("msg", "网站已进行远程连接");
|
||||
result.put("msgType", "msg");
|
||||
webSocketSession.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.rax.vital.util;
|
|||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class DatabaseNameUtil {
|
||||
|
@ -31,4 +34,5 @@ public class DatabaseNameUtil {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,8 +93,11 @@ spring:
|
|||
type: redis
|
||||
data:
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6378
|
||||
host: 110.41.142.124
|
||||
port: 16373
|
||||
password: rax137839
|
||||
connect-timeout: 5000
|
||||
|
||||
# 数据库相关配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
@ -111,7 +114,7 @@ vital-sign:
|
|||
except-database: admin,config,local
|
||||
information-database: information
|
||||
mongodb:
|
||||
host: localhost:27017
|
||||
host: 110.41.142.124:27017
|
||||
password: Xg137839mg
|
||||
username: useradmin
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
</logger>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="debug">
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user