|
@@ -1,5 +1,8 @@
|
|
|
package com.zksy.base.service.impl;
|
|
package com.zksy.base.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zksy.base.audio.domain.NoiseInfo;
|
|
import com.zksy.base.audio.domain.NoiseInfo;
|
|
|
import com.zksy.base.audio.mapper.NoiseInfoMapper;
|
|
import com.zksy.base.audio.mapper.NoiseInfoMapper;
|
|
@@ -16,16 +19,20 @@ import com.zksy.base.radar.domain.RadarData;
|
|
|
import com.zksy.base.radar.mapper.RadarDataMapper;
|
|
import com.zksy.base.radar.mapper.RadarDataMapper;
|
|
|
import com.zksy.base.telemetry.domain.TelemetryData;
|
|
import com.zksy.base.telemetry.domain.TelemetryData;
|
|
|
import com.zksy.base.telemetry.mapper.TelemetryDataMapper;
|
|
import com.zksy.base.telemetry.mapper.TelemetryDataMapper;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeAll;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
-import org.mockito.Mockito;
|
|
|
|
|
|
|
+import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
@@ -38,6 +45,12 @@ class MonitoringServiceImplTest {
|
|
|
|
|
|
|
|
private static final LocalDateTime BASE_TIME = LocalDateTime.of(2026, 9, 1, 12, 0);
|
|
private static final LocalDateTime BASE_TIME = LocalDateTime.of(2026, 9, 1, 12, 0);
|
|
|
|
|
|
|
|
|
|
+ @BeforeAll
|
|
|
|
|
+ static void initializeMybatisPlusLambdaCache() {
|
|
|
|
|
+ TableInfoHelper.initTableInfo(
|
|
|
|
|
+ new MapperBuilderAssistant(new MybatisConfiguration(), ""), EquipmentBase.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private MonitoringServiceImpl service;
|
|
private MonitoringServiceImpl service;
|
|
|
private EquipmentBaseMapper equipmentBaseMapper;
|
|
private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
private EquipmentTypeMapper equipmentTypeMapper;
|
|
private EquipmentTypeMapper equipmentTypeMapper;
|
|
@@ -64,9 +77,10 @@ class MonitoringServiceImplTest {
|
|
|
ReflectionTestUtils.setField(service, "noiseInfoMapper", noiseMapper);
|
|
ReflectionTestUtils.setField(service, "noiseInfoMapper", noiseMapper);
|
|
|
|
|
|
|
|
when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
- type("flow-type", "flow-type", "流量监测"),
|
|
|
|
|
- type("pressure-type", "pressure-type", "压力监测"),
|
|
|
|
|
- type("leakage-type", "leakage-type", "漏失监测")
|
|
|
|
|
|
|
+ type("water-root", "water_root", "供水", "0"),
|
|
|
|
|
+ type("flow-type", "flow-type", "流量监测", "water-root"),
|
|
|
|
|
+ type("pressure-type", "pressure-type", "压力监测", "water-root"),
|
|
|
|
|
+ type("leakage-type", "leakage-type", "漏失监测", "water-root")
|
|
|
));
|
|
));
|
|
|
when(radarDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
when(radarDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
when(telemetryDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
when(telemetryDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
@@ -167,6 +181,57 @@ class MonitoringServiceImplTest {
|
|
|
assertTrue(leakage.getRecords().isEmpty());
|
|
assertTrue(leakage.getRecords().isEmpty());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void flowMonitoringOnlyIncludesDevicesInsideTheWaterTypeTree() {
|
|
|
|
|
+ when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
+ type("water-root", "water_root", "供水", "0"),
|
|
|
|
|
+ type("water-flow", "water_flow", "流量监测", "water-root"),
|
|
|
|
|
+ type("other-root", "other_root", "其他系统", "0"),
|
|
|
|
|
+ type("other-flow", "other_flow", "流量监测", "other-root")
|
|
|
|
|
+ ));
|
|
|
|
|
+ when(equipmentBaseMapper.selectList(any())).thenAnswer(invocation -> {
|
|
|
|
|
+ LambdaQueryWrapper<EquipmentBase> wrapper = invocation.getArgument(0);
|
|
|
|
|
+ Set<Object> allowedTypeIds = flattenWrapperValues(wrapper);
|
|
|
|
|
+ return Arrays.asList(
|
|
|
|
|
+ device("water-flow-device", "WS-FLOW", "供水流量监测点", "water-flow", BASE_TIME),
|
|
|
|
|
+ device("other-flow-device", "OTHER-FLOW", "其他系统流量监测点", "other-flow", BASE_TIME),
|
|
|
|
|
+ device("unknown-type-device", "UNKNOWN-FLOW", "未归属流量监测点", "unknown-type", BASE_TIME)
|
|
|
|
|
+ ).stream()
|
|
|
|
|
+ .filter(device -> allowedTypeIds.contains(device.getEquipmentTypeId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ });
|
|
|
|
|
+ when(radarDataMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
+ radar("WS-FLOW", "10", BASE_TIME),
|
|
|
|
|
+ radar("OTHER-FLOW", "20", BASE_TIME),
|
|
|
|
|
+ radar("UNKNOWN-FLOW", "30", BASE_TIME)
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ Page<FlowMonitoringVO> page = service.getFlowMonitorPage(
|
|
|
|
|
+ 1, 10, null, null, null, null, null, null, null);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(1, page.getTotal());
|
|
|
|
|
+ assertEquals("water-flow-device", page.getRecords().get(0).getEquipmentId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void trendEndpointsRejectDevicesOutsideTheWaterTypeTree() {
|
|
|
|
|
+ when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
+ type("water-root", "water_root", "供水", "0"),
|
|
|
|
|
+ type("water-flow", "water_flow", "流量监测", "water-root"),
|
|
|
|
|
+ type("other-root", "other_root", "其他系统", "0"),
|
|
|
|
|
+ type("other-flow", "other_flow", "流量监测", "other-root")
|
|
|
|
|
+ ));
|
|
|
|
|
+ EquipmentBase otherDevice = device("other-flow-device", "OTHER-FLOW", "其他系统流量监测点", "other-flow", BASE_TIME);
|
|
|
|
|
+ when(equipmentBaseMapper.selectById("other-flow-device")).thenReturn(otherDevice);
|
|
|
|
|
+ when(radarDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ radar("OTHER-FLOW", "20", BASE_TIME)
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> trend = service.getFlowTrend("other-flow-device", null, null);
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(trend.isEmpty());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void trendEndpointsUseTheRequestedTimeRangeForAllMonitoringTypes() {
|
|
void trendEndpointsUseTheRequestedTimeRangeForAllMonitoringTypes() {
|
|
|
LocalDateTime start = BASE_TIME.minusHours(2);
|
|
LocalDateTime start = BASE_TIME.minusHours(2);
|
|
@@ -242,10 +307,31 @@ class MonitoringServiceImplTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static EquipmentType type(String id, String typeId, String name) {
|
|
private static EquipmentType type(String id, String typeId, String name) {
|
|
|
|
|
+ return type(id, typeId, name, "water-root");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Set<Object> flattenWrapperValues(
|
|
|
|
|
+ LambdaQueryWrapper<EquipmentBase> wrapper) {
|
|
|
|
|
+ wrapper.getSqlSegment();
|
|
|
|
|
+ Set<Object> values = new HashSet<>();
|
|
|
|
|
+ for (Object value : wrapper.getParamNameValuePairs().values()) {
|
|
|
|
|
+ if (value instanceof Collection<?>) {
|
|
|
|
|
+ values.addAll((Collection<?>) value);
|
|
|
|
|
+ } else if (value instanceof Object[]) {
|
|
|
|
|
+ values.addAll(Arrays.asList((Object[]) value));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ values.add(value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return values;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static EquipmentType type(String id, String typeId, String name, String parentTypeId) {
|
|
|
EquipmentType type = new EquipmentType();
|
|
EquipmentType type = new EquipmentType();
|
|
|
type.setId(id);
|
|
type.setId(id);
|
|
|
type.setTypeId(typeId);
|
|
type.setTypeId(typeId);
|
|
|
type.setTypeName(name);
|
|
type.setTypeName(name);
|
|
|
|
|
+ type.setParentTypeId(parentTypeId);
|
|
|
return type;
|
|
return type;
|
|
|
}
|
|
}
|
|
|
|
|
|