Authored by 王涛

删除influxdb依赖;

优化展示页面
... ... @@ -53,7 +53,6 @@
<!--<version>1.4.0-beta</version>-->
</dependency>
<!-- SpringBoot-->
<dependency>
<groupId>org.springframework.boot</groupId>
... ... @@ -196,11 +195,11 @@
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<!--<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.7</version>
</dependency>
</dependency>-->
</dependencies>
... ...
... ... @@ -2,7 +2,6 @@ package org.jeecg.modules.jmreport.ext.controller;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.QueryResult;
import org.jeecg.modules.jmreport.ext.Base.BaseApiController;
import org.jeecg.modules.jmreport.ext.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -30,7 +29,7 @@ public class APiController extends BaseApiController {
public JSONObject getTree(String resid) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("data", StringUtils.isBlank(resid) ? "empty"+System.currentTimeMillis():resid);
jsonObject.put("data", StringUtils.isBlank(resid) ? "empty" + System.currentTimeMillis() : resid);
return api(Arrays.asList(jsonObject));
}
... ...
package org.jeecg.modules.jmreport.ext.service.impl;
import org.influxdb.dto.QueryResult;
import org.jeecg.modules.jmreport.ext.service.ApiService;
import org.jeecg.modules.jmreport.utils.influx.InfluxDbUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -12,15 +10,16 @@ import java.util.Map;
@Service
public class ApiServiceImpl implements ApiService {
@Autowired
private InfluxDbUtils influxDbUtils;
// @Autowired
// private InfluxDbUtils influxDbUtils;
public List<Map<String, Object>> queryInFlux(String sql) {
QueryResult monitor = influxDbUtils.query(sql, "monitor");
List<Map<String, Object>> maps = influxDbUtils.queryResultToMapList(monitor);
return maps;
// QueryResult monitor = influxDbUtils.query(sql, "monitor");
//
//
// List<Map<String, Object>> maps = influxDbUtils.queryResultToMapList(monitor);
//
// return maps;
return null;
}
}
... ...
package org.jeecg.modules.jmreport.utils.influx;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class InfluxDBConfig {
@Value("${spring.influx.url}")
private String url;
private String database;
private String retentionPolicy;
private InfluxDB influxDB;
public InfluxDBConfig() {
}
public InfluxDBConfig(String userName, String password, String url, String database) {
// this.userName = userName;
// this.password = password;
this.url = url;
this.database = database;
build();
}
public InfluxDBConfig(String database) {
this.database = database;
build();
}
private void build() {
if (influxDB == null) {
//influxDB = InfluxDBFactory.connect(this.url,this.userName,this.password);
influxDB = InfluxDBFactory.connect(this.url);
}
influxDB.setDatabase(this.database);
influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
}
public InfluxDB getInfluxDB() {
return influxDB;
}
}
//package org.jeecg.modules.jmreport.utils.influx;
//
//import org.influxdb.InfluxDB;
//import org.influxdb.InfluxDBFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//@Component
//public class InfluxDBConfig {
//
// @Value("${spring.influx.url}")
// private String url;
//
// private String database;
//
// private String retentionPolicy;
//
// private InfluxDB influxDB;
//
// public InfluxDBConfig() {
// }
//
//
// public InfluxDBConfig(String userName, String password, String url, String database) {
//// this.userName = userName;
//// this.password = password;
// this.url = url;
// this.database = database;
// build();
// }
//
// public InfluxDBConfig(String database) {
// this.database = database;
// build();
// }
//
// private void build() {
// if (influxDB == null) {
// //influxDB = InfluxDBFactory.connect(this.url,this.userName,this.password);
// influxDB = InfluxDBFactory.connect(this.url);
// }
// influxDB.setDatabase(this.database);
// influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
// }
//
// public InfluxDB getInfluxDB() {
// return influxDB;
// }
//
//
//}
... ...
package org.jeecg.modules.jmreport.utils.influx;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class InfluxDbUtils {
@Autowired
InfluxDBConfig influxDBConfig;
@Autowired
private InfluxDB influxDB;
/**
* 创建数据库
*
* @param dbName
*/
public void createDB(String dbName) {
influxDB.createDatabase(dbName);
}
/**
* 删除数据库
*
* @param dbName
*/
public void deleteDB(String dbName) {
influxDB.deleteDatabase(dbName);
}
/**
* 创建策略
*
* @param command
* @param database
*/
public void createRetentionPolicy(String command, String defalut, String database, String policy, int fb) {
command = String.format("CREATE RETENTION POLICY \"%s\" ON \"%s\" DURATION %s REPLICATION %s DEFAULT", defalut, database, policy, fb);
query(command, database);
}
/**
* 删除策略
*
* @param command
* @param database
*/
public void removeRetentionPolicy(String command, String defalut, String database, String policy, int fb) {
}
/**
* 创建表
*
* @param command 删除语句
* @return 返回错误信息
*/
public void createMeasurementData(String command, String database) {
}
/**
* 删除表
*
* @param command 删除语句
* @return 返回错误信息
*/
public String deleteMeasurementData(String command, String database) {
QueryResult result = influxDB.query(new Query(command, database));
return result.getError();
}
/**
* 查询
*
* @param command 查询语句
* @return
*/
public QueryResult query(String command, String database) {
return influxDB.query(new Query(command, database));
}
// public void insert(String measurements, Map<String, String> tagsMap, Map<String, Object> fieldsMap) {
// influxDBConfig.getInfluxDB();
// influxDB.insert(measurements, tagsMap, fieldsMap);
//package org.jeecg.modules.jmreport.utils.influx;
//
//import lombok.extern.slf4j.Slf4j;
//import org.influxdb.InfluxDB;
//import org.influxdb.dto.Point;
//import org.influxdb.dto.Query;
//import org.influxdb.dto.QueryResult;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.text.SimpleDateFormat;
//import java.util.HashMap;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.Map;
//
//@Slf4j
//@Service
//public class InfluxDbUtils {
//
// @Autowired
// InfluxDBConfig influxDBConfig;
//
// @Autowired
// private InfluxDB influxDB;
//
// /**
// * 创建数据库
// *
// * @param dbName
// */
// public void createDB(String dbName) {
// influxDB.createDatabase(dbName);
// }
/**
* 新增
*
* @param dateabse
* @param measurements
* @param tagsMap
* @param fieldsMap
*/
public void insert(String dateabse, String measurements, Map<String, String> tagsMap, Map<String, Double> fieldsMap) {
Point.Builder builder = Point.measurement(measurements);
//builder.time(System.currentTimeMillis(),TimeUnit.MICROSECONDS);
builder.addField("kpiValue", fieldsMap.get("kpiValue"));
//builder.tag("resType", tagsMap.get("resType"));
builder.tag("resId", tagsMap.get("resId"));
builder.tag("kpiId", tagsMap.get("kpiId"));
builder.tag("flag", tagsMap.get("flag"));
//builder.tag("ipAdde", tagsMap.get("ipAdde"));
Point point = builder.build();
influxDB.setDatabase(dateabse).write(point);
}
/**
* 将queryResult 查询结果转换为 map
*
* @param queryResult 查询结果
* @return List<Map < String , Object>>
* @author 惠佳旭
* @date 2020/12/17
*/
public List<Map<String, Object>> queryResultToMapList(QueryResult queryResult) {
List<Map<String, Object>> resultList = new LinkedList<>();
for (QueryResult.Result result : queryResult.getResults()) {
if (result == null || result.getSeries() == null) {
break;
}
for (QueryResult.Series series : result.getSeries()) {
if (series == null || series.getValues() == null) {
break;
}
List<String> columns = series.getColumns();
for (List<Object> value : series.getValues()) {
if (value == null) {
break;
}
Map<String, Object> map = new HashMap<>(columns.size());
for (int i = 0; i < value.size(); i++) {
String columnName = columns.get(i);
if ("time".equals(columnName)) {
try {
String timeStr = value.get(i).toString();
map.put(columnName, timeStr.substring(0, 10) + " " + timeStr.substring(11, 19));
} catch (Exception e) {
log.error("转换失败:{}转换为日期失败", value.get(i));
map.put(columnName, value.get(i));
}
} else {
map.put(columnName, value.get(i));
}
}
resultList.add(map);
}
}
}
return resultList;
}
public List<Map<String, Object>> queryResultToMap(QueryResult queryResult, String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
List<Map<String, Object>> resultList = new LinkedList<>();
for (QueryResult.Result result : queryResult.getResults()) {
if (result == null || result.getSeries() == null) {
break;
}
for (QueryResult.Series series : result.getSeries()) {
if (series == null || series.getValues() == null) {
break;
}
List<String> columns = series.getColumns();
for (List<Object> value : series.getValues()) {
if (value == null) {
break;
}
Map<String, Object> map = new HashMap<>(columns.size());
for (int i = 0; i < value.size(); i++) {
String columnName = columns.get(i);
if ("time".equals(columnName)) {
try {
map.put(columnName, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sdf.parse(value.get(i).toString())));
} catch (Exception e) {
log.error("转换失败:{}转换为日期失败", value.get(i));
map.put(columnName, value.get(i));
}
} else {
map.put(columnName, value.get(i));
}
}
resultList.add(map);
}
}
}
return resultList;
}
}
//
// /**
// * 删除数据库
// *
// * @param dbName
// */
// public void deleteDB(String dbName) {
// influxDB.deleteDatabase(dbName);
// }
//
// /**
// * 创建策略
// *
// * @param command
// * @param database
// */
// public void createRetentionPolicy(String command, String defalut, String database, String policy, int fb) {
// command = String.format("CREATE RETENTION POLICY \"%s\" ON \"%s\" DURATION %s REPLICATION %s DEFAULT", defalut, database, policy, fb);
// query(command, database);
// }
//
// /**
// * 删除策略
// *
// * @param command
// * @param database
// */
// public void removeRetentionPolicy(String command, String defalut, String database, String policy, int fb) {
//
// }
//
// /**
// * 创建表
// *
// * @param command 删除语句
// * @return 返回错误信息
// */
// public void createMeasurementData(String command, String database) {
//
// }
//
// /**
// * 删除表
// *
// * @param command 删除语句
// * @return 返回错误信息
// */
// public String deleteMeasurementData(String command, String database) {
// QueryResult result = influxDB.query(new Query(command, database));
// return result.getError();
// }
//
// /**
// * 查询
// *
// * @param command 查询语句
// * @return
// */
// public QueryResult query(String command, String database) {
// return influxDB.query(new Query(command, database));
// }
//
//
//// public void insert(String measurements, Map<String, String> tagsMap, Map<String, Object> fieldsMap) {
//// influxDBConfig.getInfluxDB();
//// influxDB.insert(measurements, tagsMap, fieldsMap);
//// }
//
// /**
// * 新增
// *
// * @param dateabse
// * @param measurements
// * @param tagsMap
// * @param fieldsMap
// */
// public void insert(String dateabse, String measurements, Map<String, String> tagsMap, Map<String, Double> fieldsMap) {
// Point.Builder builder = Point.measurement(measurements);
// //builder.time(System.currentTimeMillis(),TimeUnit.MICROSECONDS);
// builder.addField("kpiValue", fieldsMap.get("kpiValue"));
// //builder.tag("resType", tagsMap.get("resType"));
// builder.tag("resId", tagsMap.get("resId"));
// builder.tag("kpiId", tagsMap.get("kpiId"));
// builder.tag("flag", tagsMap.get("flag"));
// //builder.tag("ipAdde", tagsMap.get("ipAdde"));
// Point point = builder.build();
// influxDB.setDatabase(dateabse).write(point);
// }
//
// /**
// * 将queryResult 查询结果转换为 map
// *
// * @param queryResult 查询结果
// * @return List<Map < String , Object>>
// * @author 惠佳旭
// * @date 2020/12/17
// */
// public List<Map<String, Object>> queryResultToMapList(QueryResult queryResult) {
// List<Map<String, Object>> resultList = new LinkedList<>();
// for (QueryResult.Result result : queryResult.getResults()) {
// if (result == null || result.getSeries() == null) {
// break;
// }
// for (QueryResult.Series series : result.getSeries()) {
// if (series == null || series.getValues() == null) {
// break;
// }
// List<String> columns = series.getColumns();
// for (List<Object> value : series.getValues()) {
// if (value == null) {
// break;
// }
// Map<String, Object> map = new HashMap<>(columns.size());
// for (int i = 0; i < value.size(); i++) {
// String columnName = columns.get(i);
// if ("time".equals(columnName)) {
// try {
// String timeStr = value.get(i).toString();
// map.put(columnName, timeStr.substring(0, 10) + " " + timeStr.substring(11, 19));
// } catch (Exception e) {
// log.error("转换失败:{}转换为日期失败", value.get(i));
// map.put(columnName, value.get(i));
// }
// } else {
// map.put(columnName, value.get(i));
// }
// }
// resultList.add(map);
// }
// }
// }
// return resultList;
// }
//
//
// public List<Map<String, Object>> queryResultToMap(QueryResult queryResult, String dateFormat) {
// SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
// List<Map<String, Object>> resultList = new LinkedList<>();
// for (QueryResult.Result result : queryResult.getResults()) {
// if (result == null || result.getSeries() == null) {
// break;
// }
// for (QueryResult.Series series : result.getSeries()) {
// if (series == null || series.getValues() == null) {
// break;
// }
// List<String> columns = series.getColumns();
// for (List<Object> value : series.getValues()) {
// if (value == null) {
// break;
// }
// Map<String, Object> map = new HashMap<>(columns.size());
// for (int i = 0; i < value.size(); i++) {
// String columnName = columns.get(i);
// if ("time".equals(columnName)) {
// try {
// map.put(columnName, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sdf.parse(value.get(i).toString())));
// } catch (Exception e) {
// log.error("转换失败:{}转换为日期失败", value.get(i));
// map.put(columnName, value.get(i));
// }
// } else {
// map.put(columnName, value.get(i));
// }
// }
// resultList.add(map);
// }
// }
// }
// return resultList;
// }
//
//
//}
... ...
server:
port: 8085
spring:
#配置静态资源
mvc:
static-path-pattern: /**
resource:
static-locations: classpath:/static/
#配置数据库
datasource:
url: jdbc:mysql://${MYSQL-HOST:192.168.0.249}:${MYSQL-PORT:3306}/${MYSQL-DB:jreport}?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
#Minidao配置
minidao :
base-package: org.jeecg.modules.jmreport.*
#JimuReport[上传配置]
jeecg :
# local|minio|alioss
uploadType: local
# local
path :
#文件路径
upload: /opt/upload
# alioss
oss:
endpoint: ??
accessKey: ??
secretKey: ??
bucketName: jimureport
# minio
minio:
minio_url: http://minio.jeecg.com
minio_name: ??
minio_pass: ??
bucketName: ??
#输出sql日志
logging:
level:
org.jeecg.modules.jmreport : info
server:
port: 8085
spring:
#配置静态资源
mvc:
static-path-pattern: /**
resource:
static-locations: classpath:/static/
#配置数据库
datasource:
url: jdbc:mysql://192.168.0.249:3306/jreport?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
#Minidao配置
minidao :
base-package: org.jeecg.modules.jmreport.*
#JimuReport[上传配置]
jeecg :
# local|minio|alioss
uploadType: local
# local
path :
#文件路径
upload: /opt/upload
# alioss
oss:
endpoint: ??
accessKey: ??
secretKey: ??
bucketName: jimureport
# minio
minio:
minio_url: http://minio.jeecg.com
minio_name: ??
minio_pass: ??
bucketName: ??
#输出sql日志
logging:
level:
org.jeecg.modules.jmreport : info
... ... @@ -8,12 +8,10 @@ spring:
static-locations: classpath:/static/
#配置数据库
datasource:
url: jdbc:mysql://${MYSQL-HOST:127.0.0.1}:${MYSQL-PORT:3306}/${MYSQL-DB:jreport}?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: yx
url: jdbc:mysql://192.168.0.249:3306/jreport?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
profiles:
active: tjserver
influx:
url: http://192.168.0.244:8086
database: monitor
... ...
... ... @@ -45,22 +45,8 @@
<!--引入自定义组件-->
<div id="app" style="padding-left: 30px;height: 100%">
<div class="layout" style="margin-left: -30px;margin-top: -10px;;height: 100%;display: flex">
<div v-if="dataSource.child && dataSource.child.length > 0" style="width: 200px;height: 100%">
<div v-if="dataSource.child && dataSource.child.length > 1" style="width: 200px;height: 100%">
<Sider breakpoint="md" collapsible :collapsed-width="78" v-model="isCollapsed">
<#--<i-menu theme="primary" width="auto" :class="menuitemClasses" active-name="datainfo"
:open-names="['sub']" @on-select="onMenuSelect">
<Submenu name="sub">
<template slot="title">
<Icon type="ios-apps"/>
</Icon>
{{dataSource.pageName}}
</template>
<Menu-Item :name="item.pageCode" v-for="(item,index) in dataSource.child">
<span>{{item.pageName}}</span>
</Menu-Item>
</Submenu>
</i-menu>-->
<i-menu theme="primary" width="auto" :class="menuitemClasses" active-name="datainfo"
:open-names="['sub']" @on-select="onMenuSelect">
<Submenu name="sub">
... ... @@ -87,11 +73,11 @@
<div slot="trigger"></div>
</Sider>
</div>
<div v-if="dataSource.child && dataSource.child.length > 0" style="width: calc(100% - 200px);height: 100%">
<#--<div v-if="dataSource.child && dataSource.child.length == 1" style="width: calc(100% - 200px);height: 100%">
<iframe id="reportFrame" frameborder="0" width="100%" :height="height" :src="src"
style="border: none;padding-top: 15px;"></iframe>
</div>
<div v-else>
</div>-->
<div v-else style="margin-left: 3px;width: 100%">
<iframe id="reportFrame" frameborder="0" width="100%" :height="height" :src="src"
style="border: none;padding-top: 15px;"></iframe>
</div>
... ... @@ -108,7 +94,8 @@
src: '',
height: document.documentElement.clientHeight,
dataSource: {},
codeMaps:[]
codeMaps:[],
hideLeftView:false
},
computed: {
menuitemClasses: function () {
... ... @@ -142,6 +129,9 @@
success: (result) => {
that.dataSource = result.root;
that.codeMaps = result.codeMaps;
if(Object.keys(that.codeMaps).length == 0){
that.hideLeftView = true;
}
if (result.reportCode) {
that.setReportSrc(result.reportCode);
} else {
... ...