生命体征模块迁移

This commit is contained in:
yy 2024-05-31 12:48:45 +08:00
parent 158129e56e
commit 815b3d4403
44 changed files with 247 additions and 280 deletions

View File

@ -106,11 +106,6 @@
<groupId>com.rax</groupId>
<artifactId>quartz</artifactId>
<version>${common.version}</version>
</dependency>
<dependency>
<groupId>com.rax</groupId>
<artifactId>vital-signs</artifactId>
<version>${common.version}</version>
</dependency>
<dependency>
<groupId>com.rax</groupId>

View File

@ -99,7 +99,6 @@
<!-- 通用模块 -->
<module>common</module>
<module>vital-signs</module>
<module>daily-plan</module>
</modules>

View File

@ -49,10 +49,6 @@
<dependency>
<groupId>com.rax</groupId>
<artifactId>common-log</artifactId>
</dependency>
<dependency>
<groupId>com.rax</groupId>
<artifactId>vital-signs</artifactId>
</dependency>
<dependency>
<groupId>com.rax</groupId>
@ -96,6 +92,19 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.21</version>
</dependency>
</dependencies>
<build>

View File

@ -4,7 +4,6 @@ import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import lombok.Getter;
import org.springframework.data.mongodb.SpringDataMongoDB;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;

View File

@ -1,7 +1,6 @@
package com.rax.vital.handler;
import com.alibaba.fastjson.JSONObject;
import com.rax.vital.timer.VitalSignTimer;
import com.rax.vital.timer.VitalSignTimerWS;
import com.rax.vital.util.DatabaseNameUtil;
import com.rax.vital.util.GetHttpParamUtil;

View File

@ -2,7 +2,6 @@ package com.rax.vital.handler.mysql;
import com.alibaba.fastjson.JSONObject;
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.security.oauth2.server.authorization.OAuth2Authorization;
@ -48,8 +47,18 @@ public class AddMedicineHandler implements WebSocketHandler {
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
String username = authorization.getPrincipalName();
if (message.getPayload() instanceof String) {
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
String payload = (String) message.getPayload();
JSONObject jsonObject = JSONObject.parseObject(payload);
synchronized (payload) {
if ("heartbeat".equals(jsonObject.getString("msgType"))) {
jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
if (pingTime > 0) {
pingTime--;
}
} else {
pingTime = 0;
// 病人名
String patientName = jsonObject.getString("patientName");
// 病人身份证
@ -59,14 +68,12 @@ public class AddMedicineHandler implements WebSocketHandler {
String databaseName = patientName + idNum;
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
jsonObject.getString("medicine"), jsonObject.getString("value"));
} else {
session.sendMessage(new PongMessage());
pingTime--;
}
}
}
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
public void handleTransportError(WebSocketSession session, Throwable exception) {
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
@ -77,7 +84,7 @@ public class AddMedicineHandler implements WebSocketHandler {
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
vitalSignTimerWS.removeWSAIFlagSession(session);
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
if (heartbeatTask != null) {
@ -105,7 +112,9 @@ public class AddMedicineHandler implements WebSocketHandler {
}
vitalSignTimerWS.removeWSAIFlagSession(session);
} else {
session.sendMessage(new PingMessage());
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
pingTime++;
}
} catch (IOException e) {

View File

@ -9,13 +9,11 @@ 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.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
public class ChatHandler implements WebSocketHandler {
@Resource
@ -24,15 +22,11 @@ public class ChatHandler implements WebSocketHandler {
@Resource
private ChatService chatService;
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
private ScheduledExecutorService scheduler;
private ScheduledFuture<?> heartbeatTask;
private int pingTime = 0;
private Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap();
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
scheduler = Executors.newScheduledThreadPool(1);
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
startHeartbeat(session);
}
@Override
@ -44,41 +38,31 @@ public class ChatHandler implements WebSocketHandler {
if (authorization != null) {
String username = authorization.getPrincipalName();
if (message.getPayload() instanceof String) {
String payload = (String) message.getPayload();
JSONObject jsonObject = JSONObject.parseObject(payload);
if ("heartbeat".equals(jsonObject.getString("msgType"))) {
// session.sendMessage(new TextMessage(""));
} else {
String patientName = jsonObject.getString("patientName");
String idNum = jsonObject.getString("idNum");
String date = jsonObject.getString("date");
// 消息内容
String msg = jsonObject.getString("msg");
chatService.sendMessageMysql(username, patientName, idNum, date, session, msg);
} else {
session.sendMessage(new PongMessage());
pingTime--;
}
}
}
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
chatService.stopTask(session.getId());
public void handleTransportError(WebSocketSession session, Throwable exception) {
System.out.println("Error: " + exception.getMessage());
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
System.out.println("CloseStatus: " + closeStatus.getReason() + closeStatus.getCode());
stopHeartbeat(session);
chatService.stopTask(session.getId());
}
@ -87,24 +71,36 @@ public class ChatHandler implements WebSocketHandler {
return false;
}
private void sendPing(WebSocketSession session) {
private void startHeartbeat(WebSocketSession session) {
if (!timerTaskMap.containsKey(session.getId())) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
try {
if (pingTime > 3) {
session.close();
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
chatService.stopTask(session.getId());
if (session.isOpen()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
} else {
session.sendMessage(new PingMessage());
pingTime++;
}
} catch (IOException e) {
stopHeartbeat(session);
chatService.stopTask(session.getId());
e.printStackTrace();
session.close();
}
} catch (Exception e) {
e.printStackTrace();
stopHeartbeat(session);
}
}
};
// 定时任务设置1秒
Timer timer = new Timer();
timer.schedule(timerTask, 0, 1000);
timerTaskMap.put(session.getId(), timerTask);
}
}
private void stopHeartbeat(WebSocketSession session) {
TimerTask timerTask = timerTaskMap.get(session.getId());
timerTask.cancel();
}
}

View File

@ -2,7 +2,6 @@ package com.rax.vital.handler.mysql;
import com.alibaba.fastjson.JSONObject;
import com.rax.vital.timer.VitalSignTimerWS;
import com.rax.vital.util.DatabaseNameUtil;
import jakarta.annotation.Resource;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import org.springframework.web.socket.*;
@ -37,8 +36,18 @@ public class MachineFeedbackHandler implements WebSocketHandler {
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
if (message.getPayload() instanceof String) {
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
String payload = (String) message.getPayload();
JSONObject jsonObject = JSONObject.parseObject(payload);
synchronized (payload) {
if ("heartbeat".equals(jsonObject.getString("msgType"))) {
jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
if (pingTime > 0) {
pingTime--;
}
} else {
pingTime = 0;
// 病人名
String patientName = jsonObject.getString("patientName");
// 病人身份证住院号
@ -49,9 +58,7 @@ public class MachineFeedbackHandler implements WebSocketHandler {
String code = jsonObject.getString("code");
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
} else {
session.sendMessage(new PongMessage());
pingTime--;
}
}
}
@ -95,7 +102,9 @@ public class MachineFeedbackHandler implements WebSocketHandler {
}
vitalSignTimerWS.removeMachineSessionMap(session);
} else {
session.sendMessage(new PingMessage());
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
pingTime++;
}
} catch (IOException e) {

View File

@ -2,7 +2,6 @@ package com.rax.vital.handler.mysql;
import com.alibaba.fastjson.JSONObject;
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.security.oauth2.server.authorization.OAuth2Authorization;
@ -13,10 +12,9 @@ import org.springframework.web.socket.*;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;
public class MedicineHandler implements WebSocketHandler {
@ -26,15 +24,11 @@ public class MedicineHandler implements WebSocketHandler {
@Resource
private OAuth2AuthorizationService authorizationService;
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
private ScheduledExecutorService scheduler;
private ScheduledFuture<?> heartbeatTask;
private int pingTime = 0;
private Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap();
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
scheduler = Executors.newScheduledThreadPool(1);
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
public void afterConnectionEstablished(WebSocketSession session) {
startHeartbeat(session);
}
@Override
@ -45,40 +39,28 @@ public class MedicineHandler implements WebSocketHandler {
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
String username = authorization.getPrincipalName();
if (message.getPayload() instanceof String) {
String payload = (String) message.getPayload();
JSONObject jsonObject = JSONObject.parseObject(payload);
if ("heartbeat".equals(jsonObject.getString("msgType"))) {
// session.sendMessage(new TextMessage(""));
} else {
String patientName = jsonObject.getString("patientName");
String idNum = jsonObject.getString("idNum");
String databaseName = patientName + idNum;
vitalSignTimerWS.createAndSendMessageMySQL(databaseName, username, session);
} else {
session.sendMessage(new PongMessage());
pingTime--;
}
}
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
public void handleTransportError(WebSocketSession session, Throwable exception) {
System.out.println("Error: " + exception.getMessage());
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
vitalSignTimerWS.stopTimerTask(session.getId());
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
System.out.println("MedicineHandler Connection closed:" + closeStatus.getReason());
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
stopHeartbeat(session);
vitalSignTimerWS.stopTimerTask(session.getId());
}
@ -87,24 +69,36 @@ public class MedicineHandler implements WebSocketHandler {
return false;
}
private void sendPing(WebSocketSession session) {
private void startHeartbeat(WebSocketSession session) {
if (!timerTaskMap.containsKey(session.getId())) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
try {
if (pingTime > 3) {
session.close();
if (heartbeatTask != null) {
heartbeatTask.cancel(true);
}
if (scheduler != null) {
scheduler.shutdown();
}
vitalSignTimerWS.stopTimerTask(session.getId());
if (session.isOpen()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgType", "heartbeat");
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
} else {
session.sendMessage(new PingMessage());
pingTime++;
}
} catch (IOException e) {
session.close();
stopHeartbeat(session);
vitalSignTimerWS.stopTimerTask(session.getId());
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
stopHeartbeat(session);
}
}
};
// 定时任务设置1秒
Timer timer = new Timer();
timer.schedule(timerTask, 0, 1000);
timerTaskMap.put(session.getId(), timerTask);
}
}
private void stopHeartbeat(WebSocketSession session) {
TimerTask timerTask = timerTaskMap.get(session.getId());
timerTask.cancel();
}
}

View File

@ -2,7 +2,6 @@ package com.rax.vital.medicine.controller;
import com.alibaba.fastjson.JSONObject;
import com.rax.vital.medicine.service.ChatService;
import com.rax.vital.util.DatabaseNameUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.MessageMapping;
@ -14,7 +13,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import java.util.ArrayList;
import java.util.HashMap;
@Controller
public class ChatController {

View File

@ -1,6 +1,5 @@
package com.rax.vital.medicine.service;
import com.rax.common.core.util.R;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.sql.Connection;

View File

@ -1,7 +1,5 @@
package com.rax.vital.medicine.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.rax.vital.medicine.entity.DoctorMedicine;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.sql.Connection;

View File

@ -3,7 +3,6 @@ package com.rax.vital.medicine.service;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.sql.Connection;
import java.util.List;
import java.util.Map;
public interface FlagService {

View File

@ -2,7 +2,6 @@ package com.rax.vital.medicine.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rax.common.core.util.R;
import com.rax.vital.datasource.MongoDBSource;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.sql.Connection;

View File

@ -55,7 +55,7 @@ public class AIMedicineServiceImpl implements AIMedicineService {
List<Map> medicineList = new ArrayList<>();
try {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `aimedicinetable` ORDER BY time DESC LIMIT 1;");
/*ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `aimedicinetable` ORDER BY time DESC LIMIT 1;");
Map medicine = new HashMap();
while (resultSet.next()) {
medicine.put("id", resultSet.getString("id"));
@ -84,8 +84,33 @@ public class AIMedicineServiceImpl implements AIMedicineService {
medicine.put("艾司洛尔sum", sumSet.getString("艾司洛尔sum"));
medicine.put("麻黄素sum", sumSet.getString("麻黄素sum"));
medicine.put("阿托品sum", sumSet.getString("阿托品sum"));
}
}*/
String sql = " SELECT " +
"rate_1, cumu_1, rate_2, cumu_2,rate_3, cumu_3,rate_4, cumu_4, rate_5, cumu_5,rate_6, cumu_6,rate_7, cumu_7,rate_8, cumu_8, time " +
" FROM fktable " +
" ORDER BY time DESC LIMIT 1; ";
ResultSet resultSet = statement.executeQuery(sql);
Map medicine = new HashMap();
while (resultSet.next()) {
medicine.put("丙泊酚", resultSet.getString("rate_1"));
medicine.put("丙泊酚sum", resultSet.getString("cumu_1"));
medicine.put("舒芬太尼", resultSet.getString("rate_2"));
medicine.put("舒芬太尼sum", resultSet.getString("cumu_2"));
medicine.put("瑞芬太尼", resultSet.getString("rate_3"));
medicine.put("瑞芬太尼sum", resultSet.getString("cumu_3"));
medicine.put("顺阿曲库胺", resultSet.getString("rate_4"));
medicine.put("顺阿曲库胺sum", resultSet.getString("cumu_4"));
medicine.put("尼卡地平", resultSet.getString("rate_5"));
medicine.put("尼卡地平sum", resultSet.getString("cumu_5"));
medicine.put("艾司洛尔", resultSet.getString("rate_6"));
medicine.put("艾司洛尔sum", resultSet.getString("cumu_6"));
medicine.put("麻黄素", resultSet.getString("rate_7"));
medicine.put("麻黄素sum", resultSet.getString("cumu_7"));
medicine.put("阿托品", resultSet.getString("rate_8"));
medicine.put("阿托品sum", resultSet.getString("cumu_8"));
medicine.put("Time", resultSet.getString("time"));
}
medicineList.add(medicine);
} catch (SQLException e) {
throw new RuntimeException(e);

View File

@ -2,11 +2,9 @@ package com.rax.vital.medicine.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.rax.admin.api.dto.UserDTO;
import com.rax.admin.api.dto.UserInfo;
import com.rax.admin.api.feign.RemoteUserService;
import com.rax.common.core.constant.SecurityConstants;
import com.rax.common.core.util.R;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.rax.admin.api.entity.SysUser;
import com.rax.admin.service.SysUserService;
import com.rax.vital.datasource.CustomDataSource;
import com.rax.vital.datasource.MongoDBSource;
import com.rax.vital.datasource.MySQLSource;
@ -24,9 +22,14 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@RefreshScope
@Service
@ -36,13 +39,13 @@ public class ChatServiceImpl implements ChatService {
private SimpMessagingTemplate simpMessagingTemplate;
@Autowired
private RemoteUserService remoteUserService;
private SysUserService SysUserService;
private static final Map<String, CustomDataSource> datasourceMap = new HashMap<>();
private static final Map<String, CustomDataSource> datasourceMap = new ConcurrentHashMap<>();
private static final Map<String, Map<String, WebSocketSession>> databaseSessionMap = new HashMap<>();
private static final Map<String, Map<String, WebSocketSession>> databaseSessionMap = new ConcurrentHashMap<>();
private static final Map<String, String> sessionDatabaseMap = new HashMap<>();
private static final Map<String, String> sessionDatabaseMap = new ConcurrentHashMap<>();
// MongoDB的地址
@Value("${vital-sign.mongodb.host}")
@ -78,10 +81,8 @@ public class ChatServiceImpl implements ChatService {
mongoDBSource.open();
}
UserDTO userDTO = new UserDTO();
userDTO.setUsername(username);
R<UserInfo> info = remoteUserService.info(userDTO, SecurityConstants.FROM_IN);
UserInfo userInfo = info.getData();
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
Map param = new HashMap();
@ -93,7 +94,7 @@ public class ChatServiceImpl implements ChatService {
document.put("create_time", now);
param.put("createTime", now);
document.put("create_user", username);
String name = userInfo.getSysUser().getName();
String name = sysUser.getName();
document.put("create_name", name);
param.put("createName", name);
document.put("deleted", 0);
@ -127,10 +128,7 @@ public class ChatServiceImpl implements ChatService {
}
}
UserDTO userDTO = new UserDTO();
userDTO.setUsername(username);
R<UserInfo> info = remoteUserService.info(userDTO, SecurityConstants.FROM_IN);
UserInfo userInfo = info.getData();
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
if (StringUtils.hasText(msg)) {
JSONObject param = new JSONObject();
@ -142,12 +140,13 @@ public class ChatServiceImpl implements ChatService {
document.put("create_time", now);
param.put("createTime", now);
document.put("create_user", username);
String name = userInfo.getSysUser().getName();
String name = sysUser.getName();
document.put("create_name", name);
param.put("createName", name);
document.put("deleted", 0);
document.put("revoked", 0);
template.insert(document, "t_chat");
param.put("msgType", "msg");
Map<String, WebSocketSession> sessionMap = databaseSessionMap.get(databaseName);
for (Map.Entry<String, WebSocketSession> entry : sessionMap.entrySet()) {
@ -161,7 +160,8 @@ public class ChatServiceImpl implements ChatService {
public void sendMessageMysql(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) {
CustomDataSource dataSource = datasourceMap.get(session.getId());
String databaseName = patientName + idNum;
synchronized (username) {
ArrayList<Map> history = new ArrayList<>();
if (dataSource == null) {
dataSource = new MySQLSource(mysqlHost, mysqlPassword, mysqlUsername, databaseName);
boolean status = dataSource.open();
@ -182,21 +182,18 @@ public class ChatServiceImpl implements ChatService {
JSONObject jsonObject = new JSONObject();
jsonObject.put("status", 1);
jsonObject.put("msg", "数据库未创建, 请重新连接。");
jsonObject.put("msgType", "msg");
try {
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
session.close();
} catch (IOException e) {
throw new RuntimeException(e);
e.printStackTrace();
}
return;
}
}
}
UserDTO userDTO = new UserDTO();
userDTO.setUsername(username);
R<UserInfo> info = remoteUserService.info(userDTO, SecurityConstants.FROM_IN);
UserInfo userInfo = info.getData();
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
if (StringUtils.hasText(msg)) {
JSONObject param = new JSONObject();
@ -229,15 +226,16 @@ public class ChatServiceImpl implements ChatService {
param.put("createTime", now);
preparedStatement.setString(3, username);
param.put("createUser", username);
String name = userInfo.getSysUser().getName();
String name = sysUser.getName();
preparedStatement.setString(4, name);
param.put("createName", name);
preparedStatement.setInt(5, 0);
preparedStatement.setInt(6, 0);
param.put("msgType", "msg");
preparedStatement.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
e.printStackTrace();
}
Map<String, WebSocketSession> sessionMap = databaseSessionMap.get(databaseName);
@ -246,7 +244,7 @@ public class ChatServiceImpl implements ChatService {
try {
value.sendMessage(new TextMessage(param.toJSONString().getBytes()));
} catch (IOException e) {
throw new RuntimeException(e);
e.printStackTrace();
}
}
}

View File

@ -1,8 +1,5 @@
package com.rax.vital.medicine.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rax.vital.medicine.entity.DoctorMedicine;
import com.rax.vital.medicine.mapper.DoctorMedicineMapper;
import com.rax.vital.medicine.service.DoctorMedicineService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -10,7 +10,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
import java.sql.Connection;
import java.util.*;

View File

@ -121,6 +121,7 @@ public class VitalSignTimerWS {
jsonObject.put("revulsionList", revulsionList);
Map flags = flagService.getFlags(template);
jsonObject.put("flags", flags);
jsonObject.put("msgType", "msg");
WebSocketMessage message = new TextMessage(jsonObject.toJSONString().getBytes());
try {
@ -156,10 +157,11 @@ public class VitalSignTimerWS {
dataSource = new MySQLSource(mysqlHost, mysqlPassword, mysqlUsername, database);
boolean status = dataSource.open();
if (status) {
dataSourceMap.put(database, dataSource);
dataSourceMap.put(sessionId, dataSource);
} else {
JSONObject jsonObject = new JSONObject();
jsonObject.put("status", 1);
jsonObject.put("msgType", "msg");
jsonObject.put("msg", "数据库未创建, 请重新连接。");
WebSocketMessage message = new TextMessage(jsonObject.toJSONString().getBytes());
try {
@ -182,12 +184,13 @@ public class VitalSignTimerWS {
jsonObject.put("vitalSignsList", vitalSignsList);
List<Map> aiMedicineList = aiMedicineService.getAIMedicine(connection);
jsonObject.put("aiMedicineList", aiMedicineList);
List<Map> docMedicineList = doctorMedicineService.getDocMedicine(connection);
jsonObject.put("docMedicineList", docMedicineList);
// List<Map> docMedicineList = doctorMedicineService.getDocMedicine(connection);
// jsonObject.put("docMedicineList", docMedicineList);
List revulsionList = revulsionService.getRevulsionServiceList(connection);
jsonObject.put("revulsionList", revulsionList);
Map flags = flagService.getFlag(connection);
jsonObject.put("flags", flags);
jsonObject.put("msgType", "msg");
WebSocketMessage message = new TextMessage(jsonObject.toJSONString().getBytes());
try {
@ -232,11 +235,13 @@ public class VitalSignTimerWS {
if (machineSession != null) {
result.put(medicine, value);
result.put("flag", flag);
result.put("msgType", "msg");
machineSession.sendMessage(new TextMessage(result.toJSONString().getBytes()));
} else {
result.put("flag", flag);
result.put("msg", "设备端未连接");
result.put("status", 1);
result.put("msgType", "msg");
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
}
} else {
@ -244,6 +249,7 @@ public class VitalSignTimerWS {
result.put("medicine", medicine);
result.put("msg", "设备端未连接");
result.put("status", 1);
result.put("msgType", "msg");
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
}
} else {
@ -251,6 +257,7 @@ public class VitalSignTimerWS {
result.put("medicine", medicine);
result.put("status", 1);
result.put("msg", "不是主控人员");
result.put("msgType", "msg");
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
}
}
@ -279,6 +286,7 @@ public class VitalSignTimerWS {
JSONObject msg = new JSONObject();
msg.put("status", 1);
msg.put("msg", "手术已有设备远程中");
msg.put("msgType", "msg");
session.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
}
} else {
@ -294,10 +302,12 @@ public class VitalSignTimerWS {
WebSocketSession webSocketSession = userSessionMap.get(userSessionId);
result.put("status", code);
result.put("msg", "");
result.put("msgType", "msg");
webSocketSession.sendMessage(new TextMessage(result.toJSONString().getBytes()));
} else {
result.put("status", 1);
result.put("msg", "网站未进行远程");
result.put("msgType", "msg");
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
}
}

View File

@ -1,9 +1,9 @@
package com.rax.vital.util;
import java.util.Base64;
import org.springframework.util.StringUtils;
import java.util.Base64;
public class DatabaseNameUtil {
private static final String key = "ruianxing112232323";

View File

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.rax</groupId>
<artifactId>rax</artifactId>
<version>3.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>vital-signs</artifactId>
<packaging>jar</packaging>
<description>病人生命特征和用药模块</description>
<dependencies>
<!--接口文档-->
<dependency>
<groupId>com.rax</groupId>
<artifactId>common-swagger</artifactId>
</dependency>
<dependency>
<groupId>com.rax</groupId>
<artifactId>common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.rax</groupId>
<artifactId>common-security</artifactId>
</dependency>
<!-- 引入quartz依赖 -->
<dependency>
<groupId>com.rax</groupId>
<artifactId>quartz</artifactId>
</dependency>
<!--日志处理-->
<dependency>
<groupId>com.rax</groupId>
<artifactId>common-log</artifactId>
</dependency>
<!--websocket, stompJs-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.21</version>
</dependency>
</dependencies>
</project>