parent
51c7e78405
commit
158129e56e
|
@ -8,8 +8,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.rax.admin.api.dto.SysLogDTO;
|
import com.rax.admin.api.dto.SysLogDTO;
|
||||||
import com.rax.admin.api.entity.SysLog;
|
import com.rax.admin.api.entity.SysLog;
|
||||||
|
import com.rax.admin.api.entity.SysRole;
|
||||||
import com.rax.admin.mapper.SysLogMapper;
|
import com.rax.admin.mapper.SysLogMapper;
|
||||||
import com.rax.admin.service.SysLogService;
|
import com.rax.admin.service.SysLogService;
|
||||||
|
import com.rax.admin.service.SysRoleService;
|
||||||
|
import com.rax.common.security.service.RaxUser;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -26,15 +31,25 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
|
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
|
||||||
|
private final static String ADMIN_ROLE_CODE = "ROLE_ADMIN";
|
||||||
|
@Autowired
|
||||||
|
private SysRoleService roleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page getLogByPage(Page page, SysLogDTO sysLog) {
|
public Page getLogByPage(Page page, SysLogDTO sysLog) {
|
||||||
|
RaxUser raxUser = (RaxUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
List<SysRole> roleList = roleService.findRolesByUserId(raxUser.getId());
|
||||||
|
List<SysRole> adminRoleList = roleList.stream().filter(predicate -> ADMIN_ROLE_CODE.contains(predicate.getRoleCode())).toList();
|
||||||
|
|
||||||
LambdaQueryWrapper<SysLog> wrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<SysLog> wrapper = Wrappers.lambdaQuery();
|
||||||
if (StrUtil.isNotBlank(sysLog.getLogType())) {
|
if (StrUtil.isNotBlank(sysLog.getLogType())) {
|
||||||
wrapper.eq(SysLog::getLogType, sysLog.getLogType());
|
wrapper.eq(SysLog::getLogType, sysLog.getLogType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (adminRoleList.isEmpty()) {
|
||||||
|
wrapper.eq(SysLog::getCreateBy, raxUser.getName());
|
||||||
|
}
|
||||||
|
|
||||||
if (ArrayUtil.isNotEmpty(sysLog.getTimeInterval())) {
|
if (ArrayUtil.isNotEmpty(sysLog.getTimeInterval())) {
|
||||||
wrapper.ge(SysLog::getCreateTime, sysLog.getTimeInterval()[0])
|
wrapper.ge(SysLog::getCreateTime, sysLog.getTimeInterval()[0])
|
||||||
.le(SysLog::getCreateTime, sysLog.getTimeInterval()[1]);
|
.le(SysLog::getCreateTime, sysLog.getTimeInterval()[1]);
|
||||||
|
|
|
@ -8,13 +8,15 @@ 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.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.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站发送给仪器给药信息
|
* 网站发送给仪器给药信息
|
||||||
|
@ -26,9 +28,16 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
private ScheduledFuture<?> heartbeatTask;
|
||||||
|
private int pingTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
vitalSignTimerWS.setWSAIFlagSession(session);
|
vitalSignTimerWS.setWSAIFlagSession(session);
|
||||||
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,31 +48,69 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
String username = authorization.getPrincipalName();
|
String username = authorization.getPrincipalName();
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
if (message.getPayload() instanceof String) {
|
||||||
// 病人名
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
String patientName = jsonObject.getString("patientName");
|
// 病人名
|
||||||
// 病人身份证
|
String patientName = jsonObject.getString("patientName");
|
||||||
String idNum = jsonObject.getString("idNum");
|
// 病人身份证
|
||||||
// yyyyMMdd
|
String idNum = jsonObject.getString("idNum");
|
||||||
String date = jsonObject.getString("date");
|
// yyyyMMdd
|
||||||
String databaseName = patientName + idNum;
|
String date = jsonObject.getString("date");
|
||||||
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
|
String databaseName = patientName + idNum;
|
||||||
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
|
||||||
|
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PongMessage());
|
||||||
|
pingTime--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.removeWSAIFlagSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
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());
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPing(WebSocketSession session) {
|
||||||
|
try {
|
||||||
|
if (pingTime > 3) {
|
||||||
|
session.close();
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.removeWSAIFlagSession(session);
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PingMessage());
|
||||||
|
pingTime++;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
vitalSignTimerWS.removeWSAIFlagSession(session);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,15 @@ 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.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.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ChatHandler implements WebSocketHandler {
|
public class ChatHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -22,8 +24,15 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
|
|
||||||
|
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
private ScheduledFuture<?> heartbeatTask;
|
||||||
|
private int pingTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,23 +44,41 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
if (authorization != null) {
|
if (authorization != null) {
|
||||||
String username = authorization.getPrincipalName();
|
String username = authorization.getPrincipalName();
|
||||||
|
|
||||||
String payload = (String) message.getPayload();
|
if (message.getPayload() instanceof String) {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
String payload = (String) message.getPayload();
|
||||||
String patientName = jsonObject.getString("patientName");
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
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.sendMessageMysql(username, patientName, idNum, date, session, msg);
|
String msg = jsonObject.getString("msg");
|
||||||
|
chatService.sendMessageMysql(username, patientName, idNum, date, session, msg);
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PongMessage());
|
||||||
|
pingTime--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
chatService.stopTask(session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
chatService.stopTask(session.getId());
|
chatService.stopTask(session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,4 +86,25 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPing(WebSocketSession session) {
|
||||||
|
try {
|
||||||
|
if (pingTime > 3) {
|
||||||
|
session.close();
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
chatService.stopTask(session.getId());
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PingMessage());
|
||||||
|
pingTime++;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
chatService.stopTask(session.getId());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.io.IOException;
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仪器获取网站给药信息
|
* 仪器获取网站给药信息
|
||||||
|
@ -20,33 +23,58 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private VitalSignTimerWS vitalSignTimerWS;
|
private VitalSignTimerWS vitalSignTimerWS;
|
||||||
|
|
||||||
|
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
private ScheduledFuture<?> heartbeatTask;
|
||||||
|
private int pingTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
vitalSignTimerWS.setMachineSessionMap(session);
|
vitalSignTimerWS.setMachineSessionMap(session);
|
||||||
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
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) throws Exception {
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
if (message.getPayload() instanceof String) {
|
||||||
// 病人名
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
String patientName = jsonObject.getString("patientName");
|
// 病人名
|
||||||
// 病人身份证住院号
|
String patientName = jsonObject.getString("patientName");
|
||||||
String idNum = jsonObject.getString("idNum");
|
// 病人身份证住院号
|
||||||
// yyyyMMdd
|
String idNum = jsonObject.getString("idNum");
|
||||||
String date = jsonObject.getString("date");
|
// yyyyMMdd
|
||||||
String databaseName = patientName + idNum;
|
String date = jsonObject.getString("date");
|
||||||
String code = jsonObject.getString("code");
|
String databaseName = patientName + idNum;
|
||||||
|
String code = jsonObject.getString("code");
|
||||||
|
|
||||||
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
vitalSignTimerWS.sendMachineFlag(databaseName, code, session);
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PongMessage());
|
||||||
|
pingTime--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
vitalSignTimerWS.removeMachineSessionMap(session);
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
System.out.println(this.getClass().getName() + " Connection closed:" + closeStatus.getReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,4 +82,25 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
public boolean supportsPartialMessages() {
|
public boolean supportsPartialMessages() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPing(WebSocketSession session) {
|
||||||
|
try {
|
||||||
|
if (pingTime > 3) {
|
||||||
|
session.close();
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PingMessage());
|
||||||
|
pingTime++;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
vitalSignTimerWS.removeMachineSessionMap(session);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,12 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
private static final long HEARTBEAT_INTERVAL = 30; // 心跳间隔秒数
|
||||||
private ScheduledExecutorService scheduler;
|
private ScheduledExecutorService scheduler;
|
||||||
private ScheduledFuture<?> heartbeatTask;
|
private ScheduledFuture<?> heartbeatTask;
|
||||||
|
private int pingTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
// scheduler = Executors.newScheduledThreadPool(1);
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
// heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
|
heartbeatTask = scheduler.scheduleAtFixedRate(() -> sendPing(session), 0, HEARTBEAT_INTERVAL, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,17 +45,29 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
String username = authorization.getPrincipalName();
|
String username = authorization.getPrincipalName();
|
||||||
|
|
||||||
String payload = (String) message.getPayload();
|
if (message.getPayload() instanceof String) {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
String payload = (String) message.getPayload();
|
||||||
String patientName = jsonObject.getString("patientName");
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
String idNum = jsonObject.getString("idNum");
|
String patientName = jsonObject.getString("patientName");
|
||||||
String databaseName = patientName + idNum;
|
String idNum = jsonObject.getString("idNum");
|
||||||
vitalSignTimerWS.createAndSendMessageMySQL(databaseName, username, session);
|
String databaseName = patientName + idNum;
|
||||||
|
vitalSignTimerWS.createAndSendMessageMySQL(databaseName, username, session);
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PongMessage());
|
||||||
|
pingTime--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
System.out.println("Error: " + exception.getMessage());
|
System.out.println("Error: " + exception.getMessage());
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.stopTimerTask(session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,8 +89,21 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
private void sendPing(WebSocketSession session) {
|
private void sendPing(WebSocketSession session) {
|
||||||
try {
|
try {
|
||||||
session.sendMessage(new PingMessage());
|
if (pingTime > 3) {
|
||||||
|
session.close();
|
||||||
|
if (heartbeatTask != null) {
|
||||||
|
heartbeatTask.cancel(true);
|
||||||
|
}
|
||||||
|
if (scheduler != null) {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
vitalSignTimerWS.stopTimerTask(session.getId());
|
||||||
|
} else {
|
||||||
|
session.sendMessage(new PingMessage());
|
||||||
|
pingTime++;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
vitalSignTimerWS.stopTimerTask(session.getId());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,8 @@ public class AIMedicineServiceImpl implements AIMedicineService {
|
||||||
try {
|
try {
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `aimedicinetable` ORDER BY time DESC LIMIT 1;");
|
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `aimedicinetable` ORDER BY time DESC LIMIT 1;");
|
||||||
|
Map medicine = new HashMap();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Map medicine = new HashMap();
|
|
||||||
medicine.put("id", resultSet.getString("id"));
|
medicine.put("id", resultSet.getString("id"));
|
||||||
medicine.put("phase", resultSet.getString("phase"));
|
medicine.put("phase", resultSet.getString("phase"));
|
||||||
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||||
|
@ -69,8 +69,24 @@ public class AIMedicineServiceImpl implements AIMedicineService {
|
||||||
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||||
medicine.put("阿托品", resultSet.getString("阿托品"));
|
medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||||
medicine.put("Time", resultSet.getString("time"));
|
medicine.put("Time", resultSet.getString("time"));
|
||||||
medicineList.add(medicine);
|
|
||||||
}
|
}
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
medicineList.add(medicine);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,7 @@ public class ChatServiceImpl implements ChatService {
|
||||||
preparedStatement.setString(2, now);
|
preparedStatement.setString(2, now);
|
||||||
param.put("createTime", now);
|
param.put("createTime", now);
|
||||||
preparedStatement.setString(3, username);
|
preparedStatement.setString(3, username);
|
||||||
|
param.put("createUser", username);
|
||||||
String name = userInfo.getSysUser().getName();
|
String name = userInfo.getSysUser().getName();
|
||||||
preparedStatement.setString(4, name);
|
preparedStatement.setString(4, name);
|
||||||
param.put("createName", name);
|
param.put("createName", name);
|
||||||
|
|
|
@ -41,10 +41,10 @@ public class DoctorMedicineServiceImpl implements DoctorMedicineService {
|
||||||
public List<Map> getDocMedicine(Connection connection) {
|
public List<Map> getDocMedicine(Connection connection) {
|
||||||
List<Map> medicineList = new ArrayList<>();
|
List<Map> medicineList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
Map medicine = new HashMap();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `doctormedicinetable` ORDER BY time DESC LIMIT 1;");
|
ResultSet resultSet = statement.executeQuery("SELECT id, phase, `丙泊酚`, `舒芬太尼`, `瑞芬太尼`, `顺阿曲库胺`, `尼卡地平`, `艾司洛尔`, `麻黄素`, `阿托品`, time FROM `doctormedicinetable` ORDER BY time DESC LIMIT 1;");
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Map medicine = new HashMap();
|
|
||||||
medicine.put("id", resultSet.getString("id"));
|
medicine.put("id", resultSet.getString("id"));
|
||||||
medicine.put("phase", resultSet.getString("phase"));
|
medicine.put("phase", resultSet.getString("phase"));
|
||||||
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
medicine.put("丙泊酚", resultSet.getString("丙泊酚"));
|
||||||
|
@ -56,8 +56,25 @@ public class DoctorMedicineServiceImpl implements DoctorMedicineService {
|
||||||
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
medicine.put("麻黄素", resultSet.getString("麻黄素"));
|
||||||
medicine.put("阿托品", resultSet.getString("阿托品"));
|
medicine.put("阿托品", resultSet.getString("阿托品"));
|
||||||
medicine.put("Time", resultSet.getString("time"));
|
medicine.put("Time", resultSet.getString("time"));
|
||||||
medicineList.add(medicine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,10 +100,13 @@ public class VitalSignServiceImpl implements VitalSignsService {
|
||||||
List<Map> vitalList = new ArrayList<>();
|
List<Map> vitalList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT id, Phase, BIS, HR, SBP, DBP, ST, TEMP, SPO2, EtCO2, PPG, ABG, TOF, Time FROM `featuretable` ORDER BY time DESC LIMIT 1;");
|
String sql = "SELECT Phase, BIS, HR, SBP, DBP, ST, TEMP, SPO2, EtCO2, PPG, ABG, TOF, Time " +
|
||||||
|
" FROM `featuretable` " +
|
||||||
|
" GROUP BY Phase, BIS, HR, SBP, DBP, ST, TEMP, SPO2, EtCO2, PPG, ABG, TOF, Time " +
|
||||||
|
" ORDER BY time DESC LIMIT 10;";
|
||||||
|
ResultSet resultSet = statement.executeQuery(sql);
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Map<String, Object> vital = new HashMap();
|
Map<String, Object> vital = new HashMap();
|
||||||
vital.put("id", resultSet.getString("id"));
|
|
||||||
vital.put("Phase", resultSet.getString("Phase"));
|
vital.put("Phase", resultSet.getString("Phase"));
|
||||||
vital.put("BIS", resultSet.getString("BIS"));
|
vital.put("BIS", resultSet.getString("BIS"));
|
||||||
vital.put("HR", resultSet.getString("HR"));
|
vital.put("HR", resultSet.getString("HR"));
|
||||||
|
|
|
@ -256,11 +256,11 @@ public class VitalSignTimerWS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setMachineSessionMap(WebSocketSession session) throws IOException {
|
public synchronized void setMachineSessionMap(WebSocketSession session) {
|
||||||
machineSessionMap.put(session.getId(), session);
|
machineSessionMap.put(session.getId(), session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMachineSessionMap(WebSocketSession session) throws Exception {
|
public void removeMachineSessionMap(WebSocketSession session) {
|
||||||
machineSessionMap.remove(session.getId());
|
machineSessionMap.remove(session.getId());
|
||||||
if (machineDatabaseSessionMap.containsValue(session.getId())) {
|
if (machineDatabaseSessionMap.containsValue(session.getId())) {
|
||||||
for (String database : machineDatabaseSessionMap.keySet()) {
|
for (String database : machineDatabaseSessionMap.keySet()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user