Compare commits

...

12 Commits

Author SHA1 Message Date
xy
0088ac746d Merge remote-tracking branch 'origin/master' 2025-12-03 16:03:46 +08:00
xy
88bf4b215b 方法微调 2025-12-03 16:01:33 +08:00
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 76 additions and 8 deletions

View File

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

View File

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

View File

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

View File

@@ -238,6 +238,20 @@ public class InfluxQueryWrapper {
return this; 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; 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的值。 * 批量返回field key较大的百分之N的值。
* @author xuyang * @author xuyang
@@ -943,6 +973,26 @@ public class InfluxQueryWrapper {
return this; 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;
String resultName = suffix + obj;
this.select(fieldName,resultName);
}
return this;
}
/**************************自定义查询条件比如between、>、<、=、>=、<=等等**************************/ /**************************自定义查询条件比如between、>、<、=、>=、<=等等**************************/
@@ -1278,6 +1328,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("查询数值集合为空,请校验!");
@@ -1346,6 +1397,20 @@ public class InfluxQueryWrapper {
return this; 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]*********************/ /********************* [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]*********************/