许鹏程
2023-06-29 cb4df5a1c9cda76e828fa202990df33be0735105
src/main/java/com/product/server/report/service/ReportDatasourceService.java
@@ -1,18 +1,16 @@
package com.product.server.report.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.service.support.QueryFilterService;
import com.product.server.report.util.QuerySqlParseUtil;
import com.product.util.BaseUtil;
import com.product.util.CallBack;
import org.springframework.beans.factory.annotation.Autowired;
@@ -148,7 +146,7 @@
    /**
     * sql解析与验证
     *
     * @param sqlText
     * @param fse
     * @return
     */
    public DataTableEntity sqlVerify(FieldSetEntity fse) throws SQLException {
@@ -266,15 +264,18 @@
                sql = sql.replace(ternaryOperator, "");
            }
        }
        sql = sql.replaceAll("\\[\\[((?!\\[).)+\\]\\]", "");
        sql = sql.replaceAll("\\[\\[((?!\\[).)+\\]\\]", "")
                .replaceAll("and\\s+1\\s*=\\s*1", "")
                .replaceAll("\\{=.+=\\}", "")
                .replaceAll("(\\t*\\n){2,}", "\n");
        sql = QuerySqlParseUtil.parseSplitTableSql(baseDao, sql, true);
        SpringMVCContextHolder.getSystemLogger().info(sql);
        //与数据库的连接
        PreparedStatement ps = null;
        Connection con = null;
        con = ConnectionManager.getConnection();
        sql = sql.replaceAll("and\\s+1\\s*=\\s*1", "");
        ps = con.prepareStatement(sql);
        try (Connection con = ConnectionManager.getConnection();
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery()) {
        //结果集元数据
        ResultSetMetaData rsmd = ps.getMetaData();
            ResultSetMetaData rsmd = rs.getMetaData();
        //表列数
        int size = rsmd.getColumnCount();
        Set<String> fieldNameSet = Sets.newHashSet();
@@ -308,6 +309,7 @@
        }
        return dataTableEntity;
    }
    }
    /**
     * 根据数据源配置,查询出数据