增加通用访问数据库JDBCD类 DatabaseUtils 访问不同的数据库 增加同步接口
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
bd491299b9
commit
bc9f1d7da8
@ -0,0 +1,92 @@
|
||||
package cn.iocoder.yudao.module.applyregistration;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class DatabaseUtils {
|
||||
|
||||
public enum DatabaseType {
|
||||
MYSQL, ORACLE, SQLSERVER
|
||||
}
|
||||
|
||||
// 数据库连接属性
|
||||
private static Properties connectionProps = new Properties();
|
||||
|
||||
// 动态设置数据库连接属性
|
||||
public static void setConnectionProperties(DatabaseType type,String url,String user,String password,String database,String port) {
|
||||
switch (type) {
|
||||
case MYSQL:
|
||||
connectionProps.setProperty("driver", "com.mysql.cj.jdbc.Driver");
|
||||
connectionProps.setProperty("url", "jdbc:mysql://"+url+":"+port+"/"+database);
|
||||
connectionProps.setProperty("user", user);
|
||||
connectionProps.setProperty("password", password);
|
||||
break;
|
||||
case ORACLE:
|
||||
connectionProps.setProperty("driver", "oracle.jdbc.driver.OracleDriver");
|
||||
connectionProps.setProperty("url", "jdbc:oracle:thin:@"+url+":"+port+":"+database);
|
||||
connectionProps.setProperty("user", user);
|
||||
connectionProps.setProperty("password", password);
|
||||
break;
|
||||
case SQLSERVER:
|
||||
connectionProps.setProperty("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
connectionProps.setProperty("url", "jdbc:sqlserver://"+url+":"+port+";databaseName="+database);
|
||||
connectionProps.setProperty("user", user);
|
||||
connectionProps.setProperty("password", password);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported database type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取数据库连接
|
||||
public static Connection getConnection(DatabaseType type) throws SQLException, ClassNotFoundException {
|
||||
// setConnectionProperties(type); // 确保连接属性已设置
|
||||
String driver = connectionProps.getProperty("driver");
|
||||
String url = connectionProps.getProperty("url");
|
||||
String user = connectionProps.getProperty("user");
|
||||
String password = connectionProps.getProperty("password");
|
||||
|
||||
Class.forName(driver);
|
||||
return DriverManager.getConnection(url, user, password);
|
||||
}
|
||||
|
||||
// 执行查询并返回结果集
|
||||
public static List<Map<String, Object>> executeQuery(DatabaseType type, String sql) throws SQLException, ClassNotFoundException {
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
try (Connection conn = getConnection(type);
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
row.put(metaData.getColumnName(i), rs.getObject(i));
|
||||
}
|
||||
results.add(row);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// 执行更新操作并返回影响的行数
|
||||
public static int executeUpdate(DatabaseType type, String sql) throws SQLException, ClassNotFoundException {
|
||||
try (Connection conn = getConnection(type);
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
|
||||
return pstmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭资源
|
||||
public static void close(ResultSet rs, PreparedStatement pstmt, Connection conn) {
|
||||
try {
|
||||
if (rs != null && !rs.isClosed()) rs.close();
|
||||
if (pstmt != null && !pstmt.isClosed()) pstmt.close();
|
||||
if (conn != null && !conn.isClosed()) conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -120,6 +120,12 @@
|
||||
<groupId>com.xingyuv</groupId>
|
||||
<artifactId>spring-boot-starter-captcha-plus</artifactId> <!-- 验证码,一般用于登录使用 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-module-system-biz</artifactId>
|
||||
<version>2.1.0-jdk8-snapshot</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,9 +1,14 @@
|
||||
package cn.iocoder.yudao.module.applyregistration.controller.admin.applyform;
|
||||
|
||||
import cn.iocoder.yudao.module.applyregistration.DatabaseUtils;
|
||||
import cn.iocoder.yudao.module.applyregistration.controller.admin.applyform.devicevo.DeviceVO;
|
||||
import cn.iocoder.yudao.module.applyregistration.controller.admin.applyform.devicevo.deviceupVO;
|
||||
import cn.iocoder.yudao.module.applyregistration.dal.device.DeviceDO;
|
||||
import cn.iocoder.yudao.module.applyregistration.service.applyform.device.DeviceService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.apiconfig.ApiconfigDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.apiconfig.ApiconfigService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
@ -16,6 +21,7 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@ -31,6 +37,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
import cn.iocoder.yudao.module.applyregistration.controller.admin.applyform.vo.*;
|
||||
import cn.iocoder.yudao.module.applyregistration.dal.dataobject.applyform.ApplyformDO;
|
||||
@ -53,6 +60,12 @@ public class ApplyformController {
|
||||
@Resource
|
||||
private DeviceService DeviceService;
|
||||
|
||||
@Resource
|
||||
private ApiconfigService apiconfigService;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建申请登记记录")
|
||||
@PreAuthorize("@ss.hasPermission('applyregistration:applyform:create')")
|
||||
@ -90,6 +103,9 @@ public class ApplyformController {
|
||||
@Operation(summary = "获得申请登记记录分页")
|
||||
@PreAuthorize("@ss.hasPermission('applyregistration:applyform:query')")
|
||||
public CommonResult<PageResult<ApplyformRespVO>> getApplyformPage(@Valid ApplyformPageReqVO pageReqVO) {
|
||||
//获取当前登陆用户
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
pageReqVO.setOrgId(user.getOrgId()) ;
|
||||
PageResult<ApplyformDO> pageResult = applyformService.getApplyformPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ApplyformRespVO.class));
|
||||
}
|
||||
@ -224,4 +240,39 @@ public class ApplyformController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/SyncDb")
|
||||
@PreAuthorize("@ss.hasPermission('applyregistration:applyform:query')")
|
||||
public CommonResult<Boolean> SyncDb(@RequestParam("AppCode") String AppCode) throws SQLException, ClassNotFoundException {
|
||||
//先从数据表中那对应的配置
|
||||
ApiconfigDO apiconfigDO= apiconfigService.getApiCodeconfig(AppCode);
|
||||
if(apiconfigDO!=null)
|
||||
{
|
||||
String sql=apiconfigDO.getApiUrl();
|
||||
switch ( apiconfigDO.getDatabaseType())
|
||||
{
|
||||
case "mysql":
|
||||
DatabaseUtils.setConnectionProperties(DatabaseUtils.DatabaseType.MYSQL,apiconfigDO.getDatabaseIP(),apiconfigDO.getDatabaseUserName(),apiconfigDO.getDatabasePwd(),apiconfigDO.getRemark(),apiconfigDO.getDatabasePort());
|
||||
DatabaseUtils.getConnection(DatabaseUtils.DatabaseType.MYSQL);
|
||||
List<Map<String, Object>> executeQuery = DatabaseUtils.executeQuery(DatabaseUtils.DatabaseType.MYSQL, sql);
|
||||
break;
|
||||
case "sqlserver":
|
||||
DatabaseUtils.setConnectionProperties(DatabaseUtils.DatabaseType.SQLSERVER,apiconfigDO.getDatabaseIP(),apiconfigDO.getDatabaseUserName(),apiconfigDO.getDatabasePwd(),apiconfigDO.getRemark(),apiconfigDO.getRemark());
|
||||
DatabaseUtils.getConnection(DatabaseUtils.DatabaseType.SQLSERVER);
|
||||
break;
|
||||
case "oracle":
|
||||
DatabaseUtils.setConnectionProperties(DatabaseUtils.DatabaseType.ORACLE,apiconfigDO.getDatabaseIP(),apiconfigDO.getDatabaseUserName(),apiconfigDO.getDatabasePwd(),apiconfigDO.getRemark(),apiconfigDO.getRemark());
|
||||
DatabaseUtils.getConnection(DatabaseUtils.DatabaseType.ORACLE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success(true);
|
||||
}
|
||||
}
|
@ -55,4 +55,5 @@ public interface ApiconfigService {
|
||||
|
||||
boolean GetApiCodeIsExist(String AppCode);
|
||||
|
||||
ApiconfigDO getApiCodeconfig(String AppCode);
|
||||
}
|
@ -84,4 +84,10 @@ public class ApiconfigServiceImpl implements ApiconfigService {
|
||||
return bol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiconfigDO getApiCodeconfig(String AppCode) {
|
||||
|
||||
return apiconfigMapper.selectOne("ApiCode",AppCode);
|
||||
}
|
||||
|
||||
}
|
@ -95,6 +95,11 @@ public class PatientexamlistController {
|
||||
@Operation(summary = "获得PACS检查列表分页")
|
||||
@PreAuthorize("@ss.hasPermission('tblist:patientexamlist:query')")
|
||||
public CommonResult<PageResult<PatientexamlistRespVO>> getPatientexamlistPage(@Valid PatientexamlistPageReqVO pageReqVO) {
|
||||
|
||||
//获取当前登陆用户
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
pageReqVO.setOrgId(user.getOrgId()) ;
|
||||
|
||||
PageResult<PatientexamlistDO> pageResult = patientexamlistService.getPatientexamlistPage(pageReqVO);
|
||||
List<PatientexamlistDO> doList=new ArrayList<>();
|
||||
String devicetype=pageReqVO.getDeviceType();
|
||||
|
@ -42,7 +42,7 @@ public interface PatientexamlistMapper extends BaseMapperX<PatientexamlistDO> {
|
||||
.betweenIfPresent(PatientexamlistDO::getReviewDate, reqVO.getReviewDate())
|
||||
.eqIfPresent(PatientexamlistDO::getThumbnailImgUrl, reqVO.getThumbnailImgUrl())
|
||||
.betweenIfPresent(PatientexamlistDO::getCreateTime, reqVO.getCreateTime())
|
||||
.inIfPresent(PatientexamlistDO::getOrgId, reqVO.getHighLevelOrgId())
|
||||
.eqIfPresent(PatientexamlistDO::getOrgId, reqVO.getHighLevelOrgId())
|
||||
.orderByDesc(PatientexamlistDO::getId));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user