Commit caa7198e8a0d384df1c24c3e2d616e086d4eadfa

Authored by YunaiV
1 parent 666f7dbc

【代码评审】IoT:评审 ThingModel 的实现

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java
... ... @@ -34,11 +34,9 @@ public class FieldParser {
34 34 * @return TdField对象
35 35 */
36 36 public static TdFieldDO parse(ThingModelProperty property) {
  37 + // 将物模型字段类型映射为 td 字段类型
37 38 String fieldName = property.getIdentifier().toLowerCase();
38   -
39   - // 将物模型字段类型映射为td字段类型
40 39 String fType = TYPE_MAPPING.get(property.getDataType().toUpperCase());
41   -
42 40 // 如果字段类型为NCHAR,默认长度为64
43 41 int dataLength = 0;
44 42 if ("NCHAR".equals(fType)) {
... ... @@ -54,6 +52,7 @@ public class FieldParser {
54 52 * @return 字段列表
55 53 */
56 54 public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
  55 + // TODO @puhui999:是不是使用 convertList
57 56 return thingModel.getModel().getProperties().stream()
58 57 .map(FieldParser::parse)
59 58 .collect(Collectors.toList());
... ... @@ -66,14 +65,12 @@ public class FieldParser {
66 65 * @return 转换后的 TDengine 字段对象列表
67 66 */
68 67 public static List<TdFieldDO> parse(List<List<Object>> rows) {
  68 + // TODO @puhui999:是不是使用 convertList
69 69 return rows.stream().map(row -> {
70 70 String type = row.get(1).toString().toUpperCase();
  71 + // TODO @puhui999:"NCHAR" 最好枚举下
71 72 int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
72   - return new TdFieldDO(
73   - row.get(0).toString(),
74   - type,
75   - dataLength
76   - );
  73 + return new TdFieldDO(row.get(0).toString(), type, dataLength);
77 74 }).collect(Collectors.toList());
78 75 }
79 76  
... ...