Browse Source

20250220 zhao_gqing
修改:接收报文及sql报错

zhao_gqing 2 months ago
parent
commit
e5fd9c2ede

+ 1 - 1
src/main/java/com/sundata/internalevaluation/calc/util/CalcUtil.java

@@ -36,7 +36,7 @@ public class CalcUtil {
      * @return 计算结果
      */
     public static CalcTaskResult calcRules(String calculateInstanceNumber, String rulesNo, Map<String, Object> context) {
-        if (StringUtils.isNotBlank(rulesNo)) {
+        if (StringUtils.isBlank(rulesNo)) {
             throw new CalcException("数据集编号不能为空!!!");
         }
         SysReqRulesService rulesService = SpringUtil.getBean(SysReqRulesService.class);

+ 42 - 56
src/main/java/com/sundata/internalevaluation/conf/JsonToCalciteExample.java

@@ -20,74 +20,60 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 public class JsonToCalciteExample {
 
-    public static SchemaPlus jsonTotable(String aa) throws Exception {
+    public static SchemaPlus jsonTotable(String schemaName, String jsonDate)  {
         // 1. JSON 数据
-        String jsonData = """
-        {
-          "orders": [
-            { "order_id": 1, "user_id": 101, "amount": 250.0 },
-            { "order_id": 2, "user_id": 102, "amount": 300.0 }
-          ],
-          "users": [
-            { "user_id": 101, "name": "Alice" },
-            { "user_id": 102, "name": "Bob" }
-          ]
-        }
-        """;
 
-        // 2. 使用 Jackson 解析 JSON 数据
-        ObjectMapper objectMapper = new ObjectMapper();
-        JsonNode rootNode = objectMapper.readTree(aa);
-
-        // 3. 创建 Calcite Schema
-        Connection connection = DriverManager.getConnection("jdbc:calcite:");
-        CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
-
-        SchemaPlus rootSchema = calciteConnection.getRootSchema();
-        rootSchema.add("credite",new AbstractSchema());
-
-        // 注册 JSON 数据为表
-        rootNode.fields().forEachRemaining(entry -> {
-            String tableName = entry.getKey();
-            JsonNode tableData = entry.getValue();
-            rootSchema.add(tableName, new JsonScannableTable(Sources.of(tableData.toString())));
-        });
-
-        // 4. 执行 SQL 查询
-        Statement statement = connection.createStatement();
-        String sql = """
-            SELECT "input"."method"  
-            FROM "input" 
+        try{
+            // 2. 使用 Jackson 解析 JSON 数据
+            ObjectMapper objectMapper = new ObjectMapper();
+            JsonNode rootNode = objectMapper.readTree(jsonDate);
+
+            // 3. 创建 Calcite Schema
+            Connection connection = DriverManager.getConnection("jdbc:calcite:");
+            CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+
+            SchemaPlus rootSchema = calciteConnection.getRootSchema();
+
+            SchemaPlus schema = rootSchema.add(schemaName,new AbstractSchema());
+
+            // 注册 JSON 数据为表
+            rootNode.fields().forEachRemaining(entry -> {
+                String tableName = entry.getKey();
+                JsonNode tableData = entry.getValue();
+                schema.add(tableName, new JsonScannableTable(Sources.of(tableData.toString())));
+            });
+            // 4. 执行 SQL 查询
+            Statement statement = connection.createStatement();
+            String sql = """
+            SELECT "test"."input"."method"   FROM "test"."input" 
         """;
 
-        ResultSet resultSet = statement.executeQuery(sql);
-
-        // 打印查询结果
-        System.out.println("Query Results:");
-        while (resultSet.next()) {
-            /*System.out.printf("Order ID: %d, Amount: %.2f, Name: %s%n",
+            ResultSet resultSet = statement.executeQuery(sql);
+            while (resultSet.next()){
+                String method=resultSet.getString("method");
+                System.out.println(method);
+            }
+            // 打印查询结果
+           /*while (resultSet.next()) {
+            System.out.printf("Order ID: %d, Amount: %.2f, Name: %s%n",
                     resultSet.getInt("user_id"),
                     resultSet.getDouble("amount"),
-                    resultSet.getString("name"))*/;
-            System.out.println(resultSet.getString("method"));
+                    resultSet.getString("name"));
+
+           }*/
 
+            // 关闭连接
+            resultSet.close();
+            statement.close();
+            connection.close();
+            return rootSchema;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
 
-        // 关闭连接
-        resultSet.close();
-        statement.close();
-        connection.close();
-        //解析完成后开启新线程 保存数据至数据库
-        ExecutorService executor= Executors.newSingleThreadExecutor();
-        executor.execute(()-> System.out.println("ExecutorService is runing..."));
-        //保存至数据库
-        executor.shutdown();//关闭线程池
-        return rootSchema;
     }
 
     // 自定义表类实现

+ 2 - 2
src/main/java/com/sundata/internalevaluation/configuration/mybatis/IndexConfigMapper.xml

@@ -154,8 +154,8 @@
             i.INDEXNO as indexNo,
             i.INDEXNAME as indexName,
             i.INDEXLOGIC as indexLogic
-        from SYS_INDEX i inner join SYS_REQ_RULE_INDEX ri on i.indexNo = ri.indexNo
-        where ri.ruleNo = #{ruleNo}
+        from SYS_INDEX i inner join SYS_REQ_RULE_INDEX ri on i.indexNo = ri.index_No
+        where ri.rule_No = #{ruleNo}
 
 
     </select>

+ 56 - 17
src/main/java/com/sundata/product/rfEngine/PublicComponent/ProjectTeam/ProjectTeamComponent.java

@@ -1,33 +1,72 @@
 package com.sundata.product.rfEngine.PublicComponent.ProjectTeam;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+
+import com.fasterxml.jackson.databind.SerializationFeature;
 import com.sundata.internalevaluation.conf.JsonToCalciteExample;
 import org.apache.calcite.schema.SchemaPlus;
+import com.sundata.internalevaluation.calc.util.CalcUtil;
 
 public class ProjectTeamComponent {
-    public Map<String,Object> doJavaLogic(Map<String,Object> inputmap) throws Exception {
-        ObjectMapper objectMapper = new ObjectMapper();
-        String aa=objectMapper.writeValueAsString(inputmap);
-        System.out.println(aa);
-        /*aa= """
-        {
-          "orders": [
-            { "order_id": 1, "user_id": 101, "amount": 250.0 },
-            { "order_id": 2, "user_id": 102, "amount": 300.0 }
-          ],
-          "users": [
-            { "user_id": 101, "name": "Alice" },
-            { "user_id": 102, "name": "Bob" }
-          ]
+    public static Map<String,Object> doJavaLogic(Map<String, Object> inputmap) throws Exception {
+
+        CalcUtil.calcRules("","rules1001",inputmap);
+        String jsonDate="";
+        try {
+            ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
+            Map<String, Object> map = new HashMap<>();
+
+            List<Map<String, String>> list = new ArrayList<>();
+
+            Map<String, String> input1 = (Map<String, String>) inputmap.get("input");
+            Map<String, String> singleEntryMap = new HashMap<>();
+            for (Map.Entry<String, String> entry : input1.entrySet()) {
+                singleEntryMap.put(entry.getKey(), entry.getValue());
+            }
+            list.add(singleEntryMap);
+            map.put("input",list);
+            jsonDate = objectMapper.writeValueAsString(map);
+            System.out.println(jsonDate);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
+
+
+        /*jsonDate="""
+        {"input":[{"custNo":"890629176414044160","method":"asyncRegularExecute"}]}
         """;*/
-        SchemaPlus rootSchema=JsonToCalciteExample.jsonTotable(aa);
-        System.out.println(aa);
+        String schemaName="test";
+        SchemaPlus rootSchema=JsonToCalciteExample.jsonTotable(schemaName,jsonDate);
+
 
 
         Map<String,Object> output=null;
         return output;
     }
 
+    public static void main(String[] args) throws Exception {
+        // 创建一个ObjectMapper实例,并启用INDENT_OUTPUT特性以便输出格式化的JSON
+        ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
+
+        // 创建一个简单的Map实例
+        Map<String, Object> map = new HashMap<>();
+
+
+        // 创建一个嵌套的Map,表示地址信息
+        Map<String, String> input = new HashMap<>();
+        input.put("custNo", "890629176414044160");
+        input.put("method", "asyncRegularExecute");
+        map.put("input", input);
+        doJavaLogic(map);
+
+        // 使用ObjectMapper将Map转换为JSON字符串
+        String jsonString = objectMapper.writeValueAsString(map);
+
+        // 打印JSON字符串
+        System.out.println(jsonString);
+    }
+
 }