commit: 配置local的配置文件
This commit is contained in:
parent
9cc5fed164
commit
9193e945df
|
@ -17,7 +17,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableScheduling // 开启定时任务 -> 清除日志相关内容
|
||||
// 一期下面解注, 二期注释掉
|
||||
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
|
||||
//@SpringBootApplication
|
||||
@ComponentScan(
|
||||
basePackages = {"com.rax"},
|
||||
excludeFilters = {
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
package com.rax.vital.v2.config;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
public class MongoConfig {
|
||||
|
||||
@Bean
|
||||
public MongoClient mongoClient() {
|
||||
MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder();
|
||||
String connectionUrl = "mongodb://useradmin:Xg137839mg@110.41.142.124:27017/information?authSource=admin";
|
||||
mongoBuilder.applyConnectionString(new ConnectionString(connectionUrl));
|
||||
mongoBuilder.applyToConnectionPoolSettings(builder -> {
|
||||
// 允许的最大连接数。
|
||||
builder.maxSize(120);
|
||||
// 最小连接数。
|
||||
builder.minSize(1);
|
||||
// 池连接可以存活的最长时间。零值表示寿命没有限制。超过其生命周期的池连接将被关闭并在必要时由新连接替换
|
||||
builder.maxConnectionLifeTime(0, TimeUnit.SECONDS);
|
||||
// 池连接的最大空闲时间。零值表示对空闲时间没有限制。超过其空闲时间的池连接将被关闭并在必要时由新连接替换
|
||||
builder.maxConnectionIdleTime(60, TimeUnit.MINUTES);
|
||||
// 默认最大连接时间6min;
|
||||
builder.maxWaitTime(6, TimeUnit.MINUTES);
|
||||
});
|
||||
return MongoClients.create(mongoBuilder.build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleMongoClientDatabaseFactory mongoDbFactory(MongoClient mongoClient) {
|
||||
return new SimpleMongoClientDatabaseFactory(mongoClient, "information");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoTemplate mongoTemplate(SimpleMongoClientDatabaseFactory mongoDbFactory) {
|
||||
return new MongoTemplate(mongoDbFactory);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.rax.vital.v2.config;
|
||||
//
|
||||
//import com.mongodb.ConnectionString;
|
||||
//import com.mongodb.MongoClientSettings;
|
||||
//import com.mongodb.client.MongoClient;
|
||||
//import com.mongodb.client.MongoClients;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||
//
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//@Configuration
|
||||
//public class MongoConfig {
|
||||
//
|
||||
// @Bean
|
||||
// public MongoClient mongoClient() {
|
||||
// MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder();
|
||||
// String connectionUrl = "mongodb://useradmin:Xg137839mg@110.41.142.124:27017/information?authSource=admin";
|
||||
// mongoBuilder.applyConnectionString(new ConnectionString(connectionUrl));
|
||||
// mongoBuilder.applyToConnectionPoolSettings(builder -> {
|
||||
// // 允许的最大连接数。
|
||||
// builder.maxSize(120);
|
||||
// // 最小连接数。
|
||||
// builder.minSize(1);
|
||||
// // 池连接可以存活的最长时间。零值表示寿命没有限制。超过其生命周期的池连接将被关闭并在必要时由新连接替换
|
||||
// builder.maxConnectionLifeTime(0, TimeUnit.SECONDS);
|
||||
// // 池连接的最大空闲时间。零值表示对空闲时间没有限制。超过其空闲时间的池连接将被关闭并在必要时由新连接替换
|
||||
// builder.maxConnectionIdleTime(60, TimeUnit.MINUTES);
|
||||
// // 默认最大连接时间6min;
|
||||
// builder.maxWaitTime(6, TimeUnit.MINUTES);
|
||||
// });
|
||||
// return MongoClients.create(mongoBuilder.build());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public SimpleMongoClientDatabaseFactory mongoDbFactory(MongoClient mongoClient) {
|
||||
// return new SimpleMongoClientDatabaseFactory(mongoClient, "information");
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public MongoTemplate mongoTemplate(SimpleMongoClientDatabaseFactory mongoDbFactory) {
|
||||
// return new MongoTemplate(mongoDbFactory);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
package com.rax.vital.v2.config;
|
||||
|
||||
import com.rax.vital.v2.handler.AddMedicineHandler;
|
||||
import com.rax.vital.v2.handler.ChatHandler;
|
||||
import com.rax.vital.v2.handler.MachineFeedbackHandler;
|
||||
import com.rax.vital.v2.handler.MedicineHandler;
|
||||
import com.rax.vital.v2.interceptor.WebSocketInterceptors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.support.HttpSessionHandshakeInterceptor;
|
||||
|
||||
/**
|
||||
* socket配置类
|
||||
* 这里使用spring托管每个socketHandler 单例
|
||||
*/
|
||||
@EnableWebSocket
|
||||
@Configuration
|
||||
public class WebSocketConfig implements WebSocketConfigurer {
|
||||
|
||||
@Autowired
|
||||
private WebSocketInterceptors webSocketInterceptors;
|
||||
|
||||
@Autowired
|
||||
private AddMedicineHandler addMedicineHandler;
|
||||
|
||||
@Autowired
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
@Autowired
|
||||
private MachineFeedbackHandler machineFeedbackHandler;
|
||||
|
||||
@Autowired
|
||||
private MedicineHandler medicineHandler;
|
||||
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(medicineHandler, "/rax/vitalSignsMedicine")
|
||||
.addHandler(chatHandler,"/rax/chatRoom")
|
||||
.addHandler(addMedicineHandler, "/rax/addMedicine")
|
||||
.addHandler(machineFeedbackHandler,"/rax/getMedicine")
|
||||
.addInterceptors(new HttpSessionHandshakeInterceptor())
|
||||
.addInterceptors(webSocketInterceptors)
|
||||
.setAllowedOrigins("*");
|
||||
}
|
||||
|
||||
}
|
||||
//package com.rax.vital.v2.config;
|
||||
//
|
||||
//import com.rax.vital.v2.handler.AddMedicineHandler;
|
||||
//import com.rax.vital.v2.handler.ChatHandler;
|
||||
//import com.rax.vital.v2.handler.MachineFeedbackHandler;
|
||||
//import com.rax.vital.v2.handler.MedicineHandler;
|
||||
//import com.rax.vital.v2.interceptor.WebSocketInterceptors;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//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.support.HttpSessionHandshakeInterceptor;
|
||||
//
|
||||
///**
|
||||
// * socket配置类
|
||||
// * 这里使用spring托管每个socketHandler 单例
|
||||
// */
|
||||
//@EnableWebSocket
|
||||
//@Configuration
|
||||
//public class WebSocketConfig implements WebSocketConfigurer {
|
||||
//
|
||||
// @Autowired
|
||||
// private WebSocketInterceptors webSocketInterceptors;
|
||||
//
|
||||
// @Autowired
|
||||
// private AddMedicineHandler addMedicineHandler;
|
||||
//
|
||||
// @Autowired
|
||||
// private ChatHandler chatHandler;
|
||||
//
|
||||
// @Autowired
|
||||
// private MachineFeedbackHandler machineFeedbackHandler;
|
||||
//
|
||||
// @Autowired
|
||||
// private MedicineHandler medicineHandler;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
// registry.addHandler(medicineHandler, "/rax/vitalSignsMedicine")
|
||||
// .addHandler(chatHandler,"/rax/chatRoom")
|
||||
// .addHandler(addMedicineHandler, "/rax/addMedicine")
|
||||
// .addHandler(machineFeedbackHandler,"/rax/getMedicine")
|
||||
// .addInterceptors(new HttpSessionHandshakeInterceptor())
|
||||
// .addInterceptors(webSocketInterceptors)
|
||||
// .setAllowedOrigins("*");
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,192 +1,192 @@
|
|||
package com.rax.vital.v2.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.admin.api.entity.SysLog;
|
||||
import com.rax.admin.service.SysLogService;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
import com.rax.vital.common.util.TokenUtil;
|
||||
import com.rax.vital.v2.timer.AIMedicineTimer;
|
||||
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 网站发送给仪器给药信息
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AddMedicineHandler implements WebSocketHandler {
|
||||
|
||||
@Autowired
|
||||
private VitalSignTimerV2 vitalSignTimerV2;
|
||||
|
||||
@Autowired
|
||||
private SysLoggerBuilder sysLoggerBuilder;
|
||||
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@Autowired
|
||||
private TokenUtil tokenUtil;
|
||||
|
||||
@Autowired
|
||||
private AIMedicineTimer aiMedicineTimer;
|
||||
|
||||
// 发送心跳任务的定时任务容器
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) {
|
||||
startHeartbeat(session);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||
String msgType = jsonObject.getString("msgType");
|
||||
if (!"heartbeat".equals(msgType)) {
|
||||
// 病人名
|
||||
String patientName = jsonObject.getString("patientName");
|
||||
// 病人身份证
|
||||
String idNum = jsonObject.getString("idNum");
|
||||
// yyyyMMdd
|
||||
String date = jsonObject.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
|
||||
// 将网站端的dbName作为key session作为Value存入Map 以便后续判断状态
|
||||
if ("init".equals(msgType)) {
|
||||
aiMedicineTimer.initWeb(databaseName, session);
|
||||
}
|
||||
|
||||
// 处理网页端接收到消息后的相应内容
|
||||
if ("webResponseConnection".equals(msgType)) {
|
||||
String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
||||
// 给unity端发送网页端拒绝连接
|
||||
aiMedicineTimer.sendConnectionResponseToUnity(patientName, idNum, date, databaseName, webConnectionFlag);
|
||||
}
|
||||
|
||||
// 处理web端请求或断开连接
|
||||
if ("webRequestConnection".equals(msgType)) {
|
||||
String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
||||
aiMedicineTimer.sendWebRequestConnectionMsg(patientName, idNum, date, databaseName, webRequestFlag);
|
||||
}
|
||||
|
||||
|
||||
// 处理发送给药相关
|
||||
if ("addMedicine".equals(msgType) && aiMedicineTimer.getWebSession(databaseName) != null && aiMedicineTimer.getUnitySession(databaseName) != null
|
||||
&& aiMedicineTimer.isReady(databaseName)) {
|
||||
// 解析获取username
|
||||
String query = session.getUri().getQuery();
|
||||
String token = GetHttpParamUtil.getParam(query, "token");
|
||||
Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
String username = (String) map.get("username");
|
||||
|
||||
// flag 0 代表人工给药, 1代表AI给药
|
||||
vitalSignTimerV2.sendMedicalMessageToUnity(databaseName, username, session, jsonObject.getString("flag"),
|
||||
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||
}
|
||||
|
||||
// 展示网页端延迟信息
|
||||
if ("ping".equals(msgType)) {
|
||||
Long timeStamp = jsonObject.getLong("msg");
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("msgType", "pong");
|
||||
if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
||||
result.put("webMsg", "网页端已登陆");
|
||||
} else {
|
||||
result.put("webMsg", "网页端未登陆");
|
||||
}
|
||||
|
||||
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||
result.put("unityMsg", "unity端已登录");
|
||||
} else {
|
||||
result.put("unityMsg", "unity端未登录");
|
||||
}
|
||||
// 当前时间戳
|
||||
Long diff = new Date().getTime() - timeStamp;
|
||||
result.put("msg", diff);
|
||||
sendMsgAsync(session,result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口异常中断:"+exception.getMessage(), "4", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口客户端,断开连接", "0", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartialMessages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void startHeartbeat(WebSocketSession session) {
|
||||
if (!timerTaskMap.containsKey(session.getId())) {
|
||||
ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("msgType", "heartbeat");
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
} else {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
session.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stopHeartbeat(session);
|
||||
}
|
||||
}, 0, 30, TimeUnit.SECONDS);
|
||||
timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopHeartbeat(WebSocketSession session) {
|
||||
ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
heartbeatExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
// 异步发送消息
|
||||
private void sendMsgAsync(WebSocketSession session, JSONObject jsonObject) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
}else {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
session.close();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
log.error("addMedicineHandler-sendMsgAsync error: {}", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.handler;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rax.admin.api.entity.SysLog;
|
||||
//import com.rax.admin.service.SysLogService;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
//import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
//import com.rax.vital.common.util.TokenUtil;
|
||||
//import com.rax.vital.v2.timer.AIMedicineTimer;
|
||||
//import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.*;
|
||||
//
|
||||
//import java.util.Date;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.*;
|
||||
//
|
||||
///**
|
||||
// * 网站发送给仪器给药信息
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class AddMedicineHandler implements WebSocketHandler {
|
||||
//
|
||||
// @Autowired
|
||||
// private VitalSignTimerV2 vitalSignTimerV2;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLoggerBuilder sysLoggerBuilder;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogService sysLogService;
|
||||
//
|
||||
// @Autowired
|
||||
// private TokenUtil tokenUtil;
|
||||
//
|
||||
// @Autowired
|
||||
// private AIMedicineTimer aiMedicineTimer;
|
||||
//
|
||||
// // 发送心跳任务的定时任务容器
|
||||
// private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionEstablished(WebSocketSession session) {
|
||||
// startHeartbeat(session);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
//
|
||||
// JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||
// String msgType = jsonObject.getString("msgType");
|
||||
// if (!"heartbeat".equals(msgType)) {
|
||||
// // 病人名
|
||||
// String patientName = jsonObject.getString("patientName");
|
||||
// // 病人身份证
|
||||
// String idNum = jsonObject.getString("idNum");
|
||||
// // yyyyMMdd
|
||||
// String date = jsonObject.getString("date");
|
||||
// String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
//
|
||||
// // 将网站端的dbName作为key session作为Value存入Map 以便后续判断状态
|
||||
// if ("init".equals(msgType)) {
|
||||
// aiMedicineTimer.initWeb(databaseName, session);
|
||||
// }
|
||||
//
|
||||
// // 处理网页端接收到消息后的相应内容
|
||||
// if ("webResponseConnection".equals(msgType)) {
|
||||
// String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
||||
// // 给unity端发送网页端拒绝连接
|
||||
// aiMedicineTimer.sendConnectionResponseToUnity(patientName, idNum, date, databaseName, webConnectionFlag);
|
||||
// }
|
||||
//
|
||||
// // 处理web端请求或断开连接
|
||||
// if ("webRequestConnection".equals(msgType)) {
|
||||
// String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
||||
// aiMedicineTimer.sendWebRequestConnectionMsg(patientName, idNum, date, databaseName, webRequestFlag);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 处理发送给药相关
|
||||
// if ("addMedicine".equals(msgType) && aiMedicineTimer.getWebSession(databaseName) != null && aiMedicineTimer.getUnitySession(databaseName) != null
|
||||
// && aiMedicineTimer.isReady(databaseName)) {
|
||||
// // 解析获取username
|
||||
// String query = session.getUri().getQuery();
|
||||
// String token = GetHttpParamUtil.getParam(query, "token");
|
||||
// Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
// String username = (String) map.get("username");
|
||||
//
|
||||
// // flag 0 代表人工给药, 1代表AI给药
|
||||
// vitalSignTimerV2.sendMedicalMessageToUnity(databaseName, username, session, jsonObject.getString("flag"),
|
||||
// jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||
// }
|
||||
//
|
||||
// // 展示网页端延迟信息
|
||||
// if ("ping".equals(msgType)) {
|
||||
// Long timeStamp = jsonObject.getLong("msg");
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("msgType", "pong");
|
||||
// if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
||||
// result.put("webMsg", "网页端已登陆");
|
||||
// } else {
|
||||
// result.put("webMsg", "网页端未登陆");
|
||||
// }
|
||||
//
|
||||
// if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||
// result.put("unityMsg", "unity端已登录");
|
||||
// } else {
|
||||
// result.put("unityMsg", "unity端未登录");
|
||||
// }
|
||||
// // 当前时间戳
|
||||
// Long diff = new Date().getTime() - timeStamp;
|
||||
// result.put("msg", diff);
|
||||
// sendMsgAsync(session,result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口异常中断:"+exception.getMessage(), "4", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口客户端,断开连接", "0", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean supportsPartialMessages() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void startHeartbeat(WebSocketSession session) {
|
||||
// if (!timerTaskMap.containsKey(session.getId())) {
|
||||
// ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
// heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("msgType", "heartbeat");
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// session.close();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// stopHeartbeat(session);
|
||||
// }
|
||||
// }, 0, 30, TimeUnit.SECONDS);
|
||||
// timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void stopHeartbeat(WebSocketSession session) {
|
||||
// ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
// heartbeatExecutor.shutdownNow();
|
||||
// }
|
||||
//
|
||||
// // 异步发送消息
|
||||
// private void sendMsgAsync(WebSocketSession session, JSONObject jsonObject) {
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// }else {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// session.close();
|
||||
// }
|
||||
// }catch (Exception e) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// log.error("addMedicineHandler-sendMsgAsync error: {}", e.getMessage());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,115 +1,115 @@
|
|||
package com.rax.vital.v2.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.admin.api.entity.SysLog;
|
||||
import com.rax.admin.service.SysLogService;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
import com.rax.vital.common.util.TokenUtil;
|
||||
import com.rax.vital.v2.medicine.service.ChatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class ChatHandler implements WebSocketHandler {
|
||||
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
|
||||
@Autowired
|
||||
private SysLoggerBuilder sysLoggerBuilder;
|
||||
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@Autowired
|
||||
private TokenUtil tokenUtil;
|
||||
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) {
|
||||
startHeartbeat(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
|
||||
String payload = (String) message.getPayload();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||
|
||||
String query = Objects.requireNonNull(session.getUri()).getQuery();
|
||||
String token = GetHttpParamUtil.getParam(query, "token");
|
||||
Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
String username = (String) map.get("username");
|
||||
|
||||
String patientName = jsonObject.getString("patientName");
|
||||
String idNum = jsonObject.getString("idNum");
|
||||
String date = jsonObject.getString("date");
|
||||
// 消息内容
|
||||
String msg = jsonObject.getString("msg");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
chatService.sendMessage(databaseName, username, session, msg);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口异常中断:"+exception.getMessage(), "4", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
stopHeartbeat(session);
|
||||
chatService.stopTask(session.getId());
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口关闭", "0", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartialMessages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void startHeartbeat(WebSocketSession session) {
|
||||
if (!timerTaskMap.containsKey(session.getId())) {
|
||||
ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("msgType", "heartbeat");
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
} else {
|
||||
stopHeartbeat(session);
|
||||
chatService.stopTask(session.getId());
|
||||
session.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stopHeartbeat(session);
|
||||
}
|
||||
}, 0, 10, TimeUnit.SECONDS);
|
||||
timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopHeartbeat(WebSocketSession session) {
|
||||
ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
heartbeatExecutor.shutdownNow();
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.handler;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rax.admin.api.entity.SysLog;
|
||||
//import com.rax.admin.service.SysLogService;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
//import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
//import com.rax.vital.common.util.TokenUtil;
|
||||
//import com.rax.vital.v2.medicine.service.ChatService;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.*;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//import java.util.Objects;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//import java.util.concurrent.Executors;
|
||||
//import java.util.concurrent.ScheduledExecutorService;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//@Component
|
||||
//public class ChatHandler implements WebSocketHandler {
|
||||
//
|
||||
// @Autowired
|
||||
// private ChatService chatService;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLoggerBuilder sysLoggerBuilder;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogService sysLogService;
|
||||
//
|
||||
// @Autowired
|
||||
// private TokenUtil tokenUtil;
|
||||
//
|
||||
// private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionEstablished(WebSocketSession session) {
|
||||
// startHeartbeat(session);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
//
|
||||
// String payload = (String) message.getPayload();
|
||||
//
|
||||
// JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||
// if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||
//
|
||||
// String query = Objects.requireNonNull(session.getUri()).getQuery();
|
||||
// String token = GetHttpParamUtil.getParam(query, "token");
|
||||
// Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
// String username = (String) map.get("username");
|
||||
//
|
||||
// String patientName = jsonObject.getString("patientName");
|
||||
// String idNum = jsonObject.getString("idNum");
|
||||
// String date = jsonObject.getString("date");
|
||||
// // 消息内容
|
||||
// String msg = jsonObject.getString("msg");
|
||||
// String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
// chatService.sendMessage(databaseName, username, session, msg);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口异常中断:"+exception.getMessage(), "4", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
// stopHeartbeat(session);
|
||||
// chatService.stopTask(session.getId());
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口关闭", "0", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean supportsPartialMessages() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void startHeartbeat(WebSocketSession session) {
|
||||
// if (!timerTaskMap.containsKey(session.getId())) {
|
||||
// ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
// heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("msgType", "heartbeat");
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// stopHeartbeat(session);
|
||||
// chatService.stopTask(session.getId());
|
||||
// session.close();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// stopHeartbeat(session);
|
||||
// }
|
||||
// }, 0, 10, TimeUnit.SECONDS);
|
||||
// timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void stopHeartbeat(WebSocketSession session) {
|
||||
// ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
// heartbeatExecutor.shutdownNow();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,209 +1,209 @@
|
|||
package com.rax.vital.v2.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.admin.api.entity.SysLog;
|
||||
import com.rax.admin.service.SysLogService;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
import com.rax.vital.v2.timer.AIMedicineTimer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 仪器获取网站给药信息
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MachineFeedbackHandler implements WebSocketHandler {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysLoggerBuilder sysLoggerBuilder;
|
||||
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
|
||||
@Autowired
|
||||
private AIMedicineTimer aiMedicineTimer;
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) throws IOException {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("msgType", "msg");
|
||||
msg.put("msg", "已成功连接服务器!");
|
||||
session.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
startHeartbeat(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||
|
||||
String msgType = jsonObject.getString("msgType");
|
||||
if (!"heartbeat".equals(msgType)) {
|
||||
// 病人名
|
||||
String patientName = jsonObject.getString("patientName");
|
||||
// 病人身份证住院号
|
||||
String idNum = jsonObject.getString("idNum");
|
||||
// yyyyMMdd
|
||||
String date = jsonObject.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
String code = jsonObject.getString("code");
|
||||
|
||||
if ("init".equals(msgType)) {
|
||||
aiMedicineTimer.initUnity(databaseName, session);
|
||||
}
|
||||
|
||||
// Unity获取到给药信息后回复
|
||||
if ("getMedicine".equals(msgType)) {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("msgType", msgType);
|
||||
msg.put("patientName", patientName);
|
||||
msg.put("idNum", idNum);
|
||||
msg.put("date", date);
|
||||
WebSocketSession webSession = aiMedicineTimer.getWebSession(databaseName);
|
||||
webSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
}
|
||||
|
||||
|
||||
// u3d发送表示请求与网页端的连接
|
||||
if ("unityRequestConnection".equals(msgType)) {
|
||||
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||
// u3d端请求网页端连接或断开
|
||||
aiMedicineTimer.sendUnityRequestConnectionMsg(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||
}
|
||||
|
||||
// u3d相应网页端的请求
|
||||
if ("unityResponseConnection".equals(msgType)) {
|
||||
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||
aiMedicineTimer.sendConnectionResponseToWeb(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||
}
|
||||
|
||||
if (aiMedicineTimer.getUnitySession(databaseName) != null
|
||||
&& aiMedicineTimer.getWebSession(databaseName) != null
|
||||
&& aiMedicineTimer.isReady(databaseName)) {
|
||||
// vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("status", code);
|
||||
msg.put("msg", "网站已进行远程连接");
|
||||
msg.put("msgType", "msg");
|
||||
WebSocketSession unitySession = aiMedicineTimer.getUnitySession(databaseName);
|
||||
unitySession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
}
|
||||
|
||||
// 展示unity端延迟信息
|
||||
if ("ping".equals(msgType)) {
|
||||
Long timeStamp = jsonObject.getLong("msg");
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("msgType", "pong");
|
||||
if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
||||
result.put("webMsg", "网页端已登陆");
|
||||
} else {
|
||||
result.put("webMsg", "网页端未登陆");
|
||||
}
|
||||
|
||||
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||
result.put("unityMsg", "unity端已登录");
|
||||
} else {
|
||||
result.put("unityMsg", "unity端未登录");
|
||||
}
|
||||
// 当前时间戳
|
||||
Long diff = new Date().getTime() - timeStamp;
|
||||
result.put("msg", diff);
|
||||
sendMsgAsync(session, result);
|
||||
}
|
||||
|
||||
// unity收到给药信息后回复把此消息推送给web
|
||||
if ("getMedicine".equals(msgType)) {
|
||||
JSONObject getMedicineMsg = new JSONObject();
|
||||
getMedicineMsg.put("msgType", "getMedicine");
|
||||
getMedicineMsg.put("patientName", patientName);
|
||||
getMedicineMsg.put("idNum", idNum);
|
||||
getMedicineMsg.put("date", date);
|
||||
getMedicineMsg.put(jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||
WebSocketSession webSession = aiMedicineTimer.getWebSession(databaseName);
|
||||
webSession.sendMessage(new TextMessage(getMedicineMsg.toJSONString().getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端获取收药口异常中断", "4", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端收药接口关闭", "0", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartialMessages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void startHeartbeat(WebSocketSession session) {
|
||||
if (!timerTaskMap.containsKey(session.getId())) {
|
||||
ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("msgType", "heartbeat");
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
} else {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
session.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stopHeartbeat(session);
|
||||
}
|
||||
}, 0, 30, TimeUnit.SECONDS);
|
||||
timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopHeartbeat(WebSocketSession session) {
|
||||
ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
heartbeatExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
// 异步发送消息
|
||||
private void sendMsgAsync(WebSocketSession session, JSONObject jsonObject) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
} else {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
session.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stopHeartbeat(session);
|
||||
aiMedicineTimer.closeConnection(session);
|
||||
log.error("addMedicineHandler-sendMsgAsync error: {}", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.handler;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rax.admin.api.entity.SysLog;
|
||||
//import com.rax.admin.service.SysLogService;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
//import com.rax.vital.v2.timer.AIMedicineTimer;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.*;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Date;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.*;
|
||||
//
|
||||
///**
|
||||
// * 仪器获取网站给药信息
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class MachineFeedbackHandler implements WebSocketHandler {
|
||||
//
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLoggerBuilder sysLoggerBuilder;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogService sysLogService;
|
||||
//
|
||||
// private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||
//
|
||||
// @Autowired
|
||||
// private AIMedicineTimer aiMedicineTimer;
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionEstablished(WebSocketSession session) throws IOException {
|
||||
// JSONObject msg = new JSONObject();
|
||||
// msg.put("msgType", "msg");
|
||||
// msg.put("msg", "已成功连接服务器!");
|
||||
// session.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
// startHeartbeat(session);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
//
|
||||
// JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||
//
|
||||
// String msgType = jsonObject.getString("msgType");
|
||||
// if (!"heartbeat".equals(msgType)) {
|
||||
// // 病人名
|
||||
// String patientName = jsonObject.getString("patientName");
|
||||
// // 病人身份证住院号
|
||||
// String idNum = jsonObject.getString("idNum");
|
||||
// // yyyyMMdd
|
||||
// String date = jsonObject.getString("date");
|
||||
// String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
// String code = jsonObject.getString("code");
|
||||
//
|
||||
// if ("init".equals(msgType)) {
|
||||
// aiMedicineTimer.initUnity(databaseName, session);
|
||||
// }
|
||||
//
|
||||
// // Unity获取到给药信息后回复
|
||||
// if ("getMedicine".equals(msgType)) {
|
||||
// JSONObject msg = new JSONObject();
|
||||
// msg.put("msgType", msgType);
|
||||
// msg.put("patientName", patientName);
|
||||
// msg.put("idNum", idNum);
|
||||
// msg.put("date", date);
|
||||
// WebSocketSession webSession = aiMedicineTimer.getWebSession(databaseName);
|
||||
// webSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // u3d发送表示请求与网页端的连接
|
||||
// if ("unityRequestConnection".equals(msgType)) {
|
||||
// String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||
// // u3d端请求网页端连接或断开
|
||||
// aiMedicineTimer.sendUnityRequestConnectionMsg(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||
// }
|
||||
//
|
||||
// // u3d相应网页端的请求
|
||||
// if ("unityResponseConnection".equals(msgType)) {
|
||||
// String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||
// aiMedicineTimer.sendConnectionResponseToWeb(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||
// }
|
||||
//
|
||||
// if (aiMedicineTimer.getUnitySession(databaseName) != null
|
||||
// && aiMedicineTimer.getWebSession(databaseName) != null
|
||||
// && aiMedicineTimer.isReady(databaseName)) {
|
||||
// // vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
||||
// JSONObject msg = new JSONObject();
|
||||
// msg.put("status", code);
|
||||
// msg.put("msg", "网站已进行远程连接");
|
||||
// msg.put("msgType", "msg");
|
||||
// WebSocketSession unitySession = aiMedicineTimer.getUnitySession(databaseName);
|
||||
// unitySession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
// }
|
||||
//
|
||||
// // 展示unity端延迟信息
|
||||
// if ("ping".equals(msgType)) {
|
||||
// Long timeStamp = jsonObject.getLong("msg");
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("msgType", "pong");
|
||||
// if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
||||
// result.put("webMsg", "网页端已登陆");
|
||||
// } else {
|
||||
// result.put("webMsg", "网页端未登陆");
|
||||
// }
|
||||
//
|
||||
// if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||
// result.put("unityMsg", "unity端已登录");
|
||||
// } else {
|
||||
// result.put("unityMsg", "unity端未登录");
|
||||
// }
|
||||
// // 当前时间戳
|
||||
// Long diff = new Date().getTime() - timeStamp;
|
||||
// result.put("msg", diff);
|
||||
// sendMsgAsync(session, result);
|
||||
// }
|
||||
//
|
||||
// // unity收到给药信息后回复把此消息推送给web
|
||||
// if ("getMedicine".equals(msgType)) {
|
||||
// JSONObject getMedicineMsg = new JSONObject();
|
||||
// getMedicineMsg.put("msgType", "getMedicine");
|
||||
// getMedicineMsg.put("patientName", patientName);
|
||||
// getMedicineMsg.put("idNum", idNum);
|
||||
// getMedicineMsg.put("date", date);
|
||||
// getMedicineMsg.put(jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||
// WebSocketSession webSession = aiMedicineTimer.getWebSession(databaseName);
|
||||
// webSession.sendMessage(new TextMessage(getMedicineMsg.toJSONString().getBytes()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端获取收药口异常中断", "4", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端收药接口关闭", "0", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean supportsPartialMessages() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void startHeartbeat(WebSocketSession session) {
|
||||
// if (!timerTaskMap.containsKey(session.getId())) {
|
||||
// ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
// heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("msgType", "heartbeat");
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// session.close();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// stopHeartbeat(session);
|
||||
// }
|
||||
// }, 0, 30, TimeUnit.SECONDS);
|
||||
// timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void stopHeartbeat(WebSocketSession session) {
|
||||
// ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
// heartbeatExecutor.shutdownNow();
|
||||
// }
|
||||
//
|
||||
// // 异步发送消息
|
||||
// private void sendMsgAsync(WebSocketSession session, JSONObject jsonObject) {
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// session.close();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// stopHeartbeat(session);
|
||||
// aiMedicineTimer.closeConnection(session);
|
||||
// log.error("addMedicineHandler-sendMsgAsync error: {}", e.getMessage());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,119 +1,119 @@
|
|||
package com.rax.vital.v2.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.admin.api.entity.SysLog;
|
||||
import com.rax.admin.service.SysLogService;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
import com.rax.vital.common.util.TokenUtil;
|
||||
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 生命体征和标志位信息
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MedicineHandler implements WebSocketHandler {
|
||||
|
||||
@Autowired
|
||||
private VitalSignTimerV2 vitalSignTimerV2;
|
||||
|
||||
@Autowired
|
||||
private SysLoggerBuilder sysLoggerBuilder;
|
||||
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@Autowired
|
||||
private TokenUtil tokenUtil;
|
||||
|
||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) {
|
||||
startHeartbeat(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||
|
||||
String payload = (String) message.getPayload();
|
||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||
|
||||
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||
|
||||
String query = session.getUri().getQuery();
|
||||
String token = GetHttpParamUtil.getParam(query, "token");
|
||||
Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
String username = (String) map.get("username");
|
||||
|
||||
String patientName = jsonObject.getString("patientName");
|
||||
String idNum = jsonObject.getString("idNum");
|
||||
String date = jsonObject.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
vitalSignTimerV2.sendMedicalMessage(databaseName, username, session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||
stopHeartbeat(session);
|
||||
vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口异常中断", "4", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||
stopHeartbeat(session);
|
||||
vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口连接关闭", "0", session);
|
||||
sysLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartialMessages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void startHeartbeat(WebSocketSession session) {
|
||||
if (!timerTaskMap.containsKey(session.getId())) {
|
||||
ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
if (session.isOpen()) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("msgType", "heartbeat");
|
||||
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
} else {
|
||||
session.close();
|
||||
stopHeartbeat(session);
|
||||
vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stopHeartbeat(session);
|
||||
}
|
||||
}, 0, 10, TimeUnit.SECONDS);
|
||||
timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopHeartbeat(WebSocketSession session) {
|
||||
ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
heartbeatExecutor.shutdownNow();
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.handler;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rax.admin.api.entity.SysLog;
|
||||
//import com.rax.admin.service.SysLogService;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
//import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
//import com.rax.vital.common.util.TokenUtil;
|
||||
//import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.*;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//import java.util.concurrent.Executors;
|
||||
//import java.util.concurrent.ScheduledExecutorService;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
///**
|
||||
// * 生命体征和标志位信息
|
||||
// */
|
||||
//
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class MedicineHandler implements WebSocketHandler {
|
||||
//
|
||||
// @Autowired
|
||||
// private VitalSignTimerV2 vitalSignTimerV2;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLoggerBuilder sysLoggerBuilder;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogService sysLogService;
|
||||
//
|
||||
// @Autowired
|
||||
// private TokenUtil tokenUtil;
|
||||
//
|
||||
// private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionEstablished(WebSocketSession session) {
|
||||
// startHeartbeat(session);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||
//
|
||||
// String payload = (String) message.getPayload();
|
||||
// JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||
//
|
||||
// if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||
//
|
||||
// String query = session.getUri().getQuery();
|
||||
// String token = GetHttpParamUtil.getParam(query, "token");
|
||||
// Map<String, Object> map = tokenUtil.parseToken(token);
|
||||
// String username = (String) map.get("username");
|
||||
//
|
||||
// String patientName = jsonObject.getString("patientName");
|
||||
// String idNum = jsonObject.getString("idNum");
|
||||
// String date = jsonObject.getString("date");
|
||||
// String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
// vitalSignTimerV2.sendMedicalMessage(databaseName, username, session);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||
// stopHeartbeat(session);
|
||||
// vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口异常中断", "4", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||
// stopHeartbeat(session);
|
||||
// vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
// SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口连接关闭", "0", session);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean supportsPartialMessages() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void startHeartbeat(WebSocketSession session) {
|
||||
// if (!timerTaskMap.containsKey(session.getId())) {
|
||||
// ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||
// heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("msgType", "heartbeat");
|
||||
// session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// session.close();
|
||||
// stopHeartbeat(session);
|
||||
// vitalSignTimerV2.stopTimerTask(session.getId());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// stopHeartbeat(session);
|
||||
// }
|
||||
// }, 0, 10, TimeUnit.SECONDS);
|
||||
// timerTaskMap.put(session.getId(), heartbeatExecutor);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void stopHeartbeat(WebSocketSession session) {
|
||||
// ScheduledExecutorService heartbeatExecutor = timerTaskMap.get(session.getId());
|
||||
// heartbeatExecutor.shutdownNow();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
package com.rax.vital.v2.interceptor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
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 java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WSChannelInterceptor implements ChannelInterceptor {
|
||||
@Autowired
|
||||
private OAuth2AuthorizationService authorizationService;
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
|
||||
if (accessor != null) {
|
||||
|
||||
List<String> accessToken = accessor.getNativeHeader("token");
|
||||
|
||||
if (accessToken != null && !accessToken.isEmpty()) {
|
||||
|
||||
String token = accessToken.get(0);
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
|
||||
if (StompCommand.CONNECT.equals(accessor.getCommand()) || StompCommand.SEND.equals(accessor.getCommand())) {
|
||||
if (authorization == null) {
|
||||
throw new AccessDeniedException("Access is denied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StompCommand.DISCONNECT.equals(accessor.getCommand())
|
||||
|| StompCommand.UNSUBSCRIBE.equals(accessor.getCommand()) || StompCommand.ABORT.equals(accessor.getCommand())) {
|
||||
// String simpSessionId = (String) accessor.getHeader("simpSessionId");
|
||||
// vitalSignTimer.stopTimerTaskMongo(simpSessionId);
|
||||
// chatService.stopTimerTask(simpSessionId);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.interceptor;
|
||||
//
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.messaging.Message;
|
||||
//import org.springframework.messaging.MessageChannel;
|
||||
//import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
//import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
//import org.springframework.messaging.support.ChannelInterceptor;
|
||||
//import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
//import org.springframework.security.access.AccessDeniedException;
|
||||
//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 java.util.List;
|
||||
//
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class WSChannelInterceptor implements ChannelInterceptor {
|
||||
// @Autowired
|
||||
// private OAuth2AuthorizationService authorizationService;
|
||||
//
|
||||
// @Override
|
||||
// public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
//
|
||||
// StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
//
|
||||
// if (accessor != null) {
|
||||
//
|
||||
// List<String> accessToken = accessor.getNativeHeader("token");
|
||||
//
|
||||
// if (accessToken != null && !accessToken.isEmpty()) {
|
||||
//
|
||||
// String token = accessToken.get(0);
|
||||
// OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
//
|
||||
// if (StompCommand.CONNECT.equals(accessor.getCommand()) || StompCommand.SEND.equals(accessor.getCommand())) {
|
||||
// if (authorization == null) {
|
||||
// throw new AccessDeniedException("Access is denied");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (StompCommand.DISCONNECT.equals(accessor.getCommand())
|
||||
// || StompCommand.UNSUBSCRIBE.equals(accessor.getCommand()) || StompCommand.ABORT.equals(accessor.getCommand())) {
|
||||
//// String simpSessionId = (String) accessor.getHeader("simpSessionId");
|
||||
//// vitalSignTimer.stopTimerTaskMongo(simpSessionId);
|
||||
//// chatService.stopTimerTask(simpSessionId);
|
||||
// }
|
||||
// }
|
||||
// return message;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
package com.rax.vital.v2.interceptor;
|
||||
|
||||
import com.rax.admin.api.entity.SysLog;
|
||||
import com.rax.admin.service.SysLogService;
|
||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
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.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Component
|
||||
public class WebSocketInterceptors implements HandshakeInterceptor {
|
||||
|
||||
@Resource
|
||||
private OAuth2AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
private SysLoggerBuilder sysLoggerBuilder;
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* 在这里做一个全局的日志插入根据路径匹配不同的操作title
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param wsHandler
|
||||
* @param attributes
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||
String query = request.getURI().getQuery();
|
||||
if (query == null) {
|
||||
return false;
|
||||
}
|
||||
Map<String, String> params = GetHttpParamUtil.getParams(query);
|
||||
if (!params.containsKey("token")) {
|
||||
return false;
|
||||
}
|
||||
String token = GetHttpParamUtil.getParam(query, "token");
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
if (authorization == null) {
|
||||
return false;
|
||||
}
|
||||
// 适配一下,根据req中不同的路径做不同的操作title
|
||||
SysLog sysLog = sysLoggerBuilder.buildLongWithLogType(request);
|
||||
sysLogService.saveLog(sysLog);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.interceptor;
|
||||
//
|
||||
//import com.rax.admin.api.entity.SysLog;
|
||||
//import com.rax.admin.service.SysLogService;
|
||||
//import com.rax.vital.common.util.GetHttpParamUtil;
|
||||
//import com.rax.vital.common.util.SysLoggerBuilder;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.server.ServerHttpRequest;
|
||||
//import org.springframework.http.server.ServerHttpResponse;
|
||||
//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.WebSocketHandler;
|
||||
//import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//
|
||||
//
|
||||
//@Component
|
||||
//public class WebSocketInterceptors implements HandshakeInterceptor {
|
||||
//
|
||||
// @Resource
|
||||
// private OAuth2AuthorizationService authorizationService;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLoggerBuilder sysLoggerBuilder;
|
||||
//
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogService sysLogService;
|
||||
//
|
||||
// /**
|
||||
// * 在这里做一个全局的日志插入根据路径匹配不同的操作title
|
||||
// *
|
||||
// * @param request
|
||||
// * @param response
|
||||
// * @param wsHandler
|
||||
// * @param attributes
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||
// String query = request.getURI().getQuery();
|
||||
// if (query == null) {
|
||||
// return false;
|
||||
// }
|
||||
// Map<String, String> params = GetHttpParamUtil.getParams(query);
|
||||
// if (!params.containsKey("token")) {
|
||||
// return false;
|
||||
// }
|
||||
// String token = GetHttpParamUtil.getParam(query, "token");
|
||||
// OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
// if (authorization == null) {
|
||||
// return false;
|
||||
// }
|
||||
// // 适配一下,根据req中不同的路径做不同的操作title
|
||||
// SysLog sysLog = sysLoggerBuilder.buildLongWithLogType(request);
|
||||
// sysLogService.saveLog(sysLog);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,94 +1,94 @@
|
|||
package com.rax.vital.v2.medicine.controller;
|
||||
|
||||
import com.rax.common.core.util.R;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.v2.medicine.service.IMedicineService;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 用药
|
||||
*
|
||||
* @date 2024.2.19
|
||||
*/
|
||||
@RestController
|
||||
@Tag(description = "medicine", name = "人工和AI用药管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
@RequestMapping("/medicine")
|
||||
public class MedicineController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IMedicineService medicineService;
|
||||
|
||||
|
||||
@PostMapping("/getPatientInfo")
|
||||
public R getPatientInfo(String patientName, String idNum, String date) {
|
||||
// todo : 存疑
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
return medicineService.getPatientInfo(databaseName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getPatientPage")
|
||||
public R getPatientPage(String name, String dept, long offset, int limit) {
|
||||
return R.ok(medicineService.getPatientPage(name, dept, offset, limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 某月手术每天台数
|
||||
*/
|
||||
@PostMapping("/getSurgeryCount")
|
||||
public R getSurgeryCount(String start, String end) {
|
||||
return R.ok(medicineService.getSurgeryCount(start, end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 某月手术每天时长
|
||||
*/
|
||||
@PostMapping("/getSurgeryDuration")
|
||||
public R getSurgeryDuration(String start, String end) {
|
||||
return R.ok(medicineService.getSurgeryDuration(start, end));
|
||||
}
|
||||
|
||||
/**
|
||||
* 某月手术类型数量
|
||||
*/
|
||||
@PostMapping("/getSurgeryTypeProportion")
|
||||
public R getSurgeryTypeProportion(String start, String end) {
|
||||
return R.ok(medicineService.getSurgeryTypeProportion(start, end));
|
||||
}
|
||||
|
||||
/**
|
||||
* 某周的麻醉和人工给药时长
|
||||
*/
|
||||
@PostMapping("/getSurgeryOtherDuration")
|
||||
public R getSurgeryOtherDuration(String start, String end) {
|
||||
return R.ok(medicineService.getSurgeryOtherDuration(start, end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的手术列表
|
||||
*/
|
||||
@PostMapping("/getPatientSurgeryList")
|
||||
public R getPatientSurgeryList(String name, String code, String surgery, String type) {
|
||||
return R.ok(medicineService.getPatientSurgeryList(name, code, surgery, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手术表名来获取所有数据
|
||||
*/
|
||||
@PostMapping("/getSurgeryTableData")
|
||||
public R getSurgeryTableData(String name, String code, String date, String table) {
|
||||
return R.ok(medicineService.getSurgeryTableData(name, code, date, table));
|
||||
}
|
||||
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.controller;
|
||||
//
|
||||
//import com.rax.common.core.util.R;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.v2.medicine.service.IMedicineService;
|
||||
//import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.HttpHeaders;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
///**
|
||||
// * 用药
|
||||
// *
|
||||
// * @date 2024.2.19
|
||||
// */
|
||||
//@RestController
|
||||
//@Tag(description = "medicine", name = "人工和AI用药管理")
|
||||
//@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
//@RequestMapping("/medicine")
|
||||
//public class MedicineController {
|
||||
//
|
||||
//
|
||||
// @Autowired
|
||||
// private IMedicineService medicineService;
|
||||
//
|
||||
//
|
||||
// @PostMapping("/getPatientInfo")
|
||||
// public R getPatientInfo(String patientName, String idNum, String date) {
|
||||
// // todo : 存疑
|
||||
// String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
// return medicineService.getPatientInfo(databaseName);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @PostMapping("/getPatientPage")
|
||||
// public R getPatientPage(String name, String dept, long offset, int limit) {
|
||||
// return R.ok(medicineService.getPatientPage(name, dept, offset, limit));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 某月手术每天台数
|
||||
// */
|
||||
// @PostMapping("/getSurgeryCount")
|
||||
// public R getSurgeryCount(String start, String end) {
|
||||
// return R.ok(medicineService.getSurgeryCount(start, end));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 某月手术每天时长
|
||||
// */
|
||||
// @PostMapping("/getSurgeryDuration")
|
||||
// public R getSurgeryDuration(String start, String end) {
|
||||
// return R.ok(medicineService.getSurgeryDuration(start, end));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 某月手术类型数量
|
||||
// */
|
||||
// @PostMapping("/getSurgeryTypeProportion")
|
||||
// public R getSurgeryTypeProportion(String start, String end) {
|
||||
// return R.ok(medicineService.getSurgeryTypeProportion(start, end));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 某周的麻醉和人工给药时长
|
||||
// */
|
||||
// @PostMapping("/getSurgeryOtherDuration")
|
||||
// public R getSurgeryOtherDuration(String start, String end) {
|
||||
// return R.ok(medicineService.getSurgeryOtherDuration(start, end));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 获取用户的手术列表
|
||||
// */
|
||||
// @PostMapping("/getPatientSurgeryList")
|
||||
// public R getPatientSurgeryList(String name, String code, String surgery, String type) {
|
||||
// return R.ok(medicineService.getPatientSurgeryList(name, code, surgery, type));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据手术表名来获取所有数据
|
||||
// */
|
||||
// @PostMapping("/getSurgeryTableData")
|
||||
// public R getSurgeryTableData(String name, String code, String date, String table) {
|
||||
// return R.ok(medicineService.getSurgeryTableData(name, code, date, table));
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package com.rax.vital.v2.medicine.dto;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MedicineDTO {
|
||||
private String linkNum;
|
||||
private String medicineName;
|
||||
private String medicineRate;
|
||||
private String countMedicine;
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.dto;
|
||||
//
|
||||
//
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.Data;
|
||||
//import lombok.NoArgsConstructor;
|
||||
//
|
||||
//@Data
|
||||
//@NoArgsConstructor
|
||||
//@AllArgsConstructor
|
||||
//public class MedicineDTO {
|
||||
// private String linkNum;
|
||||
// private String medicineName;
|
||||
// private String medicineRate;
|
||||
// private String countMedicine;
|
||||
//}
|
||||
|
|
|
@ -1,207 +1,207 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.rax.vital.v2.medicine.service.AIMedicineService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* AI给药
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AIMedicineServiceImpl implements AIMedicineService {
|
||||
|
||||
private static final Map<String, String> doctorMedicineKeyMap = new HashMap() {
|
||||
{
|
||||
put("丙泊酚", "丙泊酚");
|
||||
put("舒芬太尼", "舒芬太尼");
|
||||
put("瑞芬太尼", "瑞芬太尼");
|
||||
put("顺阿曲库胺", "顺阿曲库胺");
|
||||
put("尼卡地平", "尼卡地平");
|
||||
put("艾司洛尔", "艾司洛尔");
|
||||
put("麻黄素", "麻黄素");
|
||||
put("阿托品", "阿托品");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<Map> getAIMedicine(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> aiMedicines = template.find(query, Map.class, "fktable");
|
||||
if (!aiMedicines.isEmpty()) {
|
||||
Map medicine = new HashMap();
|
||||
for (Map map : aiMedicines) {
|
||||
medicine.put("丙泊酚", map.get("rate_1"));
|
||||
medicine.put("丙泊酚sum", map.get("cumu_1"));
|
||||
medicine.put("舒芬太尼", map.get("rate_2"));
|
||||
medicine.put("舒芬太尼sum", map.get("cumu_2"));
|
||||
medicine.put("瑞芬太尼", map.get("rate_3"));
|
||||
medicine.put("瑞芬太尼sum", map.get("cumu_3"));
|
||||
medicine.put("顺阿曲库胺", map.get("rate_4"));
|
||||
medicine.put("顺阿曲库胺sum", map.get("cumu_4"));
|
||||
medicine.put("尼卡地平", map.get("rate_5"));
|
||||
medicine.put("尼卡地平sum", map.get("cumu_5"));
|
||||
medicine.put("艾司洛尔", map.get("rate_6"));
|
||||
medicine.put("艾司洛尔sum", map.get("cumu_6"));
|
||||
medicine.put("麻黄素", map.get("rate_7"));
|
||||
medicine.put("麻黄素sum", map.get("cumu_7"));
|
||||
medicine.put("阿托品", map.get("rate_8"));
|
||||
medicine.put("阿托品sum", map.get("cumu_8"));
|
||||
medicine.put("Time", map.get("Time"));
|
||||
}
|
||||
aiMedicines.remove(0);
|
||||
aiMedicines.add(medicine);
|
||||
}
|
||||
return aiMedicines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getAIMedicine(Connection connection) {
|
||||
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;");
|
||||
Map medicine = new HashMap();
|
||||
while (resultSet.next()) {
|
||||
medicine.put("id", resultSet.getString("id"));
|
||||
medicine.put("phase", resultSet.getString("phase"));
|
||||
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
medicine.put("Time", resultSet.getString("time"));
|
||||
}
|
||||
String sql = "SELECT sum(`丙泊酚`) \"丙泊酚sum\", sum(`舒芬太尼`) \"舒芬太尼sum\", " +
|
||||
"sum(`瑞芬太尼`) \"瑞芬太尼sum\", sum(`顺阿曲库胺`) \"顺阿曲库胺sum\", " +
|
||||
"sum(`尼卡地平`) \"尼卡地平sum\", sum(`艾司洛尔`) \"艾司洛尔sum\", " +
|
||||
"sum(`麻黄素`) \"麻黄素sum\", sum(`阿托品`) \"阿托品sum\" FROM `aimedicinetable`";
|
||||
ResultSet sumSet = statement.executeQuery(sql);
|
||||
while (sumSet.next()) {
|
||||
medicine.put("丙泊酚sum", sumSet.getString("丙泊酚sum"));
|
||||
medicine.put("舒芬太尼sum", sumSet.getString("舒芬太尼sum"));
|
||||
medicine.put("瑞芬太尼sum", sumSet.getString("瑞芬太尼sum"));
|
||||
medicine.put("顺阿曲库胺sum", sumSet.getString("顺阿曲库胺sum"));
|
||||
medicine.put("尼卡地平sum", sumSet.getString("尼卡地平sum"));
|
||||
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);
|
||||
}
|
||||
return medicineList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeAIFlagMedicine(MongoTemplate template, String flag, String medicine, String value) {
|
||||
BasicDBObject obj = new BasicDBObject();
|
||||
obj.put("Flag", flag);
|
||||
obj.put("Time", LocalDateTime.now());
|
||||
obj.put("ConvertFlag", "2".equals(flag) ? 1 : 0);
|
||||
template.insert(obj, "aiflagtable");
|
||||
|
||||
if (StringUtils.hasText(value) && StringUtils.hasText(medicine)) {
|
||||
BasicDBObject medicineObj = new BasicDBObject();
|
||||
for (String key : doctorMedicineKeyMap.keySet()) {
|
||||
if (key.equals(medicine)) {
|
||||
medicineObj.put(medicine, value);
|
||||
} else {
|
||||
medicineObj.put(key, 0);
|
||||
}
|
||||
}
|
||||
medicineObj.put("phase", "");
|
||||
medicineObj.put("Time", LocalDateTime.now());
|
||||
template.insert(medicineObj, "doctormedicinetable");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getCountMedicine(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> aiMedicines = template.find(query, Map.class, "fktable");
|
||||
if (!aiMedicines.isEmpty()) {
|
||||
Map medicine = new HashMap();
|
||||
for (Map map : aiMedicines) {
|
||||
medicine.put("丙泊酚sum", map.get("cumu_1"));
|
||||
medicine.put("舒芬太尼sum", map.get("cumu_2"));
|
||||
medicine.put("瑞芬太尼sum", map.get("cumu_3"));
|
||||
medicine.put("顺阿曲库胺sum", map.get("cumu_4"));
|
||||
medicine.put("尼卡地平sum", map.get("cumu_5"));
|
||||
medicine.put("艾司洛尔sum", map.get("cumu_6"));
|
||||
medicine.put("麻黄素sum", map.get("cumu_7"));
|
||||
medicine.put("阿托品sum", map.get("cumu_8"));
|
||||
medicine.put("Time", map.get("Time"));
|
||||
}
|
||||
aiMedicines.remove(0);
|
||||
aiMedicines.add(medicine);
|
||||
return aiMedicines.get(0);
|
||||
}else {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getAiMedicine(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> aimedicinetable = template.find(query, Map.class, "aimedicinetable");
|
||||
if (aimedicinetable.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return aimedicinetable.get(0);
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.mongodb.BasicDBObject;
|
||||
//import com.rax.vital.v2.medicine.service.AIMedicineService;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.sql.Statement;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * AI给药
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//@AllArgsConstructor
|
||||
//public class AIMedicineServiceImpl implements AIMedicineService {
|
||||
//
|
||||
// private static final Map<String, String> doctorMedicineKeyMap = new HashMap() {
|
||||
// {
|
||||
// put("丙泊酚", "丙泊酚");
|
||||
// put("舒芬太尼", "舒芬太尼");
|
||||
// put("瑞芬太尼", "瑞芬太尼");
|
||||
// put("顺阿曲库胺", "顺阿曲库胺");
|
||||
// put("尼卡地平", "尼卡地平");
|
||||
// put("艾司洛尔", "艾司洛尔");
|
||||
// put("麻黄素", "麻黄素");
|
||||
// put("阿托品", "阿托品");
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getAIMedicine(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> aiMedicines = template.find(query, Map.class, "fktable");
|
||||
// if (!aiMedicines.isEmpty()) {
|
||||
// Map medicine = new HashMap();
|
||||
// for (Map map : aiMedicines) {
|
||||
// medicine.put("丙泊酚", map.get("rate_1"));
|
||||
// medicine.put("丙泊酚sum", map.get("cumu_1"));
|
||||
// medicine.put("舒芬太尼", map.get("rate_2"));
|
||||
// medicine.put("舒芬太尼sum", map.get("cumu_2"));
|
||||
// medicine.put("瑞芬太尼", map.get("rate_3"));
|
||||
// medicine.put("瑞芬太尼sum", map.get("cumu_3"));
|
||||
// medicine.put("顺阿曲库胺", map.get("rate_4"));
|
||||
// medicine.put("顺阿曲库胺sum", map.get("cumu_4"));
|
||||
// medicine.put("尼卡地平", map.get("rate_5"));
|
||||
// medicine.put("尼卡地平sum", map.get("cumu_5"));
|
||||
// medicine.put("艾司洛尔", map.get("rate_6"));
|
||||
// medicine.put("艾司洛尔sum", map.get("cumu_6"));
|
||||
// medicine.put("麻黄素", map.get("rate_7"));
|
||||
// medicine.put("麻黄素sum", map.get("cumu_7"));
|
||||
// medicine.put("阿托品", map.get("rate_8"));
|
||||
// medicine.put("阿托品sum", map.get("cumu_8"));
|
||||
// medicine.put("Time", map.get("Time"));
|
||||
// }
|
||||
// aiMedicines.remove(0);
|
||||
// aiMedicines.add(medicine);
|
||||
// }
|
||||
// return aiMedicines;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getAIMedicine(Connection connection) {
|
||||
// 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;");
|
||||
// Map medicine = new HashMap();
|
||||
// while (resultSet.next()) {
|
||||
// medicine.put("id", resultSet.getString("id"));
|
||||
// medicine.put("phase", resultSet.getString("phase"));
|
||||
// medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
// medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
// medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
// medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
// medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
// medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
// medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
// medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
// medicine.put("Time", resultSet.getString("time"));
|
||||
// }
|
||||
// String sql = "SELECT sum(`丙泊酚`) \"丙泊酚sum\", sum(`舒芬太尼`) \"舒芬太尼sum\", " +
|
||||
// "sum(`瑞芬太尼`) \"瑞芬太尼sum\", sum(`顺阿曲库胺`) \"顺阿曲库胺sum\", " +
|
||||
// "sum(`尼卡地平`) \"尼卡地平sum\", sum(`艾司洛尔`) \"艾司洛尔sum\", " +
|
||||
// "sum(`麻黄素`) \"麻黄素sum\", sum(`阿托品`) \"阿托品sum\" FROM `aimedicinetable`";
|
||||
// ResultSet sumSet = statement.executeQuery(sql);
|
||||
// while (sumSet.next()) {
|
||||
// medicine.put("丙泊酚sum", sumSet.getString("丙泊酚sum"));
|
||||
// medicine.put("舒芬太尼sum", sumSet.getString("舒芬太尼sum"));
|
||||
// medicine.put("瑞芬太尼sum", sumSet.getString("瑞芬太尼sum"));
|
||||
// medicine.put("顺阿曲库胺sum", sumSet.getString("顺阿曲库胺sum"));
|
||||
// medicine.put("尼卡地平sum", sumSet.getString("尼卡地平sum"));
|
||||
// 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);
|
||||
// }
|
||||
// return medicineList;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void changeAIFlagMedicine(MongoTemplate template, String flag, String medicine, String value) {
|
||||
// BasicDBObject obj = new BasicDBObject();
|
||||
// obj.put("Flag", flag);
|
||||
// obj.put("Time", LocalDateTime.now());
|
||||
// obj.put("ConvertFlag", "2".equals(flag) ? 1 : 0);
|
||||
// template.insert(obj, "aiflagtable");
|
||||
//
|
||||
// if (StringUtils.hasText(value) && StringUtils.hasText(medicine)) {
|
||||
// BasicDBObject medicineObj = new BasicDBObject();
|
||||
// for (String key : doctorMedicineKeyMap.keySet()) {
|
||||
// if (key.equals(medicine)) {
|
||||
// medicineObj.put(medicine, value);
|
||||
// } else {
|
||||
// medicineObj.put(key, 0);
|
||||
// }
|
||||
// }
|
||||
// medicineObj.put("phase", "");
|
||||
// medicineObj.put("Time", LocalDateTime.now());
|
||||
// template.insert(medicineObj, "doctormedicinetable");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Map getCountMedicine(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> aiMedicines = template.find(query, Map.class, "fktable");
|
||||
// if (!aiMedicines.isEmpty()) {
|
||||
// Map medicine = new HashMap();
|
||||
// for (Map map : aiMedicines) {
|
||||
// medicine.put("丙泊酚sum", map.get("cumu_1"));
|
||||
// medicine.put("舒芬太尼sum", map.get("cumu_2"));
|
||||
// medicine.put("瑞芬太尼sum", map.get("cumu_3"));
|
||||
// medicine.put("顺阿曲库胺sum", map.get("cumu_4"));
|
||||
// medicine.put("尼卡地平sum", map.get("cumu_5"));
|
||||
// medicine.put("艾司洛尔sum", map.get("cumu_6"));
|
||||
// medicine.put("麻黄素sum", map.get("cumu_7"));
|
||||
// medicine.put("阿托品sum", map.get("cumu_8"));
|
||||
// medicine.put("Time", map.get("Time"));
|
||||
// }
|
||||
// aiMedicines.remove(0);
|
||||
// aiMedicines.add(medicine);
|
||||
// return aiMedicines.get(0);
|
||||
// }else {
|
||||
// return Map.of();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Map getAiMedicine(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> aimedicinetable = template.find(query, Map.class, "aimedicinetable");
|
||||
// if (aimedicinetable.isEmpty()) {
|
||||
// return null;
|
||||
// }
|
||||
// return aimedicinetable.get(0);
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,141 +1,141 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.rax.admin.api.entity.SysUser;
|
||||
import com.rax.admin.service.SysUserService;
|
||||
import com.rax.vital.common.datasource.CustomDataSource;
|
||||
import com.rax.vital.common.datasource.MongoDBSource;
|
||||
import com.rax.vital.v2.medicine.service.ChatService;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@RefreshScope
|
||||
@Service
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
@Autowired
|
||||
private SysUserService SysUserService;
|
||||
|
||||
private static final Map<String, CustomDataSource> datasourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
// key: databaseName, value: Map<simpSessionId, WebSocketSession>
|
||||
private static final Map<String, Map<String, WebSocketSession>> databaseSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, String> sessionDatabaseMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(String databaseName, String username, WebSocketSession session, String msg) throws IOException {
|
||||
CustomDataSource mongoDBSource = datasourceMap.get(session.getId());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
|
||||
// 将聊天消息保存在mongo中
|
||||
if (StringUtils.hasText(msg)) {
|
||||
JSONObject param = new JSONObject();
|
||||
MongoTemplate template = mongoDBSource.getConnection();
|
||||
Document document = new Document();
|
||||
document.put("content", msg);
|
||||
param.put("content", msg);
|
||||
String now = DateUtil.now();
|
||||
document.put("create_time", now);
|
||||
param.put("createTime", now);
|
||||
document.put("create_user", username);
|
||||
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()) {
|
||||
WebSocketSession value = entry.getValue();
|
||||
value.sendMessage(new TextMessage(param.toJSONString().getBytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void stopTimerTask(String simpSessionId) {
|
||||
CustomDataSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
if (mongoDBSource != null) {
|
||||
mongoDBSource.close();
|
||||
datasourceMap.remove(simpSessionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void stopTask(String simpSessionId) {
|
||||
CustomDataSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
if (mongoDBSource != null) {
|
||||
mongoDBSource.close();
|
||||
datasourceMap.remove(simpSessionId);
|
||||
}
|
||||
String databaseName = sessionDatabaseMap.get(simpSessionId);
|
||||
if (databaseName != null) {
|
||||
sessionDatabaseMap.remove(simpSessionId);
|
||||
Map<String, WebSocketSession> stringWebSocketSessionMap = databaseSessionMap.get(databaseName);
|
||||
stringWebSocketSessionMap.remove(simpSessionId);
|
||||
if (stringWebSocketSessionMap.isEmpty()) {
|
||||
databaseSessionMap.remove(databaseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import cn.hutool.core.date.DateUtil;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
//import com.rax.admin.api.entity.SysUser;
|
||||
//import com.rax.admin.service.SysUserService;
|
||||
//import com.rax.vital.common.datasource.CustomDataSource;
|
||||
//import com.rax.vital.common.datasource.MongoDBSource;
|
||||
//import com.rax.vital.v2.medicine.service.ChatService;
|
||||
//import org.bson.Document;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//import org.springframework.web.socket.TextMessage;
|
||||
//import org.springframework.web.socket.WebSocketSession;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
//@RefreshScope
|
||||
//@Service
|
||||
//public class ChatServiceImpl implements ChatService {
|
||||
//
|
||||
// @Autowired
|
||||
// private SysUserService SysUserService;
|
||||
//
|
||||
// private static final Map<String, CustomDataSource> datasourceMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // key: databaseName, value: Map<simpSessionId, WebSocketSession>
|
||||
// private static final Map<String, Map<String, WebSocketSession>> databaseSessionMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// private static final Map<String, String> sessionDatabaseMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // 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;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void sendMessage(String databaseName, String username, WebSocketSession session, String msg) throws IOException {
|
||||
// CustomDataSource mongoDBSource = datasourceMap.get(session.getId());
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
//
|
||||
// // 将聊天消息保存在mongo中
|
||||
// if (StringUtils.hasText(msg)) {
|
||||
// JSONObject param = new JSONObject();
|
||||
// MongoTemplate template = mongoDBSource.getConnection();
|
||||
// Document document = new Document();
|
||||
// document.put("content", msg);
|
||||
// param.put("content", msg);
|
||||
// String now = DateUtil.now();
|
||||
// document.put("create_time", now);
|
||||
// param.put("createTime", now);
|
||||
// document.put("create_user", username);
|
||||
// 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()) {
|
||||
// WebSocketSession value = entry.getValue();
|
||||
// value.sendMessage(new TextMessage(param.toJSONString().getBytes()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public synchronized void stopTimerTask(String simpSessionId) {
|
||||
// CustomDataSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
// if (mongoDBSource != null) {
|
||||
// mongoDBSource.close();
|
||||
// datasourceMap.remove(simpSessionId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public synchronized void stopTask(String simpSessionId) {
|
||||
// CustomDataSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
// if (mongoDBSource != null) {
|
||||
// mongoDBSource.close();
|
||||
// datasourceMap.remove(simpSessionId);
|
||||
// }
|
||||
// String databaseName = sessionDatabaseMap.get(simpSessionId);
|
||||
// if (databaseName != null) {
|
||||
// sessionDatabaseMap.remove(simpSessionId);
|
||||
// Map<String, WebSocketSession> stringWebSocketSessionMap = databaseSessionMap.get(databaseName);
|
||||
// stringWebSocketSessionMap.remove(simpSessionId);
|
||||
// if (stringWebSocketSessionMap.isEmpty()) {
|
||||
// databaseSessionMap.remove(databaseName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,83 +1,83 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.rax.vital.v2.medicine.service.DoctorMedicineService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 医生给药
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DoctorMedicineServiceImpl implements DoctorMedicineService {
|
||||
|
||||
@Override
|
||||
public Map getDocMedicine(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> doctorMedicineTable = template.find(query, Map.class, "doctormedicinetable");
|
||||
if (doctorMedicineTable.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
return doctorMedicineTable.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getDocMedicine(Connection connection) {
|
||||
List<Map> medicineList = new ArrayList<>();
|
||||
try {
|
||||
Map medicine = new HashMap();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `doctormedicinetable` ORDER BY time DESC LIMIT 1;");
|
||||
while (resultSet.next()) {
|
||||
medicine.put("id", resultSet.getString("id"));
|
||||
medicine.put("phase", resultSet.getString("phase"));
|
||||
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
medicine.put("Time", resultSet.getString("time"));
|
||||
}
|
||||
|
||||
String sql = "SELECT sum(`丙泊酚`) \"丙泊酚sum\", sum(`舒芬太尼`) \"舒芬太尼sum\", " +
|
||||
"sum(`瑞芬太尼`) \"瑞芬太尼sum\", sum(`顺阿曲库胺`) \"顺阿曲库胺sum\", " +
|
||||
"sum(`尼卡地平`) \"尼卡地平sum\", sum(`艾司洛尔`) \"艾司洛尔sum\", " +
|
||||
"sum(`麻黄素`) \"麻黄素sum\", sum(`阿托品`) \"阿托品sum\" FROM `doctormedicinetable`";
|
||||
ResultSet sumSet = statement.executeQuery(sql);
|
||||
while (sumSet.next()) {
|
||||
medicine.put("丙泊酚sum", sumSet.getString("丙泊酚sum"));
|
||||
medicine.put("舒芬太尼sum", sumSet.getString("舒芬太尼sum"));
|
||||
medicine.put("瑞芬太尼sum", sumSet.getString("瑞芬太尼sum"));
|
||||
medicine.put("顺阿曲库胺sum", sumSet.getString("顺阿曲库胺sum"));
|
||||
medicine.put("尼卡地平sum", sumSet.getString("尼卡地平sum"));
|
||||
medicine.put("艾司洛尔sum", sumSet.getString("艾司洛尔sum"));
|
||||
medicine.put("麻黄素sum", sumSet.getString("麻黄素sum"));
|
||||
medicine.put("阿托品sum", sumSet.getString("阿托品sum"));
|
||||
}
|
||||
|
||||
medicineList.add(medicine);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return medicineList;
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.rax.vital.v2.medicine.service.DoctorMedicineService;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.sql.Statement;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 医生给药
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//@AllArgsConstructor
|
||||
//public class DoctorMedicineServiceImpl implements DoctorMedicineService {
|
||||
//
|
||||
// @Override
|
||||
// public Map getDocMedicine(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> doctorMedicineTable = template.find(query, Map.class, "doctormedicinetable");
|
||||
// if (doctorMedicineTable.isEmpty()){
|
||||
// return null;
|
||||
// }
|
||||
// return doctorMedicineTable.get(0);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getDocMedicine(Connection connection) {
|
||||
// List<Map> medicineList = new ArrayList<>();
|
||||
// try {
|
||||
// Map medicine = new HashMap();
|
||||
// Statement statement = connection.createStatement();
|
||||
// ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `doctormedicinetable` ORDER BY time DESC LIMIT 1;");
|
||||
// while (resultSet.next()) {
|
||||
// medicine.put("id", resultSet.getString("id"));
|
||||
// medicine.put("phase", resultSet.getString("phase"));
|
||||
// medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
// medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
// medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
// medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
// medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
// medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
// medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
// medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
// medicine.put("Time", resultSet.getString("time"));
|
||||
// }
|
||||
//
|
||||
// String sql = "SELECT sum(`丙泊酚`) \"丙泊酚sum\", sum(`舒芬太尼`) \"舒芬太尼sum\", " +
|
||||
// "sum(`瑞芬太尼`) \"瑞芬太尼sum\", sum(`顺阿曲库胺`) \"顺阿曲库胺sum\", " +
|
||||
// "sum(`尼卡地平`) \"尼卡地平sum\", sum(`艾司洛尔`) \"艾司洛尔sum\", " +
|
||||
// "sum(`麻黄素`) \"麻黄素sum\", sum(`阿托品`) \"阿托品sum\" FROM `doctormedicinetable`";
|
||||
// ResultSet sumSet = statement.executeQuery(sql);
|
||||
// while (sumSet.next()) {
|
||||
// medicine.put("丙泊酚sum", sumSet.getString("丙泊酚sum"));
|
||||
// medicine.put("舒芬太尼sum", sumSet.getString("舒芬太尼sum"));
|
||||
// medicine.put("瑞芬太尼sum", sumSet.getString("瑞芬太尼sum"));
|
||||
// medicine.put("顺阿曲库胺sum", sumSet.getString("顺阿曲库胺sum"));
|
||||
// medicine.put("尼卡地平sum", sumSet.getString("尼卡地平sum"));
|
||||
// medicine.put("艾司洛尔sum", sumSet.getString("艾司洛尔sum"));
|
||||
// medicine.put("麻黄素sum", sumSet.getString("麻黄素sum"));
|
||||
// medicine.put("阿托品sum", sumSet.getString("阿托品sum"));
|
||||
// }
|
||||
//
|
||||
// medicineList.add(medicine);
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// return medicineList;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,171 +1,171 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.rax.vital.v2.medicine.service.FlagService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 标志位
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class FlagServiceImpl implements FlagService {
|
||||
|
||||
/**
|
||||
* 新标志位接口MongoDB
|
||||
* flag 0:诱导期给药 1:维持期AI给药 2:维持期人工给药
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map getFlags(MongoTemplate template) {
|
||||
Map flagMap = new HashMap();
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> linkTable = template.find(query, Map.class, "linktable");
|
||||
List<Map> aiFlagTable = template.find(query, Map.class, "aiflagtable");
|
||||
List<Map> endFlagTable = template.find(query, Map.class, "endflagtable");
|
||||
|
||||
if (!linkTable.isEmpty()){
|
||||
flagMap.put("linkFlag", linkTable.get(0).get("Flag"));
|
||||
}else {
|
||||
flagMap.put("linkFlag", "");
|
||||
}
|
||||
|
||||
if (!aiFlagTable.isEmpty()){
|
||||
flagMap.put("aiFlag", aiFlagTable.get(0).get("Flag"));
|
||||
}else {
|
||||
flagMap.put("aiFlag", "");
|
||||
}
|
||||
|
||||
if (!endFlagTable.isEmpty()){
|
||||
flagMap.put("endFlag", endFlagTable.get(0).get("Flag"));
|
||||
}else {
|
||||
flagMap.put("endFlag", "");
|
||||
}
|
||||
|
||||
return flagMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 标志位接口MongoDB
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Map getFlag(MongoTemplate template) {
|
||||
Map allFlag = new HashMap();
|
||||
Query query1 = new Query();
|
||||
query1.limit(1);
|
||||
query1.with(Sort.by(Sort.Order.desc("_id")));
|
||||
List<Map> endFlagTable = template.find(query1, Map.class, "EndFlagTable");
|
||||
if (!endFlagTable.isEmpty()) {
|
||||
allFlag.put("endFlag", endFlagTable.get(1));
|
||||
}
|
||||
|
||||
Query query2 = new Query();
|
||||
query2.limit(1);
|
||||
query2.with(Sort.by(Sort.Order.desc("_id")));
|
||||
List<Map> aiFlagTable = template.find(query2, Map.class, "AIFlagTable");
|
||||
if (!aiFlagTable.isEmpty()) {
|
||||
allFlag.put("aiFlag", aiFlagTable);
|
||||
}
|
||||
|
||||
Query query3 = new Query();
|
||||
query3.limit(1);
|
||||
query3.with(Sort.by(Sort.Order.desc("_id")));
|
||||
List<Map> reFlagTable = template.find(query3, Map.class, "ReFlagTable");
|
||||
if (!reFlagTable.isEmpty()) {
|
||||
allFlag.put("reFlagTable", reFlagTable);
|
||||
}
|
||||
|
||||
return allFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标志位接口MySQL
|
||||
*
|
||||
* @param connection
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map getFlag(Connection connection) {
|
||||
Map allFlag = new HashMap();
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
// 0代表手术未开始或已结束、1代表手术进行中
|
||||
ResultSet resultSet = statement.executeQuery("SELECT * FROM `endflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
List<Map> endFlagList = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
Map flag = new HashMap();
|
||||
flag.put("id", resultSet.getString(1));
|
||||
flag.put("Flag", resultSet.getString(2));
|
||||
flag.put("Time", resultSet.getString(3));
|
||||
endFlagList.add(flag);
|
||||
}
|
||||
allFlag.put("endflagtable", endFlagList);
|
||||
|
||||
// Flag默认为1:0代表诱导期给药、1代表维持期AI给药、2代表维持期医生给药
|
||||
// ConvertFlag默认为0:0代表无需切换、1代表由AI给药转为医生给药
|
||||
ResultSet aiRe = statement.executeQuery("SELECT * FROM `aiflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
List<Map> aiFlagList = new ArrayList<>();
|
||||
while (aiRe.next()) {
|
||||
Map flag = new HashMap();
|
||||
flag.put("id", aiRe.getString(1));
|
||||
flag.put("Flag", aiRe.getString(2));
|
||||
flag.put("ConvertFlag", aiRe.getString(3));
|
||||
flag.put("Time", aiRe.getString(4));
|
||||
aiFlagList.add(flag);
|
||||
}
|
||||
allFlag.put("aiflagtable", aiFlagList);
|
||||
|
||||
// 诱导期标志符 0是诱导期 1是维持期
|
||||
ResultSet reRe = statement.executeQuery("SELECT * FROM `reflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
List<Map> reFlagList = new ArrayList<>();
|
||||
while (reRe.next()) {
|
||||
Map flag = new HashMap();
|
||||
flag.put("id", reRe.getString(1));
|
||||
flag.put("Flag", reRe.getString(2));
|
||||
flag.put("Time", reRe.getString(3));
|
||||
reFlagList.add(flag);
|
||||
}
|
||||
allFlag.put("reflagtable", reFlagList);
|
||||
|
||||
// Flag默认为1: 0代表泵站通讯正常、1代表泵站通讯异常
|
||||
ResultSet link = statement.executeQuery("SELECT * FROM `linktable` ORDER BY time DESC LIMIT 1;");
|
||||
List<Map> linkFlagList = new ArrayList<>();
|
||||
while (link.next()) {
|
||||
Map flag = new HashMap();
|
||||
flag.put("id", link.getString(1));
|
||||
flag.put("Flag", link.getString(2));
|
||||
flag.put("Time", link.getString(3));
|
||||
linkFlagList.add(flag);
|
||||
}
|
||||
allFlag.put("linktable", linkFlagList);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return allFlag;
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.rax.vital.v2.medicine.service.FlagService;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.sql.Statement;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 标志位
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//@AllArgsConstructor
|
||||
//public class FlagServiceImpl implements FlagService {
|
||||
//
|
||||
// /**
|
||||
// * 新标志位接口MongoDB
|
||||
// * flag 0:诱导期给药 1:维持期AI给药 2:维持期人工给药
|
||||
// *
|
||||
// * @param template
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public Map getFlags(MongoTemplate template) {
|
||||
// Map flagMap = new HashMap();
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> linkTable = template.find(query, Map.class, "linktable");
|
||||
// List<Map> aiFlagTable = template.find(query, Map.class, "aiflagtable");
|
||||
// List<Map> endFlagTable = template.find(query, Map.class, "endflagtable");
|
||||
//
|
||||
// if (!linkTable.isEmpty()){
|
||||
// flagMap.put("linkFlag", linkTable.get(0).get("Flag"));
|
||||
// }else {
|
||||
// flagMap.put("linkFlag", "");
|
||||
// }
|
||||
//
|
||||
// if (!aiFlagTable.isEmpty()){
|
||||
// flagMap.put("aiFlag", aiFlagTable.get(0).get("Flag"));
|
||||
// }else {
|
||||
// flagMap.put("aiFlag", "");
|
||||
// }
|
||||
//
|
||||
// if (!endFlagTable.isEmpty()){
|
||||
// flagMap.put("endFlag", endFlagTable.get(0).get("Flag"));
|
||||
// }else {
|
||||
// flagMap.put("endFlag", "");
|
||||
// }
|
||||
//
|
||||
// return flagMap;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 标志位接口MongoDB
|
||||
// *
|
||||
// * @param template
|
||||
// * @return
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public Map getFlag(MongoTemplate template) {
|
||||
// Map allFlag = new HashMap();
|
||||
// Query query1 = new Query();
|
||||
// query1.limit(1);
|
||||
// query1.with(Sort.by(Sort.Order.desc("_id")));
|
||||
// List<Map> endFlagTable = template.find(query1, Map.class, "EndFlagTable");
|
||||
// if (!endFlagTable.isEmpty()) {
|
||||
// allFlag.put("endFlag", endFlagTable.get(1));
|
||||
// }
|
||||
//
|
||||
// Query query2 = new Query();
|
||||
// query2.limit(1);
|
||||
// query2.with(Sort.by(Sort.Order.desc("_id")));
|
||||
// List<Map> aiFlagTable = template.find(query2, Map.class, "AIFlagTable");
|
||||
// if (!aiFlagTable.isEmpty()) {
|
||||
// allFlag.put("aiFlag", aiFlagTable);
|
||||
// }
|
||||
//
|
||||
// Query query3 = new Query();
|
||||
// query3.limit(1);
|
||||
// query3.with(Sort.by(Sort.Order.desc("_id")));
|
||||
// List<Map> reFlagTable = template.find(query3, Map.class, "ReFlagTable");
|
||||
// if (!reFlagTable.isEmpty()) {
|
||||
// allFlag.put("reFlagTable", reFlagTable);
|
||||
// }
|
||||
//
|
||||
// return allFlag;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 标志位接口MySQL
|
||||
// *
|
||||
// * @param connection
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// @Deprecated
|
||||
// public Map getFlag(Connection connection) {
|
||||
// Map allFlag = new HashMap();
|
||||
// try {
|
||||
// Statement statement = connection.createStatement();
|
||||
// // 0代表手术未开始或已结束、1代表手术进行中
|
||||
// ResultSet resultSet = statement.executeQuery("SELECT * FROM `endflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
// List<Map> endFlagList = new ArrayList<>();
|
||||
// while (resultSet.next()) {
|
||||
// Map flag = new HashMap();
|
||||
// flag.put("id", resultSet.getString(1));
|
||||
// flag.put("Flag", resultSet.getString(2));
|
||||
// flag.put("Time", resultSet.getString(3));
|
||||
// endFlagList.add(flag);
|
||||
// }
|
||||
// allFlag.put("endflagtable", endFlagList);
|
||||
//
|
||||
// // Flag默认为1:0代表诱导期给药、1代表维持期AI给药、2代表维持期医生给药
|
||||
// // ConvertFlag默认为0:0代表无需切换、1代表由AI给药转为医生给药
|
||||
// ResultSet aiRe = statement.executeQuery("SELECT * FROM `aiflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
// List<Map> aiFlagList = new ArrayList<>();
|
||||
// while (aiRe.next()) {
|
||||
// Map flag = new HashMap();
|
||||
// flag.put("id", aiRe.getString(1));
|
||||
// flag.put("Flag", aiRe.getString(2));
|
||||
// flag.put("ConvertFlag", aiRe.getString(3));
|
||||
// flag.put("Time", aiRe.getString(4));
|
||||
// aiFlagList.add(flag);
|
||||
// }
|
||||
// allFlag.put("aiflagtable", aiFlagList);
|
||||
//
|
||||
// // 诱导期标志符 0是诱导期 1是维持期
|
||||
// ResultSet reRe = statement.executeQuery("SELECT * FROM `reflagtable` ORDER BY time DESC LIMIT 1;");
|
||||
// List<Map> reFlagList = new ArrayList<>();
|
||||
// while (reRe.next()) {
|
||||
// Map flag = new HashMap();
|
||||
// flag.put("id", reRe.getString(1));
|
||||
// flag.put("Flag", reRe.getString(2));
|
||||
// flag.put("Time", reRe.getString(3));
|
||||
// reFlagList.add(flag);
|
||||
// }
|
||||
// allFlag.put("reflagtable", reFlagList);
|
||||
//
|
||||
// // Flag默认为1: 0代表泵站通讯正常、1代表泵站通讯异常
|
||||
// ResultSet link = statement.executeQuery("SELECT * FROM `linktable` ORDER BY time DESC LIMIT 1;");
|
||||
// List<Map> linkFlagList = new ArrayList<>();
|
||||
// while (link.next()) {
|
||||
// Map flag = new HashMap();
|
||||
// flag.put("id", link.getString(1));
|
||||
// flag.put("Flag", link.getString(2));
|
||||
// flag.put("Time", link.getString(3));
|
||||
// linkFlagList.add(flag);
|
||||
// }
|
||||
// allFlag.put("linktable", linkFlagList);
|
||||
//
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// return allFlag;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,306 +1,306 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rax.common.core.util.R;
|
||||
import com.rax.vital.common.datasource.MongoDBSource;
|
||||
import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
import com.rax.vital.v2.medicine.service.IMedicineService;
|
||||
import org.bson.BsonRegularExpression;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.*;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @project_name: rax-remote-v2
|
||||
* @time: 2024/9/10 17:01
|
||||
* @author: republicline
|
||||
* @description: 针对于固定数据源的读取配置操作.
|
||||
*/
|
||||
@Service
|
||||
public class MedicineService implements IMedicineService {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
@Override
|
||||
public R getPatientInfo(String databaseName) {
|
||||
// MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
// mongoDBSource.open();
|
||||
// MongoTemplate template = mongoDBSource.getConnection();
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.rax.common.core.util.R;
|
||||
//import com.rax.vital.common.datasource.MongoDBSource;
|
||||
//import com.rax.vital.common.util.DatabaseNameUtil;
|
||||
//import com.rax.vital.v2.medicine.service.IMedicineService;
|
||||
//import org.bson.BsonRegularExpression;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.aggregation.*;
|
||||
//import org.springframework.data.mongodb.core.query.Criteria;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @project_name: rax-remote-v2
|
||||
// * @time: 2024/9/10 17:01
|
||||
// * @author: republicline
|
||||
// * @description: 针对于固定数据源的读取配置操作.
|
||||
// */
|
||||
//@Service
|
||||
//public class MedicineService implements IMedicineService {
|
||||
//
|
||||
// @Autowired
|
||||
// private MongoTemplate mongoTemplate;
|
||||
//
|
||||
// @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;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public R getPatientInfo(String databaseName) {
|
||||
//// MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
//// mongoDBSource.open();
|
||||
//// MongoTemplate template = mongoDBSource.getConnection();
|
||||
//// Query query = new Query();
|
||||
//// query.limit(1);
|
||||
//// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
//// List<Map> vitalList = template.find(query, Map.class, "patienttable");
|
||||
//// mongoDBSource.close();
|
||||
//// return R.ok(vitalList);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Page getPatientPage(String name, String dept, long offset, int limit) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> vitalList = template.find(query, Map.class, "patienttable");
|
||||
// mongoDBSource.close();
|
||||
// return R.ok(vitalList);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page getPatientPage(String name, String dept, long offset, int limit) {
|
||||
Query query = new Query();
|
||||
|
||||
if (StringUtils.hasText(name)) {
|
||||
Criteria criteria = new Criteria("姓名");
|
||||
criteria.regex(new BsonRegularExpression(".*" + name + ".*"));
|
||||
query.addCriteria(criteria);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(dept)) {
|
||||
Criteria criteria = new Criteria("科室");
|
||||
criteria.regex(new BsonRegularExpression(dept));
|
||||
query.addCriteria(criteria);
|
||||
}
|
||||
|
||||
query.with(Sort.by(Sort.Order.desc("住院时间")));
|
||||
query.skip(offset).limit(limit);
|
||||
List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
long count = mongoTemplate.count(query, "patient_info");
|
||||
Page page = new Page();
|
||||
page.setRecords(list);
|
||||
page.setTotal(count);
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSurgeryCount(String start, String end) {
|
||||
// 按医院查询
|
||||
// RaxUser user = SecurityUtils.getUser();
|
||||
// Long currentHospital = AuthUtils.getCurrentHospital(user);
|
||||
|
||||
|
||||
// Criteria hosCriteria = Criteria.where("hospitalId")
|
||||
// .is(hospitalId);
|
||||
|
||||
Criteria criteria = Criteria.where("Time")
|
||||
.gte(start)
|
||||
.lte(end);
|
||||
Aggregation aggregation = Aggregation.newAggregation(
|
||||
// Aggregation.match(hosCriteria),
|
||||
Aggregation.match(criteria),
|
||||
Aggregation.project("Time")
|
||||
.and(DateOperators.DateFromString.fromStringOf("Time").withFormat("%Y-%m-%d %H:%M:%S")).as("timeDate"),
|
||||
Aggregation.project("timeDate")
|
||||
.and(DateOperators.DateToString.dateOf("timeDate").toString("%Y-%m-%d")).as("time"),
|
||||
Aggregation.group("time").count().as("count"),
|
||||
Aggregation.project("_id","count"),
|
||||
Aggregation.sort(Sort.by(Sort.Direction.ASC, "_id"))
|
||||
);
|
||||
AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "surgery_info", Map.class);
|
||||
List<Map> mappedResults = results.getMappedResults();
|
||||
return mappedResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSurgeryDuration(String start, String end) {
|
||||
|
||||
List<AggregationOperation> operations = new ArrayList<>();
|
||||
|
||||
Criteria criteria = new Criteria("Time");
|
||||
criteria.gte(start);
|
||||
criteria.lte(end);
|
||||
operations.add(Aggregation.match(criteria));
|
||||
|
||||
|
||||
ProjectionOperation timeToDateOperation = Aggregation.project()
|
||||
.andExpression("{$toLong: '$Surgery_duration(min)'}").as("Surgery_duration(min)")
|
||||
.andExpression("{$toDate: '$Time'}").as("day");
|
||||
operations.add(timeToDateOperation);
|
||||
|
||||
ProjectionOperation timeFormatOperation = Aggregation.project()
|
||||
.andInclude("Surgery_duration(min)")
|
||||
.andExpression("{ $dateToString: { format: '%Y-%m-%d', date: '$day' } }").as("time");
|
||||
operations.add(timeFormatOperation);
|
||||
|
||||
operations.add(Aggregation.group("$time").sum("Surgery_duration(min)").as("count"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("_id")
|
||||
.andExpression("count").divide(60).as("count"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("_id")
|
||||
.andExpression("{$round: {'$count', 1}}").as("duration"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("duration")
|
||||
.andExpression("{$toDate: '$_id'}").as("time"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("duration")
|
||||
.andExpression("{ $dateToString: { format: '%d', date: '$time' } }").as("_id"));
|
||||
|
||||
operations.add(Aggregation.sort(Sort.Direction.ASC, "_id"));
|
||||
|
||||
TypedAggregation typedAggregation = new TypedAggregation(Map.class, operations);
|
||||
AggregationResults<Map> aggregate = mongoTemplate.aggregate(typedAggregation, "surgery_info", Map.class);
|
||||
List<Map> mappedResults = aggregate.getMappedResults();
|
||||
return mappedResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSurgeryTypeProportion(String start, String end) {
|
||||
|
||||
// RaxUser user = SecurityUtils.getUser();
|
||||
// Long currentHospital = AuthUtils.getCurrentHospital(user);
|
||||
|
||||
|
||||
|
||||
Aggregation aggregation = Aggregation.newAggregation(
|
||||
Aggregation.match(Criteria.where("Time")
|
||||
.gte(start)
|
||||
.lte(end)),
|
||||
// Aggregation.match(Criteria.where("hospitalId")
|
||||
// .is(currentHospital)),
|
||||
Aggregation.group("Surgery_type").count().as("count")
|
||||
);
|
||||
List<Map> mappedResults = mongoTemplate.aggregate(aggregation, "surgery_info", Map.class).getMappedResults();
|
||||
|
||||
return mappedResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSurgeryOtherDuration(String start, String end) {
|
||||
// MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, informationDatabase);
|
||||
// mongoDBSource.open();
|
||||
// MongoTemplate template = mongoDBSource.getConnection();
|
||||
List<AggregationOperation> operations = new ArrayList<>();
|
||||
|
||||
Criteria criteria = new Criteria("Time");
|
||||
criteria.gte(start);
|
||||
criteria.lte(end);
|
||||
operations.add(Aggregation.match(criteria));
|
||||
|
||||
ProjectionOperation timeToDateOperation = Aggregation.project()
|
||||
.andExpression("{$toLong: '$Aianaesthesia_duration(min)'}").as("Aianaesthesia_duration(min)")
|
||||
.andExpression("{$toLong: '$Doctoranaesthesia_duration(min)'}").as("Doctoranaesthesia_duration(min)")
|
||||
.andExpression("{$toDate: '$Time'}").as("time");
|
||||
operations.add(timeToDateOperation);
|
||||
|
||||
ProjectionOperation timeFormatOperation = Aggregation.project()
|
||||
.andInclude("Aianaesthesia_duration(min)")
|
||||
.andInclude("Doctoranaesthesia_duration(min)")
|
||||
.andExpression("{ $dateToString: { format: '%Y-%m-%d', date: '$time' } }").as("time");
|
||||
operations.add(timeFormatOperation);
|
||||
|
||||
operations.add(Aggregation.group("$time")
|
||||
.sum("Aianaesthesia_duration(min)").as("aicount")
|
||||
.sum("Doctoranaesthesia_duration(min)").as("doccount"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("_id")
|
||||
.andExpression("aicount").divide(60).as("aicount")
|
||||
.andExpression("doccount").divide(60).as("doccount"));
|
||||
|
||||
operations.add(Aggregation.project()
|
||||
.andInclude("_id")
|
||||
.andExpression("{$round: {'$aicount', 1}}").as("aicount")
|
||||
.andExpression("{$round: {'$doccount', 1}}").as("doccount"));
|
||||
|
||||
operations.add(Aggregation.sort(Sort.Direction.ASC, "_id"));
|
||||
|
||||
TypedAggregation typedAggregation = new TypedAggregation(Map.class, operations);
|
||||
AggregationResults<Map> aggregate = mongoTemplate.aggregate(typedAggregation, "surgery_info", Map.class);
|
||||
List<Map> mappedResults = aggregate.getMappedResults();
|
||||
return mappedResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getPatientSurgeryList(String name, String code, String surgery, String type) {
|
||||
if (StringUtils.hasText(code)) {
|
||||
|
||||
if (!StringUtils.hasText(name)) {
|
||||
Query query = new Query();
|
||||
Criteria criteria = new Criteria("住院号");
|
||||
criteria.regex(new BsonRegularExpression(code));
|
||||
query.addCriteria(criteria);
|
||||
List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
if (!list.isEmpty()) {
|
||||
Map patient = list.get(0);
|
||||
name = (String) patient.get("姓名");
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
Query query = new Query();
|
||||
String databasePrefix = DatabaseNameUtil.encrypt(name) + "_" + DatabaseNameUtil.encrypt(code) + "_";
|
||||
Criteria criteria = new Criteria("Databasename");
|
||||
criteria.regex(new BsonRegularExpression("^" + databasePrefix));
|
||||
query.addCriteria(criteria);
|
||||
|
||||
if (StringUtils.hasText(surgery)) {
|
||||
Criteria surgeryCriteria = new Criteria("Surgery_name");
|
||||
surgeryCriteria.regex(new BsonRegularExpression(surgery));
|
||||
query.addCriteria(surgeryCriteria);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(type)) {
|
||||
Criteria anesthesiaCriteria = new Criteria("Anesthesia_way");
|
||||
anesthesiaCriteria.regex(new BsonRegularExpression(type));
|
||||
query.addCriteria(anesthesiaCriteria);
|
||||
}
|
||||
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> surgeryInfoList = mongoTemplate.find(query, Map.class, "surgery_info");
|
||||
return surgeryInfoList;
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List getSurgeryTableData(String name, String code, String date, String table) {
|
||||
if (StringUtils.hasText(code)) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
//
|
||||
// if (StringUtils.hasText(name)) {
|
||||
// Criteria criteria = new Criteria("姓名");
|
||||
// criteria.regex(new BsonRegularExpression(".*" + name + ".*"));
|
||||
// query.addCriteria(criteria);
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.hasText(dept)) {
|
||||
// Criteria criteria = new Criteria("科室");
|
||||
// criteria.regex(new BsonRegularExpression(dept));
|
||||
// query.addCriteria(criteria);
|
||||
// }
|
||||
//
|
||||
// query.with(Sort.by(Sort.Order.desc("住院时间")));
|
||||
// query.skip(offset).limit(limit);
|
||||
// List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
// long count = mongoTemplate.count(query, "patient_info");
|
||||
// Page page = new Page();
|
||||
// page.setRecords(list);
|
||||
// page.setTotal(count);
|
||||
// return page;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List getSurgeryCount(String start, String end) {
|
||||
// // 按医院查询
|
||||
//// RaxUser user = SecurityUtils.getUser();
|
||||
//// Long currentHospital = AuthUtils.getCurrentHospital(user);
|
||||
//
|
||||
//
|
||||
//// Criteria hosCriteria = Criteria.where("hospitalId")
|
||||
//// .is(hospitalId);
|
||||
//
|
||||
// Criteria criteria = Criteria.where("Time")
|
||||
// .gte(start)
|
||||
// .lte(end);
|
||||
// Aggregation aggregation = Aggregation.newAggregation(
|
||||
//// Aggregation.match(hosCriteria),
|
||||
// Aggregation.match(criteria),
|
||||
// Aggregation.project("Time")
|
||||
// .and(DateOperators.DateFromString.fromStringOf("Time").withFormat("%Y-%m-%d %H:%M:%S")).as("timeDate"),
|
||||
// Aggregation.project("timeDate")
|
||||
// .and(DateOperators.DateToString.dateOf("timeDate").toString("%Y-%m-%d")).as("time"),
|
||||
// Aggregation.group("time").count().as("count"),
|
||||
// Aggregation.project("_id","count"),
|
||||
// Aggregation.sort(Sort.by(Sort.Direction.ASC, "_id"))
|
||||
// );
|
||||
// AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "surgery_info", Map.class);
|
||||
// List<Map> mappedResults = results.getMappedResults();
|
||||
// return mappedResults;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List getSurgeryDuration(String start, String end) {
|
||||
//
|
||||
// List<AggregationOperation> operations = new ArrayList<>();
|
||||
//
|
||||
// Criteria criteria = new Criteria("Time");
|
||||
// criteria.gte(start);
|
||||
// criteria.lte(end);
|
||||
// operations.add(Aggregation.match(criteria));
|
||||
//
|
||||
//
|
||||
// ProjectionOperation timeToDateOperation = Aggregation.project()
|
||||
// .andExpression("{$toLong: '$Surgery_duration(min)'}").as("Surgery_duration(min)")
|
||||
// .andExpression("{$toDate: '$Time'}").as("day");
|
||||
// operations.add(timeToDateOperation);
|
||||
//
|
||||
// ProjectionOperation timeFormatOperation = Aggregation.project()
|
||||
// .andInclude("Surgery_duration(min)")
|
||||
// .andExpression("{ $dateToString: { format: '%Y-%m-%d', date: '$day' } }").as("time");
|
||||
// operations.add(timeFormatOperation);
|
||||
//
|
||||
// operations.add(Aggregation.group("$time").sum("Surgery_duration(min)").as("count"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("_id")
|
||||
// .andExpression("count").divide(60).as("count"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("_id")
|
||||
// .andExpression("{$round: {'$count', 1}}").as("duration"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("duration")
|
||||
// .andExpression("{$toDate: '$_id'}").as("time"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("duration")
|
||||
// .andExpression("{ $dateToString: { format: '%d', date: '$time' } }").as("_id"));
|
||||
//
|
||||
// operations.add(Aggregation.sort(Sort.Direction.ASC, "_id"));
|
||||
//
|
||||
// TypedAggregation typedAggregation = new TypedAggregation(Map.class, operations);
|
||||
// AggregationResults<Map> aggregate = mongoTemplate.aggregate(typedAggregation, "surgery_info", Map.class);
|
||||
// List<Map> mappedResults = aggregate.getMappedResults();
|
||||
// return mappedResults;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List getSurgeryTypeProportion(String start, String end) {
|
||||
//
|
||||
//// RaxUser user = SecurityUtils.getUser();
|
||||
//// Long currentHospital = AuthUtils.getCurrentHospital(user);
|
||||
//
|
||||
//
|
||||
//
|
||||
// Aggregation aggregation = Aggregation.newAggregation(
|
||||
// Aggregation.match(Criteria.where("Time")
|
||||
// .gte(start)
|
||||
// .lte(end)),
|
||||
//// Aggregation.match(Criteria.where("hospitalId")
|
||||
//// .is(currentHospital)),
|
||||
// Aggregation.group("Surgery_type").count().as("count")
|
||||
// );
|
||||
// List<Map> mappedResults = mongoTemplate.aggregate(aggregation, "surgery_info", Map.class).getMappedResults();
|
||||
//
|
||||
// return mappedResults;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List getSurgeryOtherDuration(String start, String end) {
|
||||
//// MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, informationDatabase);
|
||||
//// mongoDBSource.open();
|
||||
//// MongoTemplate template = mongoDBSource.getConnection();
|
||||
// List<AggregationOperation> operations = new ArrayList<>();
|
||||
//
|
||||
// Criteria criteria = new Criteria("Time");
|
||||
// criteria.gte(start);
|
||||
// criteria.lte(end);
|
||||
// operations.add(Aggregation.match(criteria));
|
||||
//
|
||||
// ProjectionOperation timeToDateOperation = Aggregation.project()
|
||||
// .andExpression("{$toLong: '$Aianaesthesia_duration(min)'}").as("Aianaesthesia_duration(min)")
|
||||
// .andExpression("{$toLong: '$Doctoranaesthesia_duration(min)'}").as("Doctoranaesthesia_duration(min)")
|
||||
// .andExpression("{$toDate: '$Time'}").as("time");
|
||||
// operations.add(timeToDateOperation);
|
||||
//
|
||||
// ProjectionOperation timeFormatOperation = Aggregation.project()
|
||||
// .andInclude("Aianaesthesia_duration(min)")
|
||||
// .andInclude("Doctoranaesthesia_duration(min)")
|
||||
// .andExpression("{ $dateToString: { format: '%Y-%m-%d', date: '$time' } }").as("time");
|
||||
// operations.add(timeFormatOperation);
|
||||
//
|
||||
// operations.add(Aggregation.group("$time")
|
||||
// .sum("Aianaesthesia_duration(min)").as("aicount")
|
||||
// .sum("Doctoranaesthesia_duration(min)").as("doccount"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("_id")
|
||||
// .andExpression("aicount").divide(60).as("aicount")
|
||||
// .andExpression("doccount").divide(60).as("doccount"));
|
||||
//
|
||||
// operations.add(Aggregation.project()
|
||||
// .andInclude("_id")
|
||||
// .andExpression("{$round: {'$aicount', 1}}").as("aicount")
|
||||
// .andExpression("{$round: {'$doccount', 1}}").as("doccount"));
|
||||
//
|
||||
// operations.add(Aggregation.sort(Sort.Direction.ASC, "_id"));
|
||||
//
|
||||
// TypedAggregation typedAggregation = new TypedAggregation(Map.class, operations);
|
||||
// AggregationResults<Map> aggregate = mongoTemplate.aggregate(typedAggregation, "surgery_info", Map.class);
|
||||
// List<Map> mappedResults = aggregate.getMappedResults();
|
||||
// return mappedResults;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List getPatientSurgeryList(String name, String code, String surgery, String type) {
|
||||
// if (StringUtils.hasText(code)) {
|
||||
//
|
||||
// if (!StringUtils.hasText(name)) {
|
||||
// Query query = new Query();
|
||||
// Criteria criteria = new Criteria("住院号");
|
||||
// criteria.regex(new BsonRegularExpression(code));
|
||||
// query.addCriteria(criteria);
|
||||
Query query = new Query(
|
||||
Criteria.where("住院号").is(code)
|
||||
);
|
||||
List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
if (!list.isEmpty()) {
|
||||
Map patient = list.get(0);
|
||||
name = (String) patient.get("姓名");
|
||||
}
|
||||
}
|
||||
String database = DatabaseNameUtil.encrypt(name) + "_" + DatabaseNameUtil.encrypt(code) + "_" + date;
|
||||
MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, database);
|
||||
mongoDBSource.open();
|
||||
MongoTemplate template = mongoDBSource.getConnection();
|
||||
Query query = new Query();
|
||||
query.with(Sort.by(Sort.Order.asc("_id")));
|
||||
List<Map> list = template.find(query, Map.class, table);
|
||||
System.out.println("list = " + list);
|
||||
mongoDBSource.close();
|
||||
return list;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
// List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
// if (!list.isEmpty()) {
|
||||
// Map patient = list.get(0);
|
||||
// name = (String) patient.get("姓名");
|
||||
// } else {
|
||||
// return List.of();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Query query = new Query();
|
||||
// String databasePrefix = DatabaseNameUtil.encrypt(name) + "_" + DatabaseNameUtil.encrypt(code) + "_";
|
||||
// Criteria criteria = new Criteria("Databasename");
|
||||
// criteria.regex(new BsonRegularExpression("^" + databasePrefix));
|
||||
// query.addCriteria(criteria);
|
||||
//
|
||||
// if (StringUtils.hasText(surgery)) {
|
||||
// Criteria surgeryCriteria = new Criteria("Surgery_name");
|
||||
// surgeryCriteria.regex(new BsonRegularExpression(surgery));
|
||||
// query.addCriteria(surgeryCriteria);
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.hasText(type)) {
|
||||
// Criteria anesthesiaCriteria = new Criteria("Anesthesia_way");
|
||||
// anesthesiaCriteria.regex(new BsonRegularExpression(type));
|
||||
// query.addCriteria(anesthesiaCriteria);
|
||||
// }
|
||||
//
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> surgeryInfoList = mongoTemplate.find(query, Map.class, "surgery_info");
|
||||
// return surgeryInfoList;
|
||||
// } else {
|
||||
// return List.of();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public List getSurgeryTableData(String name, String code, String date, String table) {
|
||||
// if (StringUtils.hasText(code)) {
|
||||
// if (!StringUtils.hasText(name)) {
|
||||
//// Query query = new Query();
|
||||
//// Criteria criteria = new Criteria("住院号");
|
||||
//// criteria.regex(new BsonRegularExpression(code));
|
||||
//// query.addCriteria(criteria);
|
||||
// Query query = new Query(
|
||||
// Criteria.where("住院号").is(code)
|
||||
// );
|
||||
// List<Map> list = mongoTemplate.find(query, Map.class, "patient_info");
|
||||
// if (!list.isEmpty()) {
|
||||
// Map patient = list.get(0);
|
||||
// name = (String) patient.get("姓名");
|
||||
// }
|
||||
// }
|
||||
// String database = DatabaseNameUtil.encrypt(name) + "_" + DatabaseNameUtil.encrypt(code) + "_" + date;
|
||||
// MongoDBSource mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, database);
|
||||
// mongoDBSource.open();
|
||||
// MongoTemplate template = mongoDBSource.getConnection();
|
||||
// Query query = new Query();
|
||||
// query.with(Sort.by(Sort.Order.asc("_id")));
|
||||
// List<Map> list = template.find(query, Map.class, table);
|
||||
// System.out.println("list = " + list);
|
||||
// mongoDBSource.close();
|
||||
// return list;
|
||||
// } else {
|
||||
// return new ArrayList<>();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.rax.vital.v2.medicine.service.RevulsionService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 诱导期给药数据
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class RevulsionServiceImpl implements RevulsionService {
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> getRevulsionServiceList(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> revulsionTable = template.find(query, Map.class, "revulsiontable");
|
||||
return revulsionTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getRevulsionServiceList(Connection connection) {
|
||||
List<Map> medicineList = new ArrayList<>();
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `revulsiontable` ORDER BY time DESC LIMIT 1;");
|
||||
while (resultSet.next()) {
|
||||
Map medicine = new HashMap();
|
||||
medicine.put("id", resultSet.getString("id"));
|
||||
medicine.put("phase", resultSet.getString("phase"));
|
||||
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
medicine.put("Time", resultSet.getString("time"));
|
||||
medicineList.add(medicine);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return medicineList;
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.rax.vital.v2.medicine.service.RevulsionService;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.sql.Statement;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 诱导期给药数据
|
||||
// */
|
||||
//
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//@AllArgsConstructor
|
||||
//public class RevulsionServiceImpl implements RevulsionService {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getRevulsionServiceList(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> revulsionTable = template.find(query, Map.class, "revulsiontable");
|
||||
// return revulsionTable;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getRevulsionServiceList(Connection connection) {
|
||||
// List<Map> medicineList = new ArrayList<>();
|
||||
// try {
|
||||
// Statement statement = connection.createStatement();
|
||||
// ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `revulsiontable` ORDER BY time DESC LIMIT 1;");
|
||||
// while (resultSet.next()) {
|
||||
// Map medicine = new HashMap();
|
||||
// medicine.put("id", resultSet.getString("id"));
|
||||
// medicine.put("phase", resultSet.getString("phase"));
|
||||
// medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||
// medicine.put("舒芬太尼", resultSet.getString("舒芬太尼"));
|
||||
// medicine.put("瑞芬太尼", resultSet.getString("瑞芬太尼"));
|
||||
// medicine.put("顺阿曲库胺", resultSet.getString("顺阿曲库胺"));
|
||||
// medicine.put("尼卡地平", resultSet.getString("尼卡地平"));
|
||||
// medicine.put("艾司洛尔", resultSet.getString("艾司洛尔"));
|
||||
// medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||
// medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||
// medicine.put("Time", resultSet.getString("time"));
|
||||
// medicineList.add(medicine);
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// return medicineList;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
package com.rax.vital.v2.medicine.service.impl;
|
||||
|
||||
import com.rax.vital.v2.medicine.service.SurgeryServiceV2;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* project_name:remote-control-backend
|
||||
* time:2024/8/23 16:23
|
||||
* author:republicline
|
||||
* 术中信息服务实现 V2, 针对mongoDB数据库
|
||||
*/
|
||||
@Component
|
||||
public class SurgeryServiceV2Impl implements SurgeryServiceV2 {
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> getVitalSignsList(MongoTemplate template) {
|
||||
Query query = new Query();
|
||||
query.limit(1);
|
||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
List<Map> vitalList = template.find(query, Map.class, "featuretable");
|
||||
|
||||
if (vitalList != null && vitalList.size() > 0) {
|
||||
Map map = vitalList.get(0);
|
||||
Double bis = Double.valueOf((String) map.get("BIS"));
|
||||
map.put("BIS_except", bis <= 40 || bis >= 60);
|
||||
Double hr = Double.valueOf((String) map.get("HR"));
|
||||
map.put("HR_except", hr <= 50 || hr >= 80);
|
||||
Double sbp = Double.valueOf((String) map.get("SBP"));
|
||||
map.put("SBP_except", sbp <= 90 || sbp >= 120);
|
||||
Double dbp = Double.valueOf((String) map.get("DBP"));
|
||||
map.put("DBP_except", dbp <= 60 || dbp >= 90);
|
||||
Double st = Double.valueOf((String) map.get("ST"));
|
||||
map.put("ST_except", st <= -0.2 || st >= 0.2);
|
||||
Double etCO2 = Double.valueOf((String) map.get("EtCO2"));
|
||||
map.put("EtCO2_except", etCO2 <= 30 || etCO2 >= 45);
|
||||
}
|
||||
return vitalList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.rax.vital.v2.medicine.service.impl;
|
||||
//
|
||||
//import com.rax.vital.v2.medicine.service.SurgeryServiceV2;
|
||||
//import org.springframework.data.domain.Sort;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * project_name:remote-control-backend
|
||||
// * time:2024/8/23 16:23
|
||||
// * author:republicline
|
||||
// * 术中信息服务实现 V2, 针对mongoDB数据库
|
||||
// */
|
||||
//@Component
|
||||
//public class SurgeryServiceV2Impl implements SurgeryServiceV2 {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public List<Map> getVitalSignsList(MongoTemplate template) {
|
||||
// Query query = new Query();
|
||||
// query.limit(1);
|
||||
// query.with(Sort.by(Sort.Order.desc("Time")));
|
||||
// List<Map> vitalList = template.find(query, Map.class, "featuretable");
|
||||
//
|
||||
// if (vitalList != null && vitalList.size() > 0) {
|
||||
// Map map = vitalList.get(0);
|
||||
// Double bis = Double.valueOf((String) map.get("BIS"));
|
||||
// map.put("BIS_except", bis <= 40 || bis >= 60);
|
||||
// Double hr = Double.valueOf((String) map.get("HR"));
|
||||
// map.put("HR_except", hr <= 50 || hr >= 80);
|
||||
// Double sbp = Double.valueOf((String) map.get("SBP"));
|
||||
// map.put("SBP_except", sbp <= 90 || sbp >= 120);
|
||||
// Double dbp = Double.valueOf((String) map.get("DBP"));
|
||||
// map.put("DBP_except", dbp <= 60 || dbp >= 90);
|
||||
// Double st = Double.valueOf((String) map.get("ST"));
|
||||
// map.put("ST_except", st <= -0.2 || st >= 0.2);
|
||||
// Double etCO2 = Double.valueOf((String) map.get("EtCO2"));
|
||||
// map.put("EtCO2_except", etCO2 <= 30 || etCO2 >= 45);
|
||||
// }
|
||||
// return vitalList;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,225 +1,225 @@
|
|||
package com.rax.vital.v2.timer;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* project_name:remote-control-backend
|
||||
* time:2024/8/14 15:09
|
||||
* author:republicline
|
||||
* 联调给药2.0 网页端和unity端互相确认连接状态
|
||||
*/
|
||||
@RefreshScope
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AIMedicineTimer {
|
||||
|
||||
// 存放sessionId与dbName的映射关系
|
||||
private static final Map<String, WebSocketSession> webDbSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 存放sessionId的状态
|
||||
private static final Map<WebSocketSession, Boolean> webStatusMap = new ConcurrentHashMap<>();
|
||||
|
||||
// unity 端的dbname 和 sessionId 映射
|
||||
private static final Map<String, WebSocketSession> u3DDbSessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// unity端的session状态映射
|
||||
private static final Map<WebSocketSession, Boolean> u3DStatusMap = new ConcurrentHashMap<>();
|
||||
|
||||
// unity响应web端的信息
|
||||
public void sendConnectionResponseToWeb(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
WebSocketSession webSession = getWebSession(databaseName);
|
||||
if (webSession != null) {
|
||||
JSONObject unityMsg = new JSONObject();
|
||||
if ("1".equals(flag)) {
|
||||
// unity同意连接
|
||||
setU3DStatus(databaseName, true);
|
||||
unityMsg.put("msgType", "unityResponseConnection");
|
||||
unityMsg.put("unityConnectionFlag", "1");
|
||||
unityMsg.put("patientName", patientName);
|
||||
unityMsg.put("idNum", idNum);
|
||||
unityMsg.put("date", date);
|
||||
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
}
|
||||
if ("0".equals(flag)) {
|
||||
// unity拒绝连接
|
||||
setU3DStatus(databaseName, false);
|
||||
setWebStatus(databaseName, false);
|
||||
unityMsg = new JSONObject();
|
||||
unityMsg.put("msgType", "unityResponseConnection");
|
||||
unityMsg.put("unityConnectionFlag", "0");
|
||||
unityMsg.put("patientName", patientName);
|
||||
unityMsg.put("idNum", idNum);
|
||||
unityMsg.put("date", date);
|
||||
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
}
|
||||
} else {
|
||||
// 告知u3d网页端
|
||||
System.out.println("U3d尚未初始化,无法发送连接响应消息");
|
||||
WebSocketSession webSocketSession = u3DDbSessionMap.get(databaseName);
|
||||
webSocketSession.sendMessage(new TextMessage("网页端尚未初始化,无法发送连接响应消息".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
// unity端请求网页端连接或断开连接
|
||||
public void sendUnityRequestConnectionMsg(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
WebSocketSession webSession = getWebSession(databaseName);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (webSession != null) {
|
||||
if ("1".equals(flag)) {
|
||||
jsonObject.put("patientName",patientName);
|
||||
jsonObject.put("idNum",idNum);
|
||||
jsonObject.put("date",date);
|
||||
jsonObject.put("msgType", "unityRequestConnection");
|
||||
jsonObject.put("unityConnectionFlag", "1");
|
||||
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
setU3DStatus(databaseName, true);
|
||||
}
|
||||
if ("0".equals(flag)) {
|
||||
jsonObject.put("patientName",patientName);
|
||||
jsonObject.put("idNum",idNum);
|
||||
jsonObject.put("date",date);
|
||||
jsonObject.put("msgType", "unityRequestConnection");
|
||||
jsonObject.put("unityConnectionFlag", "0");
|
||||
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
setU3DStatus(databaseName, false);
|
||||
// 把网页端的sessionStatus置为false
|
||||
setWebStatus(databaseName, false);
|
||||
}
|
||||
}else {
|
||||
// 告知u3d,网页端尚未初始化
|
||||
WebSocketSession u3dSession = u3DDbSessionMap.get(databaseName);
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("msgType","connectionMsg");
|
||||
msg.put("msg","网页端尚未初始化,无法发送连接请求消息");
|
||||
u3dSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WebSocketSession getUnitySession(String databaseName) {
|
||||
return u3DDbSessionMap.getOrDefault(databaseName, null);
|
||||
}
|
||||
|
||||
public void setU3DStatus(String dbName, boolean status) {
|
||||
WebSocketSession webSocketSession = u3DDbSessionMap.get(dbName);
|
||||
u3DStatusMap.put(webSocketSession, status);
|
||||
}
|
||||
|
||||
public boolean getUnityConnectionStatus(String dbName) {
|
||||
return u3DStatusMap.getOrDefault(u3DDbSessionMap.get(dbName),false);
|
||||
}
|
||||
|
||||
// web端请求unity端连接或断开连接
|
||||
public void sendWebRequestConnectionMsg(String patientName,String idNum, String date,String databaseName, String flag) throws IOException {
|
||||
WebSocketSession unitySession = getUnitySession(databaseName);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (unitySession != null) {
|
||||
if ("1".equals(flag)) {
|
||||
jsonObject.put("patientName",patientName);
|
||||
jsonObject.put("idNum",idNum);
|
||||
jsonObject.put("date",date);
|
||||
jsonObject.put("msgType", "webRequestConnection");
|
||||
jsonObject.put("webConnectionFlag", "1");
|
||||
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
setWebStatus(databaseName,true);
|
||||
}
|
||||
if ("0".equals(flag)) {
|
||||
jsonObject.put("patientName",patientName);
|
||||
jsonObject.put("idNum",idNum);
|
||||
jsonObject.put("date",date);
|
||||
jsonObject.put("msgType", "webRequestConnection");
|
||||
jsonObject.put("webConnectionFlag", "0");
|
||||
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
setU3DStatus(databaseName, false);
|
||||
setWebStatus(databaseName, false);
|
||||
}
|
||||
}else {
|
||||
// 告知网页端U3d尚未初始化
|
||||
WebSocketSession webSocketSession = webDbSessionMap.get(databaseName);
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("msgType","connectionMsg");
|
||||
msg.put("msg","客户端尚未初始化,无法发送连接请求消息");
|
||||
webSocketSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendConnectionResponseToUnity(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
WebSocketSession unitySession = getUnitySession(databaseName);
|
||||
if (unitySession != null) {
|
||||
JSONObject unityMsg = new JSONObject();
|
||||
if ("1".equals(flag)) {
|
||||
unityMsg.put("msgType", "webResponseConnection");
|
||||
unityMsg.put("webConnectionFlag", "1");
|
||||
unityMsg.put("patientName", patientName);
|
||||
unityMsg.put("idNum", idNum);
|
||||
unityMsg.put("date", date);
|
||||
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// 网页端同意连接
|
||||
setWebStatus(databaseName, true);
|
||||
|
||||
}
|
||||
if ("0".equals(flag)) {
|
||||
// 网页端拒绝连接
|
||||
setWebStatus(databaseName, false);
|
||||
unityMsg = new JSONObject();
|
||||
unityMsg.put("msgType", "webResponseConnection");
|
||||
unityMsg.put("webConnectionFlag", "0");
|
||||
unityMsg.put("patientName", patientName);
|
||||
unityMsg.put("idNum", idNum);
|
||||
unityMsg.put("date", date);
|
||||
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// 把unity的sessionStatus置为false
|
||||
setU3DStatus(databaseName, false);
|
||||
}
|
||||
} else {
|
||||
// 告知网页端U3d尚未初始化
|
||||
WebSocketSession webSocketSession = webDbSessionMap.get(databaseName);
|
||||
webSocketSession.sendMessage(new TextMessage("U3d尚未初始化,无法发送连接响应消息".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setWebStatus(String dbName, Boolean status) {
|
||||
WebSocketSession webSocketSession = webDbSessionMap.get(dbName);
|
||||
webStatusMap.put(webSocketSession, status);
|
||||
}
|
||||
|
||||
public boolean getWebConnectionStatus(String dbName) {
|
||||
return webStatusMap.getOrDefault(webDbSessionMap.get(dbName),false);
|
||||
}
|
||||
|
||||
public WebSocketSession getWebSession(String databaseName) {
|
||||
return webDbSessionMap.getOrDefault(databaseName, null);
|
||||
}
|
||||
|
||||
public void initWeb(String databaseName, WebSocketSession session) {
|
||||
webDbSessionMap.put(databaseName, session);
|
||||
webStatusMap.put(session, false);
|
||||
}
|
||||
|
||||
public void initUnity(String databaseName, WebSocketSession session) {
|
||||
u3DDbSessionMap.put(databaseName, session);
|
||||
u3DStatusMap.put(session, false);
|
||||
}
|
||||
|
||||
public boolean isReady(String databaseName) {
|
||||
return getUnityConnectionStatus(databaseName) && getWebConnectionStatus(databaseName);
|
||||
}
|
||||
|
||||
public void closeConnection(WebSocketSession session) {
|
||||
webDbSessionMap.values().remove(session);
|
||||
webStatusMap.remove(session);
|
||||
u3DDbSessionMap.values().remove(session);
|
||||
u3DStatusMap.remove(session);
|
||||
}
|
||||
}
|
||||
//package com.rax.vital.v2.timer;
|
||||
//
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.TextMessage;
|
||||
//import org.springframework.web.socket.WebSocketSession;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
///**
|
||||
// * project_name:remote-control-backend
|
||||
// * time:2024/8/14 15:09
|
||||
// * author:republicline
|
||||
// * 联调给药2.0 网页端和unity端互相确认连接状态
|
||||
// */
|
||||
//@RefreshScope
|
||||
//@Component
|
||||
//@RequiredArgsConstructor
|
||||
//public class AIMedicineTimer {
|
||||
//
|
||||
// // 存放sessionId与dbName的映射关系
|
||||
// private static final Map<String, WebSocketSession> webDbSessionMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // 存放sessionId的状态
|
||||
// private static final Map<WebSocketSession, Boolean> webStatusMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // unity 端的dbname 和 sessionId 映射
|
||||
// private static final Map<String, WebSocketSession> u3DDbSessionMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // unity端的session状态映射
|
||||
// private static final Map<WebSocketSession, Boolean> u3DStatusMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // unity响应web端的信息
|
||||
// public void sendConnectionResponseToWeb(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
// WebSocketSession webSession = getWebSession(databaseName);
|
||||
// if (webSession != null) {
|
||||
// JSONObject unityMsg = new JSONObject();
|
||||
// if ("1".equals(flag)) {
|
||||
// // unity同意连接
|
||||
// setU3DStatus(databaseName, true);
|
||||
// unityMsg.put("msgType", "unityResponseConnection");
|
||||
// unityMsg.put("unityConnectionFlag", "1");
|
||||
// unityMsg.put("patientName", patientName);
|
||||
// unityMsg.put("idNum", idNum);
|
||||
// unityMsg.put("date", date);
|
||||
// webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// }
|
||||
// if ("0".equals(flag)) {
|
||||
// // unity拒绝连接
|
||||
// setU3DStatus(databaseName, false);
|
||||
// setWebStatus(databaseName, false);
|
||||
// unityMsg = new JSONObject();
|
||||
// unityMsg.put("msgType", "unityResponseConnection");
|
||||
// unityMsg.put("unityConnectionFlag", "0");
|
||||
// unityMsg.put("patientName", patientName);
|
||||
// unityMsg.put("idNum", idNum);
|
||||
// unityMsg.put("date", date);
|
||||
// webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// }
|
||||
// } else {
|
||||
// // 告知u3d网页端
|
||||
// System.out.println("U3d尚未初始化,无法发送连接响应消息");
|
||||
// WebSocketSession webSocketSession = u3DDbSessionMap.get(databaseName);
|
||||
// webSocketSession.sendMessage(new TextMessage("网页端尚未初始化,无法发送连接响应消息".getBytes()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // unity端请求网页端连接或断开连接
|
||||
// public void sendUnityRequestConnectionMsg(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
// WebSocketSession webSession = getWebSession(databaseName);
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// if (webSession != null) {
|
||||
// if ("1".equals(flag)) {
|
||||
// jsonObject.put("patientName",patientName);
|
||||
// jsonObject.put("idNum",idNum);
|
||||
// jsonObject.put("date",date);
|
||||
// jsonObject.put("msgType", "unityRequestConnection");
|
||||
// jsonObject.put("unityConnectionFlag", "1");
|
||||
// webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// setU3DStatus(databaseName, true);
|
||||
// }
|
||||
// if ("0".equals(flag)) {
|
||||
// jsonObject.put("patientName",patientName);
|
||||
// jsonObject.put("idNum",idNum);
|
||||
// jsonObject.put("date",date);
|
||||
// jsonObject.put("msgType", "unityRequestConnection");
|
||||
// jsonObject.put("unityConnectionFlag", "0");
|
||||
// webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// setU3DStatus(databaseName, false);
|
||||
// // 把网页端的sessionStatus置为false
|
||||
// setWebStatus(databaseName, false);
|
||||
// }
|
||||
// }else {
|
||||
// // 告知u3d,网页端尚未初始化
|
||||
// WebSocketSession u3dSession = u3DDbSessionMap.get(databaseName);
|
||||
// JSONObject msg = new JSONObject();
|
||||
// msg.put("msgType","connectionMsg");
|
||||
// msg.put("msg","网页端尚未初始化,无法发送连接请求消息");
|
||||
// u3dSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public WebSocketSession getUnitySession(String databaseName) {
|
||||
// return u3DDbSessionMap.getOrDefault(databaseName, null);
|
||||
// }
|
||||
//
|
||||
// public void setU3DStatus(String dbName, boolean status) {
|
||||
// WebSocketSession webSocketSession = u3DDbSessionMap.get(dbName);
|
||||
// u3DStatusMap.put(webSocketSession, status);
|
||||
// }
|
||||
//
|
||||
// public boolean getUnityConnectionStatus(String dbName) {
|
||||
// return u3DStatusMap.getOrDefault(u3DDbSessionMap.get(dbName),false);
|
||||
// }
|
||||
//
|
||||
// // web端请求unity端连接或断开连接
|
||||
// public void sendWebRequestConnectionMsg(String patientName,String idNum, String date,String databaseName, String flag) throws IOException {
|
||||
// WebSocketSession unitySession = getUnitySession(databaseName);
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// if (unitySession != null) {
|
||||
// if ("1".equals(flag)) {
|
||||
// jsonObject.put("patientName",patientName);
|
||||
// jsonObject.put("idNum",idNum);
|
||||
// jsonObject.put("date",date);
|
||||
// jsonObject.put("msgType", "webRequestConnection");
|
||||
// jsonObject.put("webConnectionFlag", "1");
|
||||
// unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// setWebStatus(databaseName,true);
|
||||
// }
|
||||
// if ("0".equals(flag)) {
|
||||
// jsonObject.put("patientName",patientName);
|
||||
// jsonObject.put("idNum",idNum);
|
||||
// jsonObject.put("date",date);
|
||||
// jsonObject.put("msgType", "webRequestConnection");
|
||||
// jsonObject.put("webConnectionFlag", "0");
|
||||
// unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||
// setU3DStatus(databaseName, false);
|
||||
// setWebStatus(databaseName, false);
|
||||
// }
|
||||
// }else {
|
||||
// // 告知网页端U3d尚未初始化
|
||||
// WebSocketSession webSocketSession = webDbSessionMap.get(databaseName);
|
||||
// JSONObject msg = new JSONObject();
|
||||
// msg.put("msgType","connectionMsg");
|
||||
// msg.put("msg","客户端尚未初始化,无法发送连接请求消息");
|
||||
// webSocketSession.sendMessage(new TextMessage(msg.toJSONString().getBytes()));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void sendConnectionResponseToUnity(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||
// WebSocketSession unitySession = getUnitySession(databaseName);
|
||||
// if (unitySession != null) {
|
||||
// JSONObject unityMsg = new JSONObject();
|
||||
// if ("1".equals(flag)) {
|
||||
// unityMsg.put("msgType", "webResponseConnection");
|
||||
// unityMsg.put("webConnectionFlag", "1");
|
||||
// unityMsg.put("patientName", patientName);
|
||||
// unityMsg.put("idNum", idNum);
|
||||
// unityMsg.put("date", date);
|
||||
// unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// // 网页端同意连接
|
||||
// setWebStatus(databaseName, true);
|
||||
//
|
||||
// }
|
||||
// if ("0".equals(flag)) {
|
||||
// // 网页端拒绝连接
|
||||
// setWebStatus(databaseName, false);
|
||||
// unityMsg = new JSONObject();
|
||||
// unityMsg.put("msgType", "webResponseConnection");
|
||||
// unityMsg.put("webConnectionFlag", "0");
|
||||
// unityMsg.put("patientName", patientName);
|
||||
// unityMsg.put("idNum", idNum);
|
||||
// unityMsg.put("date", date);
|
||||
// unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||
// // 把unity的sessionStatus置为false
|
||||
// setU3DStatus(databaseName, false);
|
||||
// }
|
||||
// } else {
|
||||
// // 告知网页端U3d尚未初始化
|
||||
// WebSocketSession webSocketSession = webDbSessionMap.get(databaseName);
|
||||
// webSocketSession.sendMessage(new TextMessage("U3d尚未初始化,无法发送连接响应消息".getBytes()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void setWebStatus(String dbName, Boolean status) {
|
||||
// WebSocketSession webSocketSession = webDbSessionMap.get(dbName);
|
||||
// webStatusMap.put(webSocketSession, status);
|
||||
// }
|
||||
//
|
||||
// public boolean getWebConnectionStatus(String dbName) {
|
||||
// return webStatusMap.getOrDefault(webDbSessionMap.get(dbName),false);
|
||||
// }
|
||||
//
|
||||
// public WebSocketSession getWebSession(String databaseName) {
|
||||
// return webDbSessionMap.getOrDefault(databaseName, null);
|
||||
// }
|
||||
//
|
||||
// public void initWeb(String databaseName, WebSocketSession session) {
|
||||
// webDbSessionMap.put(databaseName, session);
|
||||
// webStatusMap.put(session, false);
|
||||
// }
|
||||
//
|
||||
// public void initUnity(String databaseName, WebSocketSession session) {
|
||||
// u3DDbSessionMap.put(databaseName, session);
|
||||
// u3DStatusMap.put(session, false);
|
||||
// }
|
||||
//
|
||||
// public boolean isReady(String databaseName) {
|
||||
// return getUnityConnectionStatus(databaseName) && getWebConnectionStatus(databaseName);
|
||||
// }
|
||||
//
|
||||
// public void closeConnection(WebSocketSession session) {
|
||||
// webDbSessionMap.values().remove(session);
|
||||
// webStatusMap.remove(session);
|
||||
// u3DDbSessionMap.values().remove(session);
|
||||
// u3DStatusMap.remove(session);
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,202 +1,202 @@
|
|||
package com.rax.vital.v2.timer;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rax.vital.common.datasource.CustomDataSource;
|
||||
import com.rax.vital.common.datasource.MongoDBSource;
|
||||
import com.rax.vital.v2.medicine.dto.MedicineDTO;
|
||||
import com.rax.vital.v2.medicine.service.AIMedicineService;
|
||||
import com.rax.vital.v2.medicine.service.DoctorMedicineService;
|
||||
import com.rax.vital.v2.medicine.service.FlagService;
|
||||
import com.rax.vital.v2.medicine.service.SurgeryServiceV2;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* project_name: remote-control-backend
|
||||
* time: 2024/8/20 15:09
|
||||
* author: republicline
|
||||
* 新的计时器任务, 用于推送生命体征数据和药物信息数据到前端
|
||||
*/
|
||||
@RefreshScope
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class VitalSignTimerV2 {
|
||||
// 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;
|
||||
|
||||
private final SurgeryServiceV2 surgeryServiceV2;
|
||||
|
||||
private final AIMedicineService aiMedicineService;
|
||||
|
||||
private final AIMedicineTimer aiMedicineTimer;
|
||||
|
||||
private final DoctorMedicineService doctorMedicineService;
|
||||
|
||||
private final FlagService flagService;
|
||||
|
||||
// 定时任务容器
|
||||
private static final Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 主控人员容器, 建立连接放入存值,生命体征信息 key:数据库名 value:网页解析的token用户名
|
||||
private static final Map<String, String> masterControlMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 链接工具类容器 ket, 主要用于关闭数据库连接
|
||||
private static final Map<String, CustomDataSource> dataSourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
// 推送生命体征数据和药物信息数据
|
||||
public void sendMedicalMessage(String database, String username, WebSocketSession session) {
|
||||
if (!masterControlMap.containsKey(database)) {
|
||||
masterControlMap.put(database, username);
|
||||
}
|
||||
String sessionId = session.getId();
|
||||
|
||||
TimerTask task = timerTaskMap.get(sessionId);
|
||||
if (task != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomDataSource dataSource = dataSourceMap.get(sessionId);
|
||||
if (dataSource == null) {
|
||||
dataSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, database);
|
||||
dataSourceMap.put(sessionId, dataSource);
|
||||
dataSource.open();
|
||||
}
|
||||
CustomDataSource finalMongoDBSource = dataSource;
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
MongoTemplate template = finalMongoDBSource.getConnection();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
// 生命体征信息
|
||||
List vitalSignsList = surgeryServiceV2.getVitalSignsList(template);
|
||||
jsonObject.put("vitalSignsList", vitalSignsList);
|
||||
|
||||
// 标记信息
|
||||
Map flags = flagService.getFlags(template);
|
||||
|
||||
/**
|
||||
* flag
|
||||
* aiFlag 1代表AI给药 0代表医生给药
|
||||
* reFlag 1代表维持期 0代表诱导期
|
||||
* endFlag 1代表手术进行 0代表手术结束
|
||||
* linkFlag 1泵异常 0正常
|
||||
*/
|
||||
jsonObject.put("flags", flags);
|
||||
Map<String, Object> medicineRateMap = new HashMap<>();
|
||||
if (flags.get("aiFlag") != null && flags.get("aiFlag").equals("1")) {
|
||||
// ai给药信息
|
||||
medicineRateMap = aiMedicineService.getAiMedicine(template);
|
||||
} else if (flags.get("aiFlag") != null && flags.get("aiFlag").equals("0")) {
|
||||
// 医生给药信息
|
||||
medicineRateMap = doctorMedicineService.getDocMedicine(template);
|
||||
}
|
||||
|
||||
ArrayList<MedicineDTO> medicineList = new ArrayList<>(8);
|
||||
medicineList.add(new MedicineDTO("1", "丙泊酚", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("2", "舒芬太尼", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("3", "瑞芬太尼", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("4", "顺阿曲库胺", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("5", "尼卡地平", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("6", "艾司洛尔", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("7", "麻黄素", "0", "0"));
|
||||
medicineList.add(new MedicineDTO("8", "阿托品", "0", "0"));
|
||||
|
||||
if (medicineRateMap != null && !medicineRateMap.isEmpty()) {
|
||||
for (String key : medicineRateMap.keySet()) {
|
||||
for (MedicineDTO medicineDTO : medicineList) {
|
||||
if (medicineDTO.getMedicineName().equals(key)) {
|
||||
medicineDTO.setMedicineRate(medicineRateMap.get(key).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
jsonObject.put("rateModTime", medicineRateMap.get("Time"));
|
||||
} else {
|
||||
jsonObject.put("rateModTime", "0");
|
||||
}
|
||||
// 总的药量信息
|
||||
Map<String, Object> countMedicineMap = aiMedicineService.getCountMedicine(template);
|
||||
if (countMedicineMap != null && !countMedicineMap.isEmpty()) {
|
||||
for (String key : countMedicineMap.keySet()) {
|
||||
for (MedicineDTO medicineDTO : medicineList) {
|
||||
if ((medicineDTO.getMedicineName() + "Sum").equals(key)) {
|
||||
medicineDTO.setMedicineRate(countMedicineMap.get(key).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsonObject.put("medicineList", medicineList);
|
||||
jsonObject.put("msgType", "msg");
|
||||
// 如果是人工给药展示人工给药的内容
|
||||
WebSocketMessage message = new TextMessage(jsonObject.toJSONString().getBytes());
|
||||
|
||||
try {
|
||||
session.sendMessage(message);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 定时任务,设置1秒
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(timerTask, 0, 2000);
|
||||
timerTaskMap.put(sessionId, timerTask);
|
||||
}
|
||||
|
||||
|
||||
// 发送给药数据到unity
|
||||
public void sendMedicalMessageToUnity(String database, String username, WebSocketSession session, String flag, String medicine, String value) throws IOException {
|
||||
JSONObject result = new JSONObject();
|
||||
if (masterControlMap.containsKey(database) && masterControlMap.get(database).equals(username)) {
|
||||
// 给药到unity
|
||||
WebSocketSession unitySession = aiMedicineTimer.getUnitySession(database);
|
||||
result.put("medicine", medicine);
|
||||
result.put("value", value);
|
||||
result.put("flag", flag);
|
||||
result.put("msgType", "addMedicine");
|
||||
unitySession.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||
} else {
|
||||
result.put("flag", flag);
|
||||
result.put("medicine", medicine);
|
||||
result.put("status", 1);
|
||||
result.put("msg", "不是主控人员");
|
||||
result.put("msgType", "msg");
|
||||
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
// 指定停止定时任务
|
||||
public void stopTimerTask(String sessionId) {
|
||||
TimerTask timerTask = timerTaskMap.get(sessionId);
|
||||
if (timerTask != null) {
|
||||
timerTask.cancel();
|
||||
CustomDataSource dataSource = dataSourceMap.get(sessionId);
|
||||
dataSource.close();
|
||||
timerTaskMap.remove(sessionId);
|
||||
dataSourceMap.remove(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//package com.rax.vital.v2.timer;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rax.vital.common.datasource.CustomDataSource;
|
||||
//import com.rax.vital.common.datasource.MongoDBSource;
|
||||
//import com.rax.vital.v2.medicine.dto.MedicineDTO;
|
||||
//import com.rax.vital.v2.medicine.service.AIMedicineService;
|
||||
//import com.rax.vital.v2.medicine.service.DoctorMedicineService;
|
||||
//import com.rax.vital.v2.medicine.service.FlagService;
|
||||
//import com.rax.vital.v2.medicine.service.SurgeryServiceV2;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.TextMessage;
|
||||
//import org.springframework.web.socket.WebSocketMessage;
|
||||
//import org.springframework.web.socket.WebSocketSession;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.*;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
///**
|
||||
// * project_name: remote-control-backend
|
||||
// * time: 2024/8/20 15:09
|
||||
// * author: republicline
|
||||
// * 新的计时器任务, 用于推送生命体征数据和药物信息数据到前端
|
||||
// */
|
||||
//@RefreshScope
|
||||
//@Component
|
||||
//@RequiredArgsConstructor
|
||||
//public class VitalSignTimerV2 {
|
||||
// // 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;
|
||||
//
|
||||
// private final SurgeryServiceV2 surgeryServiceV2;
|
||||
//
|
||||
// private final AIMedicineService aiMedicineService;
|
||||
//
|
||||
// private final AIMedicineTimer aiMedicineTimer;
|
||||
//
|
||||
// private final DoctorMedicineService doctorMedicineService;
|
||||
//
|
||||
// private final FlagService flagService;
|
||||
//
|
||||
// // 定时任务容器
|
||||
// private static final Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // 主控人员容器, 建立连接放入存值,生命体征信息 key:数据库名 value:网页解析的token用户名
|
||||
// private static final Map<String, String> masterControlMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // 链接工具类容器 ket, 主要用于关闭数据库连接
|
||||
// private static final Map<String, CustomDataSource> dataSourceMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
//
|
||||
// // 推送生命体征数据和药物信息数据
|
||||
// public void sendMedicalMessage(String database, String username, WebSocketSession session) {
|
||||
// if (!masterControlMap.containsKey(database)) {
|
||||
// masterControlMap.put(database, username);
|
||||
// }
|
||||
// String sessionId = session.getId();
|
||||
//
|
||||
// TimerTask task = timerTaskMap.get(sessionId);
|
||||
// if (task != null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// CustomDataSource dataSource = dataSourceMap.get(sessionId);
|
||||
// if (dataSource == null) {
|
||||
// dataSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, database);
|
||||
// dataSourceMap.put(sessionId, dataSource);
|
||||
// dataSource.open();
|
||||
// }
|
||||
// CustomDataSource finalMongoDBSource = dataSource;
|
||||
// TimerTask timerTask = new TimerTask() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// MongoTemplate template = finalMongoDBSource.getConnection();
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// // 生命体征信息
|
||||
// List vitalSignsList = surgeryServiceV2.getVitalSignsList(template);
|
||||
// jsonObject.put("vitalSignsList", vitalSignsList);
|
||||
//
|
||||
// // 标记信息
|
||||
// Map flags = flagService.getFlags(template);
|
||||
//
|
||||
// /**
|
||||
// * flag
|
||||
// * aiFlag 1代表AI给药 0代表医生给药
|
||||
// * reFlag 1代表维持期 0代表诱导期
|
||||
// * endFlag 1代表手术进行 0代表手术结束
|
||||
// * linkFlag 1泵异常 0正常
|
||||
// */
|
||||
// jsonObject.put("flags", flags);
|
||||
// Map<String, Object> medicineRateMap = new HashMap<>();
|
||||
// if (flags.get("aiFlag") != null && flags.get("aiFlag").equals("1")) {
|
||||
// // ai给药信息
|
||||
// medicineRateMap = aiMedicineService.getAiMedicine(template);
|
||||
// } else if (flags.get("aiFlag") != null && flags.get("aiFlag").equals("0")) {
|
||||
// // 医生给药信息
|
||||
// medicineRateMap = doctorMedicineService.getDocMedicine(template);
|
||||
// }
|
||||
//
|
||||
// ArrayList<MedicineDTO> medicineList = new ArrayList<>(8);
|
||||
// medicineList.add(new MedicineDTO("1", "丙泊酚", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("2", "舒芬太尼", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("3", "瑞芬太尼", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("4", "顺阿曲库胺", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("5", "尼卡地平", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("6", "艾司洛尔", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("7", "麻黄素", "0", "0"));
|
||||
// medicineList.add(new MedicineDTO("8", "阿托品", "0", "0"));
|
||||
//
|
||||
// if (medicineRateMap != null && !medicineRateMap.isEmpty()) {
|
||||
// for (String key : medicineRateMap.keySet()) {
|
||||
// for (MedicineDTO medicineDTO : medicineList) {
|
||||
// if (medicineDTO.getMedicineName().equals(key)) {
|
||||
// medicineDTO.setMedicineRate(medicineRateMap.get(key).toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// jsonObject.put("rateModTime", medicineRateMap.get("Time"));
|
||||
// } else {
|
||||
// jsonObject.put("rateModTime", "0");
|
||||
// }
|
||||
// // 总的药量信息
|
||||
// Map<String, Object> countMedicineMap = aiMedicineService.getCountMedicine(template);
|
||||
// if (countMedicineMap != null && !countMedicineMap.isEmpty()) {
|
||||
// for (String key : countMedicineMap.keySet()) {
|
||||
// for (MedicineDTO medicineDTO : medicineList) {
|
||||
// if ((medicineDTO.getMedicineName() + "Sum").equals(key)) {
|
||||
// medicineDTO.setMedicineRate(countMedicineMap.get(key).toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// jsonObject.put("medicineList", medicineList);
|
||||
// jsonObject.put("msgType", "msg");
|
||||
// // 如果是人工给药展示人工给药的内容
|
||||
// WebSocketMessage message = new TextMessage(jsonObject.toJSONString().getBytes());
|
||||
//
|
||||
// try {
|
||||
// session.sendMessage(message);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// // 定时任务,设置1秒
|
||||
// Timer timer = new Timer();
|
||||
// timer.schedule(timerTask, 0, 2000);
|
||||
// timerTaskMap.put(sessionId, timerTask);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 发送给药数据到unity
|
||||
// public void sendMedicalMessageToUnity(String database, String username, WebSocketSession session, String flag, String medicine, String value) throws IOException {
|
||||
// JSONObject result = new JSONObject();
|
||||
// if (masterControlMap.containsKey(database) && masterControlMap.get(database).equals(username)) {
|
||||
// // 给药到unity
|
||||
// WebSocketSession unitySession = aiMedicineTimer.getUnitySession(database);
|
||||
// result.put("medicine", medicine);
|
||||
// result.put("value", value);
|
||||
// result.put("flag", flag);
|
||||
// result.put("msgType", "addMedicine");
|
||||
// unitySession.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||
// } else {
|
||||
// result.put("flag", flag);
|
||||
// result.put("medicine", medicine);
|
||||
// result.put("status", 1);
|
||||
// result.put("msg", "不是主控人员");
|
||||
// result.put("msgType", "msg");
|
||||
// session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 指定停止定时任务
|
||||
// public void stopTimerTask(String sessionId) {
|
||||
// TimerTask timerTask = timerTaskMap.get(sessionId);
|
||||
// if (timerTask != null) {
|
||||
// timerTask.cancel();
|
||||
// CustomDataSource dataSource = dataSourceMap.get(sessionId);
|
||||
// dataSource.close();
|
||||
// timerTaskMap.remove(sessionId);
|
||||
// dataSourceMap.remove(sessionId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
server:
|
||||
port: 6679
|
||||
servlet:
|
||||
context-path: /admin
|
||||
address: 0.0.0.0
|
||||
|
||||
spring:
|
||||
# 定时任务属性配置
|
||||
quartz:
|
||||
|
@ -39,10 +45,12 @@ spring:
|
|||
username: root
|
||||
password: Xg137839
|
||||
# 一期
|
||||
# url: jdbc:mysql://localhost:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||
url: jdbc:mysql://110.41.142.124:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||
data:
|
||||
redis:
|
||||
host: 110.41.142.124
|
||||
# host: localhost
|
||||
port: 16373
|
||||
password: rax137839
|
||||
connect-timeout: 5000
|
||||
|
@ -96,13 +104,13 @@ mybatis-plus:
|
|||
|
||||
|
||||
vital-sign:
|
||||
except-database: admin,config,local
|
||||
information-database: information
|
||||
mongodb:
|
||||
host: 110.41.142.124:27017
|
||||
password: Xg137839mg
|
||||
username: useradmin
|
||||
|
||||
host: localhost
|
||||
port: 27017
|
||||
username: xxx
|
||||
password: xxx
|
||||
except-database: admin,config
|
||||
information-database: adaw
|
||||
mysql:
|
||||
host: 110.41.142.124:3306
|
||||
password: Xg137839
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
spring:
|
||||
profiles:
|
||||
active: application-loc.yml
|
||||
active: loc
|
||||
|
||||
|
||||
server:
|
||||
port: 6379
|
||||
servlet:
|
||||
context-path: /admin
|
||||
|
||||
gateway:
|
||||
# 前端密码登录解密密钥,和前端 .env 保存一致(16位)
|
||||
|
|
Loading…
Reference in New Issue
Block a user