|
@@ -242,7 +242,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getAllDeviceRealTime(){
|
|
|
// 构建查询语句,获取所有 measurement 的最新数据
|
|
|
- String queryStr = "SELECT * FROM /.*/ ORDER BY time DESC LIMIT 1";
|
|
|
+ String queryStr = "SELECT *::field FROM datarealtime tz('Asia/Shanghai')";
|
|
|
|
|
|
return tsdbUtils.fetchRealTimeRecords(queryStr);
|
|
|
}
|
|
@@ -252,45 +252,86 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
List<LastInnerResultVO> list = new ArrayList<>();
|
|
|
List<String> deviceUUIds = requestVO.getDeviceuuid();
|
|
|
List<String> metrics = requestVO.getMetrics();
|
|
|
+// if(CollectionUtils.isNotEmpty(metrics)){
|
|
|
+// String metricStr = "\""+metrics.get(0)+"\"";
|
|
|
+// for (int i = 1; i < metrics.size(); i++) {
|
|
|
+// metricStr=metricStr.concat(",\""+metrics.get(i)+"\"");
|
|
|
+// }
|
|
|
+// for (int i = 0; i < deviceUUIds.size(); i++) {
|
|
|
+// String tableName = deviceUUIds.get(i);
|
|
|
+// LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
+// resultVO.setDeviceuuid(deviceUUIds.get(i));
|
|
|
+//
|
|
|
+// String tagQuery = "SELECT \"device_id\",*::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
+// List<Map<String, String>> tag = tsdbUtils.fetchTagRecords(tagQuery);
|
|
|
+// if(CollectionUtils.isNotEmpty(tag)){
|
|
|
+// resultVO.setTags(tag.get(0));
|
|
|
+// String query = "SELECT time,"+metricStr+" FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
+// List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
+// if(CollectionUtils.isEmpty(metricList)){
|
|
|
+// throw new BusinessException(tableName+"设备没有对应属性,请添加");
|
|
|
+// }
|
|
|
+// resultVO.setMetrics(metricList.get(0));
|
|
|
+// }
|
|
|
+//
|
|
|
+// list.add(resultVO);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }else{
|
|
|
+// for (int i = 0; i < deviceUUIds.size(); i++) {
|
|
|
+// String tableName = deviceUUIds.get(i);
|
|
|
+// LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
+// resultVO.setDeviceuuid(deviceUUIds.get(i));
|
|
|
+// String tagQuery = "SELECT \"device_id\",*::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
+// List<Map<String, String>> tag = tsdbUtils.fetchTagRecords(tagQuery);
|
|
|
+// if(CollectionUtils.isNotEmpty(tag)){
|
|
|
+// resultVO.setTags(tag.get(0));
|
|
|
+// String query = "SELECT *::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
+// List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
+// resultVO.setMetrics(metricList.get(0));
|
|
|
+// }
|
|
|
+// list.add(resultVO);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ String deviceUUId = "device_uuid='"+deviceUUIds.get(0)+"'";
|
|
|
+ for (int i = 1; i < deviceUUIds.size(); i++) {
|
|
|
+ deviceUUId=deviceUUId.concat(" or device_uuid='"+deviceUUIds.get(i)+"'");
|
|
|
+ }
|
|
|
if(CollectionUtils.isNotEmpty(metrics)){
|
|
|
String metricStr = "\""+metrics.get(0)+"\"";
|
|
|
for (int i = 1; i < metrics.size(); i++) {
|
|
|
metricStr=metricStr.concat(",\""+metrics.get(i)+"\"");
|
|
|
}
|
|
|
- for (int i = 0; i < deviceUUIds.size(); i++) {
|
|
|
- String tableName = deviceUUIds.get(i);
|
|
|
- LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
- resultVO.setDeviceuuid(deviceUUIds.get(i));
|
|
|
-
|
|
|
- String tagQuery = "SELECT \"device_id\",*::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
- List<Map<String, String>> tag = tsdbUtils.fetchTagRecords(tagQuery);
|
|
|
- if(CollectionUtils.isNotEmpty(tag)){
|
|
|
- resultVO.setTags(tag.get(0));
|
|
|
- String query = "SELECT time,"+metricStr+" FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
- List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
- if(CollectionUtils.isEmpty(metricList)){
|
|
|
- throw new BusinessException(tableName+"设备没有对应属性,请添加");
|
|
|
- }
|
|
|
- resultVO.setMetrics(metricList.get(0));
|
|
|
+ String query = "SELECT \"realtime\",\"device_uuid\",\"device_id\","+metricStr+" FROM \"datarealtime\" where ("+deviceUUId+") tz('Asia/Shanghai')";
|
|
|
+ List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
+ if(CollectionUtils.isNotEmpty(metricList)){
|
|
|
+ for (int i = 0; i < metricList.size(); i++) {
|
|
|
+ LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
+ resultVO.setDeviceuuid(metricList.get(i).get("device_uuid").toString());
|
|
|
+ Map<String, String> tag = new HashMap<String,String>();
|
|
|
+ tag.put("device_id",metricList.get(i).get("device_id").toString());
|
|
|
+ resultVO.setTags(tag);
|
|
|
+ resultVO.setMetrics(metricList.get(i));
|
|
|
+
|
|
|
+ list.add(resultVO);
|
|
|
}
|
|
|
-
|
|
|
- list.add(resultVO);
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
- for (int i = 0; i < deviceUUIds.size(); i++) {
|
|
|
- String tableName = deviceUUIds.get(i);
|
|
|
- LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
- resultVO.setDeviceuuid(deviceUUIds.get(i));
|
|
|
- String tagQuery = "SELECT \"device_id\",*::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
- List<Map<String, String>> tag = tsdbUtils.fetchTagRecords(tagQuery);
|
|
|
- if(CollectionUtils.isNotEmpty(tag)){
|
|
|
- resultVO.setTags(tag.get(0));
|
|
|
- String query = "SELECT *::field FROM \""+tableName+"\" order by desc limit 1 tz('Asia/Shanghai')";
|
|
|
- List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
- resultVO.setMetrics(metricList.get(0));
|
|
|
+ String query = "SELECT *::field FROM \"datarealtime\" where ("+deviceUUId+") tz('Asia/Shanghai')";
|
|
|
+ List<Map<String, Object>> metricList = tsdbUtils.fetchRecords(query);
|
|
|
+ if(CollectionUtils.isNotEmpty(metricList)){
|
|
|
+ for (int i = 0; i < metricList.size(); i++) {
|
|
|
+ LastInnerResultVO resultVO = new LastInnerResultVO();
|
|
|
+ resultVO.setDeviceuuid(metricList.get(i).get("device_uuid").toString());
|
|
|
+ Map<String, String> tag = new HashMap<String,String>();
|
|
|
+ tag.put("device_id",metricList.get(i).get("device_id").toString());
|
|
|
+ resultVO.setTags(tag);
|
|
|
+ resultVO.setMetrics(metricList.get(i));
|
|
|
+
|
|
|
+ list.add(resultVO);
|
|
|
}
|
|
|
- list.add(resultVO);
|
|
|
}
|
|
|
}
|
|
|
|