mirror of
https://gitee.com/republicline/rax-remote-v2.git
synced 2025-08-24 00:14:58 +08:00
fix: 去除聊天室的token校验, 自由使用
This commit is contained in:
parent
419f9e20d1
commit
793e3e014d
|
@ -32,13 +32,16 @@ public class ChatHandler implements WebSocketHandler {
|
|||
|
||||
@Override
|
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||
String decode = URLDecoder.decode(session.getUri().getQuery());
|
||||
String query = session.getUri().getQuery();
|
||||
String decode = URLDecoder.decode(query);
|
||||
// System.out.println("query = " + query);
|
||||
Map params = GetHttpParamUtil.getParams(decode);
|
||||
String token = (String) params.get("token");
|
||||
// String token = "azIc_An5dRViceuMN5B5_S-k-1YH8gTCkzc9A6d8mJYguTOEOXWHLaojcpqNNrhYG_9QSUV_y9LpYCN01SqY-GHcXJoMEqCxU-3Qudvkizll3T6mOWK-MJDODMZHETGj";
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
if (authorization != null) {
|
||||
String username = authorization.getPrincipalName();
|
||||
|
||||
// System.out.println("username = " + username);
|
||||
String payload = (String) message.getPayload();
|
||||
JSONObject jsonObject = JSONObject.parseObject(payload);
|
||||
|
||||
|
|
|
@ -157,17 +157,17 @@ public class ChatServiceImpl implements ChatService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageMysql(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) {
|
||||
public void sendMessageMysql(String username, String patientName, String idNum, String date, WebSocketSession session, String msg) throws SQLException {
|
||||
CustomDataSource dataSource = datasourceMap.get(session.getId());
|
||||
// String databaseName = patientName + idNum;
|
||||
String databaseName = idNum;
|
||||
|
||||
|
||||
ArrayList<Map> history = new ArrayList<>();
|
||||
|
||||
if (dataSource == null) {
|
||||
dataSource = new MySQLSource(mysqlHost, mysqlPassword, mysqlUsername, databaseName);
|
||||
boolean status = dataSource.open();
|
||||
|
||||
if (status) {
|
||||
datasourceMap.put(session.getId(), dataSource);
|
||||
sessionDatabaseMap.put(session.getId(), databaseName);
|
||||
|
@ -183,26 +183,30 @@ public class ChatServiceImpl implements ChatService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
String sql = "select content, create_time \"creatTime\", create_user \"createUser\", create_name \"createName\" from t_chat where deleted = 0 and revoked = 0 order by create_time asc ";
|
||||
Connection connection = dataSource.getConnection();
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
while (resultSet.next()) {
|
||||
Map map = new HashMap();
|
||||
map.put("content", resultSet.getString("content"));
|
||||
map.put("creatTime", resultSet.getString("creatTime"));
|
||||
map.put("createUser", resultSet.getString("createUser"));
|
||||
map.put("createName", resultSet.getString("createName"));
|
||||
history.add(map);
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String tableName = "t_chat";
|
||||
ResultSet tablesx = metaData.getTables(null, null, tableName, new String[]{"TABLE"});
|
||||
String sql = "select content, create_time \"creatTime\", create_user \"createUser\", create_name \"createName\" from t_chat where deleted = 0 and revoked = 0 order by create_time asc ";
|
||||
if (tablesx.next()) {
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
while (resultSet.next()) {
|
||||
Map map = new HashMap();
|
||||
map.put("content", resultSet.getString("content"));
|
||||
map.put("creatTime", resultSet.getString("creatTime"));
|
||||
map.put("createUser", resultSet.getString("createUser"));
|
||||
map.put("createName", resultSet.getString("createName"));
|
||||
history.add(map);
|
||||
}
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("history", history);
|
||||
param.put("msgType", "msg");
|
||||
session.sendMessage(new TextMessage(param.toJSONString().getBytes()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("history", history);
|
||||
param.put("msgType", "msg");
|
||||
session.sendMessage(new TextMessage(param.toJSONString().getBytes()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
@ -221,27 +225,31 @@ public class ChatServiceImpl implements ChatService {
|
|||
|
||||
if (StringUtils.hasText(msg)) {
|
||||
JSONObject param = new JSONObject();
|
||||
SysUser sysUser = SysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
|
||||
Connection connection = dataSource.getConnection();
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
String sql = "CREATE TABLE `t_chat` (\n" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT,\n" +
|
||||
" `content` varchar(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_user` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_name` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `deleted` bit(1) NULL DEFAULT NULL,\n" +
|
||||
" `revoked` bit(1) NULL DEFAULT NULL,\n" +
|
||||
" PRIMARY KEY (`id`) USING BTREE\n" +
|
||||
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;";
|
||||
statement.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String tableName = "t_chat";
|
||||
ResultSet tablesx = metaData.getTables(null, null, tableName, new String[]{"TABLE"});
|
||||
System.out.println("tablesx = " + tablesx.next());
|
||||
if (!tablesx.next()) {
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
String sql = "CREATE TABLE `t_chat` (\n" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT,\n" +
|
||||
" `content` varchar(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_user` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `create_name` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,\n" +
|
||||
" `deleted` bit(1) NULL DEFAULT NULL,\n" +
|
||||
" `revoked` bit(1) NULL DEFAULT NULL,\n" +
|
||||
" PRIMARY KEY (`id`) USING BTREE\n" +
|
||||
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;";
|
||||
statement.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("INSERT INTO t_chat (content, create_time, create_user, create_name, deleted, revoked) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
@ -252,9 +260,9 @@ public class ChatServiceImpl implements ChatService {
|
|||
param.put("createTime", now);
|
||||
preparedStatement.setString(3, username);
|
||||
param.put("createUser", username);
|
||||
String name = sysUser.getName();
|
||||
preparedStatement.setString(4, name);
|
||||
param.put("createName", name);
|
||||
// String name = sysUser.getName();
|
||||
preparedStatement.setString(4, username);
|
||||
param.put("createName", username);
|
||||
preparedStatement.setInt(5, 0);
|
||||
preparedStatement.setInt(6, 0);
|
||||
param.put("msgType", "msg");
|
||||
|
|
|
@ -100,7 +100,7 @@ mybatis-plus:
|
|||
jdbc-type-for-null: 'null'
|
||||
call-setters-on-nulls: true
|
||||
shrink-whitespaces-in-sql: true
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
---
|
||||
spring:
|
||||
|
|
Loading…
Reference in New Issue
Block a user