| | |
| | | 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.common.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.ResponseTemplateUtil; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.entity.service.ServiceSql; |
| | | import com.java110.service.dao.IQueryServiceDAO; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/4/19. |
| | |
| | | if ("".equals(currentServiceSql.getQueryModel())) { |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); |
| | | } |
| | | //请求参数校验 |
| | | List<String> sysParams = currentServiceSql.getParamList(); |
| | | for(String param : sysParams) { |
| | | if(!dataQuery.getRequestParams().containsKey(param)){ |
| | | throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,"请求参数错误,请求报文中未包含参数 " + param + " 信息"); |
| | | } |
| | | } |
| | | dataQuery.setServiceSql(currentServiceSql); |
| | | if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { |
| | | doExecuteSql(dataQuery); |
| | |
| | | doExecuteProc(dataQuery); |
| | | }catch (BusinessException e){ |
| | | logger.error("公用查询异常:",e); |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | e.getMessage())); |
| | | } |
| | | |
| | |
| | | doExecuteUpdateProc(dataQuery); |
| | | }catch (BusinessException e){ |
| | | logger.error("公用查询异常:",e); |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | e.getMessage())); |
| | | } |
| | | |
| | |
| | | param = param.substring(0,param.length()-1); |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",JSONObject.parseObject(interpreter.eval("execute("+param+")").toString()))); |
| | | }catch (Exception e){ |
| | | logger.error("数据交互异常:",e); |
| | |
| | | } |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",business)); |
| | | } |
| | | |
| | |
| | | continue; |
| | | } |
| | | if (sqls[sqlIndex].startsWith("PARENT_")) { |
| | | if(obj.isEmpty()){ |
| | | currentSqlNew += "?"; |
| | | currentParams.add("''"); |
| | | continue; |
| | | } |
| | | for (String key : obj.keySet()) { |
| | | if (sqls[sqlIndex].substring("PARENT_".length()).equals(key)) { |
| | | /*currentSqlNew += obj.get(key) instanceof Integer |
| | | ? obj.getInteger(key) : "'" + obj.getString(key) + "'";*/ |
| | | currentSqlNew += "?"; |
| | | currentParams.add(obj.get(key) instanceof Integer |
| | | ? obj.getInteger(key) : "'" + obj.getString(key) + "'"); |
| | | ? obj.getInteger(key) : "" + obj.getString(key) + ""); |
| | | continue; |
| | | } |
| | | } |
| | | } else { |
| | | currentSqlNew += "?"; |
| | | currentParams.add(params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "'" + params.getString(sqls[sqlIndex]) + "'"); |
| | | currentParams.add(params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "" + params.getString(sqls[sqlIndex]) + ""); |
| | | //currentSqlNew += params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "'" + params.getString(sqls[sqlIndex]) + "'"; |
| | | } |
| | | } |
| | |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",JSONObject.parseObject(jsonStr))); |
| | | } |
| | | |
| | |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",JSONObject.parseObject(jsonStr))); |
| | | } |
| | | |