|
@@ -1,10 +1,7 @@
|
|
|
package com.zksy.base.service.impl;
|
|
package com.zksy.base.service.impl;
|
|
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.zksy.base.alarm.domain.AlarmData;
|
|
import com.zksy.base.alarm.domain.AlarmData;
|
|
|
import com.zksy.base.alarm.mapper.AlarmDataMapper;
|
|
import com.zksy.base.alarm.mapper.AlarmDataMapper;
|
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
@@ -13,24 +10,20 @@ import com.zksy.base.domain.EquipmentStatus;
|
|
|
import com.zksy.base.domain.EquipmentType;
|
|
import com.zksy.base.domain.EquipmentType;
|
|
|
import com.zksy.ops.domain.WorkOrder;
|
|
import com.zksy.ops.domain.WorkOrder;
|
|
|
import com.zksy.base.domain.vo.AbnormalDeviceVO;
|
|
import com.zksy.base.domain.vo.AbnormalDeviceVO;
|
|
|
|
|
+import com.zksy.base.domain.vo.DeviceDetailVO;
|
|
|
import com.zksy.base.domain.vo.DeviceGisVO;
|
|
import com.zksy.base.domain.vo.DeviceGisVO;
|
|
|
-import com.zksy.base.domain.vo.DeviceLedgerStatisticsVO;
|
|
|
|
|
import com.zksy.base.domain.vo.DeviceTypeStatisticsVO;
|
|
import com.zksy.base.domain.vo.DeviceTypeStatisticsVO;
|
|
|
-import com.zksy.base.domain.vo.MaintainOrderVO;
|
|
|
|
|
import com.zksy.base.mapper.EquipmentMaintainMapper;
|
|
import com.zksy.base.mapper.EquipmentMaintainMapper;
|
|
|
import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
|
import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
import com.zksy.ops.mapper.WorkOrderMapper;
|
|
import com.zksy.ops.mapper.WorkOrderMapper;
|
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
|
import com.zksy.common.core.domain.entity.SysUser;
|
|
import com.zksy.common.core.domain.entity.SysUser;
|
|
|
-import com.zksy.ops.dto.WorkOrderDispatchDTO;
|
|
|
|
|
-import com.zksy.ops.service.WorkOrderService;
|
|
|
|
|
import com.zksy.system.service.ISysUserService;
|
|
import com.zksy.system.service.ISysUserService;
|
|
|
-import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
-import org.mockito.ArgumentCaptor;
|
|
|
|
|
import org.mockito.Mockito;
|
|
import org.mockito.Mockito;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
@@ -41,16 +34,11 @@ import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
-import static org.mockito.Mockito.doReturn;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
-import static org.mockito.Mockito.never;
|
|
|
|
|
-import static org.mockito.Mockito.verify;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
class WaterSupplyDeviceServiceImplTest {
|
|
class WaterSupplyDeviceServiceImplTest {
|
|
@@ -71,7 +59,7 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
private EquipmentMaintainMapper equipmentMaintainMapper;
|
|
private EquipmentMaintainMapper equipmentMaintainMapper;
|
|
|
private AlarmDataMapper alarmDataMapper;
|
|
private AlarmDataMapper alarmDataMapper;
|
|
|
private WorkOrderMapper workOrderMapper;
|
|
private WorkOrderMapper workOrderMapper;
|
|
|
- private WorkOrderService businessWorkOrderService;
|
|
|
|
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
private EquipmentBase pressureDevice;
|
|
private EquipmentBase pressureDevice;
|
|
|
private EquipmentBase repairDevice;
|
|
private EquipmentBase repairDevice;
|
|
@@ -86,7 +74,7 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
equipmentMaintainMapper = mock(EquipmentMaintainMapper.class);
|
|
equipmentMaintainMapper = mock(EquipmentMaintainMapper.class);
|
|
|
alarmDataMapper = mock(AlarmDataMapper.class);
|
|
alarmDataMapper = mock(AlarmDataMapper.class);
|
|
|
workOrderMapper = mock(WorkOrderMapper.class);
|
|
workOrderMapper = mock(WorkOrderMapper.class);
|
|
|
- businessWorkOrderService = mock(WorkOrderService.class);
|
|
|
|
|
|
|
+ sysUserService = mock(ISysUserService.class);
|
|
|
|
|
|
|
|
ReflectionTestUtils.setField(service, "equipmentBaseService", equipmentBaseService);
|
|
ReflectionTestUtils.setField(service, "equipmentBaseService", equipmentBaseService);
|
|
|
ReflectionTestUtils.setField(service, "equipmentTypeMapper", equipmentTypeMapper);
|
|
ReflectionTestUtils.setField(service, "equipmentTypeMapper", equipmentTypeMapper);
|
|
@@ -94,7 +82,7 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
ReflectionTestUtils.setField(service, "equipmentMaintainMapper", equipmentMaintainMapper);
|
|
ReflectionTestUtils.setField(service, "equipmentMaintainMapper", equipmentMaintainMapper);
|
|
|
ReflectionTestUtils.setField(service, "alarmDataMapper", alarmDataMapper);
|
|
ReflectionTestUtils.setField(service, "alarmDataMapper", alarmDataMapper);
|
|
|
ReflectionTestUtils.setField(service, "workOrderMapper", workOrderMapper);
|
|
ReflectionTestUtils.setField(service, "workOrderMapper", workOrderMapper);
|
|
|
- ReflectionTestUtils.setField(service, "businessWorkOrderService", businessWorkOrderService);
|
|
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "sysUserService", sysUserService);
|
|
|
|
|
|
|
|
pressureDevice = device("water-pressure-1", "WS-PRESSURE-001", "供水压力监测点", "12");
|
|
pressureDevice = device("water-pressure-1", "WS-PRESSURE-001", "供水压力监测点", "12");
|
|
|
repairDevice = device("water-flow-1", "WS-FLOW-001", "供水流量监测点", "11");
|
|
repairDevice = device("water-flow-1", "WS-FLOW-001", "供水流量监测点", "11");
|
|
@@ -104,13 +92,21 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
pressureDevice, repairDevice));
|
|
pressureDevice, repairDevice));
|
|
|
when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
type(1, "供水", 0),
|
|
type(1, "供水", 0),
|
|
|
- type(12, "供水压力计", 1),
|
|
|
|
|
- type(11, "供水流量计", 1),
|
|
|
|
|
- type(3, "燃气设备", 0)));
|
|
|
|
|
|
|
+ type(12, "供水设备甲", 1),
|
|
|
|
|
+ type(11, "供水设备乙", 1),
|
|
|
|
|
+ type(3, "其他设备", 0)));
|
|
|
when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Arrays.asList(
|
|
when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Arrays.asList(
|
|
|
- type(12, "供水压力计", 1),
|
|
|
|
|
- type(11, "供水流量计", 1),
|
|
|
|
|
- type(3, "燃气设备", 0)));
|
|
|
|
|
|
|
+ type(12, "供水设备甲", 1),
|
|
|
|
|
+ type(11, "供水设备乙", 1),
|
|
|
|
|
+ type(3, "其他设备", 0)));
|
|
|
|
|
+ when(equipmentTypeMapper.selectById(any())).thenReturn(null);
|
|
|
|
|
+ when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(equipmentStatusMapper.selectOne(any())).thenReturn(null);
|
|
|
|
|
+ when(alarmDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(equipmentMaintainMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(equipmentMaintainMapper.selectOne(any())).thenReturn(null);
|
|
|
|
|
+ when(sysUserService.selectUserById(any(Long.class))).thenReturn(null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -132,388 +128,87 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void ledgerStatisticsCountsOnlyWaterDevicesAndMissingStatusAsOffline() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
-
|
|
|
|
|
- DeviceLedgerStatisticsVO stats = service.getDeviceLedgerStatistics();
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(2, stats.getTotal());
|
|
|
|
|
- assertEquals(1, stats.getOnline());
|
|
|
|
|
- assertEquals(1, stats.getOffline());
|
|
|
|
|
- assertEquals(50.0, stats.getOnlineRate());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void ledgerResolvesTypeNameByEquipmentTypePrimaryKey() {
|
|
|
|
|
- pressureDevice.setEquipmentTypeId("99");
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 0, 1)));
|
|
|
|
|
- EquipmentType resolvedType = type(99, "business-pressure", 1);
|
|
|
|
|
- when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(resolvedType));
|
|
|
|
|
-
|
|
|
|
|
- Page<DeviceGisVO> result = service.getDeviceLedgerPage(
|
|
|
|
|
- 1, 10, null, null, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("business-pressure", result.getRecords().get(0).getEquipmentTypeName());
|
|
|
|
|
|
|
+ void typeStatisticsReturnsEmptyWhenNoWaterDevices() {
|
|
|
|
|
+ when(equipmentBaseService.findByTopLevelType("供水")).thenReturn(Collections.emptyList());
|
|
|
|
|
+ assertTrue(service.getDeviceTypeStatistics().isEmpty());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void ledgerPageReturnsEquipmentImage() {
|
|
|
|
|
- pressureDevice.setEquipmentImage("https://example.com/pressure-device.jpg");
|
|
|
|
|
|
|
+ void gisPointsIncludeWaterOnlyWithCoordinatesAndStatuses() {
|
|
|
|
|
+ pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
|
|
|
+ pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
|
|
|
+ gasDevice.setLongitude(new BigDecimal("113.32000000"));
|
|
|
|
|
+ gasDevice.setLatitude(new BigDecimal("23.16000000"));
|
|
|
when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 0, 1)));
|
|
|
|
|
|
|
+ status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(
|
|
when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(
|
|
|
- type(12, "water-pressure", 1)));
|
|
|
|
|
-
|
|
|
|
|
- Page<DeviceGisVO> result = service.getDeviceLedgerPage(
|
|
|
|
|
- 1, 10, null, null, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("https://example.com/pressure-device.jpg",
|
|
|
|
|
- result.getRecords().get(0).getEquipmentImage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void ledgerPageAppliesWaterOwnershipAndCurrentStatusFilter() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 3, 0, 0),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
-
|
|
|
|
|
- Page<DeviceGisVO> result = service.getDeviceLedgerPage(
|
|
|
|
|
- 1, 10, null, null, null, 1, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals(Collections.singletonList("water-pressure-1"), result.getRecords().stream()
|
|
|
|
|
- .map(DeviceGisVO::getEquipmentId)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
- assertEquals(1, result.getRecords().get(0).getCurrentStatus());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void ledgerExportReturnsAllMatchingWaterDevicesWithoutPagination() {
|
|
|
|
|
- EquipmentBase secondPressure = device("water-pressure-2", "WS-PRESSURE-002",
|
|
|
|
|
- "第二供水压力监测点", "water-pressure");
|
|
|
|
|
- when(equipmentBaseService.findByTopLevelType("供水")).thenReturn(Arrays.asList(
|
|
|
|
|
- pressureDevice, secondPressure, repairDevice));
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(secondPressure.getEquipmentId(), 1, 0, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 3, 0, 0),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
|
|
+ type(12, "压力监测", 1)));
|
|
|
|
|
|
|
|
- List<DeviceGisVO> result = service.getDeviceLedgerExport(
|
|
|
|
|
- null, null, null, 1, null, null);
|
|
|
|
|
|
|
+ List<DeviceGisVO> points = service.getAllDeviceGisPoints(null);
|
|
|
|
|
|
|
|
- assertEquals(Arrays.asList("water-pressure-1", "water-pressure-2"), result.stream()
|
|
|
|
|
|
|
+ assertEquals(Collections.singletonList("water-pressure-1"), points.stream()
|
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
|
.collect(Collectors.toList()));
|
|
.collect(Collectors.toList()));
|
|
|
|
|
+ assertEquals("压力监测", points.get(0).getEquipmentTypeName());
|
|
|
|
|
+ assertEquals(1, points.get(0).getOnlineStatus());
|
|
|
|
|
+ assertEquals(1, points.get(0).getAlarmStatus());
|
|
|
|
|
+ assertEquals(1, points.get(0).getCurrentStatus());
|
|
|
|
|
+ assertEquals(new BigDecimal("113.28000000"), points.get(0).getLongitude());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void createWaterDeviceAcceptsWaterTypeAndRejectsNonWaterType() {
|
|
|
|
|
- EquipmentBase device = new EquipmentBase();
|
|
|
|
|
- device.setEquipmentCode("WS-NEW-001");
|
|
|
|
|
- device.setEquipmentName("新增供水设备");
|
|
|
|
|
- device.setEquipmentTypeId("12");
|
|
|
|
|
- when(equipmentTypeMapper.selectById("12"))
|
|
|
|
|
- .thenReturn(type(12, "供水压力计", 1));
|
|
|
|
|
- when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- type(1, "供水", 0),
|
|
|
|
|
- type(12, "供水压力计", 1)));
|
|
|
|
|
- doReturn(0L).when(service).count(any());
|
|
|
|
|
- doReturn(true).when(service).save(any(EquipmentBase.class));
|
|
|
|
|
-
|
|
|
|
|
- assertTrue(service.createWaterDevice(device));
|
|
|
|
|
- assertEquals("12", device.getEquipmentTypeId());
|
|
|
|
|
-
|
|
|
|
|
- EquipmentBase gasDevice = new EquipmentBase();
|
|
|
|
|
- gasDevice.setEquipmentCode("GAS-NEW-001");
|
|
|
|
|
- gasDevice.setEquipmentTypeId("3");
|
|
|
|
|
- when(equipmentTypeMapper.selectById("3"))
|
|
|
|
|
- .thenReturn(type(3, "燃气设备", 0));
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.createWaterDevice(gasDevice));
|
|
|
|
|
- assertEquals("设备类型不属于供水:3", error.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void deleteWaterDevicesRejectsNonWaterDevices() {
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.deleteWaterDevices(Collections.singletonList("gas-1")));
|
|
|
|
|
- assertEquals("存在非供水设备,无法删除:gas-1", error.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void ledgerPageAppliesAlarmStatusAndAlertLevelFilters() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 1, 0, 1),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1),
|
|
|
|
|
- alarm(gasDevice.getEquipmentCode(), "燃气浓度超限", 2)));
|
|
|
|
|
|
|
+ void gisPointsExcludesDevicesWithoutCoordinates() {
|
|
|
|
|
+ pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
|
|
|
+ pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
|
|
|
+ // repairDevice 无坐标,应被过滤
|
|
|
|
|
|
|
|
- Page<DeviceGisVO> result = service.getDeviceLedgerPage(
|
|
|
|
|
- 1, 10, null, null, null, null, 1, 1);
|
|
|
|
|
|
|
+ List<DeviceGisVO> points = service.getAllDeviceGisPoints(null);
|
|
|
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals(Collections.singletonList("water-pressure-1"), result.getRecords().stream()
|
|
|
|
|
|
|
+ assertEquals(Collections.singletonList("water-pressure-1"), points.stream()
|
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
|
.collect(Collectors.toList()));
|
|
.collect(Collectors.toList()));
|
|
|
- assertEquals(1, result.getRecords().get(0).getAlarmStatus());
|
|
|
|
|
- assertEquals(1, result.getRecords().get(0).getAlertLevel());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalPageUsesAlarmReasonAlertLevelAndUnifiedWorkOrder() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 3, 0, 0),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1),
|
|
|
|
|
- alarm(gasDevice.getEquipmentCode(), "燃气浓度超限", 2)));
|
|
|
|
|
- ISysUserService sysUserService = mock(ISysUserService.class);
|
|
|
|
|
- ReflectionTestUtils.setField(service, "sysUserService", sysUserService);
|
|
|
|
|
- when(sysUserService.selectUserById(1L)).thenReturn(sysUser(1L, "zhangsan", "张三"));
|
|
|
|
|
- when(sysUserService.selectUserById(2L)).thenReturn(sysUser(2L, "lisi", "李四"));
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-WS-001", 4, 1L),
|
|
|
|
|
- workOrder(repairDevice.getEquipmentId(), "WO-WS-002", 4, 2L),
|
|
|
|
|
- workOrder(gasDevice.getEquipmentId(), "WO-GAS-001", 2)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(2, result.getTotal());
|
|
|
|
|
- assertEquals(Arrays.asList("water-pressure-1", "water-flow-1"), result.getRecords().stream()
|
|
|
|
|
- .map(AbnormalDeviceVO::getEquipmentId)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
-
|
|
|
|
|
- AbnormalDeviceVO alarmRow = result.getRecords().get(0);
|
|
|
|
|
- assertEquals(1, alarmRow.getAlarmStatus());
|
|
|
|
|
- assertEquals(1, alarmRow.getCurrentStatus());
|
|
|
|
|
- assertEquals(1, alarmRow.getOnlineStatus());
|
|
|
|
|
- assertEquals(1, alarmRow.getAlertLevel());
|
|
|
|
|
- assertEquals("供水压力超限", ReflectionTestUtils.getField(alarmRow, "abnormalReason"));
|
|
|
|
|
- assertEquals("WO-WS-001", ReflectionTestUtils.getField(alarmRow, "relatedWorkOrderNo"));
|
|
|
|
|
- assertEquals(4, ReflectionTestUtils.getField(alarmRow, "relatedWorkOrderStatus"));
|
|
|
|
|
- assertEquals("张三", ReflectionTestUtils.getField(alarmRow, "relatedWorkOrderPerson"));
|
|
|
|
|
-
|
|
|
|
|
- AbnormalDeviceVO repairRow = result.getRecords().get(1);
|
|
|
|
|
- assertEquals(0, repairRow.getAlarmStatus());
|
|
|
|
|
- assertEquals(3, repairRow.getCurrentStatus());
|
|
|
|
|
- assertEquals(0, repairRow.getOnlineStatus());
|
|
|
|
|
- assertNull(repairRow.getAlertLevel());
|
|
|
|
|
- assertEquals("设备维修中", ReflectionTestUtils.getField(repairRow, "abnormalReason"));
|
|
|
|
|
- assertEquals("WO-WS-002", ReflectionTestUtils.getField(repairRow, "relatedWorkOrderNo"));
|
|
|
|
|
- assertEquals(4, ReflectionTestUtils.getField(repairRow, "relatedWorkOrderStatus"));
|
|
|
|
|
- assertEquals("李四", ReflectionTestUtils.getField(repairRow, "relatedWorkOrderPerson"));
|
|
|
|
|
-
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- ArgumentCaptor<Wrapper<WorkOrder>> orderWrapperCaptor =
|
|
|
|
|
- ArgumentCaptor.forClass(Wrapper.class);
|
|
|
|
|
- verify(workOrderMapper).selectList(orderWrapperCaptor.capture());
|
|
|
|
|
- String orderWrapperSql = orderWrapperCaptor.getValue().getSqlSegment();
|
|
|
|
|
- assertTrue(orderWrapperSql.contains("order_status"), "异常设备关联工单必须限定未办结状态: " + orderWrapperSql);
|
|
|
|
|
- AbstractWrapper<?, ?, ?> orderWrapper = (AbstractWrapper<?, ?, ?>) orderWrapperCaptor.getValue();
|
|
|
|
|
- assertTrue(orderWrapper.getParamNameValuePairs().containsValue(5), "关联工单必须排除 5-已结案");
|
|
|
|
|
- assertTrue(orderWrapper.getParamNameValuePairs().containsValue(7), "关联工单必须排除 7-已取消");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalPageResolvesWorkOrderReceiverToDisplayName() {
|
|
|
|
|
- ISysUserService sysUserService = mock(ISysUserService.class);
|
|
|
|
|
- ReflectionTestUtils.setField(service, "sysUserService", sysUserService);
|
|
|
|
|
- when(sysUserService.selectUserById(1L)).thenReturn(sysUser(1L, "zhangsan", "张三丰"));
|
|
|
|
|
- when(sysUserService.selectUserById(2L)).thenReturn(sysUser(2L, "lisi", null));
|
|
|
|
|
-
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-WS-003", 4, 1L)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals("张三丰", ReflectionTestUtils.getField(
|
|
|
|
|
- result.getRecords().get(0), "relatedWorkOrderPerson"));
|
|
|
|
|
- verify(sysUserService).selectUserById(1L);
|
|
|
|
|
-
|
|
|
|
|
- // 责任人没有昵称时回退展示用户名
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-WS-004", 4, 2L)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> fallback = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("lisi", ReflectionTestUtils.getField(
|
|
|
|
|
- fallback.getRecords().get(0), "relatedWorkOrderPerson"));
|
|
|
|
|
- verify(sysUserService).selectUserById(2L);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalExportReturnsAllWaterAbnormalDevicesWithoutPagination() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 3, 0, 0),
|
|
|
|
|
- status(gasDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1),
|
|
|
|
|
- alarm(gasDevice.getEquipmentCode(), "燃气浓度超限", 2)));
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-WS-001", 4),
|
|
|
|
|
- workOrder(repairDevice.getEquipmentId(), "WO-WS-002", 6),
|
|
|
|
|
- workOrder(gasDevice.getEquipmentId(), "WO-GAS-001", 2)));
|
|
|
|
|
-
|
|
|
|
|
- List<AbnormalDeviceVO> result = service.getAbnormalDeviceExport(
|
|
|
|
|
- null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(Arrays.asList("water-pressure-1", "water-flow-1"), result.stream()
|
|
|
|
|
- .map(AbnormalDeviceVO::getEquipmentId)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
- assertEquals("供水压力超限", result.get(0).getAbnormalReason());
|
|
|
|
|
- assertEquals("设备维修中", result.get(1).getAbnormalReason());
|
|
|
|
|
- assertNull(result.get(1).getAlertLevel());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalPageIncludesActiveAlarmWhenRuntimeStatusRecordIsMissing() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- AbnormalDeviceVO row = result.getRecords().get(0);
|
|
|
|
|
- assertEquals(pressureDevice.getEquipmentId(), row.getEquipmentId());
|
|
|
|
|
- assertEquals(1, row.getAlertLevel());
|
|
|
|
|
- assertEquals("供水压力超限", ReflectionTestUtils.getField(row, "abnormalReason"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalAlertLevelFilterUsesActiveAlarmLevel() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, 2);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(0, result.getTotal());
|
|
|
|
|
- assertTrue(result.getRecords().isEmpty());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void multipleActiveAlarmsChooseMostSevereLevelOne() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "一般告警", 3),
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "严重告警", 1),
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "较重告警", 2)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getRecords().get(0).getAlertLevel());
|
|
|
|
|
- assertEquals("严重告警", result.getRecords().get(0).getAbnormalReason());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalPageExcludesClosedAndCancelledWorkOrders() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-CANCELLED", 7),
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-CLOSED", 5)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertNull(result.getRecords().get(0).getRelatedWorkOrderNo());
|
|
|
|
|
- ArgumentCaptor<Wrapper<WorkOrder>> wrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
|
|
|
|
|
- verify(workOrderMapper).selectList(wrapperCaptor.capture());
|
|
|
|
|
- AbstractWrapper<?, ?, ?> wrapper = (AbstractWrapper<?, ?, ?>) wrapperCaptor.getValue();
|
|
|
|
|
- assertTrue(wrapper.getSqlSegment().contains("order_status"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void dispatchableOnlyExcludesDevicesWithActiveFaultWorkOrders() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
- status(repairDevice.getEquipmentId(), 3, 0, 1)));
|
|
|
|
|
- when(alarmDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
- workOrder(pressureDevice.getEquipmentId(), "WO-ACTIVE", 2),
|
|
|
|
|
- workOrder(repairDevice.getEquipmentId(), "WO-CLOSED", 5)));
|
|
|
|
|
-
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, null, true);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(Collections.singletonList(repairDevice.getEquipmentId()), result.getRecords().stream()
|
|
|
|
|
- .map(AbnormalDeviceVO::getEquipmentId)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void deviceGisPointsIncludeWaterOnlyWithCoordinatesAndStatuses() {
|
|
|
|
|
|
|
+ void gisPointsFilterByEquipmentTypeId() {
|
|
|
pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
|
pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
|
- gasDevice.setLongitude(new BigDecimal("113.32000000"));
|
|
|
|
|
- gasDevice.setLatitude(new BigDecimal("23.16000000"));
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- when(equipmentTypeMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- type(12, "压力监测", 1)));
|
|
|
|
|
|
|
+ repairDevice.setLongitude(new BigDecimal("113.29000000"));
|
|
|
|
|
+ repairDevice.setLatitude(new BigDecimal("23.13000000"));
|
|
|
|
|
|
|
|
- List<DeviceGisVO> points = service.getAllDeviceGisPoints(null);
|
|
|
|
|
|
|
+ List<DeviceGisVO> points = service.getAllDeviceGisPoints("12");
|
|
|
|
|
|
|
|
assertEquals(Collections.singletonList("water-pressure-1"), points.stream()
|
|
assertEquals(Collections.singletonList("water-pressure-1"), points.stream()
|
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
.map(DeviceGisVO::getEquipmentId)
|
|
|
.collect(Collectors.toList()));
|
|
.collect(Collectors.toList()));
|
|
|
- assertEquals("压力监测", points.get(0).getEquipmentTypeName());
|
|
|
|
|
- assertEquals(1, points.get(0).getOnlineStatus());
|
|
|
|
|
- assertEquals(1, points.get(0).getAlarmStatus());
|
|
|
|
|
- assertEquals(1, points.get(0).getCurrentStatus());
|
|
|
|
|
- assertEquals(new BigDecimal("113.28000000"), points.get(0).getLongitude());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void deviceDetailIncludesAlarmAndRelatedWorkOrderSummary() {
|
|
void deviceDetailIncludesAlarmAndRelatedWorkOrderSummary() {
|
|
|
- doReturn(pressureDevice).when(service).getById(pressureDevice.getEquipmentId());
|
|
|
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(status(pressureDevice.getEquipmentId(), 1, 1, 1));
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(status(pressureDevice.getEquipmentId(), 1, 1, 1));
|
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
workOrder(pressureDevice.getEquipmentId(), "WO-DETAIL", 2, 1L)));
|
|
workOrder(pressureDevice.getEquipmentId(), "WO-DETAIL", 2, 1L)));
|
|
|
|
|
+ when(sysUserService.selectUserById(1L)).thenReturn(sysUser(1L, "zhangsan", "张三"));
|
|
|
|
|
|
|
|
- com.zksy.base.domain.vo.DeviceDetailVO detail = service.getDeviceDetail(pressureDevice.getEquipmentId());
|
|
|
|
|
|
|
+ DeviceDetailVO detail = service.getDeviceDetail(pressureDevice.getEquipmentId());
|
|
|
|
|
|
|
|
assertEquals(1, detail.getAlertLevel());
|
|
assertEquals(1, detail.getAlertLevel());
|
|
|
assertEquals("供水压力超限", detail.getAbnormalReason());
|
|
assertEquals("供水压力超限", detail.getAbnormalReason());
|
|
|
assertEquals("WO-DETAIL", detail.getRelatedWorkOrderNo());
|
|
assertEquals("WO-DETAIL", detail.getRelatedWorkOrderNo());
|
|
|
assertEquals(2, detail.getRelatedWorkOrderStatus());
|
|
assertEquals(2, detail.getRelatedWorkOrderStatus());
|
|
|
- assertEquals("1", detail.getRelatedWorkOrderPerson());
|
|
|
|
|
|
|
+ assertEquals("张三", detail.getRelatedWorkOrderPerson());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void deviceDetailKeepsMaintenanceStateSeparateFromAlarmLevel() {
|
|
void deviceDetailKeepsMaintenanceStateSeparateFromAlarmLevel() {
|
|
|
- doReturn(repairDevice).when(service).getById(repairDevice.getEquipmentId());
|
|
|
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(
|
|
|
status(repairDevice.getEquipmentId(), 3, 0, 1));
|
|
status(repairDevice.getEquipmentId(), 3, 0, 1));
|
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
|
|
|
- com.zksy.base.domain.vo.DeviceDetailVO detail = service.getDeviceDetail(repairDevice.getEquipmentId());
|
|
|
|
|
|
|
+ DeviceDetailVO detail = service.getDeviceDetail(repairDevice.getEquipmentId());
|
|
|
|
|
|
|
|
assertEquals(3, detail.getCurrentStatus());
|
|
assertEquals(3, detail.getCurrentStatus());
|
|
|
assertEquals(0, detail.getAlarmStatus());
|
|
assertEquals(0, detail.getAlarmStatus());
|
|
@@ -521,58 +216,8 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
assertEquals("设备维修中", detail.getAbnormalReason());
|
|
assertEquals("设备维修中", detail.getAbnormalReason());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalOrderCreatesUnifiedFaultWorkOrderWithSingleReceiver() {
|
|
|
|
|
- MaintainOrderVO request = new MaintainOrderVO();
|
|
|
|
|
- request.setEquipmentId(pressureDevice.getEquipmentId());
|
|
|
|
|
- request.setMaintainContent("压力异常");
|
|
|
|
|
- request.setReceiveUserId(88L);
|
|
|
|
|
- when(businessWorkOrderService.createWorkOrder(any(WorkOrder.class))).thenAnswer(invocation -> {
|
|
|
|
|
- WorkOrder input = invocation.getArgument(0);
|
|
|
|
|
- input.setOrderId(99L);
|
|
|
|
|
- input.setOrderNo("WO-T6");
|
|
|
|
|
- input.setOrderStatus(1);
|
|
|
|
|
- return 99L;
|
|
|
|
|
- });
|
|
|
|
|
- WorkOrder result = service.createAbnormalWorkOrder(request);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(99L, result.getOrderId());
|
|
|
|
|
- assertEquals(1, result.getOrderLevel());
|
|
|
|
|
- assertEquals(1, result.getOrderStatus());
|
|
|
|
|
- assertNull(result.getReceiveUser());
|
|
|
|
|
- ArgumentCaptor<WorkOrder> workOrderCaptor = ArgumentCaptor.forClass(WorkOrder.class);
|
|
|
|
|
- verify(businessWorkOrderService).createWorkOrder(workOrderCaptor.capture());
|
|
|
|
|
- WorkOrder submitted = workOrderCaptor.getValue();
|
|
|
|
|
- assertEquals(pressureDevice.getEquipmentId(), submitted.getDeviceId());
|
|
|
|
|
- assertEquals(pressureDevice.getEquipmentCode(), submitted.getDeviceCode());
|
|
|
|
|
- assertEquals(1, submitted.getOrderLevel());
|
|
|
|
|
- assertEquals("压力异常", submitted.getOrderDesc());
|
|
|
|
|
- assertNull(submitted.getReceiveUser());
|
|
|
|
|
- verify(equipmentMaintainMapper, never()).insert(any(EquipmentMaintain.class));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void abnormalOrderCanCreatePendingWorkOrderWithoutReceiverId() {
|
|
|
|
|
- MaintainOrderVO request = new MaintainOrderVO();
|
|
|
|
|
- request.setEquipmentId(pressureDevice.getEquipmentId());
|
|
|
|
|
- when(businessWorkOrderService.createWorkOrder(any(WorkOrder.class))).thenAnswer(invocation -> {
|
|
|
|
|
- WorkOrder submitted = invocation.getArgument(0);
|
|
|
|
|
- submitted.setOrderId(101L);
|
|
|
|
|
- submitted.setOrderStatus(1);
|
|
|
|
|
- return 101L;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- WorkOrder result = service.createAbnormalWorkOrder(request);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(101L, result.getOrderId());
|
|
|
|
|
- assertEquals(1, result.getOrderStatus());
|
|
|
|
|
- assertNull(result.getReceiveUser());
|
|
|
|
|
- verify(businessWorkOrderService).createWorkOrder(any(WorkOrder.class));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void deviceDetailIgnoresProcessedAlarmRecordWhenEquipmentIsNormal() {
|
|
void deviceDetailIgnoresProcessedAlarmRecordWhenEquipmentIsNormal() {
|
|
|
- doReturn(repairDevice).when(service).getById(repairDevice.getEquipmentId());
|
|
|
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(
|
|
when(equipmentStatusMapper.selectOne(any())).thenReturn(
|
|
|
status(repairDevice.getEquipmentId(), 1, 0, 1));
|
|
status(repairDevice.getEquipmentId(), 1, 0, 1));
|
|
|
AlarmData processedAlarm = new AlarmData();
|
|
AlarmData processedAlarm = new AlarmData();
|
|
@@ -583,179 +228,96 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(processedAlarm));
|
|
when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(processedAlarm));
|
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
|
|
|
- com.zksy.base.domain.vo.DeviceDetailVO detail = service.getDeviceDetail(repairDevice.getEquipmentId());
|
|
|
|
|
|
|
+ DeviceDetailVO detail = service.getDeviceDetail(repairDevice.getEquipmentId());
|
|
|
|
|
|
|
|
assertEquals(0, detail.getAlarmStatus());
|
|
assertEquals(0, detail.getAlarmStatus());
|
|
|
assertNull(detail.getAlertLevel());
|
|
assertNull(detail.getAlertLevel());
|
|
|
assertNull(detail.getAbnormalReason());
|
|
assertNull(detail.getAbnormalReason());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void noWaterDevicesReturnsEmptyAbnormalPageWithoutReadingStatuses() {
|
|
|
|
|
- when(equipmentBaseService.findByTopLevelType("供水")).thenReturn(Collections.emptyList());
|
|
|
|
|
- Page<AbnormalDeviceVO> result = service.getAbnormalDevicePage(
|
|
|
|
|
- 1, 10, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(0, result.getTotal());
|
|
|
|
|
- assertTrue(result.getRecords().isEmpty());
|
|
|
|
|
- verify(equipmentStatusMapper, never()).selectList(any());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void deviceDetailDoesNotExposeNonWaterDevices() {
|
|
void deviceDetailDoesNotExposeNonWaterDevices() {
|
|
|
- doReturn(gasDevice).when(service).getById(gasDevice.getEquipmentId());
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // gasDevice 不属于供水设备,findWaterDeviceById 找不到,应返回 null
|
|
|
assertNull(service.getDeviceDetail(gasDevice.getEquipmentId()));
|
|
assertNull(service.getDeviceDetail(gasDevice.getEquipmentId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void createMaintainOrderRejectsNonWaterDevices() {
|
|
|
|
|
- MaintainOrderVO order = new MaintainOrderVO();
|
|
|
|
|
- order.setEquipmentId(gasDevice.getEquipmentId());
|
|
|
|
|
- doReturn(gasDevice).when(service).getById(gasDevice.getEquipmentId());
|
|
|
|
|
|
|
+ void deviceDetailIncludesLatestMaintainRecord() {
|
|
|
|
|
+ when(equipmentStatusMapper.selectOne(any())).thenReturn(
|
|
|
|
|
+ status(pressureDevice.getEquipmentId(), 1, 0, 1));
|
|
|
|
|
+ when(alarmDataMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(workOrderMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+ EquipmentMaintain maintain = maintain("m1", pressureDevice.getEquipmentId());
|
|
|
|
|
+ when(equipmentMaintainMapper.selectOne(any())).thenReturn(maintain);
|
|
|
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.createMaintainOrder(order));
|
|
|
|
|
|
|
+ DeviceDetailVO detail = service.getDeviceDetail(pressureDevice.getEquipmentId());
|
|
|
|
|
|
|
|
- assertEquals("仅支持供水设备派发维修工单", error.getMessage());
|
|
|
|
|
- verify(equipmentMaintainMapper, never()).insert(any(EquipmentMaintain.class));
|
|
|
|
|
|
|
+ assertTrue(detail.getLatestMaintain() != null);
|
|
|
|
|
+ assertEquals("m1", detail.getLatestMaintain().get("maintainId"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void legacyMaintainOrderSignatureUsesUnifiedWorkOrderLifecycle() {
|
|
|
|
|
- MaintainOrderVO request = new MaintainOrderVO();
|
|
|
|
|
- request.setEquipmentId(pressureDevice.getEquipmentId());
|
|
|
|
|
- request.setMaintainContent("压力异常");
|
|
|
|
|
- request.setOrderLevel(1);
|
|
|
|
|
- request.setMaintainRemark("请尽快处理");
|
|
|
|
|
- request.setReceiveUserId(88L);
|
|
|
|
|
- when(businessWorkOrderService.createWorkOrder(any(WorkOrder.class))).thenAnswer(invocation -> {
|
|
|
|
|
- WorkOrder submitted = invocation.getArgument(0);
|
|
|
|
|
- submitted.setOrderId(100L);
|
|
|
|
|
- submitted.setOrderStatus(1);
|
|
|
|
|
- return 100L;
|
|
|
|
|
- });
|
|
|
|
|
- when(businessWorkOrderService.dispatch(any(), any(WorkOrderDispatchDTO.class)))
|
|
|
|
|
- .thenReturn(true);
|
|
|
|
|
-
|
|
|
|
|
- assertTrue(service.createMaintainOrder(request));
|
|
|
|
|
-
|
|
|
|
|
- verify(equipmentMaintainMapper, never()).insert(any(EquipmentMaintain.class));
|
|
|
|
|
- ArgumentCaptor<WorkOrder> orderCaptor = ArgumentCaptor.forClass(WorkOrder.class);
|
|
|
|
|
- verify(businessWorkOrderService).createWorkOrder(orderCaptor.capture());
|
|
|
|
|
- assertEquals(1, orderCaptor.getValue().getOrderLevel());
|
|
|
|
|
- ArgumentCaptor<WorkOrderDispatchDTO> dispatchCaptor = ArgumentCaptor.forClass(WorkOrderDispatchDTO.class);
|
|
|
|
|
- verify(businessWorkOrderService).dispatch(any(), dispatchCaptor.capture());
|
|
|
|
|
- assertEquals(88L, dispatchCaptor.getValue().getHandlerId());
|
|
|
|
|
- assertEquals("请尽快处理", dispatchCaptor.getValue().getRemarks());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ void abnormalGisPointsReturnsWaterDevicesWithAlarmOrMaintenanceStatus() {
|
|
|
|
|
+ pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
|
|
|
+ pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
|
|
|
+ repairDevice.setLongitude(new BigDecimal("113.29000000"));
|
|
|
|
|
+ repairDevice.setLatitude(new BigDecimal("23.13000000"));
|
|
|
|
|
+ when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
+ status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
+ status(repairDevice.getEquipmentId(), 3, 0, 1)));
|
|
|
|
|
+ when(alarmDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ alarm(pressureDevice.getEquipmentCode(), "供水压力超限", 1)));
|
|
|
|
|
+ when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ workOrder(pressureDevice.getEquipmentId(), "WO-A", 2, 1L)));
|
|
|
|
|
+ when(equipmentMaintainMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ maintain("m1", pressureDevice.getEquipmentId())));
|
|
|
|
|
+ when(sysUserService.selectUserById(1L)).thenReturn(sysUser(1L, "zhangsan", "张三"));
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void createAbnormalWorkOrderRejectsWhenDeviceHasActiveWorkOrder() {
|
|
|
|
|
- MaintainOrderVO request = new MaintainOrderVO();
|
|
|
|
|
- request.setEquipmentId(pressureDevice.getEquipmentId());
|
|
|
|
|
- request.setMaintainContent("压力异常");
|
|
|
|
|
- doReturn(pressureDevice).when(service).getById(pressureDevice.getEquipmentId());
|
|
|
|
|
-
|
|
|
|
|
- WorkOrder activeOrder = new WorkOrder();
|
|
|
|
|
- activeOrder.setDeviceId(pressureDevice.getEquipmentId());
|
|
|
|
|
- activeOrder.setOrderNo("WO-ACTIVE");
|
|
|
|
|
- activeOrder.setOrderStatus(2);
|
|
|
|
|
- when(workOrderMapper.selectList(any())).thenReturn(Collections.singletonList(activeOrder));
|
|
|
|
|
-
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.createAbnormalWorkOrder(request));
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("该设备已有未结束故障维修工单,不能重复创建", error.getMessage());
|
|
|
|
|
- verify(businessWorkOrderService, never()).createWorkOrder(any(WorkOrder.class));
|
|
|
|
|
|
|
+ List<AbnormalDeviceVO> result = service.getAbnormalDeviceGisPoints(null);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(2, result.size());
|
|
|
|
|
+ AbnormalDeviceVO pressureRow = result.stream()
|
|
|
|
|
+ .filter(r -> "water-pressure-1".equals(r.getEquipmentId()))
|
|
|
|
|
+ .findFirst().orElseThrow();
|
|
|
|
|
+ assertEquals(1, pressureRow.getAlarmStatus());
|
|
|
|
|
+ assertEquals(1, pressureRow.getCurrentStatus());
|
|
|
|
|
+ assertEquals(1, pressureRow.getOnlineStatus());
|
|
|
|
|
+ assertEquals(1, pressureRow.getAlertLevel());
|
|
|
|
|
+ assertEquals("供水压力超限", pressureRow.getAbnormalReason());
|
|
|
|
|
+ assertEquals("WO-A", pressureRow.getRelatedWorkOrderNo());
|
|
|
|
|
+ assertEquals(2, pressureRow.getRelatedWorkOrderStatus());
|
|
|
|
|
+ assertEquals("张三", pressureRow.getRelatedWorkOrderPerson());
|
|
|
|
|
+ assertEquals("m1", pressureRow.getLatestMaintainId());
|
|
|
|
|
+
|
|
|
|
|
+ AbnormalDeviceVO repairRow = result.stream()
|
|
|
|
|
+ .filter(r -> "water-flow-1".equals(r.getEquipmentId()))
|
|
|
|
|
+ .findFirst().orElseThrow();
|
|
|
|
|
+ assertEquals(0, repairRow.getAlarmStatus());
|
|
|
|
|
+ assertEquals(3, repairRow.getCurrentStatus());
|
|
|
|
|
+ assertNull(repairRow.getAlertLevel());
|
|
|
|
|
+ assertEquals("设备维修中", repairRow.getAbnormalReason());
|
|
|
|
|
+ assertNull(repairRow.getLatestMaintainId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void maintainRecordListDoesNotExposeNonWaterDevices() {
|
|
|
|
|
- EquipmentMaintain gasRecord = new EquipmentMaintain();
|
|
|
|
|
- gasRecord.setEquipmentId(gasDevice.getEquipmentId());
|
|
|
|
|
- gasRecord.setMaintainId("gas-record");
|
|
|
|
|
- when(equipmentMaintainMapper.selectList(any())).thenReturn(Collections.singletonList(gasRecord));
|
|
|
|
|
-
|
|
|
|
|
- assertTrue(service.getMaintainRecordList(gasDevice.getEquipmentId()).isEmpty());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ void abnormalGisPointsExcludesNonWaterAndMissingCoordinates() {
|
|
|
|
|
+ // gasDevice 有坐标但非供水设备;repairDevice 供水但无坐标;仅 pressureDevice 符合
|
|
|
|
|
+ gasDevice.setLongitude(new BigDecimal("113.32000000"));
|
|
|
|
|
+ gasDevice.setLatitude(new BigDecimal("23.16000000"));
|
|
|
|
|
+ pressureDevice.setLongitude(new BigDecimal("113.28000000"));
|
|
|
|
|
+ pressureDevice.setLatitude(new BigDecimal("23.12000000"));
|
|
|
|
|
+ when(equipmentStatusMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
|
|
|
+ status(pressureDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
+ status(gasDevice.getEquipmentId(), 1, 1, 1),
|
|
|
|
|
+ status(repairDevice.getEquipmentId(), 3, 0, 1)));
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void maintainRecordPageReturnsOnlyWaterDevices() {
|
|
|
|
|
- EquipmentMaintain waterRecord = maintain("water-record", pressureDevice.getEquipmentId());
|
|
|
|
|
- EquipmentMaintain gasRecord = maintain("gas-record", gasDevice.getEquipmentId());
|
|
|
|
|
- Page<EquipmentMaintain> mapperPage = new Page<>(1, 10, 2);
|
|
|
|
|
- mapperPage.setRecords(Arrays.asList(gasRecord, waterRecord));
|
|
|
|
|
- when(equipmentMaintainMapper.selectPage(any(), any())).thenReturn(mapperPage);
|
|
|
|
|
- when(equipmentMaintainMapper.selectList(any())).thenReturn(Arrays.asList(gasRecord, waterRecord));
|
|
|
|
|
- doReturn(Arrays.asList(pressureDevice, gasDevice)).when(service).listByIds(any());
|
|
|
|
|
-
|
|
|
|
|
- Page<com.zksy.base.domain.vo.EquipmentMaintainDataVO> result =
|
|
|
|
|
- service.getMaintainRecordPage(1, 10, null, null, null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals(Collections.singletonList("water-record"), result.getRecords().stream()
|
|
|
|
|
- .map(com.zksy.base.domain.vo.EquipmentMaintainDataVO::getMaintainId)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<AbnormalDeviceVO> result = service.getAbnormalDeviceGisPoints(null);
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void myMaintainRecordPageReturnsOnlyWaterDevices() {
|
|
|
|
|
- EquipmentMaintain waterRecord = maintain("water-record", pressureDevice.getEquipmentId());
|
|
|
|
|
- EquipmentMaintain gasRecord = maintain("gas-record", gasDevice.getEquipmentId());
|
|
|
|
|
- Page<EquipmentMaintain> mapperPage = new Page<>(1, 10, 2);
|
|
|
|
|
- mapperPage.setRecords(Arrays.asList(gasRecord, waterRecord));
|
|
|
|
|
- when(equipmentMaintainMapper.selectPage(any(), any())).thenReturn(mapperPage);
|
|
|
|
|
- when(equipmentMaintainMapper.selectList(any())).thenReturn(Arrays.asList(gasRecord, waterRecord));
|
|
|
|
|
- doReturn(Arrays.asList(pressureDevice, gasDevice)).when(service).listByIds(any());
|
|
|
|
|
-
|
|
|
|
|
- Page<com.zksy.base.domain.vo.EquipmentMaintainDataVO> result =
|
|
|
|
|
- service.getMyMaintainRecordPage(1, 10, "张三", null, null, null, null);
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals(Collections.singletonList("water-record"), result.getRecords().stream()
|
|
|
|
|
- .map(com.zksy.base.domain.vo.EquipmentMaintainDataVO::getMaintainId)
|
|
|
|
|
|
|
+ assertEquals(Collections.singletonList("water-pressure-1"), result.stream()
|
|
|
|
|
+ .map(AbnormalDeviceVO::getEquipmentId)
|
|
|
.collect(Collectors.toList()));
|
|
.collect(Collectors.toList()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Test
|
|
|
|
|
- void updateMaintainRecordRejectsNonWaterRecords() {
|
|
|
|
|
- com.zksy.base.domain.vo.EquipmentMaintainDataVO vo =
|
|
|
|
|
- new com.zksy.base.domain.vo.EquipmentMaintainDataVO();
|
|
|
|
|
- vo.setMaintainId("gas-record");
|
|
|
|
|
- when(equipmentMaintainMapper.selectById("gas-record"))
|
|
|
|
|
- .thenReturn(maintain("gas-record", gasDevice.getEquipmentId()));
|
|
|
|
|
-
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.updateMaintainRecord(vo));
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("仅支持供水设备维护记录", error.getMessage());
|
|
|
|
|
- verify(equipmentMaintainMapper, never()).updateById(any(EquipmentMaintain.class));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void deleteMaintainRecordRejectsNonWaterRecords() {
|
|
|
|
|
- when(equipmentMaintainMapper.selectById("gas-record"))
|
|
|
|
|
- .thenReturn(maintain("gas-record", gasDevice.getEquipmentId()));
|
|
|
|
|
-
|
|
|
|
|
- RuntimeException error = assertThrows(RuntimeException.class,
|
|
|
|
|
- () -> service.deleteMaintainRecord("gas-record"));
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("仅支持供水设备维护记录", error.getMessage());
|
|
|
|
|
- verify(equipmentMaintainMapper, never()).deleteById("gas-record");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void returnsEmptyRecordsWhenRequestedPageIsBeyondAbnormalDevices() {
|
|
|
|
|
- when(equipmentStatusMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
- status(pressureDevice.getEquipmentId(), 1, 1, 1)));
|
|
|
|
|
- Page<AbnormalDeviceVO> result = assertDoesNotThrow(() -> service.getAbnormalDevicePage(
|
|
|
|
|
- 2, 10, null, null, null, null));
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getTotal());
|
|
|
|
|
- assertEquals(0, result.getRecords().size());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private static EquipmentBase device(String id, String code, String name, String typeId) {
|
|
private static EquipmentBase device(String id, String code, String name, String typeId) {
|
|
|
EquipmentBase device = new EquipmentBase();
|
|
EquipmentBase device = new EquipmentBase();
|
|
|
device.setEquipmentId(id);
|
|
device.setEquipmentId(id);
|
|
@@ -804,11 +366,6 @@ class WaterSupplyDeviceServiceImplTest {
|
|
|
return order;
|
|
return order;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static WorkOrder workOrder(String deviceId, String orderNo, int orderStatus) {
|
|
|
|
|
- return workOrder(deviceId, orderNo, orderStatus, null);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
private static SysUser sysUser(Long userId, String userName, String nickName) {
|
|
private static SysUser sysUser(Long userId, String userName, String nickName) {
|
|
|
SysUser user = new SysUser();
|
|
SysUser user = new SysUser();
|
|
|
user.setUserId(userId);
|
|
user.setUserId(userId);
|