微调
This commit is contained in:
@@ -53,6 +53,11 @@ public class InfluxQueryWrapper {
|
|||||||
*/
|
*/
|
||||||
private Class measurement;
|
private Class measurement;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 不确定查询表名时,动态指定
|
||||||
|
*/
|
||||||
|
private String measurementName;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 返回映射实体
|
* 返回映射实体
|
||||||
*/
|
*/
|
||||||
@@ -79,6 +84,19 @@ public class InfluxQueryWrapper {
|
|||||||
this.initSql();
|
this.initSql();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 返回和查询用的不是同一个实体
|
||||||
|
* 注意:该构建方法查询的参数必须使用string传递,禁止lambda传递
|
||||||
|
* @param measurement 查询目标表
|
||||||
|
* @param resultEntity 返回映射实体
|
||||||
|
*/
|
||||||
|
public InfluxQueryWrapper(String measurement, Class resultEntity) {
|
||||||
|
this.measurementName = measurement;
|
||||||
|
this.measurement = null;
|
||||||
|
this.resultEntity = resultEntity;
|
||||||
|
this.initSql();
|
||||||
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 初始化查询语句
|
* 初始化查询语句
|
||||||
*/
|
*/
|
||||||
@@ -116,6 +134,32 @@ public class InfluxQueryWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /***
|
||||||
|
// * 查询的结果属性
|
||||||
|
// * @author hongawen
|
||||||
|
// * @param fieldsStr 属性值
|
||||||
|
// * 输出为 select ["influxColumn" as fieldStr]的形式
|
||||||
|
// */
|
||||||
|
// @SafeVarargs
|
||||||
|
// public InfluxQueryWrapper select(String... fieldsStr) {
|
||||||
|
// if (ArrayUtil.isNotEmpty(fieldsStr)) {
|
||||||
|
// StringBuilder selectFragment = new StringBuilder();
|
||||||
|
// Arrays.stream(fieldsStr).forEach(fieldStr -> {
|
||||||
|
// selectFragment.setLength(0);
|
||||||
|
// selectFragment.append(StrPool.C_SPACE)
|
||||||
|
// .append(fieldStr)
|
||||||
|
// .append(StrPool.C_SPACE)
|
||||||
|
// .append(InfluxDbSqlConstant.AS)
|
||||||
|
// .append(StrPool.C_SPACE)
|
||||||
|
// .append(this.getColumnName(resultEntity, LambdaUtil.columnToString(fieldStr)))
|
||||||
|
// .append(StrPool.C_SPACE);
|
||||||
|
// selectColumns.add(selectFragment.toString());
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// return this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
/************常见的简单函数处理比如max/min/mean/percentile****************/
|
/************常见的简单函数处理比如max/min/mean/percentile****************/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -209,6 +253,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper mean(String columnName) {
|
public <T, R> InfluxQueryWrapper mean(String columnName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.AVG +
|
String selectFragment = InfluxDbSqlConstant.AVG +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -302,6 +347,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper mode(String columnName) {
|
public <T, R> InfluxQueryWrapper mode(String columnName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.MODE +
|
String selectFragment = InfluxDbSqlConstant.MODE +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -393,6 +439,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper sum(String columnName) {
|
public <T, R> InfluxQueryWrapper sum(String columnName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.SUM +
|
String selectFragment = InfluxDbSqlConstant.SUM +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -429,6 +476,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper top(String columnName, int num) {
|
public <T, R> InfluxQueryWrapper top(String columnName, int num) {
|
||||||
String selectFragment = InfluxDbSqlConstant.TOP +
|
String selectFragment = InfluxDbSqlConstant.TOP +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -504,6 +552,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public <T, R> InfluxQueryWrapper derivative(String columnName) {
|
public <T, R> InfluxQueryWrapper derivative(String columnName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.DERIVATIVE +
|
String selectFragment = InfluxDbSqlConstant.DERIVATIVE +
|
||||||
@@ -548,7 +597,7 @@ public class InfluxQueryWrapper {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper last(String columnName,String resultName) {
|
public <T, R> InfluxQueryWrapper last(String columnName, String resultName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.LAST +
|
String selectFragment = InfluxDbSqlConstant.LAST +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
InfluxDbSqlConstant.DQM +
|
InfluxDbSqlConstant.DQM +
|
||||||
@@ -558,7 +607,8 @@ public class InfluxQueryWrapper {
|
|||||||
InfluxDbSqlConstant.AS +
|
InfluxDbSqlConstant.AS +
|
||||||
|
|
||||||
resultName +
|
resultName +
|
||||||
StrPool.C_SPACE;;
|
StrPool.C_SPACE;
|
||||||
|
;
|
||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -641,6 +691,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper max(String columnName) {
|
public <T, R> InfluxQueryWrapper max(String columnName) {
|
||||||
String selectFragment = InfluxDbSqlConstant.MAX +
|
String selectFragment = InfluxDbSqlConstant.MAX +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -678,7 +729,6 @@ public class InfluxQueryWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 批量获取指定字段最大值
|
* 批量获取指定字段最大值
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -808,6 +858,7 @@ public class InfluxQueryWrapper {
|
|||||||
selectColumns.add(selectFragment);
|
selectColumns.add(selectFragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper percentile(String columnName, int percent) {
|
public <T, R> InfluxQueryWrapper percentile(String columnName, int percent) {
|
||||||
String selectFragment = InfluxDbSqlConstant.PERCENTILE +
|
String selectFragment = InfluxDbSqlConstant.PERCENTILE +
|
||||||
InfluxDbSqlConstant.LBK +
|
InfluxDbSqlConstant.LBK +
|
||||||
@@ -930,6 +981,7 @@ public class InfluxQueryWrapper {
|
|||||||
conditions.add(selectFragment.toString());
|
conditions.add(selectFragment.toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R> InfluxQueryWrapper ne(String columnName, Object columnValue) {
|
public <T, R> InfluxQueryWrapper ne(String columnName, Object columnValue) {
|
||||||
StringBuilder selectFragment = new StringBuilder();
|
StringBuilder selectFragment = new StringBuilder();
|
||||||
selectFragment.append(columnName)
|
selectFragment.append(columnName)
|
||||||
@@ -1129,7 +1181,7 @@ public class InfluxQueryWrapper {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, R, O> InfluxQueryWrapper or( String columnName, List<O> columnValues) {
|
public <T, R, O> InfluxQueryWrapper or(String columnName, List<O> columnValues) {
|
||||||
if (CollectionUtil.isEmpty(columnValues)) {
|
if (CollectionUtil.isEmpty(columnValues)) {
|
||||||
throw new RuntimeException("查询数值集合为空,请校验!");
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
||||||
}
|
}
|
||||||
@@ -1255,16 +1307,26 @@ public class InfluxQueryWrapper {
|
|||||||
if (CollectionUtil.isEmpty(selectColumns)) {
|
if (CollectionUtil.isEmpty(selectColumns)) {
|
||||||
sqlSelect.append(InfluxDbSqlConstant.ALL)
|
sqlSelect.append(InfluxDbSqlConstant.ALL)
|
||||||
.append(InfluxDbSqlConstant.FROM)
|
.append(InfluxDbSqlConstant.FROM)
|
||||||
.append(InfluxDbSqlConstant.DQM)
|
|
||||||
.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
|
||||||
.append(InfluxDbSqlConstant.DQM);
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
if (Objects.isNull(this.measurement)) {
|
||||||
|
sqlSelect.append(measurementName)
|
||||||
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
} else {
|
||||||
|
sqlSelect.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
||||||
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//将集合处理成查询属性
|
//将集合处理成查询属性
|
||||||
sqlSelect.append(String.join(StrPool.COMMA, selectColumns))
|
sqlSelect.append(String.join(StrPool.COMMA, selectColumns))
|
||||||
.append(InfluxDbSqlConstant.FROM)
|
.append(InfluxDbSqlConstant.FROM)
|
||||||
.append(InfluxDbSqlConstant.DQM)
|
|
||||||
.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
|
||||||
.append(InfluxDbSqlConstant.DQM);
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
if (Objects.isNull(this.measurement)) {
|
||||||
|
sqlSelect.append(measurementName)
|
||||||
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
} else {
|
||||||
|
sqlSelect.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
||||||
|
.append(InfluxDbSqlConstant.DQM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断是否有查询条件
|
//判断是否有查询条件
|
||||||
|
|||||||
Reference in New Issue
Block a user