|
|
@@ -0,0 +1,158 @@
|
|
|
+package com.zksy.web.controller.cockpit;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
+import com.zksy.base.domain.EquipmentStatus;
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
+import com.zksy.base.domain.MonitorPoint;
|
|
|
+import com.zksy.base.domain.PipeNetworkBase;
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
+import com.zksy.base.service.EquipmentStatusService;
|
|
|
+import com.zksy.base.service.EquipmentTypeService;
|
|
|
+import com.zksy.base.service.MonitorPointService;
|
|
|
+import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
+import com.zksy.cockpit.device.BusinessCockpitDeviceBoundaryAdapter;
|
|
|
+import com.zksy.cockpit.device.CockpitDeviceBoundarySnapshot;
|
|
|
+import com.zksy.cockpit.foundation.BusinessCockpitFoundationAdapter;
|
|
|
+import com.zksy.cockpit.foundation.BusinessCockpitFreshnessAdapter;
|
|
|
+import com.zksy.cockpit.foundation.CockpitFoundationSnapshot;
|
|
|
+import com.zksy.cockpit.foundation.CockpitFreshnessSource;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+class BusinessCockpitFoundationAdaptersTest {
|
|
|
+
|
|
|
+ private EquipmentBaseService equipmentBaseService;
|
|
|
+ private EquipmentTypeService equipmentTypeService;
|
|
|
+ private MonitorPointService monitorPointService;
|
|
|
+ private PipeNetworkBaseService pipeNetworkBaseService;
|
|
|
+ private EquipmentStatusService equipmentStatusService;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ equipmentBaseService = mock(EquipmentBaseService.class);
|
|
|
+ equipmentTypeService = mock(EquipmentTypeService.class);
|
|
|
+ monitorPointService = mock(MonitorPointService.class);
|
|
|
+ pipeNetworkBaseService = mock(PipeNetworkBaseService.class);
|
|
|
+ equipmentStatusService = mock(EquipmentStatusService.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void foundationIsReadyWhenAnyBaseTableHasData() {
|
|
|
+ when(equipmentBaseService.list()).thenReturn(Collections.singletonList(device("E-1", "GAS-001")));
|
|
|
+ when(monitorPointService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ CockpitFoundationSnapshot snapshot =
|
|
|
+ new BusinessCockpitFoundationAdapter(
|
|
|
+ equipmentBaseService, monitorPointService, pipeNetworkBaseService).load();
|
|
|
+
|
|
|
+ assertEquals("READY", snapshot.getMapFrame().getState());
|
|
|
+ assertTrue(snapshot.getMapFrame().isRenderable());
|
|
|
+ assertNull(snapshot.getMapFrame().getReason());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void foundationIsEmptyWhenAllBaseTablesAreEmpty() {
|
|
|
+ when(equipmentBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(monitorPointService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ CockpitFoundationSnapshot snapshot =
|
|
|
+ new BusinessCockpitFoundationAdapter(
|
|
|
+ equipmentBaseService, monitorPointService, pipeNetworkBaseService).load();
|
|
|
+
|
|
|
+ assertEquals("EMPTY", snapshot.getMapFrame().getState());
|
|
|
+ assertFalse(snapshot.getMapFrame().isRenderable());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void deviceBoundaryListsTypesDevicesAndFacilitiesWithHonestScope() {
|
|
|
+ EquipmentType gasRoot = type(3, "燃气", 0);
|
|
|
+ EquipmentType gasSensor = type(11, "燃气浓度计", 3);
|
|
|
+ when(equipmentTypeService.list()).thenReturn(Arrays.asList(gasRoot, gasSensor));
|
|
|
+ when(equipmentBaseService.list()).thenReturn(Collections.singletonList(device("E-1", "GAS-001")));
|
|
|
+ PipeNetworkBase facility = new PipeNetworkBase();
|
|
|
+ facility.setNetworkId("N-1");
|
|
|
+ facility.setNetworkCode("PIPE-001");
|
|
|
+ facility.setNetworkName("城北主管网");
|
|
|
+ facility.setNetworkType("主管");
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.singletonList(facility));
|
|
|
+
|
|
|
+ CockpitDeviceBoundarySnapshot snapshot =
|
|
|
+ new BusinessCockpitDeviceBoundaryAdapter(
|
|
|
+ equipmentTypeService, equipmentBaseService, pipeNetworkBaseService).load();
|
|
|
+
|
|
|
+ assertEquals(2, snapshot.getTypes().size());
|
|
|
+ assertEquals("11", snapshot.getTypes().get(1).getCode());
|
|
|
+ assertEquals("GAS", snapshot.getTypes().get(1).getIndustry());
|
|
|
+ assertEquals("SMART_DEVICE", snapshot.getTypes().get(1).getObjectKind());
|
|
|
+ assertNull(snapshot.getTypes().get(1).getDrainageScope());
|
|
|
+
|
|
|
+ assertEquals(1, snapshot.getDevices().size());
|
|
|
+ assertEquals("GAS-001", snapshot.getDevices().get(0).getEquipmentCode());
|
|
|
+ assertEquals("11", snapshot.getDevices().get(0).getTypeCode());
|
|
|
+
|
|
|
+ assertEquals(1, snapshot.getFacilities().size());
|
|
|
+ assertEquals("PIPE-001", snapshot.getFacilities().get(0).getFacilityCode());
|
|
|
+ assertEquals("主管", snapshot.getFacilities().get(0).getTypeCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void freshnessUsesLedgerUpdateAndStatusUpdateTimes() {
|
|
|
+ EquipmentBase device = device("E-1", "GAS-001");
|
|
|
+ device.setUpdateTime(LocalDateTime.parse("2026-09-02T09:59:50"));
|
|
|
+ when(equipmentBaseService.list(any(LambdaQueryWrapper.class)))
|
|
|
+ .thenReturn(Collections.singletonList(device));
|
|
|
+ EquipmentStatus status = new EquipmentStatus();
|
|
|
+ status.setStatusId(1);
|
|
|
+ status.setEquipmentId("E-1");
|
|
|
+ status.setStatusUpdateTime(LocalDateTime.parse("2026-09-02T09:00:00"));
|
|
|
+ when(equipmentStatusService.getByDeviceCode("GAS-001")).thenReturn(status);
|
|
|
+
|
|
|
+ CockpitFreshnessSource source =
|
|
|
+ new BusinessCockpitFreshnessAdapter(equipmentBaseService, equipmentStatusService)
|
|
|
+ .load("GAS-001");
|
|
|
+
|
|
|
+ assertEquals("GAS-001", source.getDeviceCode());
|
|
|
+ assertEquals("2026-09-02T09:59:50+08:00", source.getUpdatedAt());
|
|
|
+ assertEquals("2026-09-02T09:00:00+08:00", source.getStatusTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void freshnessOfUnknownDeviceReturnsNullForEmptySection() {
|
|
|
+ when(equipmentBaseService.list(any(LambdaQueryWrapper.class))).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ assertNull(new BusinessCockpitFreshnessAdapter(equipmentBaseService, equipmentStatusService)
|
|
|
+ .load("UNKNOWN"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static EquipmentType type(int id, String name, int parentId) {
|
|
|
+ EquipmentType type = new EquipmentType();
|
|
|
+ type.setId(id);
|
|
|
+ type.setTypeName(name);
|
|
|
+ type.setParentId(parentId);
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static EquipmentBase device(String id, String code) {
|
|
|
+ EquipmentBase device = new EquipmentBase();
|
|
|
+ device.setEquipmentId(id);
|
|
|
+ device.setEquipmentCode(code);
|
|
|
+ device.setEquipmentName(code);
|
|
|
+ device.setEquipmentTypeId(11);
|
|
|
+ return device;
|
|
|
+ }
|
|
|
+}
|