add: 一期代码
This commit is contained in:
parent
b17b11cf1a
commit
d7d377435e
|
@ -1,130 +1,130 @@
|
||||||
package com.rax.vital.controller;
|
//package com.rax.vital.controller;
|
||||||
|
//
|
||||||
import com.rax.common.core.util.R;
|
//import com.rax.common.core.util.R;
|
||||||
import com.rax.common.security.annotation.Inner;
|
//import com.rax.common.security.annotation.Inner;
|
||||||
import com.rax.vital.common.datasource.DynamicDataSource;
|
//import com.rax.vital.common.datasource.DynamicDataSource;
|
||||||
import com.rax.vital.entity.VisualBody;
|
//import com.rax.vital.entity.VisualBody;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
//import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
//import org.springframework.web.bind.annotation.RestController;
|
||||||
|
//
|
||||||
import java.sql.Connection;
|
//import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
//import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
//import java.sql.SQLException;
|
||||||
import java.util.concurrent.*;
|
//import java.util.concurrent.*;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @project_name: rax-remote-v2
|
// * @project_name: rax-remote-v2
|
||||||
* @time: 2024/11/5 11:05
|
// * @time: 2024/11/5 11:05
|
||||||
* @author: republicline
|
// * @author: republicline
|
||||||
* @description: 仪器端和服务端通信接口
|
// * @description: 仪器端和服务端通信接口
|
||||||
*/
|
// */
|
||||||
@RestController
|
//@RestController
|
||||||
@RequestMapping("/machine")
|
//@RequestMapping("/machine")
|
||||||
public class MachineController {
|
//public class MachineController {
|
||||||
|
//
|
||||||
// 生命体征表名
|
// // 生命体征表名
|
||||||
private static final String FEATURE_TABLE_NAME = "featuretable";
|
// private static final String FEATURE_TABLE_NAME = "featuretable";
|
||||||
|
//
|
||||||
// 异步入库
|
// // 异步入库
|
||||||
private ExecutorService executorService = Executors.newFixedThreadPool(5);
|
// private ExecutorService executorService = Executors.newFixedThreadPool(5);
|
||||||
|
//
|
||||||
// 动态数据源
|
// // 动态数据源
|
||||||
private ConcurrentHashMap<String, DynamicDataSource> dynamicDataSources = new ConcurrentHashMap<>();
|
// private ConcurrentHashMap<String, DynamicDataSource> dynamicDataSources = new ConcurrentHashMap<>();
|
||||||
|
//
|
||||||
// 仪器端生命体征数据入库
|
// // 仪器端生命体征数据入库
|
||||||
@PostMapping("/save")
|
// @PostMapping("/save")
|
||||||
@Inner(value = false)
|
// @Inner(value = false)
|
||||||
public R<Object> saveVitalBodyData(VisualBody visualBody) {
|
// public R<Object> saveVitalBodyData(VisualBody visualBody) {
|
||||||
System.out.println("visualBody = " + visualBody);
|
// System.out.println("visualBody = " + visualBody);
|
||||||
|
//
|
||||||
for (String key : dynamicDataSources.keySet()) System.out.println("key = " + key);
|
// for (String key : dynamicDataSources.keySet()) System.out.println("key = " + key);
|
||||||
|
//
|
||||||
// 校验
|
// // 校验
|
||||||
if (visualBody == null) return R.failed("参数不能为空");
|
// if (visualBody == null) return R.failed("参数不能为空");
|
||||||
|
//
|
||||||
if (visualBody.getDatabaseName() == null ||
|
// if (visualBody.getDatabaseName() == null ||
|
||||||
visualBody.getPhase() == null || visualBody.getBIS() == null ||
|
// visualBody.getPhase() == null || visualBody.getBIS() == null ||
|
||||||
visualBody.getHR() == null || visualBody.getSBP() == null ||
|
// visualBody.getHR() == null || visualBody.getSBP() == null ||
|
||||||
visualBody.getDBP() == null || visualBody.getST() == null ||
|
// visualBody.getDBP() == null || visualBody.getST() == null ||
|
||||||
visualBody.getTEMP() == null || visualBody.getSP02() == null ||
|
// visualBody.getTEMP() == null || visualBody.getSP02() == null ||
|
||||||
visualBody.getEtCO2() == null || visualBody.getPPG() == null ||
|
// visualBody.getEtCO2() == null || visualBody.getPPG() == null ||
|
||||||
visualBody.getABG() == null || visualBody.getTOF() == null ||
|
// visualBody.getABG() == null || visualBody.getTOF() == null ||
|
||||||
visualBody.getTIME() == null) {
|
// visualBody.getTIME() == null) {
|
||||||
return R.failed("参数含有空值");
|
// return R.failed("参数含有空值");
|
||||||
}
|
// }
|
||||||
saveVitalBodyDataAsync(visualBody);
|
// saveVitalBodyDataAsync(visualBody);
|
||||||
return R.ok("success");
|
// return R.ok("success");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 关闭数据源
|
// // 关闭数据源
|
||||||
@PostMapping("/close")
|
// @PostMapping("/close")
|
||||||
@Inner(value = false)
|
// @Inner(value = false)
|
||||||
public R<Object> closeDataSource(String databaseName) {
|
// public R<Object> closeDataSource(String databaseName) {
|
||||||
if (databaseName == null) {
|
// if (databaseName == null) {
|
||||||
return R.failed("参数不能为空");
|
// return R.failed("参数不能为空");
|
||||||
}
|
// }
|
||||||
dynamicDataSources.remove(databaseName);
|
// dynamicDataSources.remove(databaseName);
|
||||||
DynamicDataSource dynamicDataSource = dynamicDataSources.get(databaseName);
|
// DynamicDataSource dynamicDataSource = dynamicDataSources.get(databaseName);
|
||||||
if (dynamicDataSource == null) {
|
// if (dynamicDataSource == null) {
|
||||||
return R.failed("数据源不存在");
|
// return R.failed("数据源不存在");
|
||||||
}
|
// }
|
||||||
dynamicDataSource.closeDataSource();
|
// dynamicDataSource.closeDataSource();
|
||||||
return R.ok("success");
|
// return R.ok("success");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void saveVitalBodyDataAsync(VisualBody visualBody) {
|
// private void saveVitalBodyDataAsync(VisualBody visualBody) {
|
||||||
executorService.execute(() -> {
|
// executorService.execute(() -> {
|
||||||
try {
|
// try {
|
||||||
|
//
|
||||||
String databaseName = visualBody.getDatabaseName();
|
// String databaseName = visualBody.getDatabaseName();
|
||||||
if (!dynamicDataSources.containsKey(databaseName)) {
|
// if (!dynamicDataSources.containsKey(databaseName)) {
|
||||||
// 创建动态数据源
|
// // 创建动态数据源
|
||||||
System.out.println("连接池创建数据源");
|
// System.out.println("连接池创建数据源");
|
||||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
// DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||||
dynamicDataSource.createDataSource(databaseName);
|
// dynamicDataSource.createDataSource(databaseName);
|
||||||
dynamicDataSources.put(databaseName, dynamicDataSource);
|
// dynamicDataSources.put(databaseName, dynamicDataSource);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (dynamicDataSources.get(databaseName) == null) {
|
// if (dynamicDataSources.get(databaseName) == null) {
|
||||||
dynamicDataSources.remove(databaseName);
|
// dynamicDataSources.remove(databaseName);
|
||||||
throw new RuntimeException("数据源不存在");
|
// throw new RuntimeException("数据源不存在");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 获取连接
|
// // 获取连接
|
||||||
Connection connection = dynamicDataSources.get(databaseName).getConnection();
|
// Connection connection = dynamicDataSources.get(databaseName).getConnection();
|
||||||
|
//
|
||||||
if (connection == null) {
|
// if (connection == null) {
|
||||||
throw new RuntimeException("数据库连接失败");
|
// throw new RuntimeException("数据库连接失败");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 数据库操作
|
// // 数据库操作
|
||||||
String sql = String.format("""
|
// String sql = String.format("""
|
||||||
INSERT INTO %s
|
// INSERT INTO %s
|
||||||
(Phase, BIS, HR, SBP, DBP, ST, TEMP, SPO2, EtCO2, PPG, ABG, TOF, `TIME`)
|
// (Phase, BIS, HR, SBP, DBP, ST, TEMP, SPO2, EtCO2, PPG, ABG, TOF, `TIME`)
|
||||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);
|
// VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);
|
||||||
""", FEATURE_TABLE_NAME);
|
// """, FEATURE_TABLE_NAME);
|
||||||
PreparedStatement ps = connection.prepareStatement(sql);
|
// PreparedStatement ps = connection.prepareStatement(sql);
|
||||||
ps.setInt(1, visualBody.getPhase());
|
// ps.setInt(1, visualBody.getPhase());
|
||||||
ps.setDouble(2, visualBody.getBIS());
|
// ps.setDouble(2, visualBody.getBIS());
|
||||||
ps.setDouble(3, visualBody.getHR());
|
// ps.setDouble(3, visualBody.getHR());
|
||||||
ps.setDouble(4, visualBody.getSBP());
|
// ps.setDouble(4, visualBody.getSBP());
|
||||||
ps.setDouble(5, visualBody.getDBP());
|
// ps.setDouble(5, visualBody.getDBP());
|
||||||
ps.setDouble(6, visualBody.getST());
|
// ps.setDouble(6, visualBody.getST());
|
||||||
ps.setDouble(7, visualBody.getTEMP());
|
// ps.setDouble(7, visualBody.getTEMP());
|
||||||
ps.setDouble(8, visualBody.getSP02());
|
// ps.setDouble(8, visualBody.getSP02());
|
||||||
ps.setDouble(9, visualBody.getEtCO2());
|
// ps.setDouble(9, visualBody.getEtCO2());
|
||||||
ps.setDouble(10, visualBody.getPPG());
|
// ps.setDouble(10, visualBody.getPPG());
|
||||||
ps.setDouble(11, visualBody.getABG());
|
// ps.setDouble(11, visualBody.getABG());
|
||||||
ps.setDouble(12, visualBody.getTOF());
|
// ps.setDouble(12, visualBody.getTOF());
|
||||||
ps.setTimestamp(13, visualBody.getTIME());
|
// ps.setTimestamp(13, visualBody.getTIME());
|
||||||
ps.execute();
|
// ps.execute();
|
||||||
} catch (SQLException e) {
|
// } catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
@ -116,8 +116,8 @@ spring:
|
||||||
port: 16373
|
port: 16373
|
||||||
password: rax137839
|
password: rax137839
|
||||||
connect-timeout: 5000
|
connect-timeout: 5000
|
||||||
database: 0 # 二期
|
# database: 0 # 二期
|
||||||
# database: 1 # 一期
|
database: 1 # 一期
|
||||||
|
|
||||||
# 数据库相关配置
|
# 数据库相关配置
|
||||||
datasource:
|
datasource:
|
||||||
|
@ -125,13 +125,13 @@ spring:
|
||||||
username: root
|
username: root
|
||||||
password: Xg137839
|
password: Xg137839
|
||||||
# 一期
|
# 一期
|
||||||
# url: jdbc:mysql://110.41.142.124:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://110.41.142.124:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||||
# 二期
|
# 二期
|
||||||
url: jdbc:mysql://110.41.142.124: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://110.41.142.124:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
|
||||||
|
|
||||||
server:
|
server:
|
||||||
# port: 6679 #一期
|
port: 6679 #一期
|
||||||
port: 6379 #二期
|
# port: 6379 #二期
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /admin
|
context-path: /admin
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user