|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+package com.water.production.service;
|
|
|
2
|
+
|
|
|
3
|
+import com.water.production.dto.MonitorExportRequest;
|
|
|
4
|
+import com.water.production.dto.MonitorQueryRequest;
|
|
|
5
|
+import com.water.production.entity.MonitorDevice;
|
|
|
6
|
+import com.water.production.entity.MonitorRealtimeData;
|
|
|
7
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
8
|
+import org.junit.jupiter.api.Test;
|
|
|
9
|
+
|
|
|
10
|
+import java.math.BigDecimal;
|
|
|
11
|
+import java.math.RoundingMode;
|
|
|
12
|
+import java.time.LocalDateTime;
|
|
|
13
|
+import java.util.*;
|
|
|
14
|
+import java.util.stream.Collectors;
|
|
|
15
|
+
|
|
|
16
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
17
|
+
|
|
|
18
|
+/**
|
|
|
19
|
+ * 在线监测列表单元测试
|
|
|
20
|
+ * 覆盖实体、DTO、查询筛选逻辑、导出格式、状态判断等
|
|
|
21
|
+ */
|
|
|
22
|
+class MonitorListServiceTest {
|
|
|
23
|
+
|
|
|
24
|
+ // ========== 1. 实体构建测试 ==========
|
|
|
25
|
+
|
|
|
26
|
+ @Test
|
|
|
27
|
+ @DisplayName("MonitorDevice 实体字段完整性")
|
|
|
28
|
+ void testMonitorDeviceEntity() {
|
|
|
29
|
+ MonitorDevice device = new MonitorDevice();
|
|
|
30
|
+ device.setId(1L);
|
|
|
31
|
+ device.setDeviceCode("MON-FLOW-001");
|
|
|
32
|
+ device.setDeviceName("一号泵站出口流量计");
|
|
|
33
|
+ device.setDeviceType("flow");
|
|
|
34
|
+ device.setArea("一体化水厂");
|
|
|
35
|
+ device.setLocation("一号泵站出口");
|
|
|
36
|
+ device.setLng(new BigDecimal("82.07123456"));
|
|
|
37
|
+ device.setLat(new BigDecimal("44.84567890"));
|
|
|
38
|
+ device.setStatus("online");
|
|
|
39
|
+ device.setLastReportTime(LocalDateTime.of(2026, 6, 14, 16, 0, 0));
|
|
|
40
|
+ device.setBrand("E+H Promag 50");
|
|
|
41
|
+ device.setInstallTime(LocalDateTime.of(2025, 1, 15, 10, 0, 0));
|
|
|
42
|
+ device.setRemark("正常运行");
|
|
|
43
|
+
|
|
|
44
|
+ assertEquals(1L, device.getId());
|
|
|
45
|
+ assertEquals("MON-FLOW-001", device.getDeviceCode());
|
|
|
46
|
+ assertEquals("flow", device.getDeviceType());
|
|
|
47
|
+ assertEquals("online", device.getStatus());
|
|
|
48
|
+ assertEquals(new BigDecimal("82.07123456"), device.getLng());
|
|
|
49
|
+ assertNotNull(device.getLastReportTime());
|
|
|
50
|
+ assertEquals("E+H Promag 50", device.getBrand());
|
|
|
51
|
+ }
|
|
|
52
|
+
|
|
|
53
|
+ @Test
|
|
|
54
|
+ @DisplayName("MonitorRealtimeData 实体字段完整性")
|
|
|
55
|
+ void testMonitorRealtimeDataEntity() {
|
|
|
56
|
+ MonitorRealtimeData data = new MonitorRealtimeData();
|
|
|
57
|
+ data.setId(1L);
|
|
|
58
|
+ data.setDeviceId(1L);
|
|
|
59
|
+ data.setDeviceCode("MON-FLOW-001");
|
|
|
60
|
+ data.setMetricKey("flow");
|
|
|
61
|
+ data.setMetricValue(new BigDecimal("125.5000"));
|
|
|
62
|
+ data.setUnit("m³/h");
|
|
|
63
|
+ data.setThresholdHigh(new BigDecimal("200.0000"));
|
|
|
64
|
+ data.setThresholdLow(new BigDecimal("10.0000"));
|
|
|
65
|
+ data.setIsAbnormal(0);
|
|
|
66
|
+ data.setCollectTime(LocalDateTime.of(2026, 6, 14, 15, 55, 0));
|
|
|
67
|
+
|
|
|
68
|
+ assertEquals("flow", data.getMetricKey());
|
|
|
69
|
+ assertEquals(new BigDecimal("125.5000"), data.getMetricValue());
|
|
|
70
|
+ assertEquals("m³/h", data.getUnit());
|
|
|
71
|
+ assertEquals(0, data.getIsAbnormal());
|
|
|
72
|
+ assertNotNull(data.getCollectTime());
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ // ========== 2. DTO 默认值测试 ==========
|
|
|
76
|
+
|
|
|
77
|
+ @Test
|
|
|
78
|
+ @DisplayName("MonitorQueryRequest 默认分页参数")
|
|
|
79
|
+ void testQueryRequestDefaults() {
|
|
|
80
|
+ MonitorQueryRequest req = new MonitorQueryRequest();
|
|
|
81
|
+ assertEquals(1, req.getPageNum());
|
|
|
82
|
+ assertEquals(20, req.getPageSize());
|
|
|
83
|
+ assertNull(req.getArea());
|
|
|
84
|
+ assertNull(req.getDeviceType());
|
|
|
85
|
+ assertNull(req.getStatus());
|
|
|
86
|
+ assertNull(req.getSortField());
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ @Test
|
|
|
90
|
+ @DisplayName("MonitorExportRequest 默认格式为 excel")
|
|
|
91
|
+ void testExportRequestDefaults() {
|
|
|
92
|
+ MonitorExportRequest req = new MonitorExportRequest();
|
|
|
93
|
+ assertEquals("excel", req.getFormat());
|
|
|
94
|
+ assertTrue(req.getIncludeRealtime());
|
|
|
95
|
+ assertNull(req.getDeviceIds());
|
|
|
96
|
+ }
|
|
|
97
|
+
|
|
|
98
|
+ // ========== 3. 状态判断逻辑测试 ==========
|
|
|
99
|
+
|
|
|
100
|
+ @Test
|
|
|
101
|
+ @DisplayName("设备状态格式化逻辑")
|
|
|
102
|
+ void testStatusFormatting() {
|
|
|
103
|
+ // 模拟 Controller 中的状态格式化
|
|
|
104
|
+ Map<String, String> statusMap = Map.of(
|
|
|
105
|
+ "online", "在线",
|
|
|
106
|
+ "offline", "离线",
|
|
|
107
|
+ "fault", "故障",
|
|
|
108
|
+ "abnormal", "数据异常"
|
|
|
109
|
+ );
|
|
|
110
|
+
|
|
|
111
|
+ assertEquals("在线", statusMap.get("online"));
|
|
|
112
|
+ assertEquals("离线", statusMap.get("offline"));
|
|
|
113
|
+ assertEquals("故障", statusMap.get("fault"));
|
|
|
114
|
+ assertEquals("数据异常", statusMap.get("abnormal"));
|
|
|
115
|
+ assertNull(statusMap.get("unknown"));
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ @Test
|
|
|
119
|
+ @DisplayName("设备异常判定逻辑")
|
|
|
120
|
+ void testAbnormalDetection() {
|
|
|
121
|
+ // 模拟异常判定:值超出阈值范围
|
|
|
122
|
+ BigDecimal value = new BigDecimal("250.00");
|
|
|
123
|
+ BigDecimal high = new BigDecimal("200.00");
|
|
|
124
|
+ BigDecimal low = new BigDecimal("10.00");
|
|
|
125
|
+
|
|
|
126
|
+ boolean isAbnormal = (high != null && value.compareTo(high) > 0)
|
|
|
127
|
+ || (low != null && value.compareTo(low) < 0);
|
|
|
128
|
+ assertTrue(isAbnormal, "超出上限应判定为异常");
|
|
|
129
|
+
|
|
|
130
|
+ // 正常范围
|
|
|
131
|
+ value = new BigDecimal("125.50");
|
|
|
132
|
+ isAbnormal = (high != null && value.compareTo(high) > 0)
|
|
|
133
|
+ || (low != null && value.compareTo(low) < 0);
|
|
|
134
|
+ assertFalse(isAbnormal, "正常范围不应判定为异常");
|
|
|
135
|
+
|
|
|
136
|
+ // 低于下限
|
|
|
137
|
+ value = new BigDecimal("5.00");
|
|
|
138
|
+ isAbnormal = (high != null && value.compareTo(high) > 0)
|
|
|
139
|
+ || (low != null && value.compareTo(low) < 0);
|
|
|
140
|
+ assertTrue(isAbnormal, "低于下限应判定为异常");
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ // ========== 4. 筛选逻辑测试 ==========
|
|
|
144
|
+
|
|
|
145
|
+ @Test
|
|
|
146
|
+ @DisplayName("多维度筛选条件构建")
|
|
|
147
|
+ void testMultiDimensionFilter() {
|
|
|
148
|
+ // 模拟设备列表
|
|
|
149
|
+ List<MonitorDevice> devices = buildMockDevices();
|
|
|
150
|
+
|
|
|
151
|
+ // 按区域筛选
|
|
|
152
|
+ List<MonitorDevice> filtered = devices.stream()
|
|
|
153
|
+ .filter(d -> "一体化水厂".equals(d.getArea()))
|
|
|
154
|
+ .collect(Collectors.toList());
|
|
|
155
|
+ assertEquals(3, filtered.size());
|
|
|
156
|
+
|
|
|
157
|
+ // 按设备类型筛选
|
|
|
158
|
+ filtered = devices.stream()
|
|
|
159
|
+ .filter(d -> "pressure".equals(d.getDeviceType()))
|
|
|
160
|
+ .collect(Collectors.toList());
|
|
|
161
|
+ assertEquals(2, filtered.size());
|
|
|
162
|
+
|
|
|
163
|
+ // 按状态筛选
|
|
|
164
|
+ filtered = devices.stream()
|
|
|
165
|
+ .filter(d -> "online".equals(d.getStatus()))
|
|
|
166
|
+ .collect(Collectors.toList());
|
|
|
167
|
+ assertEquals(3, filtered.size());
|
|
|
168
|
+
|
|
|
169
|
+ // 组合筛选:区域 + 类型
|
|
|
170
|
+ filtered = devices.stream()
|
|
|
171
|
+ .filter(d -> "一体化水厂".equals(d.getArea()) && "flow".equals(d.getDeviceType()))
|
|
|
172
|
+ .collect(Collectors.toList());
|
|
|
173
|
+ assertEquals(2, filtered.size());
|
|
|
174
|
+
|
|
|
175
|
+ // 关键词搜索
|
|
|
176
|
+ String keyword = "流量计";
|
|
|
177
|
+ filtered = devices.stream()
|
|
|
178
|
+ .filter(d -> (d.getDeviceName() != null && d.getDeviceName().contains(keyword))
|
|
|
179
|
+ || (d.getDeviceCode() != null && d.getDeviceCode().contains(keyword)))
|
|
|
180
|
+ .collect(Collectors.toList());
|
|
|
181
|
+ assertEquals(2, filtered.size());
|
|
|
182
|
+ }
|
|
|
183
|
+
|
|
|
184
|
+ @Test
|
|
|
185
|
+ @DisplayName("排序逻辑测试")
|
|
|
186
|
+ void testSortLogic() {
|
|
|
187
|
+ List<MonitorDevice> devices = buildMockDevices();
|
|
|
188
|
+
|
|
|
189
|
+ // 按设备编号升序
|
|
|
190
|
+ devices.sort(Comparator.comparing(MonitorDevice::getDeviceCode));
|
|
|
191
|
+ assertEquals("MON-FLOW-001", devices.get(0).getDeviceCode());
|
|
|
192
|
+
|
|
|
193
|
+ // 按设备编号降序
|
|
|
194
|
+ devices.sort(Comparator.comparing(MonitorDevice::getDeviceCode).reversed());
|
|
|
195
|
+ assertEquals("MON-QUAL-001", devices.get(0).getDeviceCode());
|
|
|
196
|
+
|
|
|
197
|
+ // 按最后上报时间降序(最新在前)
|
|
|
198
|
+ devices.sort(Comparator.comparing(MonitorDevice::getLastReportTime, Comparator.nullsLast(Comparator.reverseOrder())));
|
|
|
199
|
+ assertNotNull(devices.get(0).getLastReportTime());
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ // ========== 5. 统计逻辑测试 ==========
|
|
|
203
|
+
|
|
|
204
|
+ @Test
|
|
|
205
|
+ @DisplayName("设备统计聚合逻辑")
|
|
|
206
|
+ void testDeviceStatistics() {
|
|
|
207
|
+ List<MonitorDevice> devices = buildMockDevices();
|
|
|
208
|
+
|
|
|
209
|
+ // 按状态统计
|
|
|
210
|
+ Map<String, Long> statusCount = devices.stream()
|
|
|
211
|
+ .collect(Collectors.groupingBy(MonitorDevice::getStatus, Collectors.counting()));
|
|
|
212
|
+ assertEquals(3L, statusCount.get("online"));
|
|
|
213
|
+ assertEquals(1L, statusCount.get("offline"));
|
|
|
214
|
+ assertEquals(1L, statusCount.get("fault"));
|
|
|
215
|
+
|
|
|
216
|
+ // 按类型统计
|
|
|
217
|
+ Map<String, Long> typeCount = devices.stream()
|
|
|
218
|
+ .collect(Collectors.groupingBy(MonitorDevice::getDeviceType, Collectors.counting()));
|
|
|
219
|
+ assertEquals(2L, typeCount.get("flow"));
|
|
|
220
|
+ assertEquals(2L, typeCount.get("pressure"));
|
|
|
221
|
+ assertEquals(1L, typeCount.get("quality"));
|
|
|
222
|
+
|
|
|
223
|
+ // 按区域统计
|
|
|
224
|
+ Map<String, Long> areaCount = devices.stream()
|
|
|
225
|
+ .collect(Collectors.groupingBy(MonitorDevice::getArea, Collectors.counting()));
|
|
|
226
|
+ assertEquals(3L, areaCount.get("一体化水厂"));
|
|
|
227
|
+ assertEquals(2L, areaCount.get("管网一区"));
|
|
|
228
|
+ }
|
|
|
229
|
+
|
|
|
230
|
+ // ========== 6. 分页计算测试 ==========
|
|
|
231
|
+
|
|
|
232
|
+ @Test
|
|
|
233
|
+ @DisplayName("分页参数计算")
|
|
|
234
|
+ void testPagination() {
|
|
|
235
|
+ int total = 50;
|
|
|
236
|
+ int pageSize = 20;
|
|
|
237
|
+
|
|
|
238
|
+ int pages = (int) Math.ceil((double) total / pageSize);
|
|
|
239
|
+ assertEquals(3, pages);
|
|
|
240
|
+
|
|
|
241
|
+ // 第1页偏移量
|
|
|
242
|
+ int offset = (1 - 1) * pageSize;
|
|
|
243
|
+ assertEquals(0, offset);
|
|
|
244
|
+
|
|
|
245
|
+ // 第3页偏移量
|
|
|
246
|
+ offset = (3 - 1) * pageSize;
|
|
|
247
|
+ assertEquals(40, offset);
|
|
|
248
|
+
|
|
|
249
|
+ // 整除情况
|
|
|
250
|
+ total = 40;
|
|
|
251
|
+ pages = (int) Math.ceil((double) total / pageSize);
|
|
|
252
|
+ assertEquals(2, pages);
|
|
|
253
|
+ }
|
|
|
254
|
+
|
|
|
255
|
+ // ========== 7. CSV 转义测试 ==========
|
|
|
256
|
+
|
|
|
257
|
+ @Test
|
|
|
258
|
+ @DisplayName("CSV 字段转义逻辑")
|
|
|
259
|
+ void testCsvEscaping() {
|
|
|
260
|
+ // 包含逗号
|
|
|
261
|
+ String value = "一号泵站,出口";
|
|
|
262
|
+ String escaped = csvEsc(value);
|
|
|
263
|
+ assertEquals("\"一号泵站,出口\"", escaped);
|
|
|
264
|
+
|
|
|
265
|
+ // 包含引号
|
|
|
266
|
+ value = "含\"引号\"的文本";
|
|
|
267
|
+ escaped = csvEsc(value);
|
|
|
268
|
+ assertEquals("\"含\"\"引号\"\"的文本\"", escaped);
|
|
|
269
|
+
|
|
|
270
|
+ // 普通文本
|
|
|
271
|
+ value = "正常文本";
|
|
|
272
|
+ escaped = csvEsc(value);
|
|
|
273
|
+ assertEquals("正常文本", escaped);
|
|
|
274
|
+
|
|
|
275
|
+ // null
|
|
|
276
|
+ escaped = csvEsc(null);
|
|
|
277
|
+ assertEquals("", escaped);
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ // ========== 8. 实时数据结构测试 ==========
|
|
|
281
|
+
|
|
|
282
|
+ @Test
|
|
|
283
|
+ @DisplayName("多参数实时数据结构完整性")
|
|
|
284
|
+ void testRealtimeDataStructure() {
|
|
|
285
|
+ // 模拟多参数实时数据
|
|
|
286
|
+ List<String> expectedMetrics = List.of("flow", "pressure", "level", "turbidity", "ph", "residual_chlorine");
|
|
|
287
|
+ Map<String, MonitorRealtimeData> metricMap = new LinkedHashMap<>();
|
|
|
288
|
+
|
|
|
289
|
+ for (String metric : expectedMetrics) {
|
|
|
290
|
+ MonitorRealtimeData data = new MonitorRealtimeData();
|
|
|
291
|
+ data.setDeviceId(1L);
|
|
|
292
|
+ data.setMetricKey(metric);
|
|
|
293
|
+ data.setMetricValue(new BigDecimal("100.00"));
|
|
|
294
|
+ data.setUnit("unit_" + metric);
|
|
|
295
|
+ data.setCollectTime(LocalDateTime.now());
|
|
|
296
|
+ metricMap.put(metric, data);
|
|
|
297
|
+ }
|
|
|
298
|
+
|
|
|
299
|
+ assertEquals(6, metricMap.size());
|
|
|
300
|
+ assertTrue(metricMap.containsKey("flow"));
|
|
|
301
|
+ assertTrue(metricMap.containsKey("pressure"));
|
|
|
302
|
+ assertTrue(metricMap.containsKey("level"));
|
|
|
303
|
+ assertTrue(metricMap.containsKey("turbidity"));
|
|
|
304
|
+ assertTrue(metricMap.containsKey("ph"));
|
|
|
305
|
+ assertTrue(metricMap.containsKey("residual_chlorine"));
|
|
|
306
|
+
|
|
|
307
|
+ // 验证各参数值
|
|
|
308
|
+ for (String metric : expectedMetrics) {
|
|
|
309
|
+ assertNotNull(metricMap.get(metric).getMetricValue());
|
|
|
310
|
+ assertEquals(metric, metricMap.get(metric).getMetricKey());
|
|
|
311
|
+ }
|
|
|
312
|
+ }
|
|
|
313
|
+
|
|
|
314
|
+ // ========== 9. 设备在线率计算 ==========
|
|
|
315
|
+
|
|
|
316
|
+ @Test
|
|
|
317
|
+ @DisplayName("设备在线率计算")
|
|
|
318
|
+ void testOnlineRateCalculation() {
|
|
|
319
|
+ List<MonitorDevice> devices = buildMockDevices();
|
|
|
320
|
+ int total = devices.size();
|
|
|
321
|
+ long onlineCount = devices.stream().filter(d -> "online".equals(d.getStatus())).count();
|
|
|
322
|
+
|
|
|
323
|
+ BigDecimal onlineRate = total > 0
|
|
|
324
|
+ ? BigDecimal.valueOf(onlineCount * 100.0 / total).setScale(1, RoundingMode.HALF_UP)
|
|
|
325
|
+ : BigDecimal.ZERO;
|
|
|
326
|
+
|
|
|
327
|
+ assertEquals(5, total);
|
|
|
328
|
+ assertEquals(3, onlineCount);
|
|
|
329
|
+ assertEquals(new BigDecimal("60.0"), onlineRate);
|
|
|
330
|
+ }
|
|
|
331
|
+
|
|
|
332
|
+ // ========== 10. 导出数据量限制测试 ==========
|
|
|
333
|
+
|
|
|
334
|
+ @Test
|
|
|
335
|
+ @DisplayName("导出最大数据量限制")
|
|
|
336
|
+ void testExportMaxLimit() {
|
|
|
337
|
+ MonitorExportRequest req = new MonitorExportRequest();
|
|
|
338
|
+ int maxExportLimit = 10000;
|
|
|
339
|
+
|
|
|
340
|
+ // 模拟大量设备
|
|
|
341
|
+ List<MonitorDevice> devices = new ArrayList<>();
|
|
|
342
|
+ for (int i = 0; i < 15000; i++) {
|
|
|
343
|
+ MonitorDevice d = new MonitorDevice();
|
|
|
344
|
+ d.setId((long) (i + 1));
|
|
|
345
|
+ d.setDeviceCode("MON-" + String.format("%05d", i));
|
|
|
346
|
+ devices.add(d);
|
|
|
347
|
+ }
|
|
|
348
|
+
|
|
|
349
|
+ // 导出应限制在 maxExportLimit 内
|
|
|
350
|
+ List<MonitorDevice> exportList = devices.size() > maxExportLimit
|
|
|
351
|
+ ? devices.subList(0, maxExportLimit)
|
|
|
352
|
+ : devices;
|
|
|
353
|
+
|
|
|
354
|
+ assertEquals(maxExportLimit, exportList.size());
|
|
|
355
|
+ assertTrue(devices.size() > maxExportLimit);
|
|
|
356
|
+ }
|
|
|
357
|
+
|
|
|
358
|
+ // ========== Helper Methods ==========
|
|
|
359
|
+
|
|
|
360
|
+ private List<MonitorDevice> buildMockDevices() {
|
|
|
361
|
+ List<MonitorDevice> devices = new ArrayList<>();
|
|
|
362
|
+
|
|
|
363
|
+ MonitorDevice d1 = new MonitorDevice();
|
|
|
364
|
+ d1.setId(1L);
|
|
|
365
|
+ d1.setDeviceCode("MON-FLOW-001");
|
|
|
366
|
+ d1.setDeviceName("一号泵站出口流量计");
|
|
|
367
|
+ d1.setDeviceType("flow");
|
|
|
368
|
+ d1.setArea("一体化水厂");
|
|
|
369
|
+ d1.setStatus("online");
|
|
|
370
|
+ d1.setLastReportTime(LocalDateTime.of(2026, 6, 14, 16, 0, 0));
|
|
|
371
|
+ devices.add(d1);
|
|
|
372
|
+
|
|
|
373
|
+ MonitorDevice d2 = new MonitorDevice();
|
|
|
374
|
+ d2.setId(2L);
|
|
|
375
|
+ d2.setDeviceCode("MON-FLOW-002");
|
|
|
376
|
+ d2.setDeviceName("二号泵站流量计");
|
|
|
377
|
+ d2.setDeviceType("flow");
|
|
|
378
|
+ d2.setArea("一体化水厂");
|
|
|
379
|
+ d2.setStatus("online");
|
|
|
380
|
+ d2.setLastReportTime(LocalDateTime.of(2026, 6, 14, 15, 50, 0));
|
|
|
381
|
+ devices.add(d2);
|
|
|
382
|
+
|
|
|
383
|
+ MonitorDevice d3 = new MonitorDevice();
|
|
|
384
|
+ d3.setId(3L);
|
|
|
385
|
+ d3.setDeviceCode("MON-PRES-001");
|
|
|
386
|
+ d3.setDeviceName("管网压力监测点A");
|
|
|
387
|
+ d3.setDeviceType("pressure");
|
|
|
388
|
+ d3.setArea("管网一区");
|
|
|
389
|
+ d3.setStatus("online");
|
|
|
390
|
+ d3.setLastReportTime(LocalDateTime.of(2026, 6, 14, 15, 55, 0));
|
|
|
391
|
+ devices.add(d3);
|
|
|
392
|
+
|
|
|
393
|
+ MonitorDevice d4 = new MonitorDevice();
|
|
|
394
|
+ d4.setId(4L);
|
|
|
395
|
+ d4.setDeviceCode("MON-PRES-002");
|
|
|
396
|
+ d4.setDeviceName("管网压力监测点B");
|
|
|
397
|
+ d4.setDeviceType("pressure");
|
|
|
398
|
+ d4.setArea("管网一区");
|
|
|
399
|
+ d4.setStatus("offline");
|
|
|
400
|
+ d4.setLastReportTime(LocalDateTime.of(2026, 6, 14, 14, 0, 0));
|
|
|
401
|
+ devices.add(d4);
|
|
|
402
|
+
|
|
|
403
|
+ MonitorDevice d5 = new MonitorDevice();
|
|
|
404
|
+ d5.setId(5L);
|
|
|
405
|
+ d5.setDeviceCode("MON-QUAL-001");
|
|
|
406
|
+ d5.setDeviceName("出厂水质监测仪");
|
|
|
407
|
+ d5.setDeviceType("quality");
|
|
|
408
|
+ d5.setArea("一体化水厂");
|
|
|
409
|
+ d5.setStatus("fault");
|
|
|
410
|
+ d5.setLastReportTime(LocalDateTime.of(2026, 6, 14, 15, 30, 0));
|
|
|
411
|
+ devices.add(d5);
|
|
|
412
|
+
|
|
|
413
|
+ return devices;
|
|
|
414
|
+ }
|
|
|
415
|
+
|
|
|
416
|
+ private String csvEsc(String value) {
|
|
|
417
|
+ if (value == null) return "";
|
|
|
418
|
+ if (value.contains(",") || value.contains("\"") || value.contains("\n")) {
|
|
|
419
|
+ return "\"" + value.replace("\"", "\"\"") + "\"";
|
|
|
420
|
+ }
|
|
|
421
|
+ return value;
|
|
|
422
|
+ }
|
|
|
423
|
+}
|