|
@@ -343,15 +343,43 @@ public class DataService { |
|
@@ -343,15 +343,43 @@ public class DataService { |
|
343
|
List<Map<String, Object>> tempDataList = queryDeviceIdAndDataType(deviceId, startTime, endTime); //获取设备id和数据类型
|
343
|
List<Map<String, Object>> tempDataList = queryDeviceIdAndDataType(deviceId, startTime, endTime); //获取设备id和数据类型
|
|
344
|
if(null != tempDataList && tempDataList.size()!=0)
|
344
|
if(null != tempDataList && tempDataList.size()!=0)
|
|
345
|
{
|
345
|
{
|
|
|
|
346
|
+
|
|
|
|
347
|
+ Map<String,String> dataTypeMap = new HashMap<>();
|
|
|
|
348
|
+ if (StringUtils.isEmpty(dataType))
|
|
|
|
349
|
+ {
|
|
|
|
350
|
+ List<Map<String, Object>> dataTpyeList = queryDeviceIdAndDefaultDataType(deviceId, startTime, endTime);
|
|
|
|
351
|
+ for (Map<String, Object> map:dataTpyeList)
|
|
|
|
352
|
+ {
|
|
|
|
353
|
+ String device_info_id = map.get("device_info_id")+"";
|
|
|
|
354
|
+ String all_data_value = map.get("all_data_value")+"";
|
|
|
|
355
|
+ if(!dataTypeMap.containsKey(device_info_id))
|
|
|
|
356
|
+ {
|
|
|
|
357
|
+ dataTypeMap.put(device_info_id,"");
|
|
|
|
358
|
+ }
|
|
|
|
359
|
+ if(StringUtils.isNotEmpty(all_data_value))
|
|
|
|
360
|
+ {
|
|
|
|
361
|
+ for (String data_value:all_data_value.split(","))
|
|
|
|
362
|
+ {
|
|
|
|
363
|
+ dataTypeMap.put(device_info_id,dataTypeMap.get(device_info_id)+","+deviceTypeToDataTypeMap.get(data_value));
|
|
|
|
364
|
+ }
|
|
|
|
365
|
+ }
|
|
|
|
366
|
+ }
|
|
|
|
367
|
+ }
|
|
|
|
368
|
+
|
|
346
|
Map<String,StringBuffer> deviceAndDataTypeDataMap = new HashMap();
|
369
|
Map<String,StringBuffer> deviceAndDataTypeDataMap = new HashMap();
|
|
347
|
for(Map<String, Object> deviceAndDataTypeMap:tempDataList) //遍历设备id和数据类型,获取曲线数据
|
370
|
for(Map<String, Object> deviceAndDataTypeMap:tempDataList) //遍历设备id和数据类型,获取曲线数据
|
|
348
|
{
|
371
|
{
|
|
349
|
String deviceInfoId = deviceAndDataTypeMap.get("device_info_id")+"";
|
372
|
String deviceInfoId = deviceAndDataTypeMap.get("device_info_id")+"";
|
|
350
|
String dbDataType = deviceAndDataTypeMap.get("data_type")+"";
|
373
|
String dbDataType = deviceAndDataTypeMap.get("data_type")+"";
|
|
|
|
374
|
+
|
|
351
|
if (StringUtils.isNotEmpty(dataType) && !((","+dataType+",").indexOf(dbDataType+",")>=0)) ///数据类型过滤
|
375
|
if (StringUtils.isNotEmpty(dataType) && !((","+dataType+",").indexOf(dbDataType+",")>=0)) ///数据类型过滤
|
|
352
|
{
|
376
|
{
|
|
353
|
continue;
|
377
|
continue;
|
|
354
|
}
|
378
|
}
|
|
|
|
379
|
+ if (StringUtils.isEmpty(dataType) && !((","+dataTypeMap.get(deviceInfoId)+",").indexOf(dbDataType+",")>=0)) ///数据类型过滤
|
|
|
|
380
|
+ {
|
|
|
|
381
|
+ continue;
|
|
|
|
382
|
+ }
|
|
355
|
String key = deviceInfoId+"-"+dbDataType;
|
383
|
String key = deviceInfoId+"-"+dbDataType;
|
|
356
|
if (!deviceAndDataTypeDataMap.containsKey(key))
|
384
|
if (!deviceAndDataTypeDataMap.containsKey(key))
|
|
357
|
{
|
385
|
{
|
|
@@ -410,6 +438,30 @@ public class DataService { |
|
@@ -410,6 +438,30 @@ public class DataService { |
|
410
|
return null;
|
438
|
return null;
|
|
411
|
}
|
439
|
}
|
|
412
|
|
440
|
|
|
|
|
441
|
+ public List<Map<String, Object>> queryDeviceIdAndDefaultDataType(String deviceId,int startTime,int endTime)
|
|
|
|
442
|
+ {
|
|
|
|
443
|
+ List<String> tableNames = getTableNames(startTime, endTime);
|
|
|
|
444
|
+
|
|
|
|
445
|
+ // 每次查询的最大天数,超过则分批查询
|
|
|
|
446
|
+ int BATCH_QUERY_DAYS = 30;
|
|
|
|
447
|
+
|
|
|
|
448
|
+ if(null != tableNames && tableNames.size() !=0 && null != tableNames.get(0) )
|
|
|
|
449
|
+ {
|
|
|
|
450
|
+ List<Map<String, Object>> deviceSensorDataList = new ArrayList<>();
|
|
|
|
451
|
+
|
|
|
|
452
|
+ // **分批查询**(一次最多查 30 天)
|
|
|
|
453
|
+ for (int i = 0; i < tableNames.size(); i += BATCH_QUERY_DAYS) {
|
|
|
|
454
|
+ int batchStart = i;
|
|
|
|
455
|
+ int batchEnd = Math.min(i + BATCH_QUERY_DAYS, tableNames.size());
|
|
|
|
456
|
+ List<String> batchTables = tableNames.subList(batchStart, batchEnd);
|
|
|
|
457
|
+ List<Map<String, Object>> tempDataList = queryDeviceIdAndDataTypeIsTypes(batchTables, deviceId, startTime, endTime);
|
|
|
|
458
|
+ deviceSensorDataList.addAll(tempDataList);
|
|
|
|
459
|
+ }
|
|
|
|
460
|
+ return deviceSensorDataList;
|
|
|
|
461
|
+ }
|
|
|
|
462
|
+ return null;
|
|
|
|
463
|
+ }
|
|
|
|
464
|
+
|
|
413
|
/**
|
465
|
/**
|
|
414
|
* 获取数据指定天的数据
|
466
|
* 获取数据指定天的数据
|
|
415
|
*
|
467
|
*
|
|
@@ -560,6 +612,47 @@ public class DataService { |
|
@@ -560,6 +612,47 @@ public class DataService { |
|
560
|
return publicMapper.getObjectListBySQL(finalSql);
|
612
|
return publicMapper.getObjectListBySQL(finalSql);
|
|
561
|
}
|
613
|
}
|
|
562
|
|
614
|
|
|
|
|
615
|
+ /**
|
|
|
|
616
|
+ * 在指定时间范围内,查询出所有表中出现过的设备ID和数据类型的对应关系
|
|
|
|
617
|
+ */
|
|
|
|
618
|
+ private List<Map<String, Object>> queryDeviceIdAndDataTypeIsTypes(List<String> tableNames, String deviceId, int startTime, int endTime) {
|
|
|
|
619
|
+ StringBuilder sqlBuilder = new StringBuilder(" SELECT\n" +
|
|
|
|
620
|
+ "device_info_id,\n" +
|
|
|
|
621
|
+ "data_value,\n" +
|
|
|
|
622
|
+ "MIN(creat_time) AS creat_time FROM (");
|
|
|
|
623
|
+ for (int i = 0; i < tableNames.size(); i++) {
|
|
|
|
624
|
+ if (i > 0) {
|
|
|
|
625
|
+ sqlBuilder.append(" UNION ALL ");
|
|
|
|
626
|
+ }
|
|
|
|
627
|
+ sqlBuilder.append("SELECT device_info_id, data_value, creat_time FROM ")
|
|
|
|
628
|
+ .append(tableNames.get(i))
|
|
|
|
629
|
+ .append(" WHERE device_info_id LIKE '").append(deviceId).append("%'")
|
|
|
|
630
|
+ .append(" AND creat_time BETWEEN ").append(startTime).append(" AND ").append(endTime).append(" AND data_type = 'type'");
|
|
|
|
631
|
+ }
|
|
|
|
632
|
+ sqlBuilder.append(") u GROUP BY device_info_id, data_value");
|
|
|
|
633
|
+ // 外层去重并排序(防止重复)
|
|
|
|
634
|
+ String finalSql = "SELECT device_info_id, GROUP_CONCAT(data_value ORDER BY creat_time SEPARATOR ',') AS all_data_value FROM (" + sqlBuilder + ") t GROUP BY device_info_id ORDER BY device_info_id";
|
|
563
|
|
635
|
|
|
|
|
636
|
+ return publicMapper.getObjectListBySQL(finalSql);
|
|
|
|
637
|
+ }
|
|
564
|
|
638
|
|
|
|
|
639
|
+ private static Map<String,String> deviceTypeToDataTypeMap = new HashMap<>();
|
|
|
|
640
|
+ static {
|
|
|
|
641
|
+ deviceTypeToDataTypeMap.put("1", "ecus,wt");
|
|
|
|
642
|
+ deviceTypeToDataTypeMap.put("2", "ecms,wt");
|
|
|
|
643
|
+ deviceTypeToDataTypeMap.put("3", "pH,wt");
|
|
|
|
644
|
+ deviceTypeToDataTypeMap.put("4", "orp");
|
|
|
|
645
|
+ deviceTypeToDataTypeMap.put("5", "wt,dom,dop");
|
|
|
|
646
|
+ deviceTypeToDataTypeMap.put("6", "nh3n,wt");
|
|
|
|
647
|
+ deviceTypeToDataTypeMap.put("7", "td,wt");
|
|
|
|
648
|
+ deviceTypeToDataTypeMap.put("8", "sal,wt");
|
|
|
|
649
|
+ deviceTypeToDataTypeMap.put("9", "cod,wt");
|
|
|
|
650
|
+ deviceTypeToDataTypeMap.put("10", "cl2,wt");
|
|
|
|
651
|
+ deviceTypeToDataTypeMap.put("11", "chl,wt");
|
|
|
|
652
|
+ deviceTypeToDataTypeMap.put("12", "bga,wt");
|
|
|
|
653
|
+ deviceTypeToDataTypeMap.put("13", "tp,wt");
|
|
|
|
654
|
+ deviceTypeToDataTypeMap.put("14", "ss,wt");
|
|
|
|
655
|
+ deviceTypeToDataTypeMap.put("15", "oiw,wt");
|
|
|
|
656
|
+ deviceTypeToDataTypeMap.put("16", "yw");
|
|
|
|
657
|
+ }
|
|
565
|
} |
658
|
} |