diff --git a/das/src/main/java/com/das/modules/calc/functions/FunctionGetCacheValue.java b/das/src/main/java/com/das/modules/calc/functions/FunctionCacheValue.java similarity index 57% rename from das/src/main/java/com/das/modules/calc/functions/FunctionGetCacheValue.java rename to das/src/main/java/com/das/modules/calc/functions/FunctionCacheValue.java index 149a517e..178c6af7 100644 --- a/das/src/main/java/com/das/modules/calc/functions/FunctionGetCacheValue.java +++ b/das/src/main/java/com/das/modules/calc/functions/FunctionCacheValue.java @@ -1,11 +1,6 @@ package com.das.modules.calc.functions; import com.das.common.utils.AdminRedisTemplate; -import com.das.modules.cache.domain.DeviceInfoCache; -import com.das.modules.cache.service.CacheService; -import com.das.modules.data.domain.SnapshotValueQueryParam; -import com.das.modules.data.service.DataService; -import com.googlecode.aviator.exception.StandardError; import com.googlecode.aviator.runtime.function.AbstractFunction; import com.googlecode.aviator.runtime.type.AviatorNil; import com.googlecode.aviator.runtime.type.AviatorObject; @@ -13,8 +8,6 @@ import com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -24,9 +17,11 @@ import java.util.concurrent.ConcurrentHashMap; * 函数格式: cacheValue(key) 读取缓存值 */ @Slf4j -public class FunctionGetCacheValue extends AbstractFunction { - private ConcurrentHashMap cacheValues = new ConcurrentHashMap<>(); - public FunctionGetCacheValue( ) { +public class FunctionCacheValue extends AbstractFunction { + public static final String CACHE_PREFIX = "calc:cache:"; + private AdminRedisTemplate redis = null; + public FunctionCacheValue(AdminRedisTemplate redis) { + this.redis = redis; } @Override @@ -42,9 +37,22 @@ public class FunctionGetCacheValue extends AbstractFunction { Double value = (Double) valData.getValue(env); String scriptName = (String)env.get("G_SCRIPTNAME"); - String cacheKey = String.format("%s_%s", scriptName, key); - cacheValues.put(cacheKey, value); + String cacheKey = String.format("%s%s_%s", CACHE_PREFIX, scriptName, key); + redis.set(cacheKey, value); + return AviatorRuntimeJavaType.valueOf(0); + } + @SneakyThrows + @Override + public AviatorObject call(Map env, AviatorObject keyData, AviatorObject valData, AviatorObject ttlData) { + //设备Code + String key = (String)keyData.getValue(env); + Double value = (Double) valData.getValue(env); + Long ttl = (Long) ttlData.getValue(env); + String scriptName = (String)env.get("G_SCRIPTNAME"); + + String cacheKey = String.format("%s%s_%s", CACHE_PREFIX, scriptName, key); + redis.setEx(cacheKey, value, ttl); return AviatorRuntimeJavaType.valueOf(0); } @@ -54,8 +62,8 @@ public class FunctionGetCacheValue extends AbstractFunction { String key = (String)keyData.getValue(env); String scriptName = (String)env.get("G_SCRIPTNAME"); - String cacheKey = String.format("%s_%s", scriptName, key); - Double value = cacheValues.get(cacheKey); + String cacheKey = String.format("%s%s_%s", CACHE_PREFIX, scriptName, key); + Double value = redis.get(cacheKey); if (value == null) { return AviatorNil.NIL; } 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 894d42ae..73de903e 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 @@ -82,7 +82,6 @@ public class FunctionSaveCalcData extends AbstractVariadicFunction { dt.setIotModelField(attr); dataList.add(dt); } - dataService.updateCalFieldData(dataList); return AviatorRuntimeJavaType.valueOf(0); } diff --git a/das/src/main/java/com/das/modules/calc/service/CalcJob.java b/das/src/main/java/com/das/modules/calc/service/CalcJob.java index 2596592d..310e7717 100644 --- a/das/src/main/java/com/das/modules/calc/service/CalcJob.java +++ b/das/src/main/java/com/das/modules/calc/service/CalcJob.java @@ -1,6 +1,7 @@ package com.das.modules.calc.service; +import cn.hutool.core.util.StrUtil; import com.das.modules.cache.service.CacheService; import com.das.modules.calc.domain.entity.CalcModule; import com.googlecode.aviator.AviatorEvaluatorInstance; @@ -28,9 +29,19 @@ public class CalcJob implements Job { AviatorEvaluatorInstance instance = (AviatorEvaluatorInstance) dataMap.get("aviator"); CalcModule calcModule = (CalcModule) dataMap.get("module"); CacheService cacheService = (CacheService) dataMap.get("cache"); + Boolean isDebug = (Boolean) dataMap.get("isDebug"); + String debugTaskName = (String) dataMap.get("debugTaskName"); if (instance == null || calcModule == null || cacheService == null) { throw new JobExecutionException("calcModule is null"); } + if (isDebug){ + if (StrUtil.isBlank(debugTaskName)){ + return; + } + else if (!debugTaskName.equals(calcModule.getName())){ + return; + } + } Expression expression = instance.getCachedExpressionByKey(calcModule.getName()); if (expression == null) { log.error("expression is null, calcModule={}", calcModule.getName()); @@ -38,6 +49,8 @@ public class CalcJob implements Job { } //准备全局变量 Map envs = expression.newEnv(); + //调试变量 + envs.put("ISDEBUG", isDebug); //脚本名称 envs.put("G_SCRIPTNAME", calcModule.getName()); //风场信息 diff --git a/das/src/main/java/com/das/modules/calc/service/CalcService.java b/das/src/main/java/com/das/modules/calc/service/CalcService.java index 395c68c5..0d2f9da4 100644 --- a/das/src/main/java/com/das/modules/calc/service/CalcService.java +++ b/das/src/main/java/com/das/modules/calc/service/CalcService.java @@ -2,10 +2,11 @@ package com.das.modules.calc.service; import cn.hutool.core.codec.Base64Encoder; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.das.common.utils.AdminRedisTemplate; import com.das.modules.cache.service.CacheService; import com.das.modules.calc.domain.entity.CalcModule; import com.das.modules.calc.domain.vo.CalcModuleVo; -import com.das.modules.calc.functions.FunctionGetCacheValue; +import com.das.modules.calc.functions.FunctionCacheValue; import com.das.modules.calc.functions.FunctionRealData; import com.das.modules.calc.functions.FunctionSaveCalcData; import com.das.modules.calc.mapper.CalcModuleMapper; @@ -17,19 +18,14 @@ import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; import org.quartz.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; /** * 计算引擎服务 @@ -53,6 +49,15 @@ public class CalcService { @Autowired DataService dataService; + @Autowired + AdminRedisTemplate adminRedisTemplate; + + @Value("${calc.debug.enable}") + Boolean isDebug; + + @Value("${calc.debug.task-name}") + String debugTaskName; + /** * 计算引擎实例 */ @@ -70,6 +75,8 @@ public class CalcService { dataMap.put("module", scriptModule); dataMap.put("aviator", aviator); dataMap.put("cache", cacheService); + dataMap.put("isDebug", isDebug); + dataMap.put("debugTaskName", debugTaskName); JobKey jobKey = JobKey.jobKey(scriptModule.getName(), "CalcEngine"); if (sh.checkExists(jobKey)){ throw new SchedulerException("计算模块已启动,请先停止该模块"); @@ -112,7 +119,7 @@ public class CalcService { FunctionSaveCalcData save = new FunctionSaveCalcData(dataService, cacheService); aviator.addFunction(save); - FunctionGetCacheValue cache = new FunctionGetCacheValue(); + FunctionCacheValue cache = new FunctionCacheValue(adminRedisTemplate); aviator.addFunction(cache); } diff --git a/das/src/main/java/com/das/modules/data/service/TDEngineService.java b/das/src/main/java/com/das/modules/data/service/TDEngineService.java index 860ab832..5ee1044b 100644 --- a/das/src/main/java/com/das/modules/data/service/TDEngineService.java +++ b/das/src/main/java/com/das/modules/data/service/TDEngineService.java @@ -806,4 +806,53 @@ public class TDEngineService { } return result; } + + public Boolean checkTableExist(String tableName){ + StringBuffer sb = new StringBuffer(256); + sb.append("select count(*) as tablecount from information_schema.ins_tables where table_name = '"); + sb.append(tableName); + sb.append("'"); + Integer result = null; + try (Connection conn = hikariDataSource.getConnection(); + Statement smt = conn.createStatement(); + ResultSet rs = smt.executeQuery(sb.toString())) { + if (rs.next()) { + result = rs.getInt("tablecount"); + } + } catch (Exception e) { + log.error("检查td表是否存在失败", e); + } + return result != null && result == 1; + } + + public void updateTagDeviceName(String tableName,String deviceName){ + + StringBuffer sb = new StringBuffer(256); + sb.append("ALTER table "); + sb.append(tableName); + sb.append(" SET TAG device_name = '").append(deviceName).append("'"); + + try (Connection conn = hikariDataSource.getConnection(); + Statement pstmt = conn.createStatement()) { + pstmt.executeUpdate(sb.toString()); + + } catch (Exception e) { + log.error("修改Tag值失败", e); + } + } + + public void updateTagDeviceCode(String tableName,String deviceCode){ + StringBuffer sb = new StringBuffer(256); + sb.append("ALTER table "); + sb.append(tableName); + sb.append(" SET TAG device_code = '").append(deviceCode).append("'"); + + try (Connection conn = hikariDataSource.getConnection(); + Statement pstmt = conn.createStatement()) { + pstmt.executeUpdate(sb.toString()); + + } catch (Exception e) { + log.error("修改Tag值失败", e); + } + } } 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 7b2e9205..22c4ccca 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 @@ -25,6 +25,7 @@ import org.springframework.util.StopWatch; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import java.util.stream.Collectors; @Slf4j @@ -71,6 +72,10 @@ public class DataServiceImpl implements DataService { public ConcurrentHashMap> eventLevelMap = new ConcurrentHashMap<>(10000); + public ConcurrentHashMap> stateDescMap = new ConcurrentHashMap<>(10000); + + + /** * 读取实时数据快照 * @param paramList 设备id及设备属性列表 @@ -234,6 +239,7 @@ public class DataServiceImpl implements DataService { Map calculateFieldList = allIotModelField.stream().filter(field -> field.getAttributeType() == 199).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); Map fieldCodeNameList = allIotModelField.stream().collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getAttributeName, (value1, value2) -> value1)); Map eventLevelList = allIotModelField.stream().collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getLevel, (value1, value2) -> value1)); + Map stateDescList = allIotModelField.stream().filter(field -> field.getStateDesc() != null).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getStateDesc, (value1, value2) -> value1)); Map map = new HashMap<>(); for (String field : HighModelFieldList.keySet()) { map.put(field, HighModelFieldList.get(field)); @@ -247,6 +253,8 @@ public class DataServiceImpl implements DataService { eventLevelMap.put(item.getIotModelCode(),eventLevelList); fieldCodeNameMap.put(item.getIotModelCode(),fieldCodeNameList); calculateIotFieldMap.put(item.getIotModelCode(), calculateFieldList); + stateDescMap.put(item.getIotModelCode(),stateDescList); + } tdEngineService.initIotModel(allIotModel, highIotFieldMap, lowIotFieldMap, calculateIotFieldMap); } diff --git a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java index 93db7246..1c9a9f67 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java +++ b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java @@ -75,5 +75,7 @@ public class SysIotModelFieldDto implements Serializable { private Integer level; + private String stateDesc; + } diff --git a/das/src/main/java/com/das/modules/equipment/domain/excel/SysIotModelFieldExcel.java b/das/src/main/java/com/das/modules/equipment/domain/excel/SysIotModelFieldExcel.java index 3d272ef7..28398efc 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/excel/SysIotModelFieldExcel.java +++ b/das/src/main/java/com/das/modules/equipment/domain/excel/SysIotModelFieldExcel.java @@ -67,4 +67,6 @@ public class SysIotModelFieldExcel { private Integer level; + private String stateDesc; + } diff --git a/das/src/main/java/com/das/modules/equipment/domain/vo/SysIotModelFieldVo.java b/das/src/main/java/com/das/modules/equipment/domain/vo/SysIotModelFieldVo.java index 9f72e637..48729179 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/vo/SysIotModelFieldVo.java +++ b/das/src/main/java/com/das/modules/equipment/domain/vo/SysIotModelFieldVo.java @@ -68,4 +68,6 @@ public class SysIotModelFieldVo { private Integer level; + private String stateDesc; + } diff --git a/das/src/main/java/com/das/modules/equipment/entity/SysIotModelField.java b/das/src/main/java/com/das/modules/equipment/entity/SysIotModelField.java index 3180601c..21bfb3c8 100644 --- a/das/src/main/java/com/das/modules/equipment/entity/SysIotModelField.java +++ b/das/src/main/java/com/das/modules/equipment/entity/SysIotModelField.java @@ -105,4 +105,10 @@ public class SysIotModelField extends BaseEntity { */ @TableField("level") private Integer level; + + /** + * 告警描述 + */ + @TableField("statedesc") + private String stateDesc; } diff --git a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java index 3d05481c..86d9d1f3 100644 --- a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java +++ b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java @@ -16,6 +16,7 @@ import com.das.common.utils.SequenceUtils; import com.das.modules.auth.domain.vo.SysUserVo; import com.das.modules.auth.mapper.SysOrgMapper; import com.das.modules.cache.service.CacheService; +import com.das.modules.data.service.TDEngineService; import com.das.modules.data.service.impl.DataServiceImpl; import com.das.modules.equipment.domain.dto.SysEquipmentDto; import com.das.modules.equipment.domain.excel.SysEquipmentExcel; @@ -66,6 +67,9 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Autowired private CacheService cacheService; + @Autowired + private TDEngineService tdEngineService; + @Override public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) { //去除空格 @@ -119,6 +123,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(sysEquipment.getId()); + if (tdEngineService.checkTableExist("e_"+sysEquipment.getId())){ + tdEngineService.updateTagDeviceCode("e_"+sysEquipment.getId(),sysEquipment.getCode()); + tdEngineService.updateTagDeviceName("e_"+sysEquipment.getId(),sysEquipment.getName()); + } SysEquipmentVo sysEquipmentVo = new SysEquipmentVo(); BeanCopyUtils.copy(sysEquipment, sysEquipmentVo); return sysEquipmentVo; @@ -319,6 +327,12 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(item.getId()); + + //更新td表TAG + if (tdEngineService.checkTableExist("e_"+item.getId())){ + tdEngineService.updateTagDeviceCode("e_"+item.getId(),item.getCode()); + tdEngineService.updateTagDeviceName("e_"+item.getId(),item.getName()); + } } } if (CollectionUtils.isNotEmpty(delSysEquipmentList)) { diff --git a/das/src/main/java/com/das/modules/equipment/service/impl/SysIotModelServiceImpl.java b/das/src/main/java/com/das/modules/equipment/service/impl/SysIotModelServiceImpl.java index 3d73749b..09b86505 100644 --- a/das/src/main/java/com/das/modules/equipment/service/impl/SysIotModelServiceImpl.java +++ b/das/src/main/java/com/das/modules/equipment/service/impl/SysIotModelServiceImpl.java @@ -305,6 +305,7 @@ public class SysIotModelServiceImpl implements SysIotModelService { map.put("visible", "是否可见(0:不可见,1:可见)"); map.put("highSpeed", "*属性频度(0低频属性,1高频属性)"); map.put("level","离散量级别:0提示;1告警;2故障"); + map.put("stateDesc","告警级别描述"); sheetDTO.setSheetName("物模型属性"); sheetDTO.setFieldAndAlias(map); sheetDTO.setCollection(sysIotModelFieldVoList); @@ -519,6 +520,7 @@ public class SysIotModelServiceImpl implements SysIotModelService { field.setVisible(ObjectUtil.isEmpty(row.get(10)) ? null : Integer.valueOf(row.get(10).toString())); field.setHighSpeed(Integer.valueOf(row.get(11).toString())); field.setLevel(ObjectUtil.isEmpty(row.get(12)) ? null : Integer.valueOf(row.get(12).toString())); + field.setStateDesc(ObjectUtil.isEmpty(row.get(13)) ? null : row.get(13).toString()); field.setIotModelId(Long.valueOf(iotModelId)); } @@ -633,6 +635,16 @@ public class SysIotModelServiceImpl implements SysIotModelService { } } + if (sysIotModelField.getStateDesc() != null){ + Map stateDescMap = dataService.stateDescMap.get(modelCode); + if (stateDescMap == null) { + Map calMap = new HashMap<>(); + calMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getStateDesc()); + dataService.stateDescMap.put(modelCode, calMap); + } else { + stateDescMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getStateDesc()); + } + } if (sysIotModelField.getAttributeType() == 199) { Map map = dataService.calculateIotFieldMap.get(modelCode); if (map == null) { @@ -684,6 +696,9 @@ public class SysIotModelServiceImpl implements SysIotModelService { if (sysIotModelField.getLevel() != null){ dataService.eventLevelMap.remove(sysIotModelField.getAttributeCode()); } + if (sysIotModelField.getStateDesc() != null){ + dataService.stateDescMap.remove(sysIotModelField.getAttributeCode()); + } if (sysIotModelField.getAttributeType() == 199) { Map map = dataService.calculateIotFieldMap.get(modelCode); map.remove(sysIotModelField.getAttributeCode()); diff --git a/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java index 2d17a5cb..1ad634f1 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java @@ -369,12 +369,20 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node deviceEventInfo.setEventType(item.getEventType()); deviceEventInfo.setConfirmed(0); if (!StringUtils.isEmpty(eventType) && eventType.equals("遥信变位")) { + String stateDesc = dataService.stateDescMap.get(model).get(item.getAttrCode()); if (item.getAttrValue().equals(0)) { deviceEventInfo.setEventText(item.getAttrCode()+fieldName + " 复归"); - + if (StringUtils.isNotEmpty(stateDesc)){ + List descList = Arrays.stream(stateDesc.split("\\|")).toList(); + deviceEventInfo.setEventText(item.getAttrCode()+fieldName + descList.get(0)); + } deviceEventInfo.setEventLevel(0); } else { deviceEventInfo.setEventText(item.getAttrCode()+fieldName + " 动作"); + if (StringUtils.isNotEmpty(stateDesc)){ + List descList = Arrays.stream(stateDesc.split("\\|")).toList(); + deviceEventInfo.setEventText(item.getAttrCode()+fieldName + descList.get(1)); + } Integer level = dataService.eventLevelMap.get(model).get(item.getAttrCode()); log.info("level:{}",level); log.info("fieldname{}",fieldName); diff --git a/das/src/main/resources/application-dev.yml b/das/src/main/resources/application-dev.yml index 469df38b..62cbd474 100644 --- a/das/src/main/resources/application-dev.yml +++ b/das/src/main/resources/application-dev.yml @@ -86,9 +86,15 @@ captcha: expire: 120 das: + debug: true aes: key: b6967ee87b86d85a +calc: + debug: + enable: true + task-name: + logging: level: com: @@ -96,5 +102,5 @@ logging: tdengine: password: taosdata - url: jdbc:TAOS-RS://192.168.109.160:6041/das + url: jdbc:TAOS-RS://192.168.109.187:6041/das username: root \ No newline at end of file diff --git a/das/src/main/resources/application.yml b/das/src/main/resources/application.yml index 2b490a4e..8c8f6e94 100644 --- a/das/src/main/resources/application.yml +++ b/das/src/main/resources/application.yml @@ -85,7 +85,13 @@ captcha: verify-type: calculate expire: 120 +calc: + debug: + enable: false + task-name: + das: + debug: false aes: key: b6967ee87b86d85a diff --git a/das/src/main/resources/mapper/SysIotModelMapper.xml b/das/src/main/resources/mapper/SysIotModelMapper.xml index 510289f3..e930c439 100644 --- a/das/src/main/resources/mapper/SysIotModelMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelMapper.xml @@ -36,13 +36,13 @@ diff --git a/ui/dasadmin/src/views/backend/report/SingleReport.vue b/ui/dasadmin/src/views/backend/report/SingleReport.vue index 8f17d6ba..b086fd05 100644 --- a/ui/dasadmin/src/views/backend/report/SingleReport.vue +++ b/ui/dasadmin/src/views/backend/report/SingleReport.vue @@ -148,7 +148,7 @@ const shortcuts = [ text: '今天', value: () => { const start = getFormattedDate(0) + ' 00:00:00' - const end = new Date() + const end = getFormattedDate(0) + ' 23:59:59' return [start, end] }, }, @@ -200,11 +200,13 @@ const dateValue = ref('') const windBlowerValue = ref('') const windBlowerList = ref([]) // 时间 -const timeRange = ref([]) +const timeRange = ref([]) as any // 间隔 -const interval = ref('') +const interval = ref('15m') const intervals = [ + { label: '一分钟', value: '1m' }, { label: '五分钟', value: '5m' }, + { label: '十分钟', value: '10m' }, { label: '十五分钟', value: '15m' }, { label: '一小时', value: '1h' }, { label: '一天', value: '1d' }, @@ -321,6 +323,7 @@ const queryWindBlower = () => { modelId: item.modelId, } }) + windBlowerValue.value = windBlowerList.value?.[0].irn } }) } @@ -450,7 +453,7 @@ const queryHistoryData = () => { tableData.push({ name: item, times: realResult[item].times, - value: realResult[item].values, + value: realResult[item].values.map((val: any) => (val === 0 ? 0 : val.toFixed(2))), }) } }) @@ -529,6 +532,7 @@ const timestampToTime = (timestamp: any) => { getReportTemplateList() onMounted(() => { + timeRange.value = shortcuts[0].value() queryWindBlower() }) diff --git a/ui/dasadmin/src/views/backend/report/index.vue b/ui/dasadmin/src/views/backend/report/index.vue index d6984ad7..1e4a49f8 100644 --- a/ui/dasadmin/src/views/backend/report/index.vue +++ b/ui/dasadmin/src/views/backend/report/index.vue @@ -1,7 +1,8 @@ @@ -40,7 +41,7 @@ const handleClick = (val: any) => { .mainContainer { width: 100%; height: 100%; - padding: 0 20px; + padding: 20px; .el-tabs { width: 100%; --el-tabs-header-height: 60px; diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue index 27f3457b..d2f0bf55 100644 --- a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue +++ b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue @@ -50,7 +50,7 @@ row-key="id" > - + - + @@ -79,7 +79,7 @@ :data="attrTableData" ref="attributeTableRef" @select="selectTable" - @selectAll="selectAllTable" + @selectAll="selectTable" row-key="id" class="attrtable" > @@ -200,7 +200,7 @@ onMounted(() => { }) const tableDataLeft = ref([]) const tableDataRight = ref([]) - +const iotModelId = ref('') const selectedLeft = ref([]) const selectedRight = ref([]) @@ -213,9 +213,12 @@ const queryWindTurbines = () => { queryWindTurbinesPages().then((res) => { if (res.code == 200) { const resData = res.data - const middleIndex = Math.ceil(resData.length / 2) - tableDataLeft.value = resData.slice(0, middleIndex) - tableDataRight.value = resData.slice(middleIndex) + if (resData.length) { + iotModelId.value = resData[0]['modelId'] + const middleIndex = Math.ceil(resData.length / 2) + tableDataLeft.value = resData.slice(0, middleIndex) + tableDataRight.value = resData.slice(middleIndex) + } } }) } @@ -233,7 +236,7 @@ const getcurrentPage = () => { const getCompleteData = () => { const requestData: any = { - iotModelId: '', + iotModelId: iotModelId.value, pageNum: pageSetting.current, pageSize: pageSetting.pageSize, attributeType: radioActiveName.value, @@ -271,30 +274,18 @@ const initSelect = () => { const multipleSelection: any = ref([]) const selectTable = (section: any) => { - const defaultCode = multipleSelection.value.map((item: any) => item.attributeCode) - const addSection = section - .filter((item: any) => !defaultCode.includes(item.attributeCode)) - .map((item: any) => { - return { - attributeName: item.attributeName, - attributeCode: item.attributeCode, - unit: item.unit, - } - }) - multipleSelection.value = [...multipleSelection.value, ...addSection] -} -const selectAllTable = (section: any) => { - const defaultCode = multipleSelection.value.map((item: any) => item.attributeCode) - const addSection = section - .filter((item: any) => !defaultCode.includes(item.attributeCode)) - .map((item: any) => { - return { - attributeName: item.attributeName, - attributeCode: item.attributeCode, - unit: item.unit, - } - }) - multipleSelection.value = [...multipleSelection.value, ...addSection] + const allCode = attrTableData.value.map((item: any) => { + return item.attributeCode + }) + const extraCode = multipleSelection.value.filter((item: any) => !allCode.includes(item.attributeCode)) + const setionMap = section.map((item: any) => { + return { + attributeName: item.attributeName, + attributeCode: item.attributeCode, + unit: item.unit, + } + }) + multipleSelection.value = [...extraCode, ...setionMap] } const attrTableData = ref([]) @@ -364,6 +355,7 @@ const getDateRange = (type: 'week' | 'month') => { const openMeasure = () => { showMeasure.value = true + pageSetting.current = 1 } const handleSelectionChange1 = (val: any) => {