mongo根据一期问题修改
This commit is contained in:
parent
1ff0e2a92a
commit
3dfc4c2331
|
@ -28,10 +28,7 @@ import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -80,6 +77,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建树查询 1. 不是懒加载情况,查询全部 2. 是懒加载,根据parentId 查询 2.1 父节点为空,则查询ID -1
|
* 构建树查询 1. 不是懒加载情况,查询全部 2. 是懒加载,根据parentId 查询 2.1 父节点为空,则查询ID -1
|
||||||
|
*
|
||||||
* @param parentId 父节点ID
|
* @param parentId 父节点ID
|
||||||
* @param menuName 菜单名称
|
* @param menuName 菜单名称
|
||||||
* @return
|
* @return
|
||||||
|
@ -89,13 +87,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
Long parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
|
Long parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
|
||||||
|
|
||||||
List<TreeNode<Long>> collect = baseMapper
|
List<TreeNode<Long>> collect = baseMapper
|
||||||
.selectList(Wrappers.<SysMenu>lambdaQuery()
|
.selectList(Wrappers.<SysMenu>lambdaQuery()
|
||||||
.like(StrUtil.isNotBlank(menuName), SysMenu::getName, menuName)
|
.like(StrUtil.isNotBlank(menuName), SysMenu::getName, menuName)
|
||||||
.eq(StrUtil.isNotBlank(type), SysMenu::getMenuType, type)
|
.eq(StrUtil.isNotBlank(type), SysMenu::getMenuType, type)
|
||||||
.orderByAsc(SysMenu::getSortOrder))
|
.orderByAsc(SysMenu::getSortOrder))
|
||||||
.stream()
|
.stream()
|
||||||
.map(getNodeFunction())
|
.map(getNodeFunction())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 模糊查询 不组装树结构 直接返回 表格方便编辑
|
// 模糊查询 不组装树结构 直接返回 表格方便编辑
|
||||||
if (StrUtil.isNotBlank(menuName)) {
|
if (StrUtil.isNotBlank(menuName)) {
|
||||||
|
@ -112,17 +110,22 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询菜单
|
* 查询菜单
|
||||||
* @param all 全部菜单
|
*
|
||||||
* @param type 类型
|
* @param all 全部菜单
|
||||||
|
* @param type 类型
|
||||||
* @param parentId 父节点ID
|
* @param parentId 父节点ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Tree<Long>> filterMenu(Set<SysMenu> all, String type, Long parentId) {
|
public List<Tree<Long>> filterMenu(Set<SysMenu> all, String type, Long parentId) {
|
||||||
List<TreeNode<Long>> collect = all.stream()
|
List<TreeNode<Long>> collect = all.stream()
|
||||||
.filter(menuTypePredicate(type))
|
.filter(menuTypePredicate(type))
|
||||||
.map(getNodeFunction())
|
.map(getNodeFunction())
|
||||||
.collect(Collectors.toList());
|
.sorted((p1, p2) -> {
|
||||||
|
int ageCompare = Integer.compare((Integer) p1.getExtra().get("sortOrder"), (Integer) p2.getExtra().get("sortOrder"));
|
||||||
|
return ageCompare;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Long parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
|
Long parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
|
||||||
return TreeUtil.build(collect, parent);
|
return TreeUtil.build(collect, parent);
|
||||||
|
@ -165,6 +168,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* menu 类型断言
|
* menu 类型断言
|
||||||
|
*
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @return Predicate
|
* @return Predicate
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.rax.vital.config;
|
package com.rax.vital.config;
|
||||||
|
|
||||||
import com.rax.vital.handler.mysql.AddMedicineHandler;
|
import com.rax.vital.handler.AddMedicineHandler;
|
||||||
import com.rax.vital.handler.mysql.ChatHandler;
|
import com.rax.vital.handler.ChatHandler;
|
||||||
import com.rax.vital.handler.mysql.MachineFeedbackHandler;
|
import com.rax.vital.handler.MachineFeedbackHandler;
|
||||||
import com.rax.vital.handler.mysql.MedicineHandler;
|
import com.rax.vital.handler.MedicineHandler;
|
||||||
import com.rax.vital.interceptor.WebSocketInterceptors;
|
import com.rax.vital.interceptor.WebSocketInterceptors;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -31,25 +31,21 @@ public class WebSocketConfig implements WebSocketConfigurer {
|
||||||
@Bean
|
@Bean
|
||||||
public WebSocketHandler medicineHandler() {
|
public WebSocketHandler medicineHandler() {
|
||||||
return new MedicineHandler();
|
return new MedicineHandler();
|
||||||
// return new MedicineHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebSocketHandler chatHandler() {
|
public WebSocketHandler chatHandler() {
|
||||||
return new ChatHandler();
|
return new ChatHandler();
|
||||||
// return new ChatHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebSocketHandler addMedicineHandler() {
|
public WebSocketHandler addMedicineHandler() {
|
||||||
return new AddMedicineHandler();
|
return new AddMedicineHandler();
|
||||||
// return new AddMedicineHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebSocketHandler machineHandler() {
|
public WebSocketHandler machineHandler() {
|
||||||
return new MachineFeedbackHandler();
|
return new MachineFeedbackHandler();
|
||||||
// return new MachineFeedbackHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -8,13 +8,14 @@ import jakarta.annotation.Resource;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.*;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
|
||||||
import org.springframework.web.socket.WebSocketMessage;
|
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
|
||||||
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站发送给仪器给药信息
|
* 网站发送给仪器给药信息
|
||||||
|
@ -26,9 +27,12 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
vitalSignTimerWS.setWSAIFlagSession(session);
|
vitalSignTimerWS.setWSAIFlagSession(session);
|
||||||
|
startHeartbeat(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,24 +44,27 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
String username = authorization.getPrincipalName();
|
String username = authorization.getPrincipalName();
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
// 病人名
|
|
||||||
String patientName = jsonObject.getString("patientName");
|
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||||
// 病人身份证
|
// 病人名
|
||||||
String idNum = jsonObject.getString("idNum");
|
String patientName = jsonObject.getString("patientName");
|
||||||
// yyyyMMdd
|
// 病人身份证
|
||||||
String date = jsonObject.getString("date");
|
String idNum = jsonObject.getString("idNum");
|
||||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
// yyyyMMdd
|
||||||
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
|
String date = jsonObject.getString("date");
|
||||||
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||||
|
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
|
||||||
|
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
|
stopHeartbeat(session);
|
||||||
vitalSignTimerWS.removeWSAIFlagSession(session);
|
vitalSignTimerWS.removeWSAIFlagSession(session);
|
||||||
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
||||||
}
|
}
|
||||||
|
@ -66,4 +73,32 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
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);
|
||||||
|
vitalSignTimerWS.removeWSAIFlagSession(session);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@ import jakarta.annotation.Resource;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.*;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
|
||||||
import org.springframework.web.socket.WebSocketMessage;
|
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
|
||||||
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ChatHandler implements WebSocketHandler {
|
public class ChatHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -22,8 +23,11 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
|
|
||||||
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
|
startHeartbeat(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,21 +41,25 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
|
|
||||||
String payload = (String) message.getPayload();
|
String payload = (String) message.getPayload();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
String patientName = jsonObject.getString("patientName");
|
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||||
String idNum = jsonObject.getString("idNum");
|
String patientName = jsonObject.getString("patientName");
|
||||||
String date = jsonObject.getString("date");
|
String idNum = jsonObject.getString("idNum");
|
||||||
// 消息内容
|
String date = jsonObject.getString("date");
|
||||||
String msg = jsonObject.getString("msg");
|
// 消息内容
|
||||||
chatService.sendMessage(username, patientName, idNum, date, session, msg);
|
String msg = jsonObject.getString("msg");
|
||||||
|
chatService.sendMessage(username, patientName, idNum, date, session, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
|
System.out.println("Error: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
|
stopHeartbeat(session);
|
||||||
chatService.stopTask(session.getId());
|
chatService.stopTask(session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,4 +67,32 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ import com.rax.vital.timer.VitalSignTimerWS;
|
||||||
import com.rax.vital.util.DatabaseNameUtil;
|
import com.rax.vital.util.DatabaseNameUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.*;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
|
||||||
import org.springframework.web.socket.WebSocketMessage;
|
import java.util.Map;
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仪器获取网站给药信息
|
* 仪器获取网站给药信息
|
||||||
|
@ -20,32 +23,39 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private VitalSignTimerWS vitalSignTimerWS;
|
private VitalSignTimerWS vitalSignTimerWS;
|
||||||
|
|
||||||
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
vitalSignTimerWS.setMachineSessionMap(session);
|
vitalSignTimerWS.setMachineSessionMap(session);
|
||||||
|
startHeartbeat(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
// 病人名
|
|
||||||
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");
|
|
||||||
|
|
||||||
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
if (!"heartbeat".equals(jsonObject.getString("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");
|
||||||
|
|
||||||
|
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
|
stopHeartbeat(session);
|
||||||
vitalSignTimerWS.removeMachineSessionMap(session);
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
||||||
}
|
}
|
||||||
|
@ -54,4 +64,32 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
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);
|
||||||
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,7 @@ import org.springframework.web.socket.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生命体征和标志位信息
|
* 生命体征和标志位信息
|
||||||
|
@ -29,18 +26,15 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
private ScheduledExecutorService scheduler;
|
|
||||||
private ScheduledFuture<?> heartbeatTask;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
scheduler = Executors.newScheduledThreadPool(1);
|
startHeartbeat(session);
|
||||||
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||||
String decode = URLDecoder.decode(session.getUri().getQuery());
|
String decode = URLDecoder.decode(session.getUri().getQuery());
|
||||||
Map params = GetHttpParamUtil.getParams(decode);
|
Map params = GetHttpParamUtil.getParams(decode);
|
||||||
String token = (String) params.get("token");
|
String token = (String) params.get("token");
|
||||||
|
@ -49,11 +43,14 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
String payload = (String) message.getPayload();
|
String payload = (String) message.getPayload();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
String patientName = jsonObject.getString("patientName");
|
|
||||||
String idNum = jsonObject.getString("idNum");
|
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||||
String date = jsonObject.getString("date");
|
String patientName = jsonObject.getString("patientName");
|
||||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
String idNum = jsonObject.getString("idNum");
|
||||||
vitalSignTimerWS.createAndSendWSMessageMongo(databaseName, username, session);
|
String date = jsonObject.getString("date");
|
||||||
|
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||||
|
vitalSignTimerWS.createAndSendWSMessageMongo(databaseName, username, session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,12 +61,7 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
System.out.println("MedicineHandler Connection closed:" + closeStatus.getReason());
|
System.out.println("MedicineHandler Connection closed:" + closeStatus.getReason());
|
||||||
if (heartbeatTask != null) {
|
stopHeartbeat(session);
|
||||||
heartbeatTask.cancel(true);
|
|
||||||
}
|
|
||||||
if (scheduler != null) {
|
|
||||||
scheduler.shutdown();
|
|
||||||
}
|
|
||||||
vitalSignTimerWS.stopTimerTask(session.getId());
|
vitalSignTimerWS.stopTimerTask(session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +70,31 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPing(WebSocketSession session) {
|
private void startHeartbeat(WebSocketSession session) {
|
||||||
try {
|
if (!timerTaskMap.containsKey(session.getId())) {
|
||||||
session.sendMessage(new PingMessage());
|
ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
|
||||||
} catch (IOException e) {
|
heartbeatExecutor.scheduleAtFixedRate(() -> {
|
||||||
e.printStackTrace();
|
try {
|
||||||
|
if (session.isOpen()) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("msgType", "heartbeat");
|
||||||
|
session.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||||
|
} else {
|
||||||
|
session.close();
|
||||||
|
stopHeartbeat(session);
|
||||||
|
vitalSignTimerWS.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
// private Map<String, TimerTask> timerTaskMap = new ConcurrentHashMap();
|
|
||||||
|
|
||||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,7 +46,29 @@ public class AIMedicineServiceImpl implements AIMedicineService {
|
||||||
Query query = new Query();
|
Query query = new Query();
|
||||||
query.limit(1);
|
query.limit(1);
|
||||||
query.with(Sort.by(Sort.Order.desc("Time")));
|
query.with(Sort.by(Sort.Order.desc("Time")));
|
||||||
List<Map> aiMedicines = template.find(query, Map.class, "aimedicinetable");
|
List<Map> aiMedicines = template.find(query, Map.class, "fktable");
|
||||||
|
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;
|
return aiMedicines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,8 +115,8 @@ public class VitalSignTimerWS {
|
||||||
jsonObject.put("vitalSignsList", vitalSignsList);
|
jsonObject.put("vitalSignsList", vitalSignsList);
|
||||||
List aiMedicineList = aiMedicineService.getAIMedicine(template);
|
List aiMedicineList = aiMedicineService.getAIMedicine(template);
|
||||||
jsonObject.put("aiMedicineList", aiMedicineList);
|
jsonObject.put("aiMedicineList", aiMedicineList);
|
||||||
List docMedicineList = doctorMedicineService.getDocMedicine(template);
|
// List docMedicineList = doctorMedicineService.getDocMedicine(template);
|
||||||
jsonObject.put("docMedicineList", docMedicineList);
|
// jsonObject.put("docMedicineList", docMedicineList);
|
||||||
List revulsionList = revulsionService.getRevulsionServiceList(template);
|
List revulsionList = revulsionService.getRevulsionServiceList(template);
|
||||||
jsonObject.put("revulsionList", revulsionList);
|
jsonObject.put("revulsionList", revulsionList);
|
||||||
Map flags = flagService.getFlags(template);
|
Map flags = flagService.getFlags(template);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: prod
|
active: dev
|
||||||
application:
|
application:
|
||||||
name: @project.artifactId@
|
name: @project.artifactId@
|
||||||
# 定时任务属性配置
|
# 定时任务属性配置
|
||||||
|
@ -137,7 +137,7 @@ spring:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
url: jdbc:mysql://192.168.65.130:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://192.168.65.130:3306/rax_backend2?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 9999
|
port: 9999
|
||||||
|
|
Loading…
Reference in New Issue
Block a user