This commit is contained in:
谷成伟 2024-10-17 17:13:07 +08:00
commit fbb3980044
11 changed files with 171 additions and 56 deletions

View File

@ -16,6 +16,7 @@ public class AnalogDataCommand implements BaseCommand {
@Override
public void doCommand(TerminalMessage data) {
try {
//analogData值只存入redis
dataService.handleData(data);
} catch (Exception e) {

View File

@ -17,6 +17,7 @@ public class StateDataCommand implements BaseCommand {
@Override
public void doCommand(TerminalMessage data) {
try {
//只存入redis
dataService.handleData(data);
} catch (Exception e) {
log.error("解析数据异常", e);

View File

@ -17,4 +17,10 @@ public interface NodeConstant {
String ANALOG_DATA = "analogData";
String STATE_DATA = "stateData";
String HIS_ANALOG_DATA = "historyStateData";
String HIS_STATE_DATA = "historyStateData";
String DEVICE_CONTROL_RESP = "deviceControlResp";
}

View File

@ -25,4 +25,6 @@ public class IotModelVo {
private String equipmentService;
private Object params;
private Integer highSpeed;
}

View File

@ -9,5 +9,7 @@ public class NewIotModelVo {
private String type;
private Integer highSpeed;
private Object params;
}

View File

@ -124,7 +124,7 @@ public class TDEngineService {
}
@Async
public void updateYCValues(List<RTData> values, String iotModelCode) {
public void updateYCHighValues(List<RTData> values, String iotModelCode) {
StringBuilder sb = new StringBuilder(1024*1024);
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
@ -132,12 +132,54 @@ public class TDEngineService {
sb.setLength(0);
sb.append("insert into ");
for (RTData dv : list) {
sb.append("d");
sb.append("h");
sb.append(dv.getDeviceId());
sb.append(" using " );
sb.append(" using h_" );
sb.append(iotModelCode);
sb.append(" tags (");
sb.append(dv.getDeviceId());
sb.append(") (");
dv.getValues().forEach((key, value) ->
sb.append(",").append(key)
);
sb.append(") values (");
sb.append(dv.getDataTime());
dv.getValues().forEach((key, value) ->
sb.append(",").append(value)
);
sb.append(")");
}
try {
pstmt.executeUpdate(sb.toString());
} catch (SQLException ex) {
log.error("save yc error", ex);
}
});
} catch (SQLException ex) {
log.error(ex.getMessage());
}
}
@Async
public void updateYCLowValues(List<RTData> values, String iotModelCode) {
StringBuilder sb = new StringBuilder(1024*1024);
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
ListUtil.page(values, batchSize, (list)->{
sb.setLength(0);
sb.append("insert into ");
for (RTData dv : list) {
sb.append("l");
sb.append(dv.getDeviceId());
sb.append(" using l_" );
sb.append(iotModelCode);
sb.append(" tags (");
sb.append(dv.getDeviceId());
sb.append(") (");
dv.getValues().forEach((key, value) ->
sb.append(",").append(key)
);
sb.append(") values (");
sb.append(dv.getDataTime());

View File

@ -29,10 +29,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@ -72,8 +69,6 @@ public class DataServiceImpl implements DataService {
public ConcurrentHashMap<String, Map<String, Object>> lowIotFieldMap = new ConcurrentHashMap<>(10000);
public static final String DEVICE_DATA = "deviceData:{0}";
@PostConstruct
public void init() {
//初始化高性能队列
@ -154,6 +149,7 @@ public class DataServiceImpl implements DataService {
if (info.getServiceType() == null) {
NewIotModelVo newIotModelVo = new NewIotModelVo();
newIotModelVo.setName(info.getEquipmentAttribute());
newIotModelVo.setHighSpeed(info.getHighSpeed());
if (info.getParams() == null) {
newIotModelVo.setParams(equipJsonNode);
} else {
@ -243,33 +239,52 @@ public class DataServiceImpl implements DataService {
// 先从redis里面获取设备的初始化数据
JsonNode jsonNode = data.getData();
String deviceId = jsonNode.get("deviceId").asText();
String key = MessageFormat.format(DEVICE_DATA, deviceId);
HashMap<String, Object> initValue = adminRedisTemplate.get(key);
JsonNode values = jsonNode.get("values");
List<Map.Entry<String, Object>> entryList = new ArrayList<>(initValue.entrySet());
HashMap<String, Object> newHashMap = new HashMap<>();
for (Map.Entry<String, Object> entry : entryList) {
if(values.get(entry.getKey()) == null){
newHashMap.put(entry.getKey(), entry.getValue());
} else{
newHashMap.put(entry.getKey(), values.get(entry.getKey()).asDouble());
}
}
adminRedisTemplate.set(key, newHashMap);
Long dataTime = data.getTime();
// 存入td库
JsonNode high = values.get("high");
JsonNode low = values.get("low");
Map<String, Object> keyValueMap = new HashMap<>();
// 根据设备ID获取对应的物模型属性
String iotModelCode = sysIotModelMapper.getIotModel(jsonNode.get("deviceId").asLong());
HashMap<String, Object> tdValues = adminRedisTemplate.get(key);
List<RTData> list = new ArrayList<>();
RTData rtData = RTData.builder()
.dataTime(dataTime)
.deviceId(Long.valueOf(deviceId))
.values(tdValues)
.build();
Map<String, Object> highFieldMap = highIotFieldMap.get(iotModelCode);
Map<String, Object> lowFiledMap = lowIotFieldMap.get(iotModelCode);
list.add(rtData);
tdEngineService.updateYCValues(list, iotModelCode);
//High数据
Iterator<String> keysHigh = high.fieldNames();
while (keysHigh.hasNext()) {
String fieldName = keysHigh.next();
highFieldMap.put(fieldName, high.get(fieldName));
String key = String.format("RT:[%s]:[%s]", deviceId, fieldName);
keyValueMap.put(key, high.get(fieldName).asDouble());
}
//LOW数据
Iterator<String> keysLow = low.fieldNames();
while (keysLow.hasNext()) {
String fieldName = keysLow.next();
lowFiledMap.put(fieldName, low.get(fieldName));
String key = String.format("RT:[%s]:[%s]", deviceId, fieldName);
keyValueMap.put(key, high.get(fieldName).asDouble());
}
adminRedisTemplate.mSet(keyValueMap);
// Long dataTime = data.getTime();
//
// // 存入td库
// List<RTData> highList = new ArrayList<>();
// List<RTData> lowList = new ArrayList<>();
// RTData rtHighData = RTData.builder()
// .dataTime(dataTime)
// .deviceId(Long.valueOf(deviceId))
// .values(highFieldMap)
// .build();
// RTData rtLowData = RTData.builder()
// .dataTime(dataTime)
// .deviceId(Long.valueOf(deviceId))
// .values(highFieldMap)
// .build();
// highList.add(rtHighData);
// lowList.add(rtLowData);
// tdEngineService.updateYCHighValues(highList, iotModelCode);
// tdEngineService.updateYCLowValues(lowList, iotModelCode);
}
}

View File

@ -57,7 +57,7 @@
</select>
<select id="getIotModelFieldByEquipmentId" resultType="com.das.modules.node.domain.vo.IotModelVo">
select simf.attribute_type as attributeType,sims.service_type as serviceType, se.iot_addr as iotAddr,si.equipment_attribute as equipmentAttribute,si.equipment_service as equipmentService, si.params from sys_imptabmapping si
select simf.attribute_type as attributeType,sims.service_type as serviceType, se.iot_addr as iotAddr,si.equipment_attribute as equipmentAttribute,si.equipment_service as equipmentService, si.params, simf.highspeed as highSpeed from sys_imptabmapping si
left join sys_equipment se on si.equipment_id = se.id
left join sys_iot_model_field simf on si.equipment_attribute = simf.attribute_code
left join sys_iot_model_service sims on si.equipment_service = sims.service_code

View File

@ -6,12 +6,13 @@ VITE_BASE_PATH = './'
# 代理配置(开发使用),必须在一行中
# 本地
# VITE_APP_PROXY=[["/api","http://10.65.57.55:8080/api"]]
# VITE_APP_PROXY=[["/api","http://192.168.130.12:8080/api"]]
# 线上
VITE_APP_PROXY=[["/api","https://test.jsspisoft.com/api"]]
# 开发环境下跨域代理请输入要跨域的api地址 - 尾部无需带'/'
# VITE_PROXY_URL = 'http://localhost:8000'
VITE_AXIOS_BASE_URL = 'http://localhost:1818'

View File

@ -185,13 +185,28 @@
<el-form-item :label="ModelAttributeFieldsEnums['attributeCode']" prop="attributeCode">
<el-input v-model="attributeForm.attributeCode" :placeholder="'请输入' + ModelAttributeFieldsEnums['attributeCode']"></el-input>
</el-form-item>
<div class="formRowStyle">
<el-form-item :label="ModelAttributeFieldsEnums['attributeTypeName']" prop="attributeType">
<el-select v-model="attributeForm.attributeType" :placeholder="'请选择' + ModelAttributeFieldsEnums['attributeTypeName']">
<el-select
v-model="attributeForm.attributeType"
:placeholder="'请选择' + ModelAttributeFieldsEnums['attributeTypeName']"
@change="attributeTypeChange"
>
<el-option label="模拟量" :value="138"></el-option>
<el-option label="累积量" :value="139"></el-option>
<el-option label="离散量" :value="140"></el-option>
</el-select>
</el-form-item>
<el-form-item :label="ModelAttributeFieldsEnums['dataType']" prop="dataType">
<el-select
:disabled="!attributeForm.attributeType || attributeForm.attributeType === 140"
v-model="attributeForm.dataType"
:placeholder="'请选择' + ModelAttributeFieldsEnums['dataType']"
>
<el-option v-for="v in attributeFormDataTypeOptions" :key="v.value" :label="v.value" :value="v.value"></el-option>
</el-select>
</el-form-item>
</div>
<el-form-item :label="ModelAttributeFieldsEnums['porder']" prop="porder">
<el-input v-model="attributeForm.porder" :placeholder="'请输入' + ModelAttributeFieldsEnums['porder']"></el-input>
</el-form-item>
@ -201,6 +216,9 @@
<el-form-item :label="ModelAttributeFieldsEnums['highSpeed']" prop="highSpeed">
<el-checkbox v-model="attributeForm.highSpeed"></el-checkbox>
</el-form-item>
<el-form-item :label="ModelAttributeFieldsEnums['visible']" prop="visible">
<el-checkbox v-model="attributeForm.visible"></el-checkbox>
</el-form-item>
</el-form>
<template #footer>
<el-button type="primary" @click="submitAttributeForm">提交</el-button>
@ -278,7 +296,9 @@ import {
ModelAttributeTableType,
ModelServiceTableType,
ModelServiceFieldsEnums,
ModelAttributeType,
AttributeDialogTitleStateType,
attributeTypeDataType,
serviceDialogTitleStateType,
GetModelServiceType,
GetModelAttributeType,
@ -533,6 +553,7 @@ const getAttributeList = (type?: radioGroupType, value?: string) => {
? '离散量'
: item.attributeType!,
highSpeed: item.highSpeed === 1,
visible: item.visible === 1,
}
})
pageTotal.value = res.total
@ -607,6 +628,12 @@ const delServiceForm = (data: AddModelServiceType & UpdateModelServiceType) => {
const attributeVisible = ref(false)
const attributeFormTitle = ref(AttributeDialogTitleStateType['add'])
const attributeFormDataTypeOptions: { value: attributeTypeDataType }[] = [
{ value: 'int4' },
{ value: 'int8' },
{ value: 'float4' },
{ value: 'float8' },
]
const originAttributeForm: AddModelAttributeType & UpdateModelAttributeType = {
id: null,
iotModelId: '',
@ -616,6 +643,8 @@ const originAttributeForm: AddModelAttributeType & UpdateModelAttributeType = {
porder: null,
highSpeed: false,
subsystem: '',
dataType: '',
visible: true,
revision: 1,
createdBy: undefined,
createdTime: undefined,
@ -625,6 +654,12 @@ const originAttributeForm: AddModelAttributeType & UpdateModelAttributeType = {
const attributeFormRef = ref<FormInstance>()
const attributeForm = ref<AddModelAttributeType & UpdateModelAttributeType>(JSON.parse(JSON.stringify(originAttributeForm)))
const attributeTypeChange = (value: ModelAttributeType) => {
if (value === 140) {
attributeForm.value.dataType = ''
}
}
const closeAttributeForm = () => {
attributeVisible.value = false
attributeForm.value = JSON.parse(JSON.stringify(originAttributeForm))
@ -633,11 +668,12 @@ const closeAttributeForm = () => {
const submitAttributeForm = () => {
attributeFormRef.value?.validate((valid: boolean) => {
if (valid) {
const copyFormData = JSON.parse(JSON.stringify(attributeForm.value))
copyFormData.highSpeed = copyFormData.highSpeed ? 1 : 0
copyFormData.visible = copyFormData.visible ? 1 : 0
if (attributeFormTitle.value === AttributeDialogTitleStateType['add']) {
const addFormData = JSON.parse(JSON.stringify(attributeForm.value))
addFormData.iotModelId = curContextMenuTreeData.value!.id!
addFormData.highSpeed = addFormData.highSpeed ? 1 : 0
addModelAttributeReq(addFormData)
copyFormData.iotModelId = curContextMenuTreeData.value!.id!
addModelAttributeReq(copyFormData)
.then((res) => {
if (res.success) {
ElMessage.success('新增物模型属性成功')
@ -651,9 +687,7 @@ const submitAttributeForm = () => {
ElMessage.error(err?.response?.data?.msg ?? '新增失败')
})
} else if (attributeFormTitle.value === AttributeDialogTitleStateType['edit']) {
const updateForm = JSON.parse(JSON.stringify(attributeForm.value))
updateForm.highSpeed = updateForm.highSpeed ? 1 : 0
updateModelAttributeReq(updateForm)
updateModelAttributeReq(copyFormData)
.then((res) => {
if (res.success) {
ElMessage.success('修改物模型属性成功')
@ -964,4 +998,10 @@ $paginationHeight: 32px;
}
}
}
.formRowStyle {
display: flex;
.el-select {
width: 184px;
}
}
</style>

View File

@ -64,6 +64,8 @@ export enum ModelAttributeFieldsEnums {
'porder' = '序号',
'highSpeed' = '是否高频',
'subsystem' = '子系统',
'dataType' = '数据类型',
'visible'='是否可见',
'revision' = '乐观锁',
'createdBy' = '创建人',
'createdTime' = '创建时间',
@ -94,6 +96,7 @@ export type GetModelAttributeType = {
pageNum: number
}
export type attributeTypeDataType = 'int4' | 'int8' | 'float4' | 'float8'
export type AddModelAttributeType = {
iotModelId: string
attributeCode: string
@ -102,6 +105,8 @@ export type AddModelAttributeType = {
porder: number | null
highSpeed: 0 | 1 | boolean
subsystem: string
dataType: ''
visible: 0 | 1 | boolean
revision: number
createdBy?: string
createdTime?: string