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 cf7615c3..b6c30c70 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 @@ -175,10 +175,9 @@ public class SysIotModelServiceImpl implements SysIotModelService { if (sysIotModelFieldDto.getAttributeType() == 140) { sysIotModelField.setDataType("tinyint"); } - + sysIotModelFieldMapper.insert(sysIotModelField); //动态执行创建td超级表,字段 createTdStableOrColumn(sysIotModelField); - sysIotModelFieldMapper.insert(sysIotModelField); //新增物模型属性缓存 addModelFieldCache(sysIotModelField); SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo(); @@ -204,12 +203,11 @@ public class SysIotModelServiceImpl implements SysIotModelService { throw new ServiceException("物模型属性code已经存在"); } } - sysIotModelFieldMapper.updateById(sysIotModelField); - SysIotModelField oldSysIotField = sysIotModelFieldMapper.selectById(sysIotModelFieldDto.getId()); if (oldSysIotField == null) { throw new ServiceException("未查找到该条记录"); } + sysIotModelFieldMapper.updateById(sysIotModelField); if (!oldSysIotField.getAttributeCode().equals(sysIotModelField.getAttributeCode()) || !oldSysIotField.getDataType().equals(sysIotModelField.getDataType()) || Objects.equals(oldSysIotField.getHighSpeed(), sysIotModelField.getHighSpeed())) { //更新td表结构 updateTDStableOrColumn(sysIotModelField, oldSysIotField); @@ -223,8 +221,9 @@ public class SysIotModelServiceImpl implements SysIotModelService { @Override public void deleteSysIotModelField(SysIotModelFieldDto sysIotModelFieldDto) { SysIotModelField sysIotModelField = sysIotModelFieldMapper.selectById(sysIotModelFieldDto.getId()); - deleteTDStableOrColumn(sysIotModelField); sysIotModelFieldMapper.deleteById(sysIotModelFieldDto.getId()); + //删除td表结构字段 + deleteTDStableOrColumn(sysIotModelField); //删除物模型属性缓存 deleteModelFieldCache(sysIotModelField); } @@ -437,9 +436,10 @@ public class SysIotModelServiceImpl implements SysIotModelService { } if (CollectionUtils.isNotEmpty(sysIotModelFieldList)) { //创建td表结构 - //分为高频低频两个list创建 - List lowCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 0).collect(Collectors.toList()); - List highCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 1).collect(Collectors.toList()); + //分为高频,低频,计算量三个list创建 + List lowCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 0 && item.getAttributeType() != 199).collect(Collectors.toList()); + List highCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 1 && item.getAttributeType() != 199).collect(Collectors.toList()); + List calCreateList = sysIotModelFieldList.stream().filter(item -> item.getAttributeType() == 199).collect(Collectors.toList()); for (int i = 0; i < lowCreateList.size(); i++) { if (i == 0) { createTdStableOrColumn(lowCreateList.get(i)); @@ -452,7 +452,7 @@ public class SysIotModelServiceImpl implements SysIotModelService { map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); //创建低频超级表 tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map); - + addModelFieldCache(lowCreateList.get(i)); } } for (int i = 0; i < highCreateList.size(); i++) { @@ -467,8 +467,12 @@ public class SysIotModelServiceImpl implements SysIotModelService { map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); //创建高频超级表 tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map); + addModelFieldCache(highCreateList.get(i)); } - + } + for (SysIotModelField item : calCreateList){ + createTdStableOrColumn(item); + addModelFieldCache(item); } //新增pg数据库 sysIotModelFieldMapper.insertBatch(sysIotModelFieldList); @@ -480,7 +484,7 @@ public class SysIotModelServiceImpl implements SysIotModelService { if (!oldSysIotField.getAttributeCode().equals(item.getAttributeCode()) && oldSysIotField.getDataType().equals(item.getDataType()) && Objects.equals(oldSysIotField.getHighSpeed(), item.getHighSpeed())) { //更新td表结构 updateTDStableOrColumn(item, oldSysIotField); - updateModelFieldCache(item,oldSysIotField); + updateModelFieldCache(item, oldSysIotField); } } } @@ -524,41 +528,48 @@ public class SysIotModelServiceImpl implements SysIotModelService { } public void createTdStableOrColumn(SysIotModelField sysIotModelField) { - //如果新增的是第一条记录 创建tdengine超级表 分为高频和低频 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId()); - queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed()); - List sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper); - if (CollectionUtils.isEmpty(sysIotModelFields)) { - if (sysIotModelField.getHighSpeed() == 0) { - SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); - Map map = new HashMap<>(); - map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - //创建低频超级表 - tdEngineService.createStable(sysIotModel.getIotModelCode(), "l_", map); - } - if (sysIotModelField.getHighSpeed() == 1) { - SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); - Map map = new HashMap<>(); - map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - //创建高频超级表 - tdEngineService.createStable(sysIotModel.getIotModelCode(), "h_", map); - } + //如果type是计算量199,创建单独计算量超级表 + if (sysIotModelField.getAttributeType() == 199) { + String modelCode = dataService.iotModelMap.get(sysIotModelField.getIotModelId().toString()); + tdEngineService.createCalStable(modelCode, sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); } else { - //stable已经存在,新增stable列 - if (sysIotModelField.getHighSpeed() == 0) { - SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); - Map map = new HashMap<>(); - map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - //创建低频超级表 - tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map); - } - if (sysIotModelField.getHighSpeed() == 1) { - SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); - Map map = new HashMap<>(); - map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - //创建高频超级表 - tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map); + //创建type为138 139 140的超级表 + //如果新增的是第一条记录 创建tdengine超级表 分为高频和低频 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId()); + queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed()); + List sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper); + if (CollectionUtils.isEmpty(sysIotModelFields)) { + if (sysIotModelField.getHighSpeed() == 0) { + SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); + Map map = new HashMap<>(); + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + //创建低频超级表 + tdEngineService.createStable(sysIotModel.getIotModelCode(), "l_", map); + } + if (sysIotModelField.getHighSpeed() == 1) { + SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); + Map map = new HashMap<>(); + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + //创建高频超级表 + tdEngineService.createStable(sysIotModel.getIotModelCode(), "h_", map); + } + } else { + //stable已经存在,新增stable列 + if (sysIotModelField.getHighSpeed() == 0) { + SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); + Map map = new HashMap<>(); + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + //创建低频超级表 + tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map); + } + if (sysIotModelField.getHighSpeed() == 1) { + SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); + Map map = new HashMap<>(); + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + //创建高频超级表 + tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map); + } } } } @@ -569,52 +580,70 @@ public class SysIotModelServiceImpl implements SysIotModelService { } public void deleteTDStableOrColumn(SysIotModelField sysIotModelField) { - String stableName = null; - SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); - if (sysIotModelField.getHighSpeed() == 0) { - stableName = "l_" + sysIotModel.getIotModelCode(); - } - if (sysIotModelField.getHighSpeed() == 1) { - stableName = "h_" + sysIotModel.getIotModelCode(); - } - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId()); - queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed()); - List sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper); - if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1) { - tdEngineService.deleteColumn(stableName, sysIotModelField.getAttributeCode()); - } - //物模型属性只剩下最后一个删除表 - if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1) { - tdEngineService.deleteStable(stableName); + if (sysIotModelField.getAttributeType() == 199) { + Long iotModelId = sysIotModelField.getIotModelId(); + String modelCode = dataService.iotModelMap.get(iotModelId.toString()); + tdEngineService.deleteStable("c_" + modelCode +"_"+ sysIotModelField.getAttributeCode()); + } else { + String stableName = null; + SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); + if (sysIotModelField.getHighSpeed() == 0) { + stableName = "l_" + sysIotModel.getIotModelCode(); + } + if (sysIotModelField.getHighSpeed() == 1) { + stableName = "h_" + sysIotModel.getIotModelCode(); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId()); + queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed()); + List sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper); + if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1) { + tdEngineService.deleteColumn(stableName, sysIotModelField.getAttributeCode()); + } + //物模型属性只剩下最后一个删除表 + if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1) { + tdEngineService.deleteStable(stableName); + } } + } //新增物模型属性,属性dataType缓存 private void addModelFieldCache(SysIotModelField sysIotModelField) { //获取物模型编码 String modelCode = dataService.iotModelMap.get(sysIotModelField.getIotModelId().toString()); - if (sysIotModelField.getHighSpeed() == 0) { - Map map = dataService.lowIotFieldMap.get(modelCode); - if (map == null){ - Map cacheFieldMap = new HashMap<>(); - cacheFieldMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - dataService.lowIotFieldMap.put(modelCode,cacheFieldMap); - } - else { + if (sysIotModelField.getAttributeType() == 199) { + Map map = dataService.calculateIotFieldMap.get(modelCode); + if (map == null) { + Map calMap = new HashMap<>(); + calMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + dataService.calculateIotFieldMap.put(modelCode, calMap); + } else { map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); } - } - if (sysIotModelField.getHighSpeed() == 1) { - Map map = dataService.highIotFieldMap.get(modelCode); - if (map == null){ - Map cacheFieldMap = new HashMap<>(); - cacheFieldMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); - dataService.highIotFieldMap.put(modelCode,cacheFieldMap); - }else { - map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + } else { + if (sysIotModelField.getHighSpeed() == 0) { + Map map = dataService.lowIotFieldMap.get(modelCode); + if (map == null) { + Map cacheFieldMap = new HashMap<>(); + cacheFieldMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + dataService.lowIotFieldMap.put(modelCode, cacheFieldMap); + } else { + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + } + } + if (sysIotModelField.getHighSpeed() == 1) { + Map map = dataService.highIotFieldMap.get(modelCode); + if (map == null) { + Map cacheFieldMap = new HashMap<>(); + cacheFieldMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + dataService.highIotFieldMap.put(modelCode, cacheFieldMap); + } else { + map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); + } } } + } //更新物模型属性,属性dataType缓存 @@ -625,25 +654,30 @@ public class SysIotModelServiceImpl implements SysIotModelService { addModelFieldCache(newSysIotModelField); } - //新增物模型属性,属性dataType缓存 + //删除物模型属性,删除属性缓存 private void deleteModelFieldCache(SysIotModelField sysIotModelField) { //获取物模型编码 String modelCode = dataService.iotModelMap.get(sysIotModelField.getIotModelId().toString()); - if (sysIotModelField.getHighSpeed() == 0) { - Map map = dataService.lowIotFieldMap.get(modelCode); - map.remove(sysIotModelField.getAttributeCode()); - } - if (sysIotModelField.getHighSpeed() == 1) { - Map map = dataService.highIotFieldMap.get(modelCode); + if (sysIotModelField.getAttributeType() == 199){ + Map map = dataService.calculateIotFieldMap.get(modelCode); map.remove(sysIotModelField.getAttributeCode()); + }else { + if (sysIotModelField.getHighSpeed() == 0) { + Map map = dataService.lowIotFieldMap.get(modelCode); + map.remove(sysIotModelField.getAttributeCode()); + } + if (sysIotModelField.getHighSpeed() == 1) { + Map map = dataService.highIotFieldMap.get(modelCode); + map.remove(sysIotModelField.getAttributeCode()); + } } } - private void addModelCache(SysIotModel sysIotModel){ + private void addModelCache(SysIotModel sysIotModel) { dataService.iotModelMap.put(sysIotModel.getId().toString(), sysIotModel.getIotModelCode()); } - private void deleteModelCache(Long irn){ + private void deleteModelCache(Long irn) { dataService.iotModelMap.remove(irn.toString()); } } diff --git a/das/src/main/java/com/das/modules/node/service/TDEngineService.java b/das/src/main/java/com/das/modules/node/service/TDEngineService.java index 2f805a8a..b2ef082c 100644 --- a/das/src/main/java/com/das/modules/node/service/TDEngineService.java +++ b/das/src/main/java/com/das/modules/node/service/TDEngineService.java @@ -91,6 +91,27 @@ public class TDEngineService { } } + public void createCalStable(String iotmodel, String iotModelField,String dataType) { + try (Connection conn = hikariDataSource.getConnection(); + Statement pstmt = conn.createStatement()) { + StringBuilder sb = new StringBuilder(1024 * 1024); + sb.setLength(0); + sb.append("CREATE STABLE IF NOT EXISTS "); + sb.append("c_").append(iotmodel).append("_").append(iotModelField); + sb.append(" (`updatetime` TIMESTAMP, datavalue "); + sb.append(dataType); + sb.append(") TAGS (`deviceid` BIGINT);"); + try { + log.info(sb.toString()); + pstmt.executeUpdate(sb.toString()); + } catch (Exception e) { + log.error("创建超级表失败,失败原因{}", e); + + } + } catch (Exception ignored) { + } + } + /** * 新增超级表列 */ @@ -170,14 +191,11 @@ public class TDEngineService { // 遍历所有的物模型存入内存中 - public void initIotModel(List allIotModel, ConcurrentHashMap> highIotFieldMap, ConcurrentHashMap> lowIotFieldMap) { + public void initIotModel(List allIotModel, ConcurrentHashMap> highIotFieldMap, ConcurrentHashMap> lowIotFieldMap, ConcurrentHashMap> calculateIotFieldMap) { // 创建物模型超级表 - try (Connection conn = hikariDataSource.getConnection(); Statement pstmt = conn.createStatement()) { - ListUtil.page(allIotModel, batchSize, list -> { - for (IotModelFieldVo info : list) { StringBuilder sb = new StringBuilder(1024 * 1024); sb.setLength(0); @@ -187,7 +205,6 @@ public class TDEngineService { sb.append("CREATE STABLE IF NOT EXISTS "); sb.append("h_").append(info.getIotModelCode()); sb.append(" (`updatetime` TIMESTAMP"); - // 使用增强的 for 循环遍历键 for (String key : map.keySet()) { sb.append(", "); @@ -202,7 +219,6 @@ public class TDEngineService { log.error("save yx error", ex); } } - } for (IotModelFieldVo info : list) { StringBuilder sb = new StringBuilder(1024 * 1024); @@ -227,6 +243,16 @@ public class TDEngineService { } } } + //初始化创建计算量td超级表 + for (IotModelFieldVo info : list) { + String iotModelCode = info.getIotModelCode(); + Map calFieldMap = calculateIotFieldMap.get(iotModelCode); + if (calFieldMap.keySet().size() != 0){ + for (String key : calFieldMap.keySet()){ + createCalStable(iotModelCode,key,calFieldMap.get(key)); + } + } + } }); } catch (SQLException ex) { log.error(ex.getMessage()); @@ -353,8 +379,8 @@ public class TDEngineService { } Map>> result = new HashMap<>(); Map> valueMap = new HashMap<>(); - for (String item : fieldList){ - valueMap.put(item,null); + for (String item : fieldList) { + valueMap.put(item, null); } StringBuffer sb = new StringBuffer(2048); if (StrUtil.isNotBlank(interval)) { @@ -389,17 +415,17 @@ public class TDEngineService { Statement smt = conn.createStatement(); ResultSet rs = smt.executeQuery(sb.toString())) { while (rs.next()) { - for (int i = 0; i < fieldList.size(); i++){ - if (valueMap.get(fieldList.get(i)) == null){ - Map map = new HashMap<>(); + for (int i = 0; i < fieldList.size(); i++) { + if (valueMap.get(fieldList.get(i)) == null) { + Map map = new HashMap<>(); List timeList = new ArrayList<>(); timeList.add(rs.getTimestamp(1).getTime()); List valueList = new ArrayList<>(); valueList.add(rs.getObject(fieldList.get(i).toLowerCase())); - map.put("times",timeList); - map.put("values",valueList); - valueMap.put(fieldList.get(i),map); - }else { + map.put("times", timeList); + map.put("values", valueList); + valueMap.put(fieldList.get(i), map); + } else { Map map = valueMap.get(fieldList.get(i)); List times = (List) map.get("times"); List values = (List) map.get("values"); @@ -408,7 +434,7 @@ public class TDEngineService { } } } - result.put(irn.toString(),valueMap); + result.put(irn.toString(), valueMap); } catch (Exception e) { log.error("获取数据异常", e); return result; @@ -426,8 +452,8 @@ public class TDEngineService { } Map>> result = new HashMap<>(); Map> valueMap = new HashMap<>(); - for (String item : fieldList){ - valueMap.put(item,null); + for (String item : fieldList) { + valueMap.put(item, null); } StringBuffer sb = new StringBuffer(2048); if (StrUtil.isNotBlank(interval)) { @@ -462,17 +488,17 @@ public class TDEngineService { Statement smt = conn.createStatement(); ResultSet rs = smt.executeQuery(sb.toString())) { while (rs.next()) { - for (int i = 0; i < fieldList.size(); i++){ - if (valueMap.get(fieldList.get(i)) == null){ - Map map = new HashMap<>(); + for (int i = 0; i < fieldList.size(); i++) { + if (valueMap.get(fieldList.get(i)) == null) { + Map map = new HashMap<>(); List timeList = new ArrayList<>(); timeList.add(rs.getTimestamp(1).getTime()); List valueList = new ArrayList<>(); valueList.add(rs.getObject(fieldList.get(i).toLowerCase())); - map.put("times",timeList); - map.put("values",valueList); - valueMap.put(fieldList.get(i),map); - }else { + map.put("times", timeList); + map.put("values", valueList); + valueMap.put(fieldList.get(i), map); + } else { Map map = valueMap.get(fieldList.get(i)); List times = (List) map.get("times"); List values = (List) map.get("values"); @@ -481,7 +507,7 @@ public class TDEngineService { } } } - result.put(irn.toString(),valueMap); + result.put(irn.toString(), valueMap); } catch (Exception e) { log.error("获取数据异常", e); return result; diff --git a/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java index bfde1ccb..1083ebb4 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java @@ -71,6 +71,8 @@ public class DataServiceImpl implements DataService { public ConcurrentHashMap> lowIotFieldMap = new ConcurrentHashMap<>(10000); + public ConcurrentHashMap> calculateIotFieldMap = new ConcurrentHashMap<>(10000); + @PostConstruct public void init() { //初始化高性能队列 @@ -218,8 +220,9 @@ public class DataServiceImpl implements DataService { String key = String.valueOf(item.getId()); iotModelMap.put(key, item.getIotModelCode()); List allIotModelField = sysIotModelMapper.getAllIotModelField(item.getId()); - Map LowModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 0).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); - Map HighModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 1).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); + Map LowModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 0 && field.getAttributeType() != 199).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); + Map HighModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 1 && field.getAttributeType() != 199).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); + Map calculateFieldList = allIotModelField.stream().filter(field -> field.getAttributeType() == 199).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1)); Map map = new HashMap<>(); for (String field : HighModelFieldList.keySet()) { map.put(field, HighModelFieldList.get(field)); @@ -230,8 +233,9 @@ public class DataServiceImpl implements DataService { lowMap.put(field, LowModelFieldList.get(field)); } lowIotFieldMap.put(item.getIotModelCode(), lowMap); + calculateIotFieldMap.put(item.getIotModelCode(),calculateFieldList); } - tdEngineService.initIotModel(allIotModel, highIotFieldMap, lowIotFieldMap); + tdEngineService.initIotModel(allIotModel, highIotFieldMap, lowIotFieldMap,calculateIotFieldMap); } @Override diff --git a/das/src/main/resources/mapper/SysIotModelMapper.xml b/das/src/main/resources/mapper/SysIotModelMapper.xml index 8e5d8dc7..e9e43643 100644 --- a/das/src/main/resources/mapper/SysIotModelMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelMapper.xml @@ -78,7 +78,7 @@ where se.id = #{id} diff --git a/ui/dasadmin/src/views/backend/report/index.vue b/ui/dasadmin/src/views/backend/report/index.vue new file mode 100644 index 00000000..60d83eb6 --- /dev/null +++ b/ui/dasadmin/src/views/backend/report/index.vue @@ -0,0 +1,436 @@ + + + + + diff --git a/ui/dasadmin/src/views/backend/report/measureList.vue b/ui/dasadmin/src/views/backend/report/measureList.vue new file mode 100644 index 00000000..5b5652be --- /dev/null +++ b/ui/dasadmin/src/views/backend/report/measureList.vue @@ -0,0 +1,213 @@ + + + + + diff --git a/ui/dasadmin/src/views/backend/report/type.ts b/ui/dasadmin/src/views/backend/report/type.ts new file mode 100644 index 00000000..e0617b04 --- /dev/null +++ b/ui/dasadmin/src/views/backend/report/type.ts @@ -0,0 +1,23 @@ +export type RequestReturnType = Promise<{ + code: number + msg: string + success: boolean + data?: T +}> + +export type RequestReturnRowType = Promise<{ + code: number + msg: string + rows: T + total: number +}> + +// 风机列表 +export type WindBlowerList = { + attributeMap: any + belongLine: string + irn: string + model: string + modelId: string + name: string +} diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue index c7e02d93..ed9d54a0 100644 --- a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue +++ b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue @@ -175,7 +175,7 @@ const selectstatAnalysisAttributes = () => { const chartContainer = ref(null) -const option = reactive({ +const option = { dataZoom: [ { type: 'inside', @@ -206,7 +206,7 @@ const option = reactive({ left: '3%', right: '3%', }, -}) +} const statAnalysisSelectOptions = reactive({ interval: [ @@ -316,10 +316,9 @@ const getTimeIntervals = (startTimestamp, endTimestamp) => { return count } const statAnalysisOperate = () => { - option.tooltip = {} - option.xAxis.data = [] - option.legend.data = [] option.series = [] + chart.value.setOption(option) + chart.value.clear() times.forEach((time, index) => { if (time[0] && time[1]) { const requestData = { @@ -355,7 +354,7 @@ const historyDataReq = (data, index) => { option.tooltip = { show: true, formatter: function (params) { - const x = timestampToTime(xDatas[index][params.dataIndex]) + const x = timestampToTime(xData[params.dataIndex]) return `${params.marker} ${params.seriesName} ${x} : ${params.data}` }, } @@ -367,8 +366,6 @@ const historyDataReq = (data, index) => { } option.legend.data.push(String(index + 1)) option.series.push(seriesData) - console.log('🚀 ~ historyReq ~ option:', option) - chart.value.setOption(option) } else { ElMessage.warning('查询失败1')