Merge remote-tracking branch 'origin/main'

This commit is contained in:
houwei 2024-10-14 17:31:07 +08:00
commit d7c3254874
10 changed files with 102 additions and 43 deletions

View File

@ -110,7 +110,7 @@ public class SysIotModelController {
if (sysIotModelFieldDto.getIotModelId() == null || sysIotModelFieldDto.getAttributeCode() == null
|| sysIotModelFieldDto.getAttributeName() == null || sysIotModelFieldDto.getAttributeType() == null
|| sysIotModelFieldDto.getPorder() == null) {
|| sysIotModelFieldDto.getPorder() == null || sysIotModelFieldDto.getHighSpeed() == null) {
throw new ServiceException("参数缺失");
}
return R.success(sysIotModelService.creatSysIotModelField(sysIotModelFieldDto));

View File

@ -44,4 +44,9 @@ public class SysIotModelFieldDto implements Serializable {
*/
private Integer pageNum;
/**
* 物模型属性频度
*/
private Integer highSpeed;
}

View File

@ -45,4 +45,6 @@ public class SysIotModelFieldVo {
private Integer revision;
private Integer highSpeed;
}

View File

@ -69,4 +69,10 @@ public class SysIotModelField extends BaseEntity {
*/
@TableField("porder")
private Integer porder;
/**
* 物模型属性频度
*/
@TableField("highspeed")
private Integer highSpeed;
}

View File

@ -7,6 +7,7 @@ import com.das.modules.equipment.domain.excel.SysIotModelServiceExcel;
import com.das.modules.equipment.domain.vo.IotModelFieldVo;
import com.das.modules.equipment.domain.vo.SysIotModelVo;
import com.das.modules.equipment.entity.SysIotModel;
import com.das.modules.equipment.entity.SysIotModelField;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -30,6 +31,6 @@ public interface SysIotModelMapper extends BaseMapper<SysIotModel> {
String getIotModel(Long id);
List<String> getAllIotModelField(Long id);
List<SysIotModelField> getAllIotModelField(Long id);
}

View File

@ -19,6 +19,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@ -58,33 +59,63 @@ public class TDEngineService {
}
// 遍历所有的物模型存入内存中
public void initIotModel(List<IotModelFieldVo> allIotModel, ConcurrentHashMap<String,Map<String, Object>> iotFieldMap) {
public void initIotModel(List<IotModelFieldVo> allIotModel, ConcurrentHashMap<String,Map<String, Object>> highIotFieldMap,ConcurrentHashMap<String,Map<String, Object>> lowIotFieldMap) {
// 创建物模型超级表
StringBuilder sb = new StringBuilder(1024*1024);
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
ListUtil.page(allIotModel, batchSize, (list)->{
sb.setLength(0);
for (IotModelFieldVo info : list) {
sb.append("CREATE STABLE IF NOT EXISTS ");
sb.append(info.getIotModelCode());
sb.append(" (`updatetime` TIMESTAMP");
Map<String, Object> map = iotFieldMap.get(info.getIotModelCode());
// 使用增强的 for 循环遍历键
for (String key : map.keySet()) {
sb.append(", ");
sb.append(key);
sb.append(" float");
}
sb.append(") TAGS (`deviceid` BIGINT);");
}
try {
pstmt.executeUpdate(sb.toString());
} catch (SQLException ex) {
log.error("save yx error", ex);
}
ListUtil.page(allIotModel, batchSize, list ->{
for (IotModelFieldVo info : list) {
StringBuilder sb = new StringBuilder(1024*1024);
sb.setLength(0);
Map<String, Object> map = highIotFieldMap.get(info.getIotModelCode());
Set<String> keySet = map.keySet();
if (keySet.size() != 0){
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(", ");
sb.append(key);
sb.append(" float");
}
sb.append(") TAGS (`deviceid` BIGINT);");
try {
System.out.println(sb.toString());
pstmt.executeUpdate(sb.toString());
} catch (SQLException ex) {
log.error("save yx error", ex);
}
}
}
for (IotModelFieldVo info : list) {
StringBuilder sb = new StringBuilder(1024*1024);
sb.setLength(0);
Map<String, Object> map = lowIotFieldMap.get(info.getIotModelCode());
if (map.keySet().size() != 0){
sb.append("CREATE STABLE IF NOT EXISTS ");
sb.append("l_").append(info.getIotModelCode());
sb.append(" (`updatetime` TIMESTAMP");
// 使用增强的 for 循环遍历键
for (String key : map.keySet()) {
sb.append(", ");
sb.append(key);
sb.append(" float");
}
sb.append(") TAGS (`deviceid` BIGINT);");
try {
System.out.println(sb.toString());
pstmt.executeUpdate(sb.toString());
} catch (SQLException ex) {
log.error("save yx error", ex);
}
}
}
});
} catch (SQLException ex) {
log.error(ex.getMessage());

View File

@ -3,6 +3,7 @@ package com.das.modules.node.service.impl;
import com.das.common.constant.BaseIotModelType;
import com.das.common.utils.AdminRedisTemplate;
import com.das.modules.equipment.domain.vo.IotModelFieldVo;
import com.das.modules.equipment.entity.SysIotModelField;
import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.node.disruptor.MessageEventFactory;
import com.das.modules.node.disruptor.TerminalMessageEventHandler;
@ -35,6 +36,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -66,7 +68,9 @@ public class DataServiceImpl implements DataService {
private ConcurrentHashMap<String, String> iotModelMap = new ConcurrentHashMap<>(10000);
public ConcurrentHashMap<String, Map<String, Object>> iotFieldMap = new ConcurrentHashMap<>(10000);
public ConcurrentHashMap<String, Map<String, Object>> highIotFieldMap = new ConcurrentHashMap<>(10000);
public ConcurrentHashMap<String, Map<String, Object>> lowIotFieldMap = new ConcurrentHashMap<>(10000);
public static final String DEVICE_DATA = "deviceData:{0}";
@ -217,14 +221,21 @@ public class DataServiceImpl implements DataService {
for (IotModelFieldVo item : allIotModel) {
String key = String.valueOf(item.getId());
iotModelMap.put(key, item.getIotModelCode());
List<String> modelFieldList = sysIotModelMapper.getAllIotModelField(item.getId());
List<SysIotModelField> allIotModelField = sysIotModelMapper.getAllIotModelField(item.getId());
List<String> LowModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 0).map(SysIotModelField::getAttributeCode).collect(Collectors.toList());
List<String> HighModelFieldList = allIotModelField.stream().filter(field -> field.getHighSpeed() == 1).map(SysIotModelField::getAttributeCode).collect(Collectors.toList());
Map<String, Object> map = new HashMap<>();
for (String field : modelFieldList) {
for (String field : HighModelFieldList) {
map.put(field, null);
}
iotFieldMap.put(item.getIotModelCode(), map);
highIotFieldMap.put(item.getIotModelCode(), map);
Map<String, Object> lowMap = new HashMap<>();
for (String field : LowModelFieldList) {
lowMap.put(field, null);
}
lowIotFieldMap.put(item.getIotModelCode(), lowMap);
}
tdEngineService.initIotModel(allIotModel, iotFieldMap);
tdEngineService.initIotModel(allIotModel, highIotFieldMap,lowIotFieldMap);
}
@Override

View File

@ -63,11 +63,9 @@
select sim.iot_model_code from sys_iot_model sim left join sys_equipment se on sim.id = se.iot_model_id
where se.id = #{id}
</select>
<select id="getAllIotModelField" resultType="java.lang.String">
select simf.attribute_code from sys_iot_model_field simf where simf.iot_model_id = #{id} order by simf.attribute_code
<select id="getAllIotModelField" resultType="com.das.modules.equipment.entity.SysIotModelField">
select simf.attribute_code as attributeCode,simf.highspeed as highSpeed from sys_iot_model_field simf where simf.iot_model_id = #{id} order by simf.attribute_code
</select>
</mapper>

View File

@ -195,6 +195,9 @@
<el-form-item :label="ModelAttributeFieldsEnums['porder']" prop="porder">
<el-input v-model="attributeForm.porder" :placeholder="'请输入' + ModelAttributeFieldsEnums['porder']"></el-input>
</el-form-item>
<el-form-item :label="ModelAttributeFieldsEnums['highSpeed']" prop="highSpeed">
<el-checkbox v-model="attributeForm.highSpeed"></el-checkbox>
</el-form-item>
</el-form>
<template #footer>
<el-button type="primary" @click="submitAttributeForm">提交</el-button>
@ -298,6 +301,7 @@ import {
import ContextMenu from './contextMenu.vue'
import { encrypt_aes, generateRandomNumber } from '/@/utils/crypto'
import { debounce } from 'lodash'
import { log } from '/@/api/backend/routine/AdminInfo'
const DeviceModelPropReplace = {
label: 'iotModelName',
@ -526,6 +530,7 @@ const getAttributeList = (type?: radioGroupType, value?: string) => {
: item.attributeType === 140
? '离散量'
: item.attributeType!,
highSpeed: item.highSpeed === 1,
}
})
pageTotal.value = res.total
@ -607,6 +612,7 @@ const originAttributeForm: AddModelAttributeType & UpdateModelAttributeType = {
attributeName: '',
attributeType: null,
porder: null,
highSpeed: false,
revision: 1,
createdBy: undefined,
createdTime: undefined,
@ -625,22 +631,19 @@ const submitAttributeForm = () => {
attributeFormRef.value?.validate((valid: boolean) => {
if (valid) {
if (attributeFormTitle.value === AttributeDialogTitleStateType['add']) {
attributeForm.value.iotModelId = curContextMenuTreeData.value!.id!
addModelAttributeReq(attributeForm.value)
const addFormData = JSON.parse(JSON.stringify(attributeForm.value))
addFormData.iotModelId = curContextMenuTreeData.value!.id!
addFormData.highSpeed = addFormData.highSpeed ? 1 : 0
addModelAttributeReq(addFormData)
.then((res) => {
if (res.success) {
ElMessage.success('新增物模型属性成功')
closeAttributeForm()
getAttributeList()
} else {
ElMessage.error(res.msg)
}
})
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '新增失败')
})
} else if (attributeFormTitle.value === AttributeDialogTitleStateType['edit']) {
updateModelAttributeReq(attributeForm.value)
const updateForm = JSON.parse(JSON.stringify(attributeForm.value))
updateForm.highSpeed = updateForm.highSpeed ? 1 : 0
updateModelAttributeReq(updateForm)
.then((res) => {
if (res.success) {
ElMessage.success('修改物模型属性成功')

View File

@ -62,6 +62,7 @@ export enum ModelAttributeFieldsEnums {
'attributeType' = '属性类型value',
'attributeTypeName' = '属性类型',
'porder' = '序号',
'highSpeed'='是否高频',
'revision' = '乐观锁',
'createdBy' = '创建人',
'createdTime' = '创建时间',
@ -98,6 +99,7 @@ export type AddModelAttributeType = {
attributeName: string
attributeType: ModelAttributeType | null
porder: number | null
highSpeed:0|1|boolean
revision: number
createdBy?: string
createdTime?: string