java110
2020-07-07 70862b9228ccb2156971a22085ac31b6c8b6d2cd
java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -4,18 +4,18 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import com.java110.common.cache.ServiceSqlCache;
import com.java110.common.constant.CommonConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.exception.BusinessException;
import com.java110.core.factory.DataTransactionFactory;
import com.java110.common.log.LoggerEngine;
import com.java110.common.util.Assert;
import com.java110.common.util.StringUtil;
import com.java110.service.context.DataQuery;
import com.java110.db.dao.IQueryServiceDAO;
import com.java110.entity.service.ServiceSql;
import com.java110.service.dao.IQueryServiceDAO;
import com.java110.service.context.DataQuery;
import com.java110.service.smo.IQueryServiceSMO;
import com.java110.utils.cache.ServiceSqlCache;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.BusinessException;
import com.java110.utils.log.LoggerEngine;
import com.java110.utils.util.Assert;
import com.java110.utils.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlException;
@@ -116,6 +116,23 @@
            dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR,
                    e.getMessage()));
        }
    }
    @Override
    public ResponseEntity<String> fallBack(String fallBackInfo) throws BusinessException {
        JSONArray params = JSONArray.parseArray(fallBackInfo);
        for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
            JSONObject param = params.getJSONObject(paramIndex);
            String sql = param.getString("fallBackSql");
            if (StringUtil.isEmpty(sql)) {
                return new ResponseEntity<String>("未包含sql信息", HttpStatus.BAD_REQUEST);
            }
            int flag = queryServiceDAOImpl.updateSql(sql, null);
        }
        return new ResponseEntity<String>("回退成功", HttpStatus.OK);
    }
@@ -249,7 +266,10 @@
            String currentSql = sqlObj.getString(dataQuery.getTemplateKey());
            //处理 if 判断
            logger.debug("dealSqlIf开始处理sql中的<if>节点 " + currentSql + " 入参:" + params.toJSONString());
            currentSql = dealSqlIf(currentSql, params);
            logger.debug("dealSqlIf处理完成sql中的<if>节点 " + currentSql + " 入参:" + params.toJSONString());
            String[] sqls = currentSql.split("#");
            String currentSqlNew = "";
@@ -281,7 +301,7 @@
                        param = params.getInteger(sqls[sqlIndex]);
                    }
                    //这里对 page 和 rows 特殊处理 ,目前没有想到其他的办法
                    if (StringUtils.isNumeric(param.toString()) && "page,rows".contains(sqls[sqlIndex])) {
                    if (StringUtils.isNumeric(param.toString()) && "page,rows,row".contains(sqls[sqlIndex])) {
                        param = Integer.parseInt(param.toString());
                    }
                    currentParams.add(param);
@@ -340,6 +360,11 @@
        String[] oSqls = oldSql.split("</if>");
        for (String oSql : oSqls) {
            logger.debug("处理if 节点,当前处理的oSql=" + oSql + "总的oSqls = " + oSqls);
            if (StringUtil.isNullOrNone(oSql) || !oSql.contains("<if")) {
                newSql.append(oSql);
                continue;
            }
            if (!oSql.startsWith("<if")) {
                newSql.append(oSql.substring(0, oSql.indexOf("<if")));
            }
@@ -364,10 +389,11 @@
                newSql.append(root.getText());
            }
        }
        return newSql.toString();
        return newSql.toString().replace("&gt;", ">").replace("&lt;", "<");
    }