2023-04-25 10:23:43 +08:00
|
|
|
|
package com.njcn.influx.query;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
|
import cn.hutool.core.text.StrPool;
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
2023-05-05 16:02:53 +08:00
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
import com.njcn.influx.constant.InfluxDbSqlConstant;
|
2023-04-26 11:32:11 +08:00
|
|
|
|
import com.njcn.influx.support.ICFunction;
|
|
|
|
|
|
import com.njcn.influx.utils.LambdaUtil;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
import lombok.Data;
|
|
|
|
|
|
import org.influxdb.annotation.Column;
|
2023-04-27 19:12:35 +08:00
|
|
|
|
import org.influxdb.annotation.Measurement;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
2023-04-26 11:32:11 +08:00
|
|
|
|
import java.util.*;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Data
|
|
|
|
|
|
public class InfluxQueryWrapper {
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 组装后的查询语句
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final StringBuilder sqlSelect = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 需要返回的字段
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final List<String> selectColumns = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 查询条件字段
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final List<String> conditions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 分组集合
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final List<String> groupColumn = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 排序集合
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final List<String> orderColumn = new ArrayList<>();
|
|
|
|
|
|
|
2023-08-09 09:55:19 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* LIMIT 子句,返回查询结果的前N条points
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String limitSql = "";
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 查询目标表
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Class measurement;
|
|
|
|
|
|
|
2023-06-08 19:18:14 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 不确定查询表名时,动态指定
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String measurementName;
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 返回映射实体
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Class resultEntity;
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 返回和查询用的同一个实体
|
|
|
|
|
|
* @param measurement 查询目标表
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper(Class measurement) {
|
|
|
|
|
|
this.measurement = measurement;
|
|
|
|
|
|
this.resultEntity = measurement;
|
|
|
|
|
|
this.initSql();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 返回和查询用的不是同一个实体
|
|
|
|
|
|
* @param measurement 查询目标表
|
|
|
|
|
|
* @param resultEntity 返回映射实体
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper(Class measurement, Class resultEntity) {
|
|
|
|
|
|
this.measurement = measurement;
|
|
|
|
|
|
this.resultEntity = resultEntity;
|
|
|
|
|
|
this.initSql();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 19:18:14 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 返回和查询用的不是同一个实体
|
|
|
|
|
|
* 注意:该构建方法查询的参数必须使用string传递,禁止lambda传递
|
|
|
|
|
|
* @param measurement 查询目标表
|
|
|
|
|
|
* @param resultEntity 返回映射实体
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper(String measurement, Class resultEntity) {
|
|
|
|
|
|
this.measurementName = measurement;
|
|
|
|
|
|
this.measurement = null;
|
|
|
|
|
|
this.resultEntity = resultEntity;
|
|
|
|
|
|
this.initSql();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
2023-04-26 11:32:11 +08:00
|
|
|
|
* 初始化查询语句
|
2023-04-25 10:23:43 +08:00
|
|
|
|
*/
|
2023-05-05 11:09:20 +08:00
|
|
|
|
public void initSql() {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
this.selectColumns.clear();
|
|
|
|
|
|
this.conditions.clear();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.groupColumn.clear();
|
|
|
|
|
|
this.orderColumn.clear();
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 查询的结果属性
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param fieldsStr 属性值
|
|
|
|
|
|
* 输出为 select ["influxColumn" as fieldStr]的形式
|
|
|
|
|
|
*/
|
2023-05-05 11:09:20 +08:00
|
|
|
|
@SafeVarargs
|
|
|
|
|
|
public final <T, R> InfluxQueryWrapper select(ICFunction<T, R>... fieldsStr) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
if (ArrayUtil.isNotEmpty(fieldsStr)) {
|
|
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
|
|
|
|
|
Arrays.stream(fieldsStr).forEach(fieldStr -> {
|
|
|
|
|
|
selectFragment.setLength(0);
|
|
|
|
|
|
selectFragment.append(StrPool.C_SPACE)
|
2023-04-26 11:32:11 +08:00
|
|
|
|
.append(this.getColumnName(resultEntity, LambdaUtil.columnToString(fieldStr)))
|
2023-04-25 10:23:43 +08:00
|
|
|
|
.append(StrPool.C_SPACE)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AS)
|
|
|
|
|
|
.append(StrPool.C_SPACE)
|
2023-05-04 14:22:18 +08:00
|
|
|
|
.append(this.getColumnName(resultEntity, LambdaUtil.columnToString(fieldStr)))
|
2023-04-25 10:23:43 +08:00
|
|
|
|
.append(StrPool.C_SPACE);
|
|
|
|
|
|
selectColumns.add(selectFragment.toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-07-17 10:45:52 +08:00
|
|
|
|
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper select(String columnName, String resultColumnName) {
|
2023-06-15 16:17:57 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
2023-06-15 16:17:57 +08:00
|
|
|
|
selectFragment.append(StrPool.C_SPACE)
|
2023-07-17 10:45:52 +08:00
|
|
|
|
.append(columnName)
|
|
|
|
|
|
.append(StrPool.C_SPACE)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AS)
|
|
|
|
|
|
.append(StrPool.C_SPACE)
|
|
|
|
|
|
.append(resultColumnName)
|
|
|
|
|
|
.append(StrPool.C_SPACE);
|
|
|
|
|
|
selectColumns.add(selectFragment + "");
|
2023-06-15 16:17:57 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
2023-06-08 19:18:14 +08:00
|
|
|
|
// /***
|
|
|
|
|
|
// * 查询的结果属性
|
|
|
|
|
|
// * @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;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/************常见的简单函数处理比如max/min/mean/percentile****************/
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param functionName 指定函数 max min mean等
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper functionByCustom(String functionName, String columnName, String resultName) {
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计记录数
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出COUNT("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper count(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return count(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计记录数
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出COUNT("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper count(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.COUNT +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 统计平均值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MEAN("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper mean(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return mean(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计平均值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MEAN("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper mean(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.AVG +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-07-17 10:45:52 +08:00
|
|
|
|
public InfluxQueryWrapper mean(String columnName) {
|
2023-05-22 11:40:14 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.AVG +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
2023-07-17 10:45:52 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 批量获取指定字段平均值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param prefix 表字段名
|
|
|
|
|
|
* @param suffix 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 mean(prefix+diffContent+suffix) as prefix+diffContent+suffix
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper meanSamePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
|
|
|
|
|
|
if (CollectionUtil.isEmpty(diffContent)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
for (Object obj : diffContent) {
|
|
|
|
|
|
String fieldName = prefix + obj + suffix;
|
|
|
|
|
|
this.mean(fieldName);
|
|
|
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计中位数
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MEDIAN("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper median(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return median(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计中位数
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MEDIAN("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper median(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MEDIAN +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段的最常出现的值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MODE("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper mode(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return mode(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段的最常出现的值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出MODE("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper mode(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MODE +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段最大值和最小值的差
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出SPREAD("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper spread(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return spread(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段最大值和最小值的差
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出SPREAD("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper spread(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.SPREAD +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段值求和
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出SUM("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper sum(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return sum(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段值求和
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出SUM("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper sum(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.SUM +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最大值的集合
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出TOP("columnName",number)
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper top(ICFunction<T, R> columnName, int num) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.TOP +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
StrPool.COMMA +
|
|
|
|
|
|
num +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-05 11:09:20 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(columnName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最小值的集合
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出BOTTOM("columnName",number)
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper bottom(ICFunction<T, R> columnName, int num) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.BOTTOM +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
StrPool.COMMA +
|
|
|
|
|
|
num +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-05 11:09:20 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(columnName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 注:该函数还需调研,暂时不要用
|
|
|
|
|
|
* 统计指定字段邻近值的变化率
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出DERIVATIVE("columnName")
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Deprecated
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper derivative(ICFunction<T, R> columnName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.DERIVATIVE +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS_VALUE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
@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;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段值时间戳最近的值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出LAST("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper last(ICFunction<T, R> columnName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.LAST +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS_VALUE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 19:18:14 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper last(String columnName, String resultName) {
|
2023-05-22 11:40:14 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.LAST +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
2023-05-22 12:11:08 +08:00
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
|
2023-05-22 11:43:14 +08:00
|
|
|
|
resultName +
|
2023-06-08 19:18:14 +08:00
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
;
|
2023-05-22 11:40:14 +08:00
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段绝对值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出ABS("columnName")
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper abs(ICFunction<T, R> columnName) {
|
|
|
|
|
|
return abs(columnName, columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 统计指定字段绝对值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出ABS("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper abs(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
|
|
|
|
|
String selectFragment = InfluxDbSqlConstant.ABS +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最大值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MAX("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper max(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return max(columnName, columnName);
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最大值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MAX("columnName") as resultName
|
|
|
|
|
|
*/
|
2023-05-04 14:22:18 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper max(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MAX +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-05-04 14:22:18 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最大值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MAX("columnName") as resultName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper max(String columnName, String resultName) {
|
|
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MAX +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
resultName +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 批量获取指定字段最大值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param prefix 表字段名
|
|
|
|
|
|
* @param suffix 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MAX(prefix+diffContent+suffix) as prefix+diffContent+suffix
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper maxSamePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
|
|
|
|
|
|
if (CollectionUtil.isEmpty(diffContent)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
for (Object obj : diffContent) {
|
|
|
|
|
|
String fieldName = prefix + obj + suffix;
|
|
|
|
|
|
this.max(fieldName, fieldName);
|
|
|
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最小值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MIN("columnName")
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper min(ICFunction<T, R> columnName) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return min(columnName, columnName);
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最小值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MIN("columnName") as resultName
|
|
|
|
|
|
*/
|
2023-05-04 14:22:18 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper min(ICFunction<T, R> columnName, ICFunction<T, R> resultName) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MIN +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取指定字段最小值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
2023-05-05 15:38:11 +08:00
|
|
|
|
* 输出 MIN("columnName") as resultName
|
2023-05-04 14:22:18 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper min(String columnName, String resultName) {
|
2023-05-05 15:38:11 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.MIN +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
resultName +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 批量获取指定字段最小值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param prefix 表字段名
|
|
|
|
|
|
* @param suffix 映射名称
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 MIN(prefix+diffContent+suffix) as prefix+diffContent+suffix
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper minSamePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
|
|
|
|
|
|
if (CollectionUtil.isEmpty(diffContent)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
for (Object obj : diffContent) {
|
|
|
|
|
|
String fieldName = prefix + obj + suffix;
|
|
|
|
|
|
this.min(fieldName, fieldName);
|
|
|
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 返回field key较大的百分之N的值。
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param percent 百分之percent
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 PERCENTILE("columnName",95)
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper percentile(ICFunction<T, R> columnName, int percent) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
return percentile(columnName, columnName, percent);
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 返回field key较大的百分之N的值。
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param resultName 映射名称
|
|
|
|
|
|
* @param percent 百分之percent
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 PERCENTILE("columnName",95) as resultName
|
|
|
|
|
|
*/
|
2023-05-04 14:22:18 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper percentile(ICFunction<T, R> columnName, ICFunction<T, R> resultName, int percent) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.PERCENTILE +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
2023-04-26 11:32:11 +08:00
|
|
|
|
this.getColumnName(measurement, LambdaUtil.columnToString(columnName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
StrPool.COMMA +
|
|
|
|
|
|
percent +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
2023-05-04 14:22:18 +08:00
|
|
|
|
this.getColumnName(resultEntity, LambdaUtil.columnToString(resultName)) +
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 14:02:17 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper percentile(String columnName, int percent) {
|
|
|
|
|
|
String selectFragment = InfluxDbSqlConstant.PERCENTILE +
|
|
|
|
|
|
InfluxDbSqlConstant.LBK +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
InfluxDbSqlConstant.DQM +
|
|
|
|
|
|
StrPool.COMMA +
|
|
|
|
|
|
percent +
|
|
|
|
|
|
InfluxDbSqlConstant.RBK +
|
|
|
|
|
|
InfluxDbSqlConstant.AS +
|
|
|
|
|
|
columnName +
|
|
|
|
|
|
StrPool.C_SPACE;
|
|
|
|
|
|
selectColumns.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/**************************自定义查询条件,比如between、>、<、=、>=、<=等等**************************/
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 注:influxdb
|
|
|
|
|
|
* 在WHERE子句中单引号来表示字符串字段值。具有无引号字符串字段值或双引号字符串字段值的查询将不会返回任何数据
|
|
|
|
|
|
* ,并且在大多数情况下也不会返回错误。
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param fieldName 字段名
|
|
|
|
|
|
* @param val1 起始值
|
|
|
|
|
|
* @param val2 结束值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出为:time >='2022-04-30 16:00:00' AND time <='2022-05-30 16:00:00'
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper between(ICFunction<T, R> fieldName, Object val1, Object val2) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
2023-04-25 10:23:43 +08:00
|
|
|
|
selectFragment.append(StrPool.C_SPACE)
|
|
|
|
|
|
.append(columnName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.GE);
|
|
|
|
|
|
|
|
|
|
|
|
if (val1 instanceof String) {
|
|
|
|
|
|
//需要用单引号包装下
|
|
|
|
|
|
selectFragment.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(val1)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AND)
|
|
|
|
|
|
.append(columnName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.LE)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(val2)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
selectFragment.append(val1)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AND)
|
|
|
|
|
|
.append(columnName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.LE)
|
|
|
|
|
|
.append(val2);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.conditions.add(selectFragment.toString());
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-15 16:17:57 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper between(String fieldName, Object val1, Object val2) {
|
|
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
|
|
|
|
|
selectFragment.append(StrPool.C_SPACE)
|
|
|
|
|
|
.append(fieldName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.GE);
|
|
|
|
|
|
|
|
|
|
|
|
if (val1 instanceof String) {
|
|
|
|
|
|
//需要用单引号包装下
|
|
|
|
|
|
selectFragment.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(val1)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AND)
|
|
|
|
|
|
.append(fieldName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.LE)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM)
|
|
|
|
|
|
.append(val2)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.QM);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
selectFragment.append(val1)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.AND)
|
|
|
|
|
|
.append(fieldName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.LE)
|
|
|
|
|
|
.append(val2);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.conditions.add(selectFragment.toString());
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段等于某个值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName = columnValue
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper eq(ICFunction<T, R> columnName, Object columnValue) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
selectFragment.append(this.getColumnName(measurement, LambdaUtil.columnToString(columnName)))
|
2023-04-25 10:23:43 +08:00
|
|
|
|
.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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段不等于某个值
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName != columnValue
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper ne(ICFunction<T, R> columnName, Object columnValue) {
|
|
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
|
|
|
|
|
selectFragment.append(this.getColumnName(measurement, LambdaUtil.columnToString(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;
|
|
|
|
|
|
}
|
2023-06-08 19:18:14 +08:00
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-05-04 14:22:18 +08:00
|
|
|
|
|
2023-04-26 11:32:11 +08:00
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段大于某个值
|
|
|
|
|
|
* @author hongawen
|
2023-04-26 11:32:11 +08:00
|
|
|
|
* @param fieldName 表字段名
|
2023-04-25 10:23:43 +08:00
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName > columnValue
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper gt(ICFunction<T, R> fieldName, Object columnValue) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
2023-04-25 10:23:43 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段大于等于某个值
|
|
|
|
|
|
* @author hongawen
|
2023-04-26 11:32:11 +08:00
|
|
|
|
* @param fieldName 表字段名
|
2023-04-25 10:23:43 +08:00
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName >= columnValue
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper ge(ICFunction<T, R> fieldName, Object columnValue) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
2023-04-25 10:23:43 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段小于某个值
|
|
|
|
|
|
* @author hongawen
|
2023-05-22 11:40:14 +08:00
|
|
|
|
* @param columnName 表字段名
|
2023-04-25 10:23:43 +08:00
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName < columnValue
|
|
|
|
|
|
*/
|
2023-05-22 11:40:14 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper lt(String columnName, Object columnValue) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
|
|
|
|
|
selectFragment.append(columnName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.LT);
|
|
|
|
|
|
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
|
2023-04-26 11:32:11 +08:00
|
|
|
|
* @param fieldName 表字段名
|
2023-04-25 10:23:43 +08:00
|
|
|
|
* @param columnValue 数值
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName <= columnValue
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public <T, R> InfluxQueryWrapper le(ICFunction<T, R> fieldName, Object columnValue) {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
StringBuilder selectFragment = new StringBuilder();
|
2023-04-26 11:32:11 +08:00
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
2023-04-25 10:23:43 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 查询条件有多个选项时,效果等同于关系型数据库的in,同时or的内容如果超过100个选项时
|
|
|
|
|
|
* 会带来严重的性能问题,查询很慢
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param fieldName 表字段名
|
|
|
|
|
|
* @param columnValues 数值集合
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 (columnName = columnValue or columnName = columnValue or columnName = columnValue )
|
|
|
|
|
|
*/
|
2023-05-18 19:57:27 +08:00
|
|
|
|
public <T, R, O> InfluxQueryWrapper or(ICFunction<T, R> fieldName, List<O> columnValues) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
if (CollectionUtil.isEmpty(columnValues)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
|
|
|
|
|
List<String> orConditionList = new ArrayList<>();
|
2023-05-18 19:57:27 +08:00
|
|
|
|
for (O columnValue : columnValues) {
|
2023-05-04 14:22:18 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 19:18:14 +08:00
|
|
|
|
public <T, R, O> InfluxQueryWrapper or(String columnName, List<O> columnValues) {
|
2023-05-22 11:40:14 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-05 16:02:53 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param fieldName 表字段名
|
|
|
|
|
|
* @param columnValues 数值集合
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName=正则表达式
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper regular(ICFunction<T, R> fieldName, String columnValues) {
|
|
|
|
|
|
if (StrUtil.isEmpty(columnValues)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
|
|
|
|
|
String conditionSql = columnName + InfluxDbSqlConstant.EQ;
|
|
|
|
|
|
conditionSql = conditionSql + InfluxDbSqlConstant.REGULAR_PREFIX
|
|
|
|
|
|
+ columnValues
|
|
|
|
|
|
+ InfluxDbSqlConstant.REGULAR_SUFFIX;
|
|
|
|
|
|
conditions.add(conditionSql);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 14:22:18 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 查询条件有多个选项时,效果等同于关系型数据库的in,同时or的内容如果超过100个选项时
|
|
|
|
|
|
* 会带来严重的性能问题,查询很慢
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param fieldName 表字段名
|
|
|
|
|
|
* @param columnValues 数值集合
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName=正则表达式
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T, R> InfluxQueryWrapper regular(ICFunction<T, R> fieldName, List<String> columnValues) {
|
|
|
|
|
|
if (CollectionUtil.isEmpty(columnValues)) {
|
|
|
|
|
|
throw new RuntimeException("查询数值集合为空,请校验!");
|
|
|
|
|
|
}
|
|
|
|
|
|
String columnName = this.getColumnName(measurement, LambdaUtil.columnToString(fieldName));
|
|
|
|
|
|
String conditionSql = columnName + InfluxDbSqlConstant.EQ;
|
|
|
|
|
|
String middleSql = String.join(InfluxDbSqlConstant.REGULAR_MIDDLE, columnValues);
|
|
|
|
|
|
conditionSql = conditionSql + InfluxDbSqlConstant.REGULAR_PREFIX
|
|
|
|
|
|
+ middleSql
|
|
|
|
|
|
+ InfluxDbSqlConstant.REGULAR_SUFFIX;
|
|
|
|
|
|
conditions.add(conditionSql);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/********************* [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]*********************/
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段分组
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param columnName 表字段名
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 columnName
|
|
|
|
|
|
*/
|
2023-05-05 11:09:20 +08:00
|
|
|
|
@SafeVarargs
|
2023-05-05 14:23:26 +08:00
|
|
|
|
public final <T, R> InfluxQueryWrapper groupBy(ICFunction<T, R>... columnName) {
|
2023-05-05 11:09:20 +08:00
|
|
|
|
for (ICFunction<T, R> tricFunction : columnName) {
|
|
|
|
|
|
groupColumn.add(this.getColumnName(measurement, LambdaUtil.columnToString(tricFunction)));
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-15 16:17:57 +08:00
|
|
|
|
public final <T, R> InfluxQueryWrapper groupBy(String columnName) {
|
|
|
|
|
|
|
2023-07-17 10:45:52 +08:00
|
|
|
|
groupColumn.add(columnName);
|
2023-06-15 16:17:57 +08:00
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-22 11:40:14 +08:00
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段降序
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 time desc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper timeDesc() {
|
|
|
|
|
|
String selectFragment = InfluxDbSqlConstant.TIME
|
|
|
|
|
|
+ InfluxDbSqlConstant.DESC;
|
|
|
|
|
|
orderColumn.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 指定字段升序
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 time asc
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
public InfluxQueryWrapper timeAsc() {
|
2023-04-25 10:23:43 +08:00
|
|
|
|
String selectFragment = InfluxDbSqlConstant.TIME
|
|
|
|
|
|
+ InfluxDbSqlConstant.ASC;
|
|
|
|
|
|
orderColumn.add(selectFragment);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-09 09:55:19 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* LIMIT 子句,返回查询结果的前N条points
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @return InfluxQueryWrapper
|
|
|
|
|
|
* 输出 limit 10
|
|
|
|
|
|
*/
|
|
|
|
|
|
public InfluxQueryWrapper limit(int limit) {
|
|
|
|
|
|
limitSql = InfluxDbSqlConstant.LIMIT + limit;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 根据配置后的实体生成对应的sql
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @return String 最终查询的sql语句
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String generateSql() {
|
|
|
|
|
|
this.sqlSelect.setLength(0);
|
|
|
|
|
|
this.sqlSelect.append(InfluxDbSqlConstant.SELECT);
|
|
|
|
|
|
//判断用户需要返回的属性
|
|
|
|
|
|
if (CollectionUtil.isEmpty(selectColumns)) {
|
|
|
|
|
|
sqlSelect.append(InfluxDbSqlConstant.ALL)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.FROM)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
2023-06-08 19:18:14 +08:00
|
|
|
|
if (Objects.isNull(this.measurement)) {
|
|
|
|
|
|
sqlSelect.append(measurementName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sqlSelect.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
//将集合处理成查询属性
|
|
|
|
|
|
sqlSelect.append(String.join(StrPool.COMMA, selectColumns))
|
|
|
|
|
|
.append(InfluxDbSqlConstant.FROM)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
2023-06-08 19:18:14 +08:00
|
|
|
|
if (Objects.isNull(this.measurement)) {
|
|
|
|
|
|
sqlSelect.append(measurementName)
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sqlSelect.append(((Measurement) measurement.getAnnotation(Measurement.class)).name())
|
|
|
|
|
|
.append(InfluxDbSqlConstant.DQM);
|
|
|
|
|
|
}
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否有查询条件
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(conditions)) {
|
|
|
|
|
|
sqlSelect.append(InfluxDbSqlConstant.WHERE)
|
|
|
|
|
|
.append(String.join(InfluxDbSqlConstant.AND, conditions));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否有分组
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(groupColumn)) {
|
|
|
|
|
|
sqlSelect.append(InfluxDbSqlConstant.GB)
|
|
|
|
|
|
.append(String.join(StrPool.COMMA, groupColumn));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否有排序
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(orderColumn)) {
|
|
|
|
|
|
sqlSelect.append(InfluxDbSqlConstant.OB)
|
|
|
|
|
|
.append(String.join(StrPool.COMMA, orderColumn));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-09 09:55:19 +08:00
|
|
|
|
//判断是否有limit子句
|
|
|
|
|
|
if(StrUtil.isNotBlank(limitSql)){
|
|
|
|
|
|
sqlSelect.append(limitSql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
//最后拼接上时区
|
|
|
|
|
|
sqlSelect.append(InfluxDbSqlConstant.TZ);
|
|
|
|
|
|
|
|
|
|
|
|
return sqlSelect.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @param beanClass 实体类
|
|
|
|
|
|
* @param fieldName 属性名
|
|
|
|
|
|
* @return Field 属性
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Field getTargetClassField(Class<?> beanClass, String fieldName) {
|
|
|
|
|
|
Field field = ReflectUtil.getField(beanClass, fieldName);
|
|
|
|
|
|
if (Objects.isNull(field)) {
|
|
|
|
|
|
throw new RuntimeException(fieldName + "在目标实体类中不存在!!!");
|
|
|
|
|
|
}
|
|
|
|
|
|
return field;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 获取sql拼接的名称,存在注解名就用注解名,否则就用属性名
|
|
|
|
|
|
* @author hongawen
|
2023-04-26 11:32:11 +08:00
|
|
|
|
* @param clazz 类型
|
2023-04-25 10:23:43 +08:00
|
|
|
|
* @param fieldName 属性名
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
2023-04-26 11:32:11 +08:00
|
|
|
|
private String getColumnName(Class<?> clazz, String fieldName) {
|
|
|
|
|
|
Field field = this.getTargetClassField(clazz, fieldName);
|
2023-05-05 14:23:26 +08:00
|
|
|
|
return getColumnName(field);
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-05 13:54:13 +08:00
|
|
|
|
/***
|
|
|
|
|
|
* 获取sql拼接的名称,存在注解名就用注解名,否则就用属性名
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getColumnName(Field field) {
|
|
|
|
|
|
Column column = field.getAnnotation(Column.class);
|
|
|
|
|
|
//数据库字段
|
|
|
|
|
|
String influxColumn;
|
|
|
|
|
|
if (Objects.isNull(column)) {
|
|
|
|
|
|
//没有注解,就用属性名
|
|
|
|
|
|
influxColumn = field.getName();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//获取注解映射的名称
|
|
|
|
|
|
influxColumn = column.name();
|
|
|
|
|
|
}
|
|
|
|
|
|
return influxColumn;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-25 10:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|