Browse Source

fix(water): scope threshold devices and refine UI (#9)

Kazerin 2 days ago
parent
commit
eb3d42a775

+ 9 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/WaterSupply/MonitorAlarm/WaterSupplyThresholdController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zksy.WaterSupply.MonitorAlarm.dto.in.WaterThresholdSaveInDTO;
 import com.zksy.WaterSupply.MonitorAlarm.service.IWaterSupplyThresholdService;
 import com.zksy.base.alarm.domain.WarningThreshold;
+import com.zksy.base.domain.EquipmentBase;
 import com.zksy.common.annotation.Log;
 import com.zksy.common.core.domain.AjaxResult;
 import com.zksy.common.enums.BusinessType;
@@ -55,6 +56,14 @@ public class WaterSupplyThresholdController {
         return AjaxResult.success(waterSupplyThresholdService.findThresholdList(deviceCode, warningType, warningCode));
     }
 
+    @GetMapping("/devices")
+    @ApiOperation("可配置阈值的供水监测设备")
+    @PreAuthorize("@ss.hasPermi('waterSupply:alarm:threshold:list')")
+    public AjaxResult getThresholdDevices() {
+        List<EquipmentBase> devices = waterSupplyThresholdService.findThresholdDevices();
+        return AjaxResult.success(devices);
+    }
+
     @GetMapping("/detail/{id}")
     @ApiOperation("阈值详情")
     @PreAuthorize("@ss.hasPermi('waterSupply:alarm:threshold:list')")

+ 46 - 0
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/WaterSupply/MonitorAlarm/WaterSupplyThresholdControllerTest.java

@@ -0,0 +1,46 @@
+package com.zksy.web.controller.WaterSupply.MonitorAlarm;
+
+import com.zksy.WaterSupply.MonitorAlarm.service.IWaterSupplyThresholdService;
+import com.zksy.base.domain.EquipmentBase;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import java.util.Arrays;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+class WaterSupplyThresholdControllerTest {
+
+    private IWaterSupplyThresholdService thresholdService;
+    private MockMvc mockMvc;
+
+    @BeforeEach
+    void setUp() {
+        thresholdService = mock(IWaterSupplyThresholdService.class);
+        WaterSupplyThresholdController controller = new WaterSupplyThresholdController();
+        ReflectionTestUtils.setField(controller, "waterSupplyThresholdService", thresholdService);
+        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
+    }
+
+    @Test
+    void thresholdDeviceEndpointReturnsOnlyWaterDevices() throws Exception {
+        EquipmentBase flow = new EquipmentBase();
+        flow.setEquipmentCode("CN-GS-202609020001");
+        EquipmentBase pressure = new EquipmentBase();
+        pressure.setEquipmentCode("CB-GS-202609020001");
+        when(thresholdService.findThresholdDevices()).thenReturn(Arrays.asList(flow, pressure));
+
+        mockMvc.perform(get("/waterSupply/alarm/threshold/devices"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.code").value(200))
+                .andExpect(jsonPath("$.data[0].equipmentCode").value("CN-GS-202609020001"))
+                .andExpect(jsonPath("$.data[1].equipmentCode").value("CB-GS-202609020001"));
+    }
+}

+ 6 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/WaterSupply/MonitorAlarm/service/IWaterSupplyThresholdService.java

@@ -3,6 +3,7 @@ package com.zksy.WaterSupply.MonitorAlarm.service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zksy.WaterSupply.MonitorAlarm.dto.in.WaterThresholdSaveInDTO;
 import com.zksy.base.alarm.domain.WarningThreshold;
+import com.zksy.base.domain.EquipmentBase;
 
 import java.util.List;
 
@@ -23,6 +24,11 @@ public interface IWaterSupplyThresholdService {
      */
     List<WarningThreshold> findThresholdList(String deviceCode, String warningType, String warningCode);
 
+    /**
+     * 查询可配置阈值的供水监测设备
+     */
+    List<EquipmentBase> findThresholdDevices();
+
     /**
      * 根据ID查询阈值详情
      */

+ 12 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/WaterSupply/MonitorAlarm/service/impl/WaterSupplyThresholdServiceImpl.java

@@ -67,6 +67,13 @@ public class WaterSupplyThresholdServiceImpl extends ServiceImpl<WarningThreshol
         return this.list(wrapper);
     }
 
+    @Override
+    public List<EquipmentBase> findThresholdDevices() {
+        return waterEquipmentList().stream()
+                .filter(equipment -> StrUtil.isNotBlank(equipment.getEquipmentCode()))
+                .collect(Collectors.toList());
+    }
+
     @Override
     public WarningThreshold getThresholdDetail(String id) {
         WarningThreshold threshold = this.getById(id);
@@ -182,7 +189,7 @@ public class WaterSupplyThresholdServiceImpl extends ServiceImpl<WarningThreshol
     }
 
     private Set<String> resolveWaterDeviceCodes() {
-        List<EquipmentBase> equipmentList = equipmentBaseService.findByTopLevelType(waterTopLevelTypeName);
+        List<EquipmentBase> equipmentList = waterEquipmentList();
         if (CollUtil.isEmpty(equipmentList)) {
             return Collections.emptySet();
         }
@@ -193,6 +200,10 @@ public class WaterSupplyThresholdServiceImpl extends ServiceImpl<WarningThreshol
                 .collect(Collectors.toSet());
     }
 
+    private List<EquipmentBase> waterEquipmentList() {
+        return equipmentBaseService.findByTopLevelType(waterTopLevelTypeName);
+    }
+
     private List<String> splitDeviceCodes(String deviceCode) {
         if (StrUtil.isBlank(deviceCode)) {
             return Collections.emptyList();

+ 12 - 0
pipe-network-service/zksy-system/src/test/java/com/zksy/WaterSupply/MonitorAlarm/WaterSupplyThresholdServiceContractTest.java

@@ -287,6 +287,18 @@ class WaterSupplyThresholdServiceContractTest {
         assertFalse(values.contains("GAS-FLOW-1"));
     }
 
+    @Test
+    void thresholdDeviceOptionsOnlyContainWaterDevices() {
+        List<EquipmentBase> devices = service.findThresholdDevices();
+
+        assertEquals(Arrays.asList("WS-FLOW-1", "WS-FLOW-2", "WS-PRESSURE-1"), devices.stream()
+                .map(EquipmentBase::getEquipmentCode)
+                .collect(Collectors.toList()));
+        assertFalse(devices.stream()
+                .map(EquipmentBase::getEquipmentCode)
+                .anyMatch(code -> code.startsWith("YJ-")));
+    }
+
     @Test
     void pageReturnsEmptyDataWhenNoWaterDevicesExist() {
         when(equipmentBaseService.findByTopLevelType("供水")).thenReturn(Collections.emptyList());