实时数据查询,历史区间数据查询接口新增
This commit is contained in:
parent
e3c6d293b6
commit
ca0195cb38
@ -36,88 +36,97 @@ public class DataService {
|
||||
private DataServiceImpl dataService;
|
||||
|
||||
// 读取实时数据快照
|
||||
public Map<String,Map<String,Object>> querySnapshotValues(List<SnapshotValueQueryParam> paramList){
|
||||
public Map<String, Map<String, Object>> querySnapshotValues(List<SnapshotValueQueryParam> paramList) {
|
||||
long start = System.currentTimeMillis();
|
||||
Map<String,Map<String,Object>> result = new HashMap<>(paramList.size());
|
||||
Map<String,Map<String,Object>> finalResult = result;
|
||||
ListUtil.page(paramList, COMMIT_COUNT, list->{
|
||||
Map<String, Map<String, Object>> result = new HashMap<>(paramList.size());
|
||||
Map<String, Map<String, Object>> finalResult = result;
|
||||
ListUtil.page(paramList, COMMIT_COUNT, list -> {
|
||||
List<String> keyList = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
SnapshotValueQueryParam snapshotValueQueryParam = list.get(i);
|
||||
List<String> attributes = snapshotValueQueryParam.getAttributes();
|
||||
if (CollectionUtils.isEmpty(attributes)){
|
||||
if (CollectionUtils.isEmpty(attributes)) {
|
||||
//为空查全部
|
||||
List<String> sysIotModelFields = sysIotModelFieldMapper.queryAllFiledNames(Long.valueOf(snapshotValueQueryParam.getDeviceId()));
|
||||
for (String item : sysIotModelFields){
|
||||
for (String item : sysIotModelFields) {
|
||||
String key = String.format("RT:[%s]:[%s]", snapshotValueQueryParam.getDeviceId(), item);
|
||||
keyList.add(key);
|
||||
}
|
||||
}else {
|
||||
for (String item :attributes){
|
||||
} else {
|
||||
for (String item : attributes) {
|
||||
String key = String.format("RT:[%s]:[%s]", snapshotValueQueryParam.getDeviceId(), item);
|
||||
keyList.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Object> dataList = adminRedisTemplate.mGet(keyList);
|
||||
for (int i = 0; i < keyList.size(); i++){
|
||||
for (int i = 0; i < keyList.size(); i++) {
|
||||
String key = keyList.get(i);
|
||||
int firstColonIndex = key.indexOf('[');
|
||||
int firstIndex = key.indexOf(']');
|
||||
int secondIndex = key.indexOf(']',firstIndex + 1);
|
||||
int secondIndex = key.indexOf(']', firstIndex + 1);
|
||||
int secondColonIndex = key.indexOf('[', firstColonIndex + 1);
|
||||
String deviceId = key.substring(firstColonIndex + 1, firstIndex);
|
||||
String fieldName = key.substring(secondColonIndex + 1,secondIndex);
|
||||
if (finalResult.get(deviceId) == null){
|
||||
Map<String,Object> valueMap = new HashMap<>();
|
||||
valueMap.put(fieldName,dataList.get(i));
|
||||
finalResult.put(deviceId,valueMap);
|
||||
}else {
|
||||
finalResult.get(deviceId).put(fieldName,dataList.get(i));
|
||||
String fieldName = key.substring(secondColonIndex + 1, secondIndex);
|
||||
if (finalResult.get(deviceId) == null) {
|
||||
Map<String, Object> valueMap = new HashMap<>();
|
||||
valueMap.put(fieldName, dataList.get(i));
|
||||
finalResult.put(deviceId, valueMap);
|
||||
} else {
|
||||
finalResult.get(deviceId).put(fieldName, dataList.get(i));
|
||||
}
|
||||
}
|
||||
});
|
||||
long end = System.currentTimeMillis();
|
||||
log.debug("读取快照{}个,耗时: {}秒", paramList.size(), (end-start)/ 1000.0);
|
||||
log.debug("读取快照{}个,耗时: {}秒", paramList.size(), (end - start) / 1000.0);
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Map<String, Map<String, Object>>> queryTimeSeriesValues(TSValueQueryParam param) {
|
||||
if(CollectionUtil.isEmpty(param.getDevices()) || (param.getStartTime() == null && param.getEndTime() == null)){
|
||||
if (CollectionUtil.isEmpty(param.getDevices()) || (param.getStartTime() == null && param.getEndTime() == null)) {
|
||||
throw new ServiceException("必要参数缺失");
|
||||
}
|
||||
Date startTime = new Date(Long.parseLong(param.getStartTime()));
|
||||
Date endTime = new Date(Long.parseLong(param.getEndTime()));
|
||||
Map<String, Map<String, Map<String, Object>>> result = new HashMap<>(param.getDevices().size());
|
||||
List<SnapshotValueQueryParam> deviceFieldList = param.getDevices();
|
||||
for (SnapshotValueQueryParam item : deviceFieldList){
|
||||
for (SnapshotValueQueryParam item : deviceFieldList) {
|
||||
//field分为高频和低频查询
|
||||
Map<String, Map<String, Map<String, Object>>> values = queryHistoryCurveValues(Long.valueOf(item.getDeviceId()), startTime, endTime, param.getInterval(), param.getFill(),item.getAttributes());
|
||||
Map<String, Map<String, Map<String, Object>>> values = queryHistoryCurveValues(Long.valueOf(item.getDeviceId()), startTime, endTime, param.getInterval(), param.getFill(), item.getAttributes());
|
||||
result.putAll(values);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Map<String, Map<String, Object>>> queryHistoryCurveValues(Long irn, Date startTime, Date endTime, String interval, String fill,List<String> attributes ){
|
||||
private Map<String, Map<String, Map<String, Object>>> queryHistoryCurveValues(Long irn, Date startTime, Date endTime, String interval, String fill, List<String> attributes) {
|
||||
|
||||
String iotModelCode = sysIotModelFieldMapper.queryModelCodeByDeviceId(irn);
|
||||
Map<String, Object> highSpeedFieldMap = dataService.highIotFieldMap.get(iotModelCode);
|
||||
Map<String, Object> lowSpeedFieldMap = dataService.lowIotFieldMap.get(iotModelCode);
|
||||
List<String> highSpeedField = new ArrayList<>();
|
||||
List<String> lowSpeedField = new ArrayList<>();
|
||||
for (String field : attributes){
|
||||
if (highSpeedFieldMap.containsKey(field)){
|
||||
for (String field : attributes) {
|
||||
if (highSpeedFieldMap.containsKey(field)) {
|
||||
highSpeedField.add(field);
|
||||
}
|
||||
if (lowSpeedFieldMap.containsKey(field)){
|
||||
if (lowSpeedFieldMap.containsKey(field)) {
|
||||
lowSpeedField.add(field);
|
||||
}
|
||||
}
|
||||
Map<String, Map<String, Map<String, Object>>> lowHistoryCurve = tdEngineService.fetchLowHistoryCurve(irn, startTime, endTime, interval, lowSpeedField);
|
||||
Map<String, Map<String, Map<String, Object>>> result = new HashMap<>();
|
||||
if (!CollectionUtils.isEmpty(highSpeedField)) {
|
||||
Map<String, Map<String, Map<String, Object>>> highHistoryCurve = tdEngineService.fetchHighHistoryCurve(irn, startTime, endTime, interval, highSpeedField);
|
||||
Map<String, Map<String, Map<String, Object>>> result = new HashMap<>(lowHistoryCurve);
|
||||
result.get(irn.toString()).putAll(highHistoryCurve.get(irn.toString()));
|
||||
result.putAll(highHistoryCurve);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(lowSpeedField)) {
|
||||
Map<String, Map<String, Map<String, Object>>> lowHistoryCurve = tdEngineService.fetchLowHistoryCurve(irn, startTime, endTime, interval, lowSpeedField);
|
||||
if (result.get(irn.toString()) == null) {
|
||||
result.putAll(lowHistoryCurve);
|
||||
} else {
|
||||
result.get(irn.toString()).putAll(lowHistoryCurve.get(irn.toString()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user