From bc9f1d7da8894727940e5fe4c99182977f06d960 Mon Sep 17 00:00:00 2001 From: lxd <1004405501@qq.com> Date: Thu, 1 Aug 2024 15:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=94=A8=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=95=B0=E6=8D=AE=E5=BA=93JDBCD=E7=B1=BB=20=20Databas?= =?UTF-8?q?eUtils=20=20=E8=AE=BF=E9=97=AE=E4=B8=8D=E5=90=8C=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=20=E5=A2=9E=E5=8A=A0=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applyregistration/DatabaseUtils.java | 92 +++++++++++++++++++ .../pom.xml | 6 ++ .../admin/applyform/ApplyformController.java | 51 ++++++++++ .../service/apiconfig/ApiconfigService.java | 1 + .../apiconfig/ApiconfigServiceImpl.java | 6 ++ .../PatientexamlistController.java | 5 + .../PatientexamlistMapper.java | 2 +- 7 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 yudao-module-applyregistration/yudao-module-applyregistration-api/src/main/java/cn/iocoder/yudao/module/applyregistration/DatabaseUtils.java diff --git a/yudao-module-applyregistration/yudao-module-applyregistration-api/src/main/java/cn/iocoder/yudao/module/applyregistration/DatabaseUtils.java b/yudao-module-applyregistration/yudao-module-applyregistration-api/src/main/java/cn/iocoder/yudao/module/applyregistration/DatabaseUtils.java new file mode 100644 index 000000000..09e910293 --- /dev/null +++ b/yudao-module-applyregistration/yudao-module-applyregistration-api/src/main/java/cn/iocoder/yudao/module/applyregistration/DatabaseUtils.java @@ -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> executeQuery(DatabaseType type, String sql) throws SQLException, ClassNotFoundException { + List> 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 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(); + } + } +} \ No newline at end of file diff --git a/yudao-module-applyregistration/yudao-module-applyregistration-biz/pom.xml b/yudao-module-applyregistration/yudao-module-applyregistration-biz/pom.xml index 442aaf5a0..a9a5a4dc0 100644 --- a/yudao-module-applyregistration/yudao-module-applyregistration-biz/pom.xml +++ b/yudao-module-applyregistration/yudao-module-applyregistration-biz/pom.xml @@ -120,6 +120,12 @@ com.xingyuv spring-boot-starter-captcha-plus + + cn.iocoder.boot + yudao-module-system-biz + 2.1.0-jdk8-snapshot + compile + diff --git a/yudao-module-applyregistration/yudao-module-applyregistration-biz/src/main/java/cn/iocoder/yudao/module/applyregistration/controller/admin/applyform/ApplyformController.java b/yudao-module-applyregistration/yudao-module-applyregistration-biz/src/main/java/cn/iocoder/yudao/module/applyregistration/controller/admin/applyform/ApplyformController.java index cb012d985..6a052b59e 100644 --- a/yudao-module-applyregistration/yudao-module-applyregistration-biz/src/main/java/cn/iocoder/yudao/module/applyregistration/controller/admin/applyform/ApplyformController.java +++ b/yudao-module-applyregistration/yudao-module-applyregistration-biz/src/main/java/cn/iocoder/yudao/module/applyregistration/controller/admin/applyform/ApplyformController.java @@ -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> getApplyformPage(@Valid ApplyformPageReqVO pageReqVO) { + //获取当前登陆用户 + AdminUserDO user = userService.getUser(getLoginUserId()); + pageReqVO.setOrgId(user.getOrgId()) ; PageResult 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 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> 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); + } } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigService.java index 717b48c5b..9b021e1c7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigService.java @@ -55,4 +55,5 @@ public interface ApiconfigService { boolean GetApiCodeIsExist(String AppCode); + ApiconfigDO getApiCodeconfig(String AppCode); } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigServiceImpl.java index d27b61267..4aa9a8062 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/apiconfig/ApiconfigServiceImpl.java @@ -84,4 +84,10 @@ public class ApiconfigServiceImpl implements ApiconfigService { return bol; } + @Override + public ApiconfigDO getApiCodeconfig(String AppCode) { + + return apiconfigMapper.selectOne("ApiCode",AppCode); + } + } \ No newline at end of file diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java index 340cc8557..4af019762 100644 --- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java @@ -95,6 +95,11 @@ public class PatientexamlistController { @Operation(summary = "获得PACS检查列表分页") @PreAuthorize("@ss.hasPermission('tblist:patientexamlist:query')") public CommonResult> getPatientexamlistPage(@Valid PatientexamlistPageReqVO pageReqVO) { + + //获取当前登陆用户 + AdminUserDO user = userService.getUser(getLoginUserId()); + pageReqVO.setOrgId(user.getOrgId()) ; + PageResult pageResult = patientexamlistService.getPatientexamlistPage(pageReqVO); List doList=new ArrayList<>(); String devicetype=pageReqVO.getDeviceType(); diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/dal/mysql/patientexamlist/PatientexamlistMapper.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/dal/mysql/patientexamlist/PatientexamlistMapper.java index 8b0c63190..e5288992d 100644 --- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/dal/mysql/patientexamlist/PatientexamlistMapper.java +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/dal/mysql/patientexamlist/PatientexamlistMapper.java @@ -42,7 +42,7 @@ public interface PatientexamlistMapper extends BaseMapperX { .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)); }