mirror of
https://gitee.com/republicline/rax-remote-v2.git
synced 2025-08-23 23:34:56 +08:00
add: 给socket的远程相关功能添加日志记录
This commit is contained in:
parent
33821e5af5
commit
f2d7305ed7
2
pom.xml
2
pom.xml
|
@ -91,7 +91,7 @@
|
||||||
<!-- 代码生成模块 -->
|
<!-- 代码生成模块 -->
|
||||||
<!--<module>codegen</module>-->
|
<!--<module>codegen</module>-->
|
||||||
<!-- Quartz模块 -->
|
<!-- Quartz模块 -->
|
||||||
<module>quartz</module>
|
<!-- <module>quartz</module>-->
|
||||||
<!-- 身份验证模块 -->
|
<!-- 身份验证模块 -->
|
||||||
<module>auth</module>
|
<module>auth</module>
|
||||||
<!-- 用户管理系统模块 -->
|
<!-- 用户管理系统模块 -->
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
<artifactId>auth</artifactId>
|
<artifactId>auth</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 引入quartz依赖 -->
|
<!-- 引入quartz依赖 -->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.rax</groupId>
|
<!-- <groupId>com.rax</groupId>-->
|
||||||
<artifactId>quartz</artifactId>
|
<!-- <artifactId>quartz</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<!--upms api、model 模块-->
|
<!--upms api、model 模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rax</groupId>
|
<groupId>com.rax</groupId>
|
||||||
|
|
|
@ -126,17 +126,27 @@ public class SysHospitalServiceImpl extends ServiceImpl<SysHospitalMapper, SysHo
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这里的currentHospital, 针对管理员Role_ADMIN是获取当前医院
|
||||||
|
* 其余的角色则直接从token获取,无需存储到redis
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getCurrentHospital() {
|
public String getCurrentHospital() {
|
||||||
RaxUser user = SecurityUtils.getUser();
|
RaxUser user = SecurityUtils.getUser();
|
||||||
String key = CacheConstants.CURRENT_HOSPITAL + ":" + user.getId();
|
List<String> roleCodeList = user.getRoleCodeList();
|
||||||
if (RedisUtils.hasKey(key)) {
|
// 管理员
|
||||||
return Convert.toStr(RedisUtils.get(key));
|
if (roleCodeList.contains(RoleRecord.ADMIN_ROLE_CODE)) {
|
||||||
} else {
|
String key = CacheConstants.CURRENT_HOSPITAL + ":" + user.getId();
|
||||||
|
if (RedisUtils.hasKey(key)) {
|
||||||
|
return Convert.toStr(RedisUtils.get(key));
|
||||||
|
}
|
||||||
RedisUtils.set(key, user.getHospitalId());
|
RedisUtils.set(key, user.getHospitalId());
|
||||||
return Convert.toStr(user.getHospitalId());
|
return Convert.toStr(user.getHospitalId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// 其余角色
|
||||||
|
return Convert.toStr(user.getHospitalId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.rax.admin.service.SysLogService;
|
||||||
import com.rax.admin.utils.AuthUtils;
|
import com.rax.admin.utils.AuthUtils;
|
||||||
import com.rax.common.security.service.RaxUser;
|
import com.rax.common.security.service.RaxUser;
|
||||||
import com.rax.common.security.util.SecurityUtils;
|
import com.rax.common.security.util.SecurityUtils;
|
||||||
|
import org.jacoco.agent.rt.internal_3570298.core.internal.flow.IFrame;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -114,12 +115,14 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean saveLog(SysLog sysLog) {
|
public Boolean saveLog(SysLog sysLog) {
|
||||||
// 获取到医院ID
|
if (sysLog.getHospitalId() == null) {
|
||||||
LambdaQueryWrapper<SysUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
// 获取到医院ID
|
||||||
userLambdaQueryWrapper.eq(SysUser::getUsername, sysLog.getCreateBy());
|
LambdaQueryWrapper<SysUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
SysUser sysUser = sysUserMapper.selectOne(userLambdaQueryWrapper);
|
userLambdaQueryWrapper.eq(SysUser::getUsername, sysLog.getCreateBy());
|
||||||
// 设置到日志对象中
|
SysUser sysUser = sysUserMapper.selectOne(userLambdaQueryWrapper);
|
||||||
sysLog.setHospitalId(sysUser.getHospitalId());
|
// 设置到日志对象中
|
||||||
|
sysLog.setHospitalId(sysUser.getHospitalId());
|
||||||
|
}
|
||||||
baseMapper.insert(sysLog);
|
baseMapper.insert(sysLog);
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.rax.admin.timmer;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.rax.admin.api.entity.SysLog;
|
||||||
|
import com.rax.admin.mapper.SysLogMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* project_name: remote-control-backend
|
||||||
|
* author republicline
|
||||||
|
* time: 2024/9/4 16:20
|
||||||
|
* description: 日志定时任务清除
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@Service
|
||||||
|
public class LogTimerTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogMapper sysLogMapper;
|
||||||
|
|
||||||
|
|
||||||
|
//每天晚上12:00定时删除30天之前的数据
|
||||||
|
@Scheduled(cron = "0 0 0 * * ?")
|
||||||
|
public void scheduled() {
|
||||||
|
// 查询系统的全部用户的集合
|
||||||
|
QueryWrapper<SysLog> sysLogQueryWrapper = new QueryWrapper<>();
|
||||||
|
sysLogQueryWrapper.select("distinct create_by");
|
||||||
|
List<String> userList = sysLogMapper.selectList(sysLogQueryWrapper)
|
||||||
|
.stream().map(SysLog::getCreateBy).toList();
|
||||||
|
// 获取30天前的时间
|
||||||
|
String agoDate = getDate(new Date(), 30);
|
||||||
|
for (String user : userList) {
|
||||||
|
// 查询指定用户的日志集合id
|
||||||
|
List<Long> idList = sysLogMapper.selectListByTime(user, agoDate)
|
||||||
|
.stream()
|
||||||
|
.map(SysLog::getId)
|
||||||
|
.toList();
|
||||||
|
if (!idList.isEmpty()) {
|
||||||
|
sysLogMapper.deleteBatchByIds(idList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 获取时间
|
||||||
|
* @param: [now, days]
|
||||||
|
* @return: java.lang.String
|
||||||
|
*/
|
||||||
|
public static String getDate(Date now, int days) {
|
||||||
|
// 将 java.util.Date 转换为 java.time.LocalDateTime
|
||||||
|
LocalDateTime localDateTime = now.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||||
|
|
||||||
|
// 计算 days 天前的日期时间
|
||||||
|
LocalDateTime daysAgo = localDateTime.minusDays(days);
|
||||||
|
|
||||||
|
// 格式化为年月日时分秒
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return daysAgo.format(formatter);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,25 +12,30 @@ import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* project_name:remote-control-backend
|
* project_name: remote-control-backend
|
||||||
* time:2024/9/3 15:17
|
* time: 2024/9/3 15:17
|
||||||
* 根据解析到的Token, 构造一个日志对象, 添加日志表中
|
* author: republicline
|
||||||
|
* description: 日志对象构造, 根据解析到的Token, 构造一个日志对象, 添加日志表中
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysLoggerBuilder {
|
public class SysLoggerBuilder {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private TokenUtil tokenUtil;
|
||||||
|
|
||||||
|
public SysLog buildSysLog(String title, String logType, WebSocketSession session) {
|
||||||
|
|
||||||
|
String query = session.getUri().getQuery();
|
||||||
|
String token = GetHttpParamUtil.getParam(query, "token");
|
||||||
|
|
||||||
|
|
||||||
public SysLog buildSysLog(String token, String title, String logType, WebSocketSession session) {
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
// 从session中获取一些信息
|
// 从session中获取一些信息
|
||||||
String ip = session.getRemoteAddress() != null ? session.getRemoteAddress().toString() : "unknown";
|
String ip = session.getRemoteAddress() != null ? session.getRemoteAddress().toString() : "unknown";
|
||||||
String uri = session.getUri() != null ? session.getUri().toString() : "unknown";
|
String uri = session.getUri() != null ? session.getUri().toString() : "unknown";
|
||||||
|
@ -40,11 +45,9 @@ public class SysLoggerBuilder {
|
||||||
session.getUri().getQuery() : "unknown";
|
session.getUri().getQuery() : "unknown";
|
||||||
|
|
||||||
// 解析token
|
// 解析token
|
||||||
OAuth2Authorization byToken = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
Map<String, Object> stringObjectMap = tokenUtil.parseToken(token);
|
||||||
Map<String, Object> stringObjectMap = parseToken(token);
|
|
||||||
Long hospitalId = (Long) stringObjectMap.get("hospitalId");
|
Long hospitalId = (Long) stringObjectMap.get("hospitalId");
|
||||||
String userName = (String) stringObjectMap.get("userName");
|
String userName = (String) stringObjectMap.get("username");
|
||||||
|
|
||||||
|
|
||||||
// 填充属性
|
// 填充属性
|
||||||
SysLog sysLog = new SysLog();
|
SysLog sysLog = new SysLog();
|
||||||
|
@ -52,6 +55,7 @@ public class SysLoggerBuilder {
|
||||||
sysLog.setTitle(title);
|
sysLog.setTitle(title);
|
||||||
sysLog.setCreateTime(LocalDateTime.now());
|
sysLog.setCreateTime(LocalDateTime.now());
|
||||||
sysLog.setRemoteAddr(ip);
|
sysLog.setRemoteAddr(ip);
|
||||||
|
sysLog.setMethod("ws");
|
||||||
sysLog.setDelFlag("0");
|
sysLog.setDelFlag("0");
|
||||||
sysLog.setParams(params);
|
sysLog.setParams(params);
|
||||||
sysLog.setUserAgent(userAgent);
|
sysLog.setUserAgent(userAgent);
|
||||||
|
@ -65,15 +69,15 @@ public class SysLoggerBuilder {
|
||||||
|
|
||||||
// 获取信息
|
// 获取信息
|
||||||
HttpHeaders headers = request.getHeaders();
|
HttpHeaders headers = request.getHeaders();
|
||||||
String req_url = headers.getFirst("origin");
|
|
||||||
String agent = headers.getFirst("User-Agent");
|
String agent = headers.getFirst("User-Agent");
|
||||||
|
String req_addr = request.getRemoteAddress().toString();
|
||||||
|
|
||||||
// 获取解析token
|
// 获取解析token
|
||||||
String query = request.getURI().getQuery();
|
String query = request.getURI().getQuery();
|
||||||
String token = GetHttpParamUtil.getParam(query, "token");
|
String token = GetHttpParamUtil.getParam(query, "token");
|
||||||
Map<String, Object> stringObjectMap = parseToken(token);
|
Map<String, Object> stringObjectMap = tokenUtil.parseToken(token);
|
||||||
|
|
||||||
String userName = (String) stringObjectMap.get("userName");
|
String userName = (String) stringObjectMap.get("username");
|
||||||
Long hospitalId = (Long) stringObjectMap.get("hospitalId");
|
Long hospitalId = (Long) stringObjectMap.get("hospitalId");
|
||||||
|
|
||||||
// 填充属性
|
// 填充属性
|
||||||
|
@ -83,24 +87,30 @@ public class SysLoggerBuilder {
|
||||||
sysLog.setDelFlag("0");
|
sysLog.setDelFlag("0");
|
||||||
sysLog.setCreateBy(userName);
|
sysLog.setCreateBy(userName);
|
||||||
sysLog.setParams(query);
|
sysLog.setParams(query);
|
||||||
sysLog.setRemoteAddr(req_url);
|
sysLog.setRemoteAddr(req_addr);
|
||||||
sysLog.setMethod("ws");
|
sysLog.setMethod("ws");
|
||||||
sysLog.setHospitalId(hospitalId);
|
sysLog.setHospitalId(hospitalId);
|
||||||
sysLog.setCreateTime(LocalDateTime.now());
|
sysLog.setCreateTime(LocalDateTime.now());
|
||||||
|
sysLog.setUserAgent(agent);
|
||||||
return sysLog;
|
return sysLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Map<String,Object> parseToken(String token) {
|
public SysLog buildLongWithLogType(ServerHttpRequest request){
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
URI uri = request.getURI();
|
||||||
OAuth2Authorization byToken = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
String uriStr = uri.toString();
|
||||||
String userName = byToken.getPrincipalName();
|
if (uriStr.contains("/rax/vitalSignsMedicine")) {
|
||||||
map.put("userName", userName);
|
return buildSysLog("连接生命体征接口","0",request);
|
||||||
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = byToken.getAccessToken();
|
}
|
||||||
RaxUser o = (RaxUser) accessToken.getClaims().get("user_info");
|
if (uriStr.contains("/rax/chatRoom")) {
|
||||||
Long hospitalId = o.getHospitalId();
|
return buildSysLog("连接聊天室接口","0",request);
|
||||||
map.put("hospitalId", hospitalId);
|
}
|
||||||
return map;
|
if (uriStr.contains("/rax/addMedicine")){
|
||||||
|
return buildSysLog("网页端连接给药接口","0",request);
|
||||||
|
}
|
||||||
|
if (uriStr.contains("/rax/getMedicine")){
|
||||||
|
return buildSysLog("仪器端连接收药接口","0",request);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.rax.vital.common.util;
|
||||||
|
|
||||||
|
import com.rax.common.security.service.RaxUser;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||||
|
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.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* project_name: remote-control-backend
|
||||||
|
* time: 2024/9/4 14:56
|
||||||
|
* author: republicline
|
||||||
|
* description:
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TokenUtil {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
public Map<String,Object> parseToken(String token) {
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
OAuth2Authorization byToken = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
|
String username = byToken.getPrincipalName();
|
||||||
|
map.put("username", username);
|
||||||
|
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = byToken.getAccessToken();
|
||||||
|
RaxUser o = (RaxUser) accessToken.getClaims().get("user_info");
|
||||||
|
Long hospitalId = o.getHospitalId();
|
||||||
|
map.put("hospitalId", hospitalId);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,7 @@ import com.rax.vital.v2.handler.MachineFeedbackHandler;
|
||||||
import com.rax.vital.v2.handler.MedicineHandler;
|
import com.rax.vital.v2.handler.MedicineHandler;
|
||||||
import com.rax.vital.v2.interceptor.WebSocketInterceptors;
|
import com.rax.vital.v2.interceptor.WebSocketInterceptors;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
|
||||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
|
@ -21,37 +19,28 @@ public class WebSocketConfig implements WebSocketConfigurer {
|
||||||
@Autowired
|
@Autowired
|
||||||
private WebSocketInterceptors webSocketInterceptors;
|
private WebSocketInterceptors webSocketInterceptors;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AddMedicineHandler addMedicineHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChatHandler chatHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MachineFeedbackHandler machineFeedbackHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MedicineHandler medicineHandler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(medicineHandler(), "/rax/vitalSignsMedicine")
|
registry.addHandler(medicineHandler, "/rax/vitalSignsMedicine")
|
||||||
.addHandler(chatHandler(), "/rax/chatRoom")
|
.addHandler(chatHandler,"/rax/chatRoom")
|
||||||
.addHandler(addMedicineHandler(), "/rax/addMedicine")
|
.addHandler(addMedicineHandler, "/rax/addMedicine")
|
||||||
.addHandler(machineFeedbackHandler(),"/rax/getMedicine")
|
.addHandler(machineFeedbackHandler,"/rax/getMedicine")
|
||||||
.addInterceptors(new HttpSessionHandshakeInterceptor())
|
.addInterceptors(new HttpSessionHandshakeInterceptor())
|
||||||
.addInterceptors(webSocketInterceptors)
|
.addInterceptors(webSocketInterceptors)
|
||||||
.setAllowedOrigins("*");
|
.setAllowedOrigins("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSocketHandler medicineHandler() {
|
|
||||||
return new MedicineHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSocketHandler chatHandler() {
|
|
||||||
return new ChatHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSocketHandler addMedicineHandler() {
|
|
||||||
return new AddMedicineHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSocketHandler machineFeedbackHandler() {
|
|
||||||
return new MachineFeedbackHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
package com.rax.vital.v2.handler;
|
package com.rax.vital.v2.handler;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.DatabaseNameUtil;
|
||||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
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.AIMedicineTimer;
|
||||||
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
@ -23,38 +21,37 @@ import java.util.concurrent.*;
|
||||||
* 网站发送给仪器给药信息
|
* 网站发送给仪器给药信息
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class AddMedicineHandler implements WebSocketHandler {
|
public class AddMedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private VitalSignTimerV2 vitalSignTimerV2;
|
private VitalSignTimerV2 vitalSignTimerV2;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private SysLoggerBuilder sysLoggerBuilder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogService sysLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenUtil tokenUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AIMedicineTimer aiMedicineTimer;
|
||||||
|
|
||||||
// 发送心跳任务的定时任务容器
|
// 发送心跳任务的定时任务容器
|
||||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AIMedicineTimer aiMedicineTimer;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionEstablished(WebSocketSession session) {
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
URI uri = session.getUri();
|
|
||||||
System.out.println("uri = " + uri);
|
|
||||||
startHeartbeat(session);
|
startHeartbeat(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||||
String decode = URLDecoder.decode(session.getUri().getQuery());
|
|
||||||
Map params = GetHttpParamUtil.getParams(decode);
|
|
||||||
String token = (String) params.get("token");
|
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
|
||||||
String username = authorization.getPrincipalName();
|
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
String msgType = jsonObject.getString("msgType");
|
String msgType = jsonObject.getString("msgType");
|
||||||
|
@ -88,7 +85,12 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
// 处理发送给药相关
|
// 处理发送给药相关
|
||||||
if ("addMedicine".equals(msgType) && aiMedicineTimer.getWebSession(databaseName) != null && aiMedicineTimer.getUnitySession(databaseName) != null
|
if ("addMedicine".equals(msgType) && aiMedicineTimer.getWebSession(databaseName) != null && aiMedicineTimer.getUnitySession(databaseName) != null
|
||||||
&& aiMedicineTimer.isReady(databaseName)) {
|
&& aiMedicineTimer.isReady(databaseName)) {
|
||||||
// todo 注意修改
|
// 解析获取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给药
|
// flag 0 代表人工给药, 1代表AI给药
|
||||||
vitalSignTimerV2.sendMedicalMessageToUnity(databaseName, username, session, jsonObject.getString("flag"),
|
vitalSignTimerV2.sendMedicalMessageToUnity(databaseName, username, session, jsonObject.getString("flag"),
|
||||||
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||||
|
@ -123,12 +125,16 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
aiMedicineTimer.closeConnection(session);
|
aiMedicineTimer.closeConnection(session);
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口异常中断:"+exception.getMessage(), "4", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
aiMedicineTimer.closeConnection(session);
|
aiMedicineTimer.closeConnection(session);
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("给药接口客户端,断开连接", "0", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,25 +1,42 @@
|
||||||
package com.rax.vital.v2.handler;
|
package com.rax.vital.v2.handler;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.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 com.rax.vital.v2.medicine.service.ChatService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class ChatHandler implements WebSocketHandler {
|
public class ChatHandler implements WebSocketHandler {
|
||||||
@Resource
|
|
||||||
private OAuth2AuthorizationService authorizationService;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLoggerBuilder sysLoggerBuilder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogService sysLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenUtil tokenUtil;
|
||||||
|
|
||||||
|
|
||||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,35 +46,40 @@ public class ChatHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||||
// String decode = URLDecoder.decode(session.getUri().getQuery());
|
|
||||||
// Map params = GetHttpParamUtil.getParams(decode);
|
String payload = (String) message.getPayload();
|
||||||
// String token = (String) params.get("token");
|
|
||||||
// OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
// if (authorization != null) {
|
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
||||||
// String username = authorization.getPrincipalName();
|
|
||||||
String payload = (String) message.getPayload();
|
String query = Objects.requireNonNull(session.getUri()).getQuery();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
String token = GetHttpParamUtil.getParam(query, "token");
|
||||||
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
Map<String, Object> map = tokenUtil.parseToken(token);
|
||||||
String patientName = jsonObject.getString("patientName");
|
String username = (String) map.get("username");
|
||||||
String idNum = jsonObject.getString("idNum");
|
|
||||||
String date = jsonObject.getString("date");
|
String patientName = jsonObject.getString("patientName");
|
||||||
// 消息内容
|
String idNum = jsonObject.getString("idNum");
|
||||||
String msg = jsonObject.getString("msg");
|
String date = jsonObject.getString("date");
|
||||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
// 消息内容
|
||||||
chatService.sendMessage(databaseName,"admin",session, msg);
|
String msg = jsonObject.getString("msg");
|
||||||
}
|
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||||
// }
|
chatService.sendMessage(databaseName, username, session, msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
System.out.println("Error: " + exception.getMessage());
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口异常中断:"+exception.getMessage(), "4", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
chatService.stopTask(session.getId());
|
chatService.stopTask(session.getId());
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("聊天室接口关闭", "0", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package com.rax.vital.v2.handler;
|
package com.rax.vital.v2.handler;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.DatabaseNameUtil;
|
||||||
|
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.AIMedicineTimer;
|
||||||
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
import com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -17,11 +22,21 @@ import java.util.concurrent.*;
|
||||||
* 仪器获取网站给药信息
|
* 仪器获取网站给药信息
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class MachineFeedbackHandler implements WebSocketHandler {
|
public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private VitalSignTimerV2 vitalSignTimerV2;
|
private VitalSignTimerV2 vitalSignTimerV2;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLoggerBuilder sysLoggerBuilder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogService sysLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenUtil tokenUtil;
|
||||||
|
|
||||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -54,7 +69,6 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
|
|
||||||
if ("init".equals(msgType)) {
|
if ("init".equals(msgType)) {
|
||||||
aiMedicineTimer.initUnity(databaseName, session);
|
aiMedicineTimer.initUnity(databaseName, session);
|
||||||
// vitalSignTimerWS.initUnity(databaseName, session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unity获取到给药信息后回复
|
// Unity获取到给药信息后回复
|
||||||
|
@ -79,7 +93,7 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
// u3d相应网页端的请求
|
// u3d相应网页端的请求
|
||||||
if ("unityResponseConnection".equals(msgType)) {
|
if ("unityResponseConnection".equals(msgType)) {
|
||||||
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||||
aiMedicineTimer.sendConnectionResponseToWeb(patientName, idNum, date,databaseName, unityConnectionFlag);
|
aiMedicineTimer.sendConnectionResponseToWeb(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiMedicineTimer.getUnitySession(databaseName) != null && aiMedicineTimer.getWebSession(databaseName) != null
|
if (aiMedicineTimer.getUnitySession(databaseName) != null && aiMedicineTimer.getWebSession(databaseName) != null
|
||||||
|
@ -106,7 +120,7 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
|
|
||||||
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||||
result.put("unityMsg", "unity端已登录");
|
result.put("unityMsg", "unity端已登录");
|
||||||
}else {
|
} else {
|
||||||
result.put("unityMsg", "unity端未登录");
|
result.put("unityMsg", "unity端未登录");
|
||||||
}
|
}
|
||||||
// 当前时间戳
|
// 当前时间戳
|
||||||
|
@ -135,12 +149,16 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
aiMedicineTimer.closeConnection(session);
|
aiMedicineTimer.closeConnection(session);
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端获取收药口异常中断", "4", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
aiMedicineTimer.closeConnection(session);
|
aiMedicineTimer.closeConnection(session);
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("仪器端收药接口关闭", "0", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package com.rax.vital.v2.handler;
|
package com.rax.vital.v2.handler;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.DatabaseNameUtil;
|
||||||
import com.rax.vital.common.util.GetHttpParamUtil;
|
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 com.rax.vital.v2.timer.VitalSignTimerV2;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -23,14 +25,20 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class MedicineHandler implements WebSocketHandler {
|
public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
@Resource
|
|
||||||
private VitalSignTimerV2 vitalSignTimerV2;
|
private VitalSignTimerV2 vitalSignTimerV2;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private SysLoggerBuilder sysLoggerBuilder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogService sysLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenUtil tokenUtil;
|
||||||
|
|
||||||
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
private Map<String, ScheduledExecutorService> timerTaskMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@ -41,16 +49,18 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||||
String decode = URLDecoder.decode(session.getUri().getQuery());
|
|
||||||
Map params = GetHttpParamUtil.getParams(decode);
|
|
||||||
String token = (String) params.get("token");
|
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
|
||||||
String username = authorization.getPrincipalName();
|
|
||||||
|
|
||||||
String payload = (String) message.getPayload();
|
String payload = (String) message.getPayload();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||||
|
|
||||||
if (!"heartbeat".equals(jsonObject.getString("msgType"))) {
|
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 patientName = jsonObject.getString("patientName");
|
||||||
String idNum = jsonObject.getString("idNum");
|
String idNum = jsonObject.getString("idNum");
|
||||||
String date = jsonObject.getString("date");
|
String date = jsonObject.getString("date");
|
||||||
|
@ -63,12 +73,16 @@ public class MedicineHandler implements WebSocketHandler {
|
||||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
vitalSignTimerV2.stopTimerTask(session.getId());
|
vitalSignTimerV2.stopTimerTask(session.getId());
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口异常中断", "4", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
stopHeartbeat(session);
|
stopHeartbeat(session);
|
||||||
vitalSignTimerV2.stopTimerTask(session.getId());
|
vitalSignTimerV2.stopTimerTask(session.getId());
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildSysLog("生命体征接口连接关闭", "0", session);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package com.rax.vital.v2.interceptor;
|
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.GetHttpParamUtil;
|
||||||
|
import com.rax.vital.common.util.SysLoggerBuilder;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
|
@ -20,8 +24,16 @@ public class WebSocketInterceptors implements HandshakeInterceptor {
|
||||||
@Resource
|
@Resource
|
||||||
private OAuth2AuthorizationService authorizationService;
|
private OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLoggerBuilder sysLoggerBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogService sysLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在这里做一个全局的日志插入根据路径匹配不同的操作title
|
* 在这里做一个全局的日志插入根据路径匹配不同的操作title
|
||||||
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @param response
|
* @param response
|
||||||
* @param wsHandler
|
* @param wsHandler
|
||||||
|
@ -34,14 +46,17 @@ public class WebSocketInterceptors implements HandshakeInterceptor {
|
||||||
String query = request.getURI().getQuery();
|
String query = request.getURI().getQuery();
|
||||||
String token = GetHttpParamUtil.getParam(query, "token");
|
String token = GetHttpParamUtil.getParam(query, "token");
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
if (authorization == null ) {
|
if (authorization == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 适配一下,根据req中不同的路径做不同的操作title
|
||||||
|
SysLog sysLog = sysLoggerBuilder.buildLongWithLogType(request);
|
||||||
|
sysLogService.saveLog(sysLog);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||||
System.out.println("request = " + request + ", response = " + response + ", wsHandler = " + wsHandler + ", exception = " + exception);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* project_name:remote-control-backend
|
* project_name: remote-control-backend
|
||||||
* time:2024/8/20 15:09
|
* time: 2024/8/20 15:09
|
||||||
* author:republicline
|
* author: republicline
|
||||||
* 新的计时器任务, 和一期代码解耦
|
* 新的计时器任务, 和一期代码解耦
|
||||||
*/
|
*/
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
|
|
Loading…
Reference in New Issue
Block a user