From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目

---
 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java |   50 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java
index 93c73f5..77db754 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java
@@ -1,7 +1,6 @@
 package cn.iocoder.yudao.module.iot.service.device.property;
 
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ObjUtil;
@@ -119,7 +118,7 @@
     private List<TDengineTableField> buildTableFieldList(List<IotThingModelDO> thingModels) {
         return convertList(thingModels, thingModel -> {
             TDengineTableField field = new TDengineTableField(
-                    StrUtil.toUnderlineCase(thingModel.getIdentifier()), // TDengine 瀛楁榛樿閮芥槸灏忓啓
+                    TDengineTableField.buildFieldName(thingModel.getIdentifier()),
                     TYPE_MAPPING.get(thingModel.getProperty().getDataType()));
             String dataType = thingModel.getProperty().getDataType();
             if (Objects.equals(dataType, IotDataSpecsDataTypeEnum.TEXT.getDataType())) {
@@ -148,8 +147,16 @@
         // 1. 鏍规嵁鐗╂ā鍨嬶紝鎷兼帴鍚堟硶鐨勫睘鎬�
         // TODO @鑺嬭壙锛氥�愬緟瀹� 004銆戣祴鑳藉悗锛屽睘鎬у埌搴曚互 thingModel 涓哄噯锛坕k锛夛紝杩樻槸 db 鐨勮〃缁撴瀯涓哄噯锛坱l锛夛紵
         List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductIdFromCache(device.getProductId());
-        Map<String, Object> properties = new HashMap<>();
+        Map<String, Object> properties = new LinkedHashMap<>();
         params.forEach((key, value) -> {
+            if (!(key instanceof CharSequence)) {
+                log.error("[saveDeviceProperty][娑堟伅({}) 鐨勫睘鎬� key({}) 绫诲瀷涓嶆纭甝", message, key);
+                return;
+            }
+            if (value == null) {
+                log.warn("[saveDeviceProperty][娑堟伅({}) 鐨勫睘鎬�({}) 鍊间负绌猴紝璺宠繃]", message, key);
+                return;
+            }
             // 蹇界暐澶у皬鍐欏尮閰嶇墿妯″瀷锛岄伩鍏嶈澶囦笂鎶ョ殑 key 涓� identifier 澶у皬鍐欎笉涓�鑷村鑷翠涪澶�
             IotThingModelDO thingModel = CollUtil.findOne(thingModels,
                     o -> StrUtil.equalsIgnoreCase(o.getIdentifier(), (CharSequence) key));
@@ -158,21 +165,9 @@
                 return;
             }
             String identifier = thingModel.getIdentifier(); // 缁熶竴浠ョ墿妯″瀷 identifier 浣滀负 key锛岄伩鍏嶅ぇ灏忓啓闂
-            String dataType = thingModel.getProperty().getDataType();
-            if (ObjectUtils.equalsAny(dataType,
-                    IotDataSpecsDataTypeEnum.STRUCT.getDataType(), IotDataSpecsDataTypeEnum.ARRAY.getDataType())) {
-                // 鐗规畩锛歋TRUCT 鍜� ARRAY 绫诲瀷锛屽湪 TDengine 閲岋紝鏈夋病瀵瑰簲鏁版嵁绫诲瀷锛屽彧鑳介�氳繃 JSON 鏉ュ瓨鍌�
-                properties.put(identifier, JsonUtils.toJsonString(value));
-            } else if (IotDataSpecsDataTypeEnum.INT.getDataType().equals(dataType)) {
-                properties.put(identifier, Convert.toInt(value));
-            } else if (IotDataSpecsDataTypeEnum.FLOAT.getDataType().equals(dataType)) {
-                properties.put(identifier, Convert.toFloat(value));
-            } else if (IotDataSpecsDataTypeEnum.DOUBLE.getDataType().equals(dataType)) {
-                properties.put(identifier, Convert.toDouble(value));
-            } else if (IotDataSpecsDataTypeEnum.BOOL.getDataType().equals(dataType)) {
-                properties.put(identifier, Convert.toBool(value, false) ? (byte) 1 : (byte) 0);
-            } else {
-                properties.put(identifier, value);
+            Object convertedValue = convertPropertyValue(message, thingModel, value);
+            if (convertedValue != null) {
+                properties.put(identifier, convertedValue);
             }
         });
         if (CollUtil.isEmpty(properties)) {
@@ -192,6 +187,23 @@
         // 2.3 鎻愬彇 GeoLocation 骞舵洿鏂拌澶囧畾浣�
         // 涓轰粈涔� properties 涓虹┖锛屼篃瑕佹墽琛屽畾浣嶆洿鏂帮紵鍥犱负鍙兘涓婃姤鐨勫睘鎬ч噷锛屾病鏈夊悎娉曞睘鎬э紝浣嗘槸鍖呭惈 GeoLocation 瀹氫綅灞炴��
         extractAndUpdateDeviceLocation(device, (Map<?, ?>) message.getParams());
+    }
+
+    private Object convertPropertyValue(IotDeviceMessage message, IotThingModelDO thingModel, Object value) {
+        String identifier = thingModel.getIdentifier();
+        String dataType = thingModel.getProperty().getDataType();
+        try {
+            Object convertedValue = thingModelService.convertThingModelPropertyValue(thingModel, value);
+            if (convertedValue == null) {
+                log.warn("[saveDeviceProperty][娑堟伅({}) 鐨勫睘鎬�({}) 鍊�({}) 鏃犳硶杞崲涓虹被鍨�({})锛岃烦杩嘳",
+                        message, identifier, value, dataType);
+            }
+            return convertedValue;
+        } catch (Exception e) {
+            log.error("[saveDeviceProperty][娑堟伅({}) 鐨勫睘鎬�({}) 鍊�({}) 杞崲涓虹被鍨�({}) 寮傚父锛岃烦杩嘳",
+                    message, identifier, value, dataType, e);
+            return null;
+        }
     }
 
     @Override
@@ -310,4 +322,4 @@
         return new BigDecimal[]{longitude, latitude};
     }
 
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3