新增方法
This commit is contained in:
@@ -163,6 +163,20 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper count(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.COUNT +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 统计平均值
|
||||
@@ -195,6 +209,19 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper mean(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.AVG +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
@@ -229,6 +256,21 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper median(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.MEDIAN +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 统计指定字段的最常出现的值
|
||||
* @author hongawen
|
||||
@@ -260,6 +302,19 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper mode(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.MODE +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 统计指定字段最大值和最小值的差
|
||||
@@ -293,6 +348,20 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper spread(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.SPREAD +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 统计指定字段值求和
|
||||
* @author hongawen
|
||||
@@ -324,6 +393,19 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper sum(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.SUM +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
this.getColumnName(measurement, columnName) +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
this.getColumnName(resultEntity, columnName) +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取指定字段最大值的集合
|
||||
@@ -347,6 +429,21 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper top(String columnName, int num) {
|
||||
String selectFragment = InfluxDbSqlConstant.TOP +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
StrPool.COMMA +
|
||||
num +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取指定字段最小值的集合
|
||||
@@ -371,6 +468,22 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper bottom(String columnName, int num) {
|
||||
String selectFragment = InfluxDbSqlConstant.BOTTOM +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
StrPool.COMMA +
|
||||
num +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 注:该函数还需调研,暂时不要用
|
||||
* 统计指定字段邻近值的变化率
|
||||
@@ -391,6 +504,18 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
@Deprecated
|
||||
public <T, R> InfluxQueryWrapper derivative(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.DERIVATIVE +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS_VALUE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 统计指定字段值时间戳最近的值
|
||||
@@ -411,6 +536,30 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper last(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.LAST +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS_VALUE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper last(String columnName,String resultName) {
|
||||
String selectFragment = InfluxDbSqlConstant.LAST +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
resultName;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 统计指定字段绝对值
|
||||
* @author hongawen
|
||||
@@ -443,6 +592,20 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper abs(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.ABS +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取指定字段最大值
|
||||
* @author hongawen
|
||||
@@ -475,6 +638,19 @@ public class InfluxQueryWrapper {
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper max(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.MAX +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
columnName +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
InfluxDbSqlConstant.RBK +
|
||||
InfluxDbSqlConstant.AS +
|
||||
columnName +
|
||||
StrPool.C_SPACE;
|
||||
selectColumns.add(selectFragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取指定字段最大值
|
||||
@@ -498,6 +674,8 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 批量获取指定字段最大值
|
||||
* @author hongawen
|
||||
@@ -695,6 +873,22 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper eq(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.EQ);
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectFragment.append(InfluxDbSqlConstant.QM)
|
||||
.append(columnValue)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
} else {
|
||||
selectFragment.append(columnValue);
|
||||
}
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 指定字段不等于某个值
|
||||
* @author hongawen
|
||||
@@ -718,6 +912,21 @@ public class InfluxQueryWrapper {
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper ne(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.NE);
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectFragment.append(InfluxDbSqlConstant.QM)
|
||||
.append(columnValue)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
} else {
|
||||
selectFragment.append(columnValue);
|
||||
}
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
@@ -745,6 +954,22 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper gt(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.GT);
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectFragment.append(InfluxDbSqlConstant.QM)
|
||||
.append(columnValue)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
} else {
|
||||
selectFragment.append(columnValue);
|
||||
}
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 指定字段大于等于某个值
|
||||
* @author hongawen
|
||||
@@ -770,17 +995,32 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper ge(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.GE);
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectFragment.append(InfluxDbSqlConstant.QM)
|
||||
.append(columnValue)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
} else {
|
||||
selectFragment.append(columnValue);
|
||||
}
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 指定字段小于某个值
|
||||
* @author hongawen
|
||||
* @param fieldName 表字段名
|
||||
* @param columnName 表字段名
|
||||
* @param columnValue 数值
|
||||
* @return InfluxQueryWrapper
|
||||
* 输出 columnName < columnValue
|
||||
*/
|
||||
public <T, R> InfluxQueryWrapper lt(ICFunction<T, R> fieldName, Object columnValue) {
|
||||
public <T, R> InfluxQueryWrapper lt(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.LT);
|
||||
if (columnValue instanceof String) {
|
||||
@@ -820,6 +1060,22 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper le(String columnName, Object columnValue) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
selectFragment.append(columnName)
|
||||
.append(InfluxDbSqlConstant.LE);
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectFragment.append(InfluxDbSqlConstant.QM)
|
||||
.append(columnValue)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
} else {
|
||||
selectFragment.append(columnValue);
|
||||
}
|
||||
conditions.add(selectFragment.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 查询条件有多个选项时,效果等同于关系型数据库的in,同时or的内容如果超过100个选项时
|
||||
* 会带来严重的性能问题,查询很慢
|
||||
@@ -855,6 +1111,31 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R, O> InfluxQueryWrapper or( String columnName, List<O> columnValues) {
|
||||
if (CollectionUtil.isEmpty(columnValues)) {
|
||||
throw new RuntimeException("查询数值集合为空,请校验!");
|
||||
}
|
||||
List<String> orConditionList = new ArrayList<>();
|
||||
for (O columnValue : columnValues) {
|
||||
String selectConditionFragment = columnName + InfluxDbSqlConstant.EQ;
|
||||
if (columnValue instanceof String) {
|
||||
//需要用单引号包装下
|
||||
selectConditionFragment = selectConditionFragment
|
||||
+ InfluxDbSqlConstant.QM
|
||||
+ columnValue
|
||||
+ InfluxDbSqlConstant.QM;
|
||||
} else {
|
||||
selectConditionFragment = selectConditionFragment + columnValue;
|
||||
}
|
||||
orConditionList.add(selectConditionFragment);
|
||||
}
|
||||
String conditionSql = InfluxDbSqlConstant.LBK
|
||||
+ String.join(InfluxDbSqlConstant.OR, orConditionList)
|
||||
+ InfluxDbSqlConstant.RBK;
|
||||
conditions.add(conditionSql);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* @author hongawen
|
||||
* @param fieldName 表字段名
|
||||
@@ -916,6 +1197,7 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 指定字段降序
|
||||
* @author hongawen
|
||||
|
||||
Reference in New Issue
Block a user