Browse Source

update td-engine nchar类型报错

jay 1 year ago
parent
commit
0b66c071f8

+ 9 - 1
iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java

@@ -22,6 +22,7 @@
  */
 package cc.iotkit.temporal.td.dm;
 
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.model.product.ThingModel;
 
 import java.util.List;
@@ -58,7 +59,14 @@ public class FieldParser {
         if (specs instanceof Map) {
             Object objLen = ((Map<?, ?>) specs).get("length");
             if (objLen != null) {
-                len = Integer.parseInt(objLen.toString());
+                try{
+                    len = Integer.parseInt(objLen.toString());
+                }catch (Exception e){
+                    throw new BizException(filedName+" 长度错误");
+                }
+                if("NCHAR".equals(fType) && len <1){
+                    throw new BizException(filedName+" 长度错误");
+                }
             }
         }
 

+ 6 - 2
iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java

@@ -30,6 +30,7 @@ import cc.iotkit.temporal.td.config.Constants;
 import cc.iotkit.temporal.td.dm.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
@@ -43,6 +44,9 @@ public class DbStructureDataImpl implements IDbStructureData {
     @Autowired
     private TdRestApi tdRestApi;
 
+    @Value("${spring.td-datasource.db:iita_iot}")
+    private String dbName;
+
     /**
      * 根据物模型创建超级表
      */
@@ -137,7 +141,7 @@ public class DbStructureDataImpl implements IDbStructureData {
                 }
             }
         } catch (Throwable e) {
-            log.error("update thingmodel stable failed", e);
+            throw e;
         }
     }
 
@@ -147,7 +151,7 @@ public class DbStructureDataImpl implements IDbStructureData {
     @Override
     @PostConstruct
     public void initDbStructure() {
-        tdRestApi.execSql("CREATE DATABASE IF NOT EXISTS iotkit KEEP 365 DURATION 10 BUFFER 16 WAL_LEVEL 1;");
+        tdRestApi.execSql(String.format("CREATE DATABASE IF NOT EXISTS %s KEEP 365 DURATION 10 BUFFER 16 WAL_LEVEL 1;", dbName));
 
         //创建规则日志超级表
         String sql = TableManager.getCreateSTableSql("rule_log", List.of(