|
@ -45,6 +45,8 @@ import javax.xml.namespace.QName;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -332,6 +334,98 @@ public class DatacollectService implements IDatacollectService {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取条件SQL
|
|
|
* @param dbType
|
|
|
* @param conditionString
|
|
|
* @return
|
|
|
* @throws ParseException
|
|
|
*/
|
|
|
private String getConditionSql(DBType dbType,String conditionString) throws ParseException {
|
|
|
String conditionSql = "";
|
|
|
JSONArray conditions = new JSONArray(conditionString);
|
|
|
Iterator iterator = conditions.iterator();
|
|
|
|
|
|
while (iterator.hasNext())
|
|
|
{
|
|
|
JSONObject condition = (JSONObject)iterator.next();
|
|
|
String logic = condition.getString("condition");
|
|
|
String andOr = condition.getString("andOr");
|
|
|
String field = condition.getString("field");
|
|
|
String value = condition.getString("value");
|
|
|
String fieldType = condition.getString("type");
|
|
|
String keys = "";
|
|
|
|
|
|
if(andOr.equals(" AND "))
|
|
|
{
|
|
|
conditionSql = conditionSql + " and ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
conditionSql = conditionSql + " or ";
|
|
|
}
|
|
|
|
|
|
if(logic.equals(" IN ") || logic.equals(" NOT IN "))
|
|
|
{
|
|
|
String[] keywords = value.split(",");
|
|
|
|
|
|
for(String key : keywords)
|
|
|
{
|
|
|
keys += "'" + key + "',";
|
|
|
}
|
|
|
|
|
|
keys = " (" + keys.substring(0,keys.length() - 1) + ") ";
|
|
|
}
|
|
|
else if(logic.equals(" LIKE "))
|
|
|
{
|
|
|
keys += " '%" + value + "%' ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(fieldType.equals("DATE"))
|
|
|
{
|
|
|
keys += getDateFormatSql(dbType,value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
keys += " '" + value + "' ";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
conditionSql += field + logic + keys;
|
|
|
}
|
|
|
|
|
|
return conditionSql;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取对应数据库时间格式
|
|
|
* @param dbType
|
|
|
* @param key
|
|
|
* @return
|
|
|
* @throws ParseException
|
|
|
*/
|
|
|
private String getDateFormatSql(DBType dbType,String key) throws ParseException {
|
|
|
String dateFormat = "yyyy-MM-dd HH:mm:ss";
|
|
|
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date d = formatDate.parse(key);
|
|
|
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
|
|
|
|
|
|
switch (dbType)
|
|
|
{
|
|
|
case Oracle:
|
|
|
key = "to_date(\'" + format.format(d) + "\',\'YYYY-MM-DD HH24:MI:SS\')";
|
|
|
break;
|
|
|
case Sqlserver:
|
|
|
|
|
|
break;
|
|
|
default:
|
|
|
key = "date_format(\'" + format.format(d) + "\',\'%y-%m-%d %T\')";
|
|
|
}
|
|
|
|
|
|
return key;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 采集入库
|
|
|
* @return
|
|
@ -430,7 +524,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
//采集范围
|
|
|
if(condition!=null && condition.length()>0)
|
|
|
{
|
|
|
strWhere += getCondition(dbType,condition);
|
|
|
strWhere += getConditionSql(dbType,condition);
|
|
|
}
|
|
|
//增量采集
|
|
|
String maxKey = "0";
|
|
@ -655,7 +749,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
String strWhere = " where 1=1";
|
|
|
//采集范围
|
|
|
if (condition != null && condition.length() > 0) {
|
|
|
strWhere += getCondition(dbType, condition);
|
|
|
strWhere += getConditionSql(dbType, condition);
|
|
|
}
|
|
|
//增量采集
|
|
|
String maxKey = "0";
|