mirror of
https://gitee.com/republicline/rax-remote-v2.git
synced 2025-08-24 03:34:57 +08:00
parent
8d176fc965
commit
9355c44b13
|
@ -314,14 +314,16 @@ public abstract class OAuth2ResourceOwnerBaseAuthenticationProvider<T extends OA
|
|||
String previousAccessToken = redisTemplate.opsForValue().get(LOGGED_IN + username + "::a::");
|
||||
String previousRefreshToken = redisTemplate.opsForValue().get(LOGGED_IN + username + "::c::");
|
||||
String accessToken = authorization.getAccessToken().getToken().getTokenValue();
|
||||
String refreshToken = authorization.getRefreshToken().getToken().getTokenValue();
|
||||
if (StringUtils.hasText(previousAccessToken)) {
|
||||
redisTemplate.delete("token::access_token::" + previousAccessToken);
|
||||
redisTemplate.delete("token::refresh_token::" + previousRefreshToken);
|
||||
}
|
||||
R<SysOauthClientDetails> clientDetailsById = clientDetailsService.getClientDetailsById(authorization.getRegisteredClientId(), SecurityConstants.FROM_IN);
|
||||
redisTemplate.opsForValue().set(LOGGED_IN + username + "::a::", accessToken, clientDetailsById.getData().getAccessTokenValidity(), TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(LOGGED_IN + username + "::c::", refreshToken, clientDetailsById.getData().getRefreshTokenValidity(), TimeUnit.SECONDS);
|
||||
if (authorization.getRefreshToken() != null) {
|
||||
String refreshToken = authorization.getRefreshToken().getToken().getTokenValue();
|
||||
redisTemplate.opsForValue().set(LOGGED_IN + username + "::c::", refreshToken, clientDetailsById.getData().getRefreshTokenValidity(), TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public interface CommonConstants {
|
|||
/**
|
||||
* 锁定
|
||||
*/
|
||||
String STATUS_LOCK = "9";
|
||||
String STATUS_LOCK = "1";
|
||||
|
||||
/**
|
||||
* 菜单树根节点
|
||||
|
|
27
db/pig.sql
27
db/pig.sql
|
@ -1,11 +1,11 @@
|
|||
DROP DATABASE IF EXISTS `pig`;
|
||||
DROP DATABASE IF EXISTS `rax_backend`;
|
||||
|
||||
CREATE DATABASE `pig` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
||||
CREATE DATABASE `rax_backend` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
USE `pig`;
|
||||
USE `rax_backend`;
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
|
@ -725,5 +725,26 @@ CREATE TABLE `sys_job_log` (
|
|||
PRIMARY KEY (`job_log_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='定时任务执行日志表';
|
||||
|
||||
DROP TABLE IF EXISTS `sys_hospital`;
|
||||
CREATE TABLE `sys_hospital` (
|
||||
`id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '医院名称',
|
||||
`code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`start_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`end_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`status` bit(1) NULL DEFAULT NULL,
|
||||
`domain` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`create_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`deleted` bit(1) NULL DEFAULT NULL,
|
||||
`update_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`province` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
`city` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_hospital
|
||||
-- ----------------------------
|
||||
INSERT INTO `sys_hospital` VALUES ('111', '111', '111', '111', '111', b'1', '111', '11', b'0', '111', '11', '111');
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
|
|
@ -11,13 +11,13 @@ spring:
|
|||
type: redis
|
||||
data:
|
||||
redis:
|
||||
host: 192.168.65.130
|
||||
host: localhost
|
||||
# 数据库相关配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: 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://localhost:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||
# 定时任务属性配置
|
||||
quartz:
|
||||
properties:
|
||||
|
@ -101,10 +101,10 @@ mybatis-plus:
|
|||
|
||||
vital-sign:
|
||||
mongodb:
|
||||
host: 192.168.65.130:27017
|
||||
host: localhost:27017
|
||||
password: root
|
||||
username: root
|
||||
mysql:
|
||||
host: 192.168.65.130:3306
|
||||
host: localhost:3306
|
||||
password: root
|
||||
username: root
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.springframework.security.oauth2.server.authorization.OAuth2Authorizat
|
|||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Controller
|
||||
|
@ -25,21 +27,23 @@ public class ChatController {
|
|||
|
||||
@MessageMapping("/sendMessage")
|
||||
public void sendMessage(MessageHeaders messageHeaders, String body) {
|
||||
JSONObject params = JSONObject.parseObject(body);
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(params.getString("token"), OAuth2TokenType.ACCESS_TOKEN);
|
||||
LinkedMultiValueMap nativeHeaders = (LinkedMultiValueMap) messageHeaders.get("nativeHeaders");
|
||||
ArrayList tokenList = (ArrayList) nativeHeaders.get("token");
|
||||
String token = (String) tokenList.get(0);
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
if (authorization != null) {
|
||||
String username = authorization.getPrincipalName();
|
||||
String simpSessionId = messageHeaders.get("simpSessionId", String.class);
|
||||
JSONObject params = JSONObject.parseObject(body);
|
||||
// 病人名
|
||||
String patientName = params.getString("patientName");
|
||||
// 病人身份证
|
||||
String idNum = params.getString("idNum");
|
||||
// yyyyMMdd
|
||||
String date = params.getString("date");
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
// 消息内容
|
||||
String msg = params.getString("msg");
|
||||
chatService.sendMessage(databaseName, username, simpSessionId, msg);
|
||||
chatService.sendMessage(username, patientName, idNum, date, simpSessionId, msg);
|
||||
} else {
|
||||
throw new AccessDeniedException("Access is denied");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.rax.vital.medicine.service;
|
||||
|
||||
public interface ChatService {
|
||||
void sendMessage(String db, String username, String simpSessionId, String msg);
|
||||
void sendMessage(String username, String patientName, String idNum, String date, String simpSessionId, String msg);
|
||||
|
||||
void stopTimerTaskMongo(String simpSessionId);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package com.rax.vital.medicine.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.rax.admin.api.dto.UserDTO;
|
||||
import com.rax.admin.api.dto.UserInfo;
|
||||
import com.rax.admin.api.feign.RemoteUserService;
|
||||
import com.rax.common.core.constant.SecurityConstants;
|
||||
import com.rax.common.core.util.R;
|
||||
import com.rax.vital.datasource.MongoDBSource;
|
||||
import com.rax.vital.medicine.service.ChatService;
|
||||
import com.rax.vital.util.DatabaseNameUtil;
|
||||
import org.bson.Document;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
|
@ -21,6 +28,9 @@ public class ChatServiceImpl implements ChatService {
|
|||
@Autowired
|
||||
private SimpMessagingTemplate simpMessagingTemplate;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
private static final Map<String, MongoDBSource> datasourceMap = new HashMap<>(100);
|
||||
|
||||
// MongoDB的地址
|
||||
|
@ -36,24 +46,38 @@ public class ChatServiceImpl implements ChatService {
|
|||
private String mongoPassword;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String db, String username, String simpSessionId, String msg) {
|
||||
public void sendMessage(String username, String patientName, String idNum, String date, String simpSessionId, String msg) {
|
||||
MongoDBSource mongoDBSource = datasourceMap.get(simpSessionId);
|
||||
if (mongoDBSource == null) {
|
||||
mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, db);
|
||||
String databaseName = DatabaseNameUtil.encrypt(patientName) + "_" + DatabaseNameUtil.encrypt(idNum) + "_" + date;
|
||||
mongoDBSource = new MongoDBSource(mongoDBHost, mongoPassword, mongoUsername, databaseName);
|
||||
datasourceMap.put(simpSessionId, mongoDBSource);
|
||||
mongoDBSource.open();
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setUsername(username);
|
||||
R<UserInfo> info = remoteUserService.info(userDTO, SecurityConstants.FROM_IN);
|
||||
UserInfo userInfo = info.getData();
|
||||
|
||||
Map param = new HashMap();
|
||||
|
||||
MongoTemplate template = mongoDBSource.getTemplate();
|
||||
Document document = new Document();
|
||||
document.put("content", msg);
|
||||
document.put("create_time", DateUtil.now());
|
||||
param.put("content", msg);
|
||||
String now = DateUtil.now();
|
||||
document.put("create_time", now);
|
||||
param.put("createTime", now);
|
||||
document.put("create_user", username);
|
||||
String name = userInfo.getSysUser().getName();
|
||||
document.put("create_name", name);
|
||||
param.put("createName", name);
|
||||
document.put("deleted", 0);
|
||||
document.put("revoked", 0);
|
||||
template.insert(document, "t_chat");
|
||||
|
||||
simpMessagingTemplate.convertAndSendToUser(db, "/chatroomMessage", document);
|
||||
simpMessagingTemplate.convertAndSendToUser(patientName + idNum + date, "/chatroomMessage", param);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user