wuxw
2019-02-02 9454b49eeabd56894550f1419f14e96f9d10c2ef
java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -8,7 +8,7 @@
import com.java110.common.constant.CommonConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.exception.BusinessException;
import com.java110.common.factory.DataTransactionFactory;
import com.java110.core.factory.DataTransactionFactory;
import com.java110.common.log.LoggerEngine;
import com.java110.common.util.Assert;
import com.java110.common.util.StringUtil;
@@ -16,7 +16,12 @@
import com.java110.entity.service.ServiceSql;
import com.java110.service.dao.IQueryServiceDAO;
import com.java110.service.smo.IQueryServiceSMO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -32,12 +37,17 @@
@Transactional
public class QueryServiceSMOImpl extends LoggerEngine implements IQueryServiceSMO {
    private final static Logger logger = LoggerFactory.getLogger(QueryServiceSMOImpl.class);
    @Autowired
    private IQueryServiceDAO queryServiceDAOImpl;
    @Override
    public void commonQueryService(DataQuery dataQuery) throws BusinessException {
        //查询缓存查询 对应处理的ServiceSql
        ResponseEntity<String> responseEntity = null;
        try {
            ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode());
            if (currentServiceSql == null) {
@@ -56,17 +66,21 @@
            dataQuery.setServiceSql(currentServiceSql);
            if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) {
                doExecuteSql(dataQuery);
                return;
            }else if(CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())){
                doExecuteJava(dataQuery);
                return ;
            }else {
                doExecuteProc(dataQuery);
            }
            doExecuteProc(dataQuery);
            responseEntity = new ResponseEntity<String>(dataQuery.getResponseInfo().toJSONString(), HttpStatus.OK);
        }catch (BusinessException e){
            logger.error("公用查询异常:",e);
            dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR,
                    e.getMessage()));
            /*dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR,
                    e.getMessage()));*/
            responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }finally {
            dataQuery.setResponseEntity(responseEntity);
        }
    }
    @Override
@@ -254,7 +268,15 @@
                    }
                } else {
                    currentSqlNew += "?";
                    currentParams.add(params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "" + params.getString(sqls[sqlIndex]) + "");
                    Object param =  params.getString(sqls[sqlIndex]);
                    if(params.get(sqls[sqlIndex]) instanceof Integer){
                        param = params.getInteger(sqls[sqlIndex]);
                    }
                   //这里对 page 和 rows 特殊处理 ,目前没有想到其他的办法
                    if(StringUtils.isNumeric(param.toString()) && "page,rows".contains(sqls[sqlIndex])){
                        param = Integer.parseInt(param.toString());
                    }
                    currentParams.add(param);
                    //currentSqlNew += params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "'" + params.getString(sqls[sqlIndex]) + "'";
                }
            }
@@ -265,7 +287,7 @@
                if(StringUtil.isNullOrNone(values[1])){
                    return ;
                }
                obj.put(values[1], new JSONObject());
                obj.put(values[1], values[2].equals("Object")?new JSONObject():new JSONArray());
                return;
            }
            if (values[2].equals("Object")) {