Compare commits

...

10 Commits

Author SHA1 Message Date
c8b9b6f730 Merge remote-tracking branch 'origin/master' 2025-02-13 09:39:12 +08:00
xy
f4ff6b2f1c 新增方法 2025-02-12 10:14:21 +08:00
222080344c Merge remote-tracking branch 'origin/master' 2024-12-02 10:27:19 +08:00
hzj
8d12f409bb 完胜报表功能需要的方法属性映射忽略下划线 2024-11-22 14:55:42 +08:00
dd053bc5ca 微调 增加配置类条件,提高代码健壮性 2024-11-07 19:26:59 +08:00
xy
742079e5c2 新增方法 2024-11-01 15:54:00 +08:00
41784494a1 微调常量 2024-09-29 08:49:02 +08:00
hzj
9252193a91 完胜报表功能需要的方法属性映射忽略下划线 2024-09-19 09:10:19 +08:00
hzj
44347310c1 完胜报表功能需要的方法 2024-09-18 18:33:31 +08:00
hzj
9b91feead6 恢复代码 2024-02-28 19:52:44 +08:00
4 changed files with 75 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.impl.InfluxDBMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -20,6 +21,7 @@ import org.springframework.core.io.ResourceLoader;
*/
@Data
@Configuration
@ConditionalOnProperty(name = "spring.influx.database")
public class InfluxDbConfig {

View File

@@ -75,6 +75,7 @@ public interface InfluxDbSqlConstant {
String AS_VALUE = StrPool.C_SPACE + "as value" + StrPool.C_SPACE;
String EQ = "=";
String DOUBLE_EQ = "==";
String NE = "!=";
String QM = "'";
String DQM = "\"";
@@ -84,6 +85,7 @@ public interface InfluxDbSqlConstant {
String GE = ">=";
String LT = "<";
String LE = "<=";
String SLASH = "/";
/**
* influxDB函数拼接.

View File

@@ -41,7 +41,7 @@ public class InfluxExecutor {
public <E> List<E> select(String sql, Class domainClass) {
List<E> results;
//如果domainClass没有注解Measurement则使用influxdb去查询
if (domainClass.isAnnotationPresent(Measurement.class)) {
if (!domainClass.isAnnotationPresent(Measurement.class)) {
QueryResult queryResult = influxDb.query(new Query(sql, database));
results = new ArrayList<>();
try {
@@ -70,7 +70,7 @@ public class InfluxExecutor {
//处理tag分组数据
for (String columnName : tags.keySet()) {
for (Field declaredField : fields) {
if (columnName.equalsIgnoreCase(InfluxQueryWrapper.getColumnName(declaredField))) {
if (columnName.replace("_","").equalsIgnoreCase(InfluxQueryWrapper.getColumnName(declaredField).replace("_",""))) {
//获取属性定义的类型
declaredField.setAccessible(true);
//判断是否过滤该条记录,当数据返回 null时
@@ -109,7 +109,7 @@ public class InfluxExecutor {
String columnName = columns.get(i);
//属性名有下划线的替换掉
for (Field declaredField : fields) {
if (columnName.equalsIgnoreCase(InfluxQueryWrapper.getColumnName(declaredField))) {
if (columnName.replace("_","").equalsIgnoreCase(InfluxQueryWrapper.getColumnName(declaredField).replace("_",""))) {
//获取属性定义的类型
declaredField.setAccessible(true);
//判断是否过滤该条记录,当数据返回 null时
@@ -123,16 +123,16 @@ public class InfluxExecutor {
declaredField.set(object, InstantUtil.stringToInstant(columnValue.get(i).toString().replace("+08:00", "Z")));
//字符串
} else if (declaredField.getType() == String.class) {
declaredField.set(object, columnValue.get(i).toString());
declaredField.set(object,Objects.isNull(columnValue.get(i))?"":columnValue.get(i).toString());
//浮点双精度
} else if (declaredField.getType() == Double.class) {
declaredField.set(object, Double.parseDouble(columnValue.get(i).toString()));
declaredField.set(object,Objects.isNull(columnValue.get(i))?null: Double.parseDouble(columnValue.get(i).toString()));
//浮点
} else if (declaredField.getType() == Float.class) {
declaredField.set(object, Float.parseFloat(columnValue.get(i).toString()));
declaredField.set(object, Objects.isNull(columnValue.get(i))?null: Float.parseFloat(columnValue.get(i).toString()));
//整型
} else if (declaredField.getType() == Integer.class) {
declaredField.set(object, Integer.parseInt(columnValue.get(i).toString()));
declaredField.set(object,Objects.isNull(columnValue.get(i))?null: Integer.parseInt(columnValue.get(i).toString()));
}
}
}
@@ -221,5 +221,4 @@ public class InfluxExecutor {
return originalSql.concat(InfluxDbSqlConstant.TZ);
}
}

View File

@@ -238,6 +238,20 @@ public class InfluxQueryWrapper {
return this;
}
public <T, R> InfluxQueryWrapper count(String columnName,String resultName) {
String selectFragment = InfluxDbSqlConstant.COUNT +
InfluxDbSqlConstant.LBK +
InfluxDbSqlConstant.DQM +
columnName +
InfluxDbSqlConstant.DQM +
InfluxDbSqlConstant.RBK +
InfluxDbSqlConstant.AS +
resultName +
StrPool.C_SPACE;
selectColumns.add(selectFragment);
return this;
}
/***
* 统计平均值
@@ -924,6 +938,22 @@ public class InfluxQueryWrapper {
return this;
}
public <T, R> InfluxQueryWrapper percentile(String columnName,String resultName, int percent) {
String selectFragment = InfluxDbSqlConstant.PERCENTILE +
InfluxDbSqlConstant.LBK +
InfluxDbSqlConstant.DQM +
columnName +
InfluxDbSqlConstant.DQM +
StrPool.COMMA +
percent +
InfluxDbSqlConstant.RBK +
InfluxDbSqlConstant.AS +
resultName +
StrPool.C_SPACE;
selectColumns.add(selectFragment);
return this;
}
/***
* 批量返回field key较大的百分之N的值。
* @author xuyang
@@ -943,6 +973,25 @@ public class InfluxQueryWrapper {
return this;
}
/***
* 批量返回包含谐波次数的数据。
* @author xuyang
* @param prefix 表字段名
* @param suffix 映射名称
* @return InfluxQueryWrapper
* 输出 prefix+diffContent+suffix as prefix+diffContent+suffix
*/
public InfluxQueryWrapper samePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
if (CollectionUtil.isEmpty(diffContent)) {
throw new RuntimeException("查询数值集合为空,请校验!");
}
for (Object obj : diffContent) {
String fieldName = prefix + obj + suffix;
this.select(fieldName,fieldName);
}
return this;
}
/**************************自定义查询条件比如between、>、<、=、>=、<=等等**************************/
@@ -1278,6 +1327,7 @@ public class InfluxQueryWrapper {
return this;
}
public <T, R, O> InfluxQueryWrapper or(String columnName, List<O> columnValues) {
if (CollectionUtil.isEmpty(columnValues)) {
throw new RuntimeException("查询数值集合为空,请校验!");
@@ -1346,6 +1396,20 @@ public class InfluxQueryWrapper {
return this;
}
public <T, R> InfluxQueryWrapper regular(String fieldName, List<String> columnValues) {
if (CollectionUtil.isEmpty(columnValues)) {
throw new RuntimeException("查询数值集合为空,请校验!");
}
String columnName = this.getColumnName(measurement, 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;
}
/********************* [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]*********************/