提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.influxdb.common.utils; |
H |
2 |
|
|
3 |
import com.iailab.module.data.common.enums.TagValueTypeConstant; |
|
4 |
import com.iailab.module.data.channel.tag.dto.TagValueDTO; |
|
5 |
import com.iailab.module.data.influxdb.pojo.*; |
|
6 |
import com.iailab.module.data.influxdb.common.enums.DataMeasurement; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author PanZhibao |
|
10 |
* @Description |
|
11 |
* @createTime 2023年05月03日 23:00:00 |
|
12 |
*/ |
|
13 |
public class TagValueUtils { |
|
14 |
|
|
15 |
public static Object getByTagType(String type, String value) { |
|
16 |
switch (type) { |
|
17 |
case TagValueTypeConstant.BOOLEAN: |
|
18 |
return Double.parseDouble(value); |
|
19 |
case TagValueTypeConstant.INT8: |
|
20 |
return Integer.parseInt(value); |
|
21 |
case TagValueTypeConstant.INT16: |
|
22 |
return Integer.parseInt(value); |
|
23 |
case TagValueTypeConstant.INT32: |
|
24 |
return Integer.parseInt(value); |
|
25 |
case TagValueTypeConstant.INT64: |
|
26 |
return Integer.parseInt(value); |
|
27 |
case TagValueTypeConstant.UINT8: |
|
28 |
return Integer.parseInt(value); |
|
29 |
case TagValueTypeConstant.UINT16: |
|
30 |
return Double.parseDouble(value); |
|
31 |
case TagValueTypeConstant.UINT32: |
|
32 |
return Integer.parseInt(value); |
|
33 |
case TagValueTypeConstant.UINT64: |
|
34 |
return Integer.parseInt(value); |
|
35 |
case TagValueTypeConstant.FLOAT: |
|
36 |
return Double.parseDouble(value); |
|
37 |
case TagValueTypeConstant.DOUBLE: |
|
38 |
return Double.parseDouble(value); |
|
39 |
default: |
|
40 |
break; |
|
41 |
} |
|
42 |
return value; |
|
43 |
} |
|
44 |
|
|
45 |
public static String getMeasurement(String type) { |
|
46 |
switch (type) { |
|
47 |
case TagValueTypeConstant.BOOLEAN: |
|
48 |
return DataMeasurement.t_tag_bool_value.name(); |
|
49 |
case TagValueTypeConstant.INT8: |
|
50 |
return DataMeasurement.t_tag_int_value.name(); |
|
51 |
case TagValueTypeConstant.INT16: |
|
52 |
return DataMeasurement.t_tag_int_value.name(); |
|
53 |
case TagValueTypeConstant.INT32: |
|
54 |
return DataMeasurement.t_tag_int_value.name(); |
|
55 |
case TagValueTypeConstant.INT64: |
|
56 |
return DataMeasurement.t_tag_int_value.name(); |
|
57 |
case TagValueTypeConstant.UINT8: |
|
58 |
return DataMeasurement.t_tag_int_value.name(); |
|
59 |
case TagValueTypeConstant.UINT16: |
|
60 |
return DataMeasurement.t_tag_int_value.name(); |
|
61 |
case TagValueTypeConstant.UINT32: |
|
62 |
return DataMeasurement.t_tag_int_value.name(); |
|
63 |
case TagValueTypeConstant.UINT64: |
|
64 |
return DataMeasurement.t_tag_int_value.name(); |
|
65 |
case TagValueTypeConstant.FLOAT: |
|
66 |
return DataMeasurement.t_tag_float_value.name(); |
|
67 |
case TagValueTypeConstant.DOUBLE: |
|
68 |
return DataMeasurement.t_tag_float_value.name(); |
|
69 |
default: |
|
70 |
return DataMeasurement.t_tag_str_value.name(); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
public static InfluxTagValuePOJO getByTag(TagValueDTO dto, String value) { |
|
75 |
switch (dto.getType()) { |
|
76 |
case TagValueTypeConstant.BOOLEAN: |
|
77 |
InfluxTagValuePOJO boolPojo = new InfluxTagValueBoolPOJO(); |
|
78 |
((InfluxTagValueBoolPOJO) boolPojo).setValue(Boolean.parseBoolean(value.toString())); |
|
79 |
return boolPojo; |
|
80 |
case TagValueTypeConstant.INT8: |
|
81 |
InfluxTagValuePOJO int8Pojo = new InfluxTagValueIntPOJO(); |
|
82 |
((InfluxTagValueIntPOJO) int8Pojo).setValue(Integer.parseInt(value.toString())); |
|
83 |
return int8Pojo; |
|
84 |
case TagValueTypeConstant.INT16: |
|
85 |
InfluxTagValuePOJO int16Pojo = new InfluxTagValueIntPOJO(); |
|
86 |
((InfluxTagValueIntPOJO) int16Pojo).setValue(Integer.parseInt(value.toString())); |
|
87 |
return int16Pojo; |
|
88 |
case TagValueTypeConstant.INT32: |
|
89 |
InfluxTagValuePOJO int32Pojo = new InfluxTagValueIntPOJO(); |
|
90 |
((InfluxTagValueIntPOJO) int32Pojo).setValue(Integer.parseInt(value.toString())); |
|
91 |
return int32Pojo; |
|
92 |
case TagValueTypeConstant.INT64: |
|
93 |
InfluxTagValuePOJO int64Pojo = new InfluxTagValueIntPOJO(); |
|
94 |
((InfluxTagValueIntPOJO) int64Pojo).setValue(Integer.parseInt(value.toString())); |
|
95 |
return int64Pojo; |
|
96 |
case TagValueTypeConstant.UINT8: |
|
97 |
InfluxTagValuePOJO uint8Pojo = new InfluxTagValueIntPOJO(); |
|
98 |
((InfluxTagValueIntPOJO) uint8Pojo).setValue(Integer.parseInt(value.toString())); |
|
99 |
return uint8Pojo; |
|
100 |
case TagValueTypeConstant.UINT16: |
|
101 |
InfluxTagValuePOJO uint16Pojo = new InfluxTagValueIntPOJO(); |
|
102 |
((InfluxTagValueIntPOJO) uint16Pojo).setValue(Integer.parseInt(value.toString())); |
|
103 |
return uint16Pojo; |
|
104 |
case TagValueTypeConstant.UINT32: |
|
105 |
InfluxTagValuePOJO uint32Pojo = new InfluxTagValueIntPOJO(); |
|
106 |
((InfluxTagValueIntPOJO) uint32Pojo).setValue(Integer.parseInt(value.toString())); |
|
107 |
return uint32Pojo; |
|
108 |
case TagValueTypeConstant.UINT64: |
|
109 |
InfluxTagValuePOJO uint64Pojo = new InfluxTagValueIntPOJO(); |
|
110 |
((InfluxTagValueIntPOJO) uint64Pojo).setValue(Integer.parseInt(value.toString())); |
|
111 |
return uint64Pojo; |
|
112 |
case TagValueTypeConstant.FLOAT: |
|
113 |
InfluxTagValuePOJO floatPojo = new InfluxTagValueFloatPOJO(); |
|
114 |
((InfluxTagValueFloatPOJO) floatPojo).setValue(Double.parseDouble(value.toString())); |
|
115 |
return floatPojo; |
|
116 |
case TagValueTypeConstant.DOUBLE: |
|
117 |
InfluxTagValuePOJO doublePojo = new InfluxTagValueFloatPOJO(); |
|
118 |
((InfluxTagValueFloatPOJO) doublePojo).setValue(Double.parseDouble(value.toString())); |
|
119 |
return doublePojo; |
|
120 |
default: |
|
121 |
InfluxTagValuePOJO strPojo = new InfluxTagValueStrPOJO(); |
|
122 |
((InfluxTagValueStrPOJO) strPojo).setValue(value.toString()); |
|
123 |
return strPojo; |
|
124 |
} |
|
125 |
} |
|
126 |
} |