|
@ -0,0 +1,109 @@
|
|
|
package com.yihu.hos.test;
|
|
|
|
|
|
import com.yihu.ehr.dbhelper.common.DBList;
|
|
|
import com.yihu.ehr.dbhelper.common.DBQuery;
|
|
|
import com.yihu.ehr.dbhelper.common.QueryCondition;
|
|
|
import com.yihu.ehr.dbhelper.common.enums.DBType;
|
|
|
import com.yihu.ehr.dbhelper.common.sqlparser.ParserMysql;
|
|
|
import com.yihu.ehr.dbhelper.common.sqlparser.ParserOracle;
|
|
|
import com.yihu.ehr.dbhelper.common.sqlparser.ParserSql;
|
|
|
import com.yihu.ehr.dbhelper.common.sqlparser.ParserSqlserver;
|
|
|
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
|
|
|
import com.yihu.hos.gateway.exception.EHRException;
|
|
|
import com.yihu.hos.gateway.exception.EHRExceptionConstant;
|
|
|
import com.yihu.hos.gateway.model.rest.RestRequsetResult;
|
|
|
import com.yihu.hos.gateway.model.rest.RestResponseResult;
|
|
|
import com.yihu.hos.gateway.thread.ResponseThread;
|
|
|
import com.yihu.hos.resource.viewModel.ResourceRestDetailModel;
|
|
|
import com.yihu.hos.resource.viewModel.SQLResponResult;
|
|
|
import net.sf.json.JSON;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.Writer;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2016/5/12.
|
|
|
*/
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/test")
|
|
|
public class TestController {
|
|
|
@ResponseBody
|
|
|
@RequestMapping("/db")
|
|
|
public String db(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
String tablename = request.getParameter("table");
|
|
|
/**
|
|
|
* [{"andOr":" AND ","field":"HDSD00_01_457","condition":" > ","value":"2016-05-12"},
|
|
|
* {"andOr":" AND ","field":"JDSA00_01_010","condition":" < ","value":"120"}]
|
|
|
*/
|
|
|
String params = request.getParameter("params");
|
|
|
String key = request.getParameter("key");
|
|
|
String keytype = request.getParameter("keytype");
|
|
|
String start = request.getParameter("start");
|
|
|
String rows = request.getParameter("keytype");
|
|
|
String config = "jdbc:oracle:thin:newhos/newhos@//172.19.103.71:1521/neworcl";
|
|
|
DBHelper db = new DBHelper("1111", config);
|
|
|
DBType dbType = db.dbType;
|
|
|
String sqlWhere = getCondition(dbType, params);
|
|
|
//为空查询数据
|
|
|
DBQuery dbq = new DBQuery("1111", config);
|
|
|
String sql = "select * from " + tablename;
|
|
|
DBList dv = dbq.queryBySql(sql + sqlWhere, StringUtils.isEmpty(start) ? 1 : java.lang.Integer.valueOf(start), StringUtils.isEmpty(start) ? 10 : java.lang.Integer.valueOf(rows));
|
|
|
|
|
|
if (StringUtils.isEmpty(key)) {
|
|
|
return JSONObject.fromObject(dv.getList()).toString();
|
|
|
} else {
|
|
|
String sqlT = "select max(" + key + ") from " + tablename;
|
|
|
//不为空查询总条数和最大值
|
|
|
return "{\"count\":\"" + dv.getCount() + "\",\"maxKeyvalue\":\"9999\"}";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取过滤条件
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getCondition(DBType dbType, String conditionString) {
|
|
|
org.json.JSONArray array = new org.json.JSONArray(conditionString);
|
|
|
|
|
|
if (array != null && array.length() > 0) {
|
|
|
List<QueryCondition> conditions = new ArrayList<>();
|
|
|
for (Object item : array) {
|
|
|
JSONObject obj = (JSONObject) item;
|
|
|
String logical = obj.getString("andOr");
|
|
|
String operation = obj.getString("condition");
|
|
|
String field = obj.getString("field");
|
|
|
String keyword = obj.getString("value");
|
|
|
conditions.add(new QueryCondition(logical, operation, field, keyword));
|
|
|
}
|
|
|
//条件语句转换
|
|
|
ParserSql ps;
|
|
|
switch (dbType) {
|
|
|
case Oracle:
|
|
|
ps = new ParserOracle();
|
|
|
break;
|
|
|
case Sqlserver:
|
|
|
ps = new ParserSqlserver();
|
|
|
break;
|
|
|
default:
|
|
|
ps = new ParserMysql();
|
|
|
}
|
|
|
return ps.getConditionSql(conditions);
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|