6c
5 天以前 80a310f54039fabd20aecc2677fe6bbc191f4a5c
src/main/java/com/product/server/report/service/ReportDatasourceService.java
@@ -1,21 +1,8 @@
package com.product.server.report.service;
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.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;
import org.springframework.stereotype.Component;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.connection.ConnectionManager;
@@ -25,11 +12,25 @@
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.core.util.ReflectUtil;
import com.product.server.report.config.CmnConst;
import com.product.server.report.config.ReportCode;
import com.product.server.report.service.idel.IReportDatasourceService;
import com.product.server.report.util.QuerySqlParseUtil;
import com.product.util.BaseUtil;
import com.product.util.CallBack;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.sql.*;
import java.util.Date;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
public class ReportDatasourceService extends AbstractBaseService implements IReportDatasourceService {
@@ -255,13 +256,27 @@
        String executeContent;
        String resultValue;
        for (String ternaryOperator : ternaryOperatorSuitList) {
            executeContent = ternaryOperator.substring(2, ternaryOperator.length() - 2);
            executeContent = ternaryOperator.substring(2, ternaryOperator.length() - 2).trim();
            try {
                resultValue = BaseUtil.executeExpression(executeContent).toString();
                String reg = "\\w+\\.\\w+\\((\\w+)?((,\\w+)*)?\\)";
                if (executeContent.matches(reg)) {
                    // bean调用方法处理
                    int split1 = executeContent.indexOf(".");
                    int split2 = executeContent.indexOf("(");
                    String beanName = executeContent.substring(0, split1);
                    String methodName = executeContent.substring(split1 + 1, split2);
                    String paramStr = executeContent.substring(split2 + 1, executeContent.length() - 1);
                    if (StringUtils.isEmpty(paramStr)) {
                        resultValue = ReflectUtil.invoke(beanName, methodName, new Object[]{}).toString();
                    } else {
                        resultValue = ReflectUtil.invoke(beanName, methodName, Arrays.asList(paramStr.split(",")).toArray()).toString();
                    }
                } else {
                    resultValue = BaseUtil.executeExpression(executeContent).toString();
                }
                sql = sql.replace(ternaryOperator, resultValue);
            } catch (Exception e) {
                SpringMVCContextHolder.getSystemLogger().error(e);
                sql = sql.replace(ternaryOperator, "");
                throw new BaseException(ReportCode.APPLY_SQL_FAIL.getValue(), ReportCode.APPLY_SQL_FAIL.getText() + e.getMessage());
            }
        }
        sql = sql.replaceAll("\\[\\[((?!\\[).)+\\]\\]", "")