Просмотр исходного кода

feat(cockpit): 字典端点透传风险与隐患六类字典

票 04(.scratch/cockpit-emergency-detail)。应急保障详情与预警详情的风险等级、
风险颜色、隐患类型/等级/来源/状态原来只拿得到码值,前端被迫内置第二份词表。

- /dict/{dictType} 白名单由 pump_station_type 扩到七类,新增 risk_level、risk_color、
  hazard_type、hazard_level、hazard_source、hazard_status
- 仍走 ISysDictTypeService.selectDictDataByType,读 sys_dict_data(status='0'、
  order by dict_sort),前后端都不落词表;契约外类型照旧返回空列表且不读库
- 测试:新增「六类逐类透传」与「契约外字典不读库」两条断言,CockpitDictControllerTest 4/4

zksy-admin 774 项全绿;zksy-system 4 项失败为既有红点
(CollectionRecordAssessmentServiceTest 2、LegacyPipeTableRetirementTest 1、
PipeNetworkStatusDictionaryContractTest 1),与本次改动无关。
Kazerin 3 дней назад
Родитель
Сommit
7b30ca773b

+ 6 - 1
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/cockpit/CockpitDictController.java

@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -22,7 +23,11 @@ import java.util.stream.Collectors;
 @RequestMapping("/api/cockpit/v1")
 public class CockpitDictController extends BaseCockpitController {
     /** 只透传驾驶舱契约需要的字典,避免把后台任意字典暴露到公开端点。 */
-    private static final List<String> ALLOWED = Collections.singletonList("pump_station_type");
+    private static final Set<String> ALLOWED = Set.of(
+            "pump_station_type",
+            // 风险评估与隐患台账:预警详情与应急保障详情的唯一词表来源(ADR 0010),前端不内置第二份。
+            "risk_level", "risk_color",
+            "hazard_type", "hazard_level", "hazard_source", "hazard_status");
 
     private final ISysDictTypeService dictTypeService;
 

+ 36 - 0
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitDictControllerTest.java

@@ -8,6 +8,7 @@ import org.springframework.test.web.servlet.MockMvc;
 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
 
 import java.util.Arrays;
+import java.util.Collections;
 
 import static org.mockito.Mockito.*;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -19,6 +20,14 @@ class CockpitDictControllerTest {
 
     @BeforeEach void setup() { mvc = MockMvcBuilders.standaloneSetup(new CockpitDictController(dictTypeService)).setControllerAdvice(new CockpitExceptionAdvice()).build(); }
 
+    private void stubPublished(String dictType, String dictValue, String dictLabel) {
+        SysDictData row = new SysDictData();
+        row.setDictType(dictType);
+        row.setDictValue(dictValue);
+        row.setDictLabel(dictLabel);
+        when(dictTypeService.selectDictDataByType(dictType)).thenReturn(Collections.singletonList(row));
+    }
+
     @Test void exposesPumpStationTypeDictionaryUnderCockpitDomain() throws Exception {
         SysDictData supply = new SysDictData(); supply.setDictType("pump_station_type"); supply.setDictValue("0"); supply.setDictLabel("供水泵站");
         SysDictData drainage = new SysDictData(); drainage.setDictType("pump_station_type"); drainage.setDictValue("1"); drainage.setDictLabel("排水泵站");
@@ -32,6 +41,33 @@ class CockpitDictControllerTest {
         verify(dictTypeService).selectDictDataByType("pump_station_type");
     }
 
+    @Test void exposesRiskAndHazardDictionariesUsedByDetailPanels() throws Exception {
+        String[][] samples = {
+                {"risk_level", "0", "重大风险"},
+                {"risk_color", "0", "红"},
+                {"hazard_type", "0", "腐蚀"},
+                {"hazard_level", "1", "一级隐患"},
+                {"hazard_source", "0", "巡检"},
+                {"hazard_status", "0", "整改中"},
+        };
+        for (String[] sample : samples) {
+            stubPublished(sample[0], sample[1], sample[2]);
+            mvc.perform(get("/api/cockpit/v1/dict/" + sample[0]))
+                    .andExpect(status().isOk())
+                    .andExpect(jsonPath("$.code").value(200))
+                    .andExpect(jsonPath("$.data.length()").value(1))
+                    .andExpect(jsonPath("$.data[0].dictValue").value(sample[1]))
+                    .andExpect(jsonPath("$.data[0].dictLabel").value(sample[2]));
+        }
+    }
+
+    @Test void dictionaryOutsideCockpitContractIsNotRead() throws Exception {
+        mvc.perform(get("/api/cockpit/v1/dict/equipment_type"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.length()").value(0));
+        verifyNoInteractions(dictTypeService);
+    }
+
     @Test void missingDictionaryIsEmptyNotError() throws Exception {
         when(dictTypeService.selectDictDataByType("unknown_type")).thenReturn(null);
         mvc.perform(get("/api/cockpit/v1/dict/unknown_type"))