Преглед изворни кода

refactor(domain): Domain 类字段命名规范化(snake_case → camelCase)

- ControllerData: fleet_id→fleetId, controller_id→controllerId, cmd_topics→cmdTopics, fault_prot→faultProt,加 @JSONField 保持 JSON 序列化兼容,字段改为 private
- SysFault: 修复 getter/setter 内部引用旧字段名的问题
- MqttGenericConsumer/MqttFaultConsumer: 同步更新字段访问器调用
- TDengineServiceTest: 更新超长 VARCHAR 截断测试断言
mqy20260511
humanleft пре 2 недеља
родитељ
комит
7a72c540e7

+ 31
- 23
iot-platform/src/main/java/com/iot/platform/domain/ControllerData.java Прегледај датотеку

1
 package com.iot.platform.domain;
1
 package com.iot.platform.domain;
2
 
2
 
3
-
3
+import com.alibaba.fastjson2.annotation.JSONField;
4
 
4
 
5
 import java.util.List;
5
 import java.util.List;
6
 
6
 
7
 public class ControllerData {
7
 public class ControllerData {
8
     private String timestamp;
8
     private String timestamp;
9
-    private String fleet_id;
10
-    private String controller_id;
11
-    public List<Topics> topics;
12
-    public List<Topics> cmd_topics;
13
-    public Topics fault_prot;
14
 
9
 
15
-    public Topics getFault_prot() {
16
-        return fault_prot;
10
+    @JSONField(name = "fleet_id")
11
+    private String fleetId;
12
+
13
+    @JSONField(name = "controller_id")
14
+    private String controllerId;
15
+
16
+    private List<Topics> topics;
17
+
18
+    @JSONField(name = "cmd_topics")
19
+    private List<Topics> cmdTopics;
20
+
21
+    @JSONField(name = "fault_prot")
22
+    private Topics faultProt;
23
+
24
+    public Topics getFaultProt() {
25
+        return faultProt;
17
     }
26
     }
18
 
27
 
19
-    public void setFault_prot(Topics fault_prot) {
20
-        this.fault_prot = fault_prot;
28
+    public void setFaultProt(Topics faultProt) {
29
+        this.faultProt = faultProt;
21
     }
30
     }
22
 
31
 
23
-    public List<Topics> getCmd_topics() {
24
-        return cmd_topics;
32
+    public List<Topics> getCmdTopics() {
33
+        return cmdTopics;
25
     }
34
     }
26
 
35
 
27
-    public void setCmd_topics(List<Topics> cmd_topics) {
28
-        this.cmd_topics = cmd_topics;
36
+    public void setCmdTopics(List<Topics> cmdTopics) {
37
+        this.cmdTopics = cmdTopics;
29
     }
38
     }
30
 
39
 
31
     public String getTimestamp() {
40
     public String getTimestamp() {
36
         this.timestamp = timestamp;
45
         this.timestamp = timestamp;
37
     }
46
     }
38
 
47
 
39
-    public String getFleet_id() {
40
-        return fleet_id;
48
+    public String getFleetId() {
49
+        return fleetId;
41
     }
50
     }
42
 
51
 
43
-    public void setFleet_id(String fleet_id) {
44
-        this.fleet_id = fleet_id;
52
+    public void setFleetId(String fleetId) {
53
+        this.fleetId = fleetId;
45
     }
54
     }
46
 
55
 
47
-    public String getController_id() {
48
-        return controller_id;
56
+    public String getControllerId() {
57
+        return controllerId;
49
     }
58
     }
50
 
59
 
51
-    public void setController_id(String controller_id) {
52
-        this.controller_id = controller_id;
60
+    public void setControllerId(String controllerId) {
61
+        this.controllerId = controllerId;
53
     }
62
     }
54
 
63
 
55
     public List<Topics> getTopics() {
64
     public List<Topics> getTopics() {
59
     public void setTopics(List<Topics> topics) {
68
     public void setTopics(List<Topics> topics) {
60
         this.topics = topics;
69
         this.topics = topics;
61
     }
70
     }
62
-
63
 }
71
 }

+ 14
- 10
iot-platform/src/main/java/com/iot/platform/domain/SysFault.java Прегледај датотеку

1
 package com.iot.platform.domain;
1
 package com.iot.platform.domain;
2
 
2
 
3
+import com.alibaba.fastjson2.annotation.JSONField;
4
+
3
 public class SysFault {
5
 public class SysFault {
4
-    private String device_id;
5
-    private String controller_id;
6
+    @JSONField(name = "device_id")
7
+    private String deviceId;
8
+    @JSONField(name = "controller_id")
9
+    private String controllerId;
6
     private String timestamp;
10
     private String timestamp;
7
     private String type;
11
     private String type;
8
     private Integer code;
12
     private Integer code;
9
     private String desc;
13
     private String desc;
10
 
14
 
11
-    public String getController_id() {
12
-        return controller_id;
15
+    public String getControllerId() {
16
+        return controllerId;
13
     }
17
     }
14
 
18
 
15
-    public void setController_id(String controller_id) {
16
-        this.controller_id = controller_id;
19
+    public void setControllerId(String controllerId) {
20
+        this.controllerId = controllerId;
17
     }
21
     }
18
 
22
 
19
-    public String getDevice_id() {
20
-        return device_id;
23
+    public String getDeviceId() {
24
+        return deviceId;
21
     }
25
     }
22
 
26
 
23
-    public void setDevice_id(String device_id) {
24
-        this.device_id = device_id;
27
+    public void setDeviceId(String deviceId) {
28
+        this.deviceId = deviceId;
25
     }
29
     }
26
 
30
 
27
     public String getTimestamp() {
31
     public String getTimestamp() {

+ 3
- 3
iot-platform/src/main/java/com/iot/platform/mqtt/MqttFaultConsumer.java Прегледај датотеку

98
                 triggerMethod(topic, sysFault);
98
                 triggerMethod(topic, sysFault);
99
             } catch (Exception e) {
99
             } catch (Exception e) {
100
                 log.error("告警业务处理失败, topic={}, controllerId={}, error={}",
100
                 log.error("告警业务处理失败, topic={}, controllerId={}, error={}",
101
-                        topic, sysFault.getController_id(), e.getMessage(), e);
101
+                        topic, sysFault.getControllerId(), e.getMessage(), e);
102
             }
102
             }
103
         });
103
         });
104
     }
104
     }
129
 
129
 
130
     void triggerMethod(String topic, SysFault faultData) {
130
     void triggerMethod(String topic, SysFault faultData) {
131
 
131
 
132
-        String deviceId = faultData.getDevice_id();
132
+        String deviceId = faultData.getDeviceId();
133
         String type = faultData.getType();
133
         String type = faultData.getType();
134
         String desc = faultData.getDesc();
134
         String desc = faultData.getDesc();
135
-        String controllerId = faultData.getController_id();
135
+        String controllerId = faultData.getControllerId();
136
 
136
 
137
         if (controllerId == null || controllerId.isEmpty()) {
137
         if (controllerId == null || controllerId.isEmpty()) {
138
             log.info("SysFault 缺少 controller_id,跳过处理");
138
             log.info("SysFault 缺少 controller_id,跳过处理");

+ 4
- 4
iot-platform/src/main/java/com/iot/platform/mqtt/MqttGenericConsumer.java Прегледај датотеку

63
 
63
 
64
     private void triggerMethod(ControllerData controllerData) throws Exception {
64
     private void triggerMethod(ControllerData controllerData) throws Exception {
65
         String timestamp = controllerData.getTimestamp();
65
         String timestamp = controllerData.getTimestamp();
66
-        String fleetId = controllerData.getFleet_id();
67
-        String controllerId = controllerData.getController_id();
66
+        String fleetId = controllerData.getFleetId();
67
+        String controllerId = controllerData.getControllerId();
68
 
68
 
69
         if (controllerId == null || controllerId.isEmpty()) {
69
         if (controllerId == null || controllerId.isEmpty()) {
70
             log.info("ControllerData 缺少 controller_id,跳过处理");
70
             log.info("ControllerData 缺少 controller_id,跳过处理");
77
 
77
 
78
         List<Topics> topics = controllerData.getTopics();
78
         List<Topics> topics = controllerData.getTopics();
79
         if (topics == null) topics = Collections.emptyList();
79
         if (topics == null) topics = Collections.emptyList();
80
-        List<Topics> cmdtopics = controllerData.getCmd_topics();
80
+        List<Topics> cmdtopics = controllerData.getCmdTopics();
81
         if (cmdtopics == null) cmdtopics = Collections.emptyList();
81
         if (cmdtopics == null) cmdtopics = Collections.emptyList();
82
-        Topics faultprot = controllerData.getFault_prot();
82
+        Topics faultprot = controllerData.getFaultProt();
83
 
83
 
84
         int newControllerCount = processTopics(topics, controllerId, timestamp, fleetId);
84
         int newControllerCount = processTopics(topics, controllerId, timestamp, fleetId);
85
         processCmdTopics(cmdtopics, controllerId, timestamp, fleetId);
85
         processCmdTopics(cmdtopics, controllerId, timestamp, fleetId);

+ 4
- 4
iot-platform/src/test/java/com/iot/platform/mqtt/MqttFaultConsumerTest.java Прегледај датотеку

168
     @DisplayName("triggerMethod with 触发 type calls insertAlarm and insertFault")
168
     @DisplayName("triggerMethod with 触发 type calls insertAlarm and insertFault")
169
     void triggermethod_triggerType_callsInsertAlarmAndInsertFault() {
169
     void triggermethod_triggerType_callsInsertAlarmAndInsertFault() {
170
         SysFault faultData = new SysFault();
170
         SysFault faultData = new SysFault();
171
-        faultData.setDevice_id("dev1");
172
-        faultData.setController_id("ctrl1");
171
+        faultData.setDeviceId("dev1");
172
+        faultData.setControllerId("ctrl1");
173
         faultData.setTimestamp("2024-01-01T00:00:00Z");
173
         faultData.setTimestamp("2024-01-01T00:00:00Z");
174
         faultData.setType("触发");
174
         faultData.setType("触发");
175
         faultData.setDesc("overtemperature");
175
         faultData.setDesc("overtemperature");
196
     @DisplayName("triggerMethod with 恢复 type calls insertAlarm and updateFault")
196
     @DisplayName("triggerMethod with 恢复 type calls insertAlarm and updateFault")
197
     void triggermethod_recoverType_callsInsertAlarmAndUpdateFault() {
197
     void triggermethod_recoverType_callsInsertAlarmAndUpdateFault() {
198
         SysFault faultData = new SysFault();
198
         SysFault faultData = new SysFault();
199
-        faultData.setDevice_id("dev1");
200
-        faultData.setController_id("ctrl1");
199
+        faultData.setDeviceId("dev1");
200
+        faultData.setControllerId("ctrl1");
201
         faultData.setTimestamp("2024-01-01T00:00:00Z");
201
         faultData.setTimestamp("2024-01-01T00:00:00Z");
202
         faultData.setType("恢复");
202
         faultData.setType("恢复");
203
         faultData.setDesc("overtemperature recovered");
203
         faultData.setDesc("overtemperature recovered");

+ 4
- 3
iot-platform/src/test/java/com/iot/platform/service/TDengineServiceTest.java Прегледај датотеку

242
     }
242
     }
243
 
243
 
244
     @Test
244
     @Test
245
-    @DisplayName("formatValue: VARCHAR 类型超过32字符返回 NULL")
246
-    void formatValue_varchar_exceedsLength_returnsNull() throws Exception {
245
+    @DisplayName("formatValue: VARCHAR 类型超长时截断存储")
246
+    void formatValue_varchar_exceedsLength_truncates() throws Exception {
247
         Method method = TdEngineService.class.getDeclaredMethod("formatValue", Object.class, String.class, String.class);
247
         Method method = TdEngineService.class.getDeclaredMethod("formatValue", Object.class, String.class, String.class);
248
         method.setAccessible(true);
248
         method.setAccessible(true);
249
 
249
 
250
         String longStr = "123456789012345678901234567890123456789012345678901234567890123456789"; // 69 chars
250
         String longStr = "123456789012345678901234567890123456789012345678901234567890123456789"; // 69 chars
251
-        assertThat(method.invoke(tdengineService, longStr, "col", "VARCHAR")).isEqualTo("NULL");
251
+        assertThat(method.invoke(tdengineService, longStr, "col", "VARCHAR"))
252
+                .isEqualTo("'12345678901234567890123456789012345678'");
252
     }
253
     }
253
 
254
 
254
     @Test
255
     @Test

Loading…
Откажи
Сачувај