将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

@@ -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');