andy 1 year ago
parent
commit
e593c3adb7

+ 9 - 2
pom.xml

@@ -29,11 +29,18 @@
             <artifactId>kafka-clients</artifactId>
         </dependency>
         <!-- https://mvnrepository.com/artifact/com.ibm.mq/com.ibm.mq.jakarta.client -->
+<!--        <dependency>-->
+<!--            <groupId>com.ibm.mq</groupId>-->
+<!--            <artifactId>mq-jms-spring-boot-starter</artifactId>-->
+<!--            <version>3.2.1</version>-->
+<!--        </dependency>-->
+        <!-- https://mvnrepository.com/artifact/com.ibm.mq/com.ibm.mq.jakarta.client -->
         <dependency>
             <groupId>com.ibm.mq</groupId>
-            <artifactId>mq-jms-spring-boot-starter</artifactId>
-            <version>3.2.1</version>
+            <artifactId>com.ibm.mq.jakarta.client</artifactId>
+            <version>9.3.4.1</version>
         </dependency>
+
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jms</artifactId>

+ 1 - 2
src/main/java/com/scbfkj/uni/UniApplication.java

@@ -1,13 +1,12 @@
 package com.scbfkj.uni;
 
-import com.ibm.mq.spring.boot.MQAutoConfiguration;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-@SpringBootApplication(exclude = {ElasticsearchRestClientAutoConfiguration.class, MQAutoConfiguration.class})
+@SpringBootApplication(exclude = {ElasticsearchRestClientAutoConfiguration.class})
 @EnableAspectJAutoProxy
 @EnableScheduling
 public class UniApplication {

+ 51 - 24
src/main/java/com/scbfkj/uni/process/DataBase.java

@@ -371,44 +371,71 @@ public class DataBase {
         return names;
     }
 
-    public List<Map<String, String>> getColumnsByConnection(String connection, String catalog, String tableName) {
+    public List<Map<String, String>> getColumnsByConnection(String connection, String tableName) throws Exception {
 
         ResultSet resultSet;
         DatabaseMetaData metaData;
         ArrayList<Map<String, String>> result = new ArrayList<>();
-        try (Connection conn = getDataSourcePool(connection).getConnection()) {
-            metaData = conn.getMetaData();
-            resultSet = metaData.getColumns(catalog, null, tableName, null);
+        Connection conn = getDataSourcePool(connection).getConnection();
+        metaData = conn.getMetaData();
+
+        if(connection.contains("jdbc:kingbase") || connection.contains("jdbc:postgres")) {
+            resultSet = metaData.getColumns(null, "public", tableName, null);
+        }else if(connection.contains("jdbc:oracle") ) {
+            resultSet = metaData.getColumns(null, conn.getMetaData().getUserName(), tableName, null);
+        }else{
+            resultSet = metaData.getColumns(conn.getCatalog(), null, tableName, null);
+        }
 
-            while (resultSet.next()) {
-                HashMap<String, String> value = new HashMap<>();
-                String columnName = resultSet.getString("COLUMN_NAME"); // 获取字段名
-                value.put("name", columnName);
-                String columnType = resultSet.getString("TYPE_NAME"); // 获取字段类型
-                value.put("typeName", columnType);
-                String remarks = resultSet.getString("REMARKS"); // 获取字段注释
-                value.put("remarks", remarks);
-                value.put("isPrimaryKey", resultSet.getString("IS_AUTOINCREMENT"));// 判断是否为主键
-                result.add(value);
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+//        resultSet = metaData.getColumns(catalog, null, tableName, null);
+        ResultSet primaryKeys = metaData.getPrimaryKeys(conn.getCatalog(), null, tableName);
+        List<String> primaryKeyColumns = new ArrayList<>();
+        while (primaryKeys.next()) {
+            String name = primaryKeys.getString("COLUMN_NAME");
+            primaryKeyColumns.add(name);
         }
+
+        ResultSet uniqueKeys = metaData.getIndexInfo(conn.getCatalog(), null, tableName, true, false);
+        List<String> uniqueKeyColumns = new ArrayList<>();
+        while (uniqueKeys.next()) {
+            String name = uniqueKeys.getString("COLUMN_NAME");
+            uniqueKeyColumns.add(name);
+        }
+
+        while (resultSet.next()) {
+            HashMap<String, String> value = new HashMap<>();
+            String columnName = resultSet.getString("COLUMN_NAME"); // 获取字段名
+            value.put("name", columnName);
+            String columnType = resultSet.getString("TYPE_NAME"); // 获取字段类型
+            value.put("typeName", columnType);
+            String remarks = resultSet.getString("REMARKS"); // 获取字段注释
+            value.put("remarks", remarks);
+
+            value.put("isPrimaryKey", primaryKeyColumns.contains(columnName) ? "YES" : "NO");// 判断是否为主键
+            value.put("isUniqueKey", uniqueKeyColumns.contains(columnName) ? "YES" : "NO");// 判断是否为唯一键
+            result.add(value);
+        }
+
         return result;
     }
 
-    public List<Map<String, String>> getColumnsByDataSourceId(String dataSourceId, String catalog, String tableName) throws Exception {
-        return getColumnsByConnection(queryConnectionStr(dataSourceId), catalog, tableName);
+    public List<Map<String, String>> getColumnsByDataSourceId(String dataSourceId, String tableName) throws Exception {
+        return getColumnsByConnection(queryConnectionStr(dataSourceId), tableName);
     }
 
-    public List<String> getTablesByConnection(String connection, String catalog) {
+    public List<String> getTablesByConnection(String connection) {
         ResultSet resultSet;
         DatabaseMetaData metaData;
         ArrayList<String> result = new ArrayList<>();
         try (Connection conn = getDataSourcePool(connection).getConnection()) {
             metaData = conn.getMetaData();
-            resultSet = metaData.getTables(catalog, null, null, new String[]{"TABLE"});
-
+            if(connection.contains("jdbc:kingbase") || connection.contains("jdbc:postgres")) {
+                resultSet = metaData.getTables(null, "public", null, new String[]{"TABLE"});
+            }else if(connection.contains("jdbc:oracle") ) {
+                resultSet = metaData.getTables(null, conn.getMetaData().getUserName(), "%", new String[]{"TABLE"});
+            }else{
+                resultSet = metaData.getTables(conn.getCatalog(), null, null, new String[]{"TABLE"});
+            }
             while (resultSet.next()) {
                 String tableName = resultSet.getString("TABLE_NAME"); // 获取字段名
 
@@ -420,8 +447,8 @@ public class DataBase {
         return result;
     }
 
-    public List<String> getTablesByDataSourceId(String dataSourceId, String catalog) throws Exception {
-        return getTablesByConnection(queryConnectionStr(dataSourceId), catalog);
+    public List<String> getTablesByDataSourceId(String dataSourceId) throws Exception {
+        return getTablesByConnection(queryConnectionStr(dataSourceId));
     }
 
     public List<Map<String, Object>> getResult(String connection, String sql, ResultSet resultSet) throws SQLException {

+ 2 - 1
src/main/java/com/scbfkj/uni/service/DataProcessService.java

@@ -131,7 +131,8 @@ public class DataProcessService {
 
                     String preCode;
 //                    前置算法参数
-                    List<Object> params = getParams(Optional.ofNullable(preparameterset).map(DataFormatUtil::toString).orElse(null), source);
+                    List<Object> params = new ArrayList<>(getParams(Optional.ofNullable(preparameterset).map(DataFormatUtil::toString).orElse(null), source));
+
                     params.add(0, DataFormatUtil.toString(preConditions));
                     Map<String, Object> eval = JsScriptEngineUtil.eval(params.toArray());
 

+ 25 - 0
src/test/java/com/scbfkj/uni/library/JsonPathTest.java

@@ -0,0 +1,25 @@
+package com.scbfkj.uni.library;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+public class JsonPathTest {
+    @Test
+    void test1() throws JsonProcessingException {
+        ObjectMapper objectMapper = new ObjectMapper();
+        JsonNode jsonNode = objectMapper.readTree("""
+                                [{
+                  "serviceid": "133",
+                  "datacontent": [{
+                    "datasourceid": "13",
+                    "tableName": "datasource"
+                  }],
+                  "event": "0",
+                  "page": 1,
+                  "size": 9999
+                }]""");
+        System.out.println(jsonNode.at("/0/datacontent/0/datasourceid"));
+    }
+}