将influxDB的数据库名配置调整为配置文件

This commit is contained in:
2022-10-08 12:50:20 +08:00
parent ab8e86f257
commit 5ba00aca0a
18 changed files with 135 additions and 79 deletions

View File

@@ -4,7 +4,9 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.EventDetailCount;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.querybuilder.SelectQueryImpl;
@@ -12,6 +14,7 @@ import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@@ -19,7 +22,7 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
@@ -32,6 +35,10 @@ import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
*/
@Component
public class PqsEventDetailQuery extends QueryBuilder {
@Resource
private InfluxDbConfig influxDbConfig;
protected PqsEventDetailQuery(InfluxDbUtils influxDbUtils) {
super(influxDbUtils);
}
@@ -58,7 +65,7 @@ public class PqsEventDetailQuery extends QueryBuilder {
* @see SelectQueryImpl
*/
private SelectQueryImpl fromTable(SelectionQueryImpl column) {
return column.from(DATABASE, PQS_EVENT_DETAIL);
return column.from(influxDbConfig.getDatabase(), PQS_EVENT_DETAIL);
}
/**

View File

@@ -1,6 +1,7 @@
package com.njcn.event.influxdb;
import com.njcn.event.pojo.po.PqsOnlinerate;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.querybuilder.SelectQueryImpl;
@@ -8,15 +9,19 @@ import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_ONLINERATE;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
@Component
public class PqsOnlinerateQuery extends QueryBuilder {
@Resource
private InfluxDbConfig influxDbConfig;
protected PqsOnlinerateQuery(InfluxDbUtils influxDbUtils) {
super(influxDbUtils);
@@ -29,7 +34,7 @@ public class PqsOnlinerateQuery extends QueryBuilder {
* @see SelectQueryImpl
*/
private SelectQueryImpl fromTable(SelectionQueryImpl column) {
return column.from(DATABASE, PQS_ONLINERATE);
return column.from(influxDbConfig.getDatabase(), PQS_ONLINERATE);
}
/**

View File

@@ -3,6 +3,7 @@ package com.njcn.event;
import com.njcn.event.pojo.PqsEventDetail;
import com.njcn.event.pojo.PqsOnlinerateAggregate;
import com.njcn.event.pojo.PqsEventDetailCount;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
@@ -18,10 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
import static org.influxdb.querybuilder.FunctionFactory.sum;
@@ -30,8 +32,11 @@ import static org.influxdb.querybuilder.FunctionFactory.sum;
@RunWith(SpringRunner.class)
@SpringBootTest
public class EventBootApplicationTest {
@Resource
private InfluxDbConfig influxDbConfig;
@Autowired
private InfluxDbUtils influxDbUtils;
@@ -42,7 +47,7 @@ public class EventBootApplicationTest {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().column("line_id").column("eventass_index").from(DATABASE, PQS_EVENT_DETAIL);
SelectQueryImpl selectQuery = select().column("line_id").column("eventass_index").from(influxDbConfig.getDatabase(), PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
@@ -63,7 +68,7 @@ public class EventBootApplicationTest {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().count("eventass_index").from(DATABASE, PQS_EVENT_DETAIL);
SelectQueryImpl selectQuery = select().count("eventass_index").from(influxDbConfig.getDatabase(), PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
@@ -86,7 +91,7 @@ public class EventBootApplicationTest {
SelectionQueryImpl select = select();
SelectionQueryImpl sum = select.op(op(sum("onlinemin"), "/", op(sum("onlinemin"), "+", sum("offlinemin"))), "*", 100)
.as("value");
SelectQueryImpl selectQuery = sum.from(DATABASE, "pqs_onlinerate");
SelectQueryImpl selectQuery = sum.from(influxDbConfig.getDatabase(), "pqs_onlinerate");
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');