diff --git a/das/src/main/java/com/das/modules/cache/domain/IotFieldInfoCache.java b/das/src/main/java/com/das/modules/cache/domain/IotFieldInfoCache.java index 4ec4bfac..299726c9 100644 --- a/das/src/main/java/com/das/modules/cache/domain/IotFieldInfoCache.java +++ b/das/src/main/java/com/das/modules/cache/domain/IotFieldInfoCache.java @@ -9,5 +9,17 @@ public class IotFieldInfoCache { private Integer attributeType; private Integer porder; private Integer highspeed; - private Integer datatype; + private String datatype; + + public boolean isHighSpeed() { + return highspeed.equals(1) && attributeType.equals(138); + } + + public boolean isLowSpeed() { + return highspeed.equals(0) && attributeType.equals(138); + } + + public boolean isCalculate() { + return attributeType.equals(139); + } } diff --git a/das/src/main/java/com/das/modules/cache/domain/IotModelInfoCache.java b/das/src/main/java/com/das/modules/cache/domain/IotModelInfoCache.java index 17d0c6c4..00e20474 100644 --- a/das/src/main/java/com/das/modules/cache/domain/IotModelInfoCache.java +++ b/das/src/main/java/com/das/modules/cache/domain/IotModelInfoCache.java @@ -8,5 +8,4 @@ import java.util.concurrent.ConcurrentHashMap; public class IotModelInfoCache { private Long iotModelId; private String iodModelCode; - private ConcurrentHashMap fieldInfoCache; } diff --git a/das/src/main/java/com/das/modules/cache/service/IotModelCache.java b/das/src/main/java/com/das/modules/cache/service/IotModelCache.java index 29cd805a..315538f3 100644 --- a/das/src/main/java/com/das/modules/cache/service/IotModelCache.java +++ b/das/src/main/java/com/das/modules/cache/service/IotModelCache.java @@ -1,5 +1,7 @@ package com.das.modules.cache.service; public interface IotModelCache { - + public boolean isHighSpeed(Long modelId, String attr); + public boolean isLowSpeed(Long modelId, String attr); + public boolean isCalculate(Long modelId, String attr); } diff --git a/das/src/main/java/com/das/modules/cache/service/impl/IotModelCacheImpl.java b/das/src/main/java/com/das/modules/cache/service/impl/IotModelCacheImpl.java index 7d26fe91..be670f65 100644 --- a/das/src/main/java/com/das/modules/cache/service/impl/IotModelCacheImpl.java +++ b/das/src/main/java/com/das/modules/cache/service/impl/IotModelCacheImpl.java @@ -1,5 +1,7 @@ package com.das.modules.cache.service.impl; +import com.das.modules.cache.domain.IotFieldInfoCache; +import com.das.modules.cache.domain.IotModelInfoCache; import com.das.modules.cache.service.IotModelCache; import com.das.modules.equipment.mapper.SysIotModelMapper; import jakarta.annotation.PostConstruct; @@ -7,18 +9,70 @@ import jakarta.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; + @Service public class IotModelCacheImpl implements IotModelCache { @Autowired SysIotModelMapper sysIotModelMapper; + private ConcurrentHashMap iotFieldsMap = new ConcurrentHashMap<>(); + private ConcurrentHashMap iotModelInfoIdMap = new ConcurrentHashMap<>(); @PostConstruct public void init(){ + //缓存模型 + sysIotModelMapper.getAllIotModel().forEach(item -> { + IotModelInfoCache info = new IotModelInfoCache(); + info.setIotModelId(item.getId()); + info.setIodModelCode(item.getIotModelCode()); + iotModelInfoIdMap.put(item.getId(), info); + }); + //缓存模型属性 + iotModelInfoIdMap.forEach((k,v)->{ + sysIotModelMapper.queryFieldByModelId(k).forEach(item -> { + IotFieldInfoCache fieldInfoCache = new IotFieldInfoCache(); + fieldInfoCache.setAttributeCode(item.getAttributeCode()); + fieldInfoCache.setPorder(item.getPorder()); + fieldInfoCache.setAttributeName(item.getAttributeName()); + fieldInfoCache.setAttributeType(item.getAttributeType()); + fieldInfoCache.setHighspeed(item.getHighSpeed()); + fieldInfoCache.setDatatype(item.getDataType()); + iotFieldsMap.put(String.format("%d_%s", k, item.getAttributeCode()), fieldInfoCache); + }); + }); } @PreDestroy public void destroy(){ } + + @Override + public boolean isHighSpeed(Long modelId, String attr) { + IotFieldInfoCache fieldInfoCache = iotFieldsMap.get(String.format("%d_%s", modelId, attr)); + if (fieldInfoCache == null) { + return false; + } + return fieldInfoCache.isHighSpeed(); + } + + @Override + public boolean isLowSpeed(Long modelId, String attr) { + IotFieldInfoCache fieldInfoCache = iotFieldsMap.get(String.format("%d_%s", modelId, attr)); + if (fieldInfoCache == null) { + return false; + } + return fieldInfoCache.isLowSpeed(); + } + + @Override + public boolean isCalculate(Long modelId, String attr) { + IotFieldInfoCache fieldInfoCache = iotFieldsMap.get(String.format("%d_%s", modelId, attr)); + if (fieldInfoCache == null) { + return false; + } + return fieldInfoCache.isCalculate(); + } } diff --git a/das/src/main/java/com/das/modules/calc/functions/FunctionSaveCalcData.java b/das/src/main/java/com/das/modules/calc/functions/FunctionSaveCalcData.java index a49a1d33..894d42ae 100644 --- a/das/src/main/java/com/das/modules/calc/functions/FunctionSaveCalcData.java +++ b/das/src/main/java/com/das/modules/calc/functions/FunctionSaveCalcData.java @@ -4,10 +4,12 @@ import com.das.modules.cache.domain.DeviceInfoCache; import com.das.modules.cache.service.CacheService; import com.das.modules.data.service.DataService; import com.das.modules.node.domain.bo.CalculateRTData; +import com.googlecode.aviator.exception.StandardError; import com.googlecode.aviator.runtime.function.AbstractVariadicFunction; import com.googlecode.aviator.runtime.function.FunctionUtils; import com.googlecode.aviator.runtime.type.AviatorObject; import com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import java.util.*; @@ -56,6 +58,7 @@ public class FunctionSaveCalcData extends AbstractVariadicFunction { // return AviatorRuntimeJavaType.valueOf(result); // } + @SneakyThrows @Override public AviatorObject variadicCall(Map env, AviatorObject... args) { if (args.length < 4) { return AviatorRuntimeJavaType.valueOf(1);} @@ -63,6 +66,9 @@ public class FunctionSaveCalcData extends AbstractVariadicFunction { //deviceCode String code = (String)args[0].getValue(env); DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCacheByCode(code); + if(deviceInfoCache == null) { + throw new StandardError(String.format("设备%s不存在", code)); + } List dataList = new ArrayList<>(); for (int i = 1; i < args.length; i+=3) { Date date = (Date)FunctionUtils.getJavaObject(args[i], env); diff --git a/das/src/main/java/com/das/modules/calc/functions/FunctionTopValue.java b/das/src/main/java/com/das/modules/calc/functions/FunctionTopValue.java index d03fcb4b..eedd5860 100644 --- a/das/src/main/java/com/das/modules/calc/functions/FunctionTopValue.java +++ b/das/src/main/java/com/das/modules/calc/functions/FunctionTopValue.java @@ -77,8 +77,20 @@ public class FunctionTopValue extends AbstractFunction { return AviatorRuntimeJavaType.valueOf(cacheValue.value); } } + else { + cacheValue = new CacheValue(); + } + Date startTime = DateUtil.beginOfDay(curTimeValue); + Date endTime = DateUtil.endOfDay(curTimeValue); + Double value = dataService.getTimeTopValue(deviceInfoCache.getDeviceId(), attrName, startTime.getTime(), endTime.getTime()); + if (value == null){ + return AviatorNil.NIL; + } + cacheValue.setValue(value); + cacheValue.setCurTimeValue(curTimeValue); + cacheValues.put(key, cacheValue); //未找到缓存,查询时序API获取数据 - return AviatorRuntimeJavaType.valueOf(1); + return AviatorRuntimeJavaType.valueOf(value); } @Data diff --git a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java index a555d1a2..7b2e9205 100644 --- a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java +++ b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java @@ -261,11 +261,18 @@ public class DataServiceImpl implements DataService { */ @Override public Double getTimeTopValue(Long devcieId, String attr, long startTime, long endTime){ - DeviceInfoCache deviceInfoCacheById = cacheService.getEquipmentCache().getDeviceInfoCacheById(devcieId); - if (deviceInfoCacheById == null) { + DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCacheById(devcieId); + if (deviceInfoCache == null) { return null; } String tableName = ""; + if (cacheService.getIotModelCache().isHighSpeed(deviceInfoCache.getIotModelId(), attr)){ + tableName = String.format("h_%s", deviceInfoCache.getDeviceId()); + } else if (cacheService.getIotModelCache().isLowSpeed(deviceInfoCache.getIotModelId(), attr)){ + tableName = String.format("l_%s", deviceInfoCache.getDeviceId()); + } else if (cacheService.getIotModelCache().isCalculate(deviceInfoCache.getIotModelId(), attr)){ + tableName = String.format("c_%s", deviceInfoCache.getDeviceId()); + } return tdEngineService.getTimeTopValue(tableName, attr, startTime, endTime); } } diff --git a/ui/dasadmin/src/views/backend/statAnalysis/index.vue b/ui/dasadmin/src/views/backend/statAnalysis/index.vue index c7b2f26c..0655da8d 100644 --- a/ui/dasadmin/src/views/backend/statAnalysis/index.vue +++ b/ui/dasadmin/src/views/backend/statAnalysis/index.vue @@ -2,16 +2,12 @@
{{ headerList[0] }} - - - - - - + + {{ headerList[1] }} + + + {{ headerList[2] }} + diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue index 76b5fe99..4bbc7270 100644 --- a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue +++ b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue @@ -1,92 +1,96 @@