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

fix(cockpit): 允许编码含斜杠的设备被按编码寻址(票120)

设备编码含字面斜杠(视频监控/排口+内涝点,如 41010500002000000004/34020000001310000002),前端取数须百分号编码 -> %2F。四层拦截:①Tomcat 连接器默认 400 拒绝 %2F;②Spring Security StrictHttpFirewall 默认拒绝编码斜杠 400;③AntPathMatcher 无法让路径变量跨 '/'(Spring UrlPathHelper 会把 %2F 解码成 '/' 拆段);④采集记录 Service 校验把 / 当非法。本仓必须保持 ant_path_matcher(springfox/Swagger 2.10.5 在 PathPatternParser 下 documentationPluginsBootstrapper 会 NPE),故不切匹配策略。修复:1) TomcatConnectorConfig encodedSolidusHandling=passthrough,保留 %2F 不解码;2) WebMvcUrlDecodeConfig 设 UrlPathHelper.urlDecode=false,匹配阶段不解码,%2F 作为普通字符留在单段、{deviceCode} 可整段匹配;3) CockpitHttpFirewallConfig 放开 allowUrlEncodedSlash/Percent;4) 采集记录 Service 校验不再拒绝 '/'(仍拒控制字符/空白/反斜杠/百分号)。各设备 Controller 已自解码路径变量。真实运行实例实测 detail-aggregate/archive/freshness/collection-records/metrics/work-orders/events 对带 / 设备均 200,普通设备与 map-snapshot 无回退。新增真实嵌入式 Tomcat 回归(passthrough+urlDecode=false 下 %2F->200)与防火墙默认/放开行为对照。
Kazerin 2 недель назад
Родитель
Сommit
e64e595b41

+ 3 - 1
pipe-network-service/pom.xml

@@ -41,6 +41,8 @@
         <mybatis-plus.version>3.5.7</mybatis-plus.version>
         <hutool.version>5.7.14</hutool.version>
         <minioutil.version>1.0.1</minioutil.version>
+        <!-- default: skip tests during ordinary builds; pass -DskipTests=false to run them -->
+        <skipTests>true</skipTests>
     </properties>
 
     <!-- 依赖声明 -->
@@ -269,7 +271,7 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
-                    <skipTests>true</skipTests>
+                    <skipTests>${skipTests}</skipTests>
                 </configuration>
             </plugin>
         </plugins>

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

@@ -282,6 +282,17 @@ class CockpitCollectionRecordsControllerTest {
         org.mockito.Mockito.verifyNoInteractions(equipmentMapper, recordsMapper);
     }
 
+    @Test
+    void deviceCodeWithSlashIsValidNotRejectedAsIllegal() throws Exception {
+        // 票 120:编码含 '/' 是合法业务编码(视频监控等),不得被当作「设备编码不合法」拒绝。
+        // 用 %2F 编码送入;服务解码后应接受该编码并继续按编码查库(此夹具无该设备 → 404「设备不存在」,
+        // 关键断言是**不是** 400「设备编码不合法」)。
+        String slashCode = "41010500002000000004/34020000001310000002";
+        mvc.perform(get("/api/cockpit/v1/equipments/" + slashCode.replace("/", "%2F") + "/collection-records"))
+                .andExpect(status().isNotFound())
+                .andExpect(jsonPath("$.data.stateReason").value("设备不存在"));
+    }
+
     static Map<String, Object> record(String time, String key, Object value) {
         Map<String, Object> record = new LinkedHashMap<>();
         record.put("create_time", time == null ? null : LocalDateTime.parse(time));

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

@@ -0,0 +1,186 @@
+package com.zksy.web.controller.cockpit;
+
+import com.zksy.base.domain.EquipmentBase;
+import com.zksy.base.domain.EquipmentType;
+import com.zksy.base.mapper.EquipmentBaseMapper;
+import com.zksy.base.mapper.EquipmentStatusMapper;
+import com.zksy.base.mapper.EquipmentTypeMapper;
+import com.zksy.base.perception.mapper.PerceptionMapper;
+import com.zksy.base.perception.service.impl.PerceptionServiceImpl;
+import com.zksy.base.warning.mapper.EquipmentWarningTypeMapper;
+import com.zksy.cockpit.collectionRecords.CockpitCollectionRecordsService;
+import org.apache.catalina.Context;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Tomcat;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.security.web.firewall.RequestRejectedException;
+import org.springframework.security.web.firewall.StrictHttpFirewall;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.web.servlet.DispatcherServlet;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+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;
+
+/**
+ * 真实嵌入式 Tomcat + 真防火墙回归(票 120)。编码含斜杠的设备要在四层都放行:
+ * 1) Tomcat 连接器 {@code encodedSolidusHandling=decode}(%2F→'/' 继续路由);
+ * 2) Spring Security StrictHttpFirewall 允许编码斜杠;
+ * 3) PathPatternParser + {@code {deviceCode:.+}} 映射跨 '/' 捕获;
+ * 4) Service 校验不再把 '/' 当非法。
+ * 生产由 PathPatternMatchingEnvironmentPostProcessor 强制 path_pattern_parser 匹配策略(覆盖 Nacos 的 ant_path_matcher)。
+ *
+ * <p>MockMvc 不经过连接器/防火墙,无法复现 %2F 的 400,故用真实 Tomcat + 原始 socket 断言 200。
+ */
+class CockpitEquipmentSlashCodeConnectorTest {
+
+    private static final String SLASH_CODE = "41010500002000000004/34020000001310000002";
+    private static Tomcat tomcat;
+    private static int port;
+
+    @BeforeAll
+    static void startTomcat() throws Exception {
+        port = freePort();
+        tomcat = new Tomcat();
+        tomcat.setBaseDir(System.getProperty("java.io.tmpdir"));
+        Connector connector = tomcat.getConnector();
+        connector.setPort(port);
+        // 与 TomcatConnectorConfig 一致:decode,让 %2F 变 '/' 交给 PathPatternParser
+        connector.setEncodedSolidusHandling("passthrough");
+        Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+        Tomcat.addServlet(ctx, "dispatcher", buildDispatcher());
+        ctx.addServletMappingDecoded("/*", "dispatcher");
+        tomcat.start();
+    }
+
+    private static DispatcherServlet buildDispatcher() {
+        EquipmentBaseMapper equipmentMapper = mock(EquipmentBaseMapper.class);
+        EquipmentTypeMapper typeMapper = mock(EquipmentTypeMapper.class);
+        PerceptionMapper recordsMapper = mock(PerceptionMapper.class);
+
+        EquipmentBase base = new EquipmentBase();
+        base.setEquipmentId("slash-uuid");
+        base.setEquipmentCode(SLASH_CODE);
+        base.setEquipmentTypeId(10);
+        when(equipmentMapper.selectOne(any())).thenReturn(base);
+        when(equipmentMapper.selectById("slash-uuid")).thenReturn(base);
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("firefighting_pressure");
+        when(typeMapper.selectById(10)).thenReturn(type);
+
+        Map<String, Object> rec = new LinkedHashMap<>();
+        rec.put("create_time", LocalDateTime.parse("2026-11-04T10:20:00"));
+        rec.put("pressure_value", 0);
+        rec.put("report_time", LocalDateTime.parse("2027-01-01T00:00:00"));
+        rec.put("id", "private-record-id");
+        when(recordsMapper.selectLatestRecords("firefighting_pressure", "telemetering_station", SLASH_CODE, 50))
+                .thenReturn(Collections.singletonList(rec));
+
+        EquipmentWarningTypeMapper indicators = mock(EquipmentWarningTypeMapper.class);
+        when(indicators.selectList(any())).thenReturn(Collections.emptyList());
+        PerceptionServiceImpl profile = new PerceptionServiceImpl();
+        ReflectionTestUtils.setField(profile, "equipmentBaseMapper", equipmentMapper);
+        ReflectionTestUtils.setField(profile, "equipmentTypeMapper", typeMapper);
+        ReflectionTestUtils.setField(profile, "equipmentStatusMapper", mock(EquipmentStatusMapper.class));
+        ReflectionTestUtils.setField(profile, "perceptionMapper", recordsMapper);
+        ReflectionTestUtils.setField(profile, "equipmentWarningTypeMapper", indicators);
+
+        CONTROLLER = new CockpitCollectionRecordsController(
+                new CockpitCollectionRecordsService(equipmentMapper, profile));
+
+        org.springframework.web.context.support.AnnotationConfigWebApplicationContext ac =
+                new org.springframework.web.context.support.AnnotationConfigWebApplicationContext();
+        ac.setServletContext(new org.springframework.mock.web.MockServletContext());
+        ac.register(TestConfig.class);
+        ac.refresh();
+        return new DispatcherServlet(ac);
+    }
+
+    private static CockpitCollectionRecordsController CONTROLLER;
+
+    @EnableWebMvc
+    static class TestConfig {
+        @org.springframework.context.annotation.Bean
+        CockpitCollectionRecordsController cockpitCollectionRecordsController() { return CONTROLLER; }
+
+        @org.springframework.context.annotation.Bean
+        static org.springframework.web.servlet.config.annotation.WebMvcConfigurer urlPathHelperConfigurer() {
+            return new org.springframework.web.servlet.config.annotation.WebMvcConfigurer() {
+                @Override
+                public void configurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer) {
+                    org.springframework.web.util.UrlPathHelper helper = new org.springframework.web.util.UrlPathHelper();
+                    helper.setUrlDecode(false); // 不对路径做 URL 解码,%2F 保持为普通字符(单段),交由 Controller 解码
+                    configurer.setUrlPathHelper(helper);
+                }
+            };
+        }
+    }
+
+    @AfterAll
+    static void stopTomcat() throws Exception {
+        if (tomcat != null) { tomcat.stop(); tomcat.destroy(); }
+    }
+
+    @Test
+    void encodedSlashDeviceCodeReturnsTwoHundredUnderPathPatternParser() throws Exception {
+        String response = rawGet("/api/cockpit/v1/equipments/"
+                + SLASH_CODE.replace("/", "%2F") + "/collection-records");
+        String statusLine = response.split("\\r?\\n", 2)[0];
+        assertTrue(statusLine.contains("200"),
+                "编码含斜杠的设备应返回 200,实际状态行: " + statusLine + " | body head: " + response.substring(0, Math.min(300, response.length())));
+        assertTrue(response.contains(SLASH_CODE), "响应应回显解码后的完整设备编码");
+        assertTrue(response.contains("READY"), "响应应带采集记录 READY 状态");
+    }
+
+    @Test
+    void defaultStrictHttpFirewallRejectsEncodedSlashButConfiguredOneAllows() {
+        String uri = "/api/cockpit/v1/equipments/" + SLASH_CODE.replace("/", "%2F") + "/collection-records";
+        assertThrows(RequestRejectedException.class, () -> {
+            MockHttpServletRequest req = new MockHttpServletRequest("GET", uri);
+            new StrictHttpFirewall().getFirewalledRequest(req);
+        });
+        StrictHttpFirewall configured = new StrictHttpFirewall();
+        configured.setAllowUrlEncodedSlash(true);
+        configured.setAllowUrlEncodedPercent(true);
+        assertDoesNotThrow(() -> {
+            MockHttpServletRequest req = new MockHttpServletRequest("GET", uri);
+            configured.getFirewalledRequest(req);
+        });
+    }
+
+    private static String rawGet(String path) throws Exception {
+        try (Socket socket = new Socket("127.0.0.1", port)) {
+            OutputStream out = socket.getOutputStream();
+            String request = "GET " + path + " HTTP/1.1\r\nHost: 127.0.0.1:" + port + "\r\nConnection: close\r\n\r\n";
+            out.write(request.getBytes(StandardCharsets.US_ASCII));
+            out.flush();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
+            StringBuilder sb = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); }
+            return sb.toString();
+        }
+    }
+
+    private static int freePort() throws Exception {
+        try (ServerSocket socket = new ServerSocket(0)) { return socket.getLocalPort(); }
+    }
+}

+ 31 - 0
pipe-network-service/zksy-framework/src/main/java/com/zksy/framework/config/CockpitHttpFirewallConfig.java

@@ -0,0 +1,31 @@
+package com.zksy.framework.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.web.firewall.HttpFirewall;
+import org.springframework.security.web.firewall.StrictHttpFirewall;
+
+/**
+ * Spring Security 防火墙放宽:允许 URL 路径中被编码的斜杠(%2F)与编码百分号(%25)。
+ *
+ * <p>背景(票 120):设备编码里可能含字面斜杠(如视频监控「41010500002000000004/34020000001310000002」),
+ * 前端按 {@code /equipments/{deviceCode}/...} 取数时必须把编码百分号编码,斜杠变成 {@code %2F}。
+ * Spring Boot 默认装配的 {@link StrictHttpFirewall} **默认拒绝被编码的斜杠**({@code allowUrlEncodedSlash=false}),
+ * 在请求进入 Spring MVC 之前就以 400 拒绝——这是设备详情「整包取不到」的最后一层拦截。
+ * 这里在默认严格防火墙基础上只放开「编码斜杠」与「编码百分号」,其余严格校验保留,
+ * 使这类设备能被按编码寻址,同时不整体降级安全策略。
+ *
+ * @author zksy
+ */
+@Configuration
+public class CockpitHttpFirewallConfig {
+
+    @Bean
+    public HttpFirewall httpFirewall() {
+        StrictHttpFirewall firewall = new StrictHttpFirewall();
+        // 允许 %2F(编码斜杠)与 %25(编码百分号),其余默认严格策略保持不变
+        firewall.setAllowUrlEncodedSlash(true);
+        firewall.setAllowUrlEncodedPercent(true);
+        return firewall;
+    }
+}

+ 29 - 0
pipe-network-service/zksy-framework/src/main/java/com/zksy/framework/config/TomcatConnectorConfig.java

@@ -0,0 +1,29 @@
+package com.zksy.framework.config;
+
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.stereotype.Component;
+
+/**
+ * 允许 URL 路径中出现被编码的斜杠(%2F)。
+ *
+ * <p>背景(票 120):部分设备编码本身含字面斜杠(如视频监控「41010500002000000004/34020000001310000002」)。
+ * 前端按 {@code /equipments/{deviceCode}/...} 取数时必须把编码做百分号编码,斜杠变成 {@code %2F}。
+ * Tomcat 默认在连接器层直接以 400「encoded slash not allowed」拒绝这类请求,请求根本到不了 Controller。
+ * 这里开启 {@code encodedSolidusHandling=passthrough},让 {@code %2F} 原样(不解码)交给 Spring MVC,
+ * 配合各设备端点把路径变量写成 {@code {deviceCode:.+}}(贪婪匹配,允许解码后的斜杠不当作路径分隔符),
+ * 这类设备即可被按编码寻址。此设置只放宽「解码后的斜杠」,不改其它安全/路由语义。
+ *
+ * @author zksy
+ */
+@Component
+public class TomcatConnectorConfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
+
+    @Override
+    public void customize(TomcatServletWebServerFactory factory) {
+        // Tomcat 9 用 encodedSolidusHandling=passthrough 保留 %2F 不解码(旧属性 allowEncodedSlash 在 9.x 已失效)。
+        // 配合 UrlPathHelper(urlDecode=false):%2F 作为普通字符留在单个路径段,AntPathMatcher {deviceCode} 可整段匹配,
+        // 再由 Controller 的 UriUtils.decode 还原成 '/'。
+        factory.addConnectorCustomizers(connector -> connector.setEncodedSolidusHandling("passthrough"));
+    }
+}

+ 31 - 0
pipe-network-service/zksy-framework/src/main/java/com/zksy/framework/config/WebMvcUrlDecodeConfig.java

@@ -0,0 +1,31 @@
+package com.zksy.framework.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.util.UrlPathHelper;
+
+/**
+ * 票 120:设备编码含字面斜杠(视频监控等)时,前端把编码百分号编码,斜杠成 {@code %2F}。
+ *
+ * <p>本仓 **必须保持 {@code ant_path_matcher}**(springfox/Swagger 2.10.5 在 PathPatternParser 下会 NPE),
+ * 而 AntPathMatcher 无法让路径变量跨 '/'。解决办法:连接器用 {@code passthrough} 保留 {@code %2F} 不解码,
+ * 再用 {@link UrlPathHelper#setUrlDecode(boolean) urlDecode=false} 让 Spring 在**匹配阶段不做 URL 解码**——
+ * 于是 {@code %2F} 作为普通字符留在同一个路径段里,{@code {deviceCode}} 能整段匹配(值里仍是 {@code %2F})。
+ * 各驾驶舱设备 Controller 已自行 {@code UriUtils.decode} 路径变量,届时会把 {@code %2F} 还原成 '/'。
+ *
+ * <p>影响面:全局关闭「路径匹配阶段的 URL 解码」。所有路径变量在匹配时保持原始编码;本仓路径变量为
+ * 设备/点位/工单编码与 id,均为 ASCII,且驾驶舱设备端点本就自行解码,故安全。查询串解码不受影响。
+ *
+ * @author zksy
+ */
+@Configuration
+public class WebMvcUrlDecodeConfig implements WebMvcConfigurer {
+
+    @Override
+    public void configurePathMatch(PathMatchConfigurer configurer) {
+        UrlPathHelper helper = new UrlPathHelper();
+        helper.setUrlDecode(false);
+        configurer.setUrlPathHelper(helper);
+    }
+}

+ 36 - 7
pipe-network-service/zksy-framework/src/main/java/com/zksy/framework/config/properties/PermitAllUrlProperties.java

@@ -1,10 +1,11 @@
 package com.zksy.framework.config.properties;
 
 import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
+import java.util.Set;
 import java.util.regex.Pattern;
 import org.apache.commons.lang3.RegExUtils;
 import org.springframework.beans.BeansException;
@@ -16,11 +17,18 @@ import org.springframework.core.annotation.AnnotationUtils;
 import org.springframework.web.method.HandlerMethod;
 import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
 import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
+import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition;
+import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
 import com.zksy.common.annotation.Anonymous;
 
 /**
  * 设置Anonymous注解允许匿名访问的url
- * 
+ *
+ * <p>票 120:路径匹配策略切到 {@code PathPatternParser} 后,{@code RequestMappingInfo} 改由
+ * {@code PathPatternsRequestCondition} 承载路径({@code getPatternsCondition()} 会返回 null),
+ * 因此这里同时兼容两种条件:优先取 PathPattern,再退回 Ant 的 PatternsCondition,
+ * 避免 {@code getPatternsCondition()} 为 null 时抛 NPE。语义不变。
+ *
  * @author zksy
  */
 @Configuration
@@ -45,16 +53,37 @@ public class PermitAllUrlProperties implements InitializingBean, ApplicationCont
 
             // 获取方法上边的注解 替代path variable 为 *
             Anonymous method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Anonymous.class);
-            Optional.ofNullable(method).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns())
-                    .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
+            Optional.ofNullable(method).ifPresent(anonymous ->
+                    patternsOf(info).forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
 
             // 获取类上边的注解, 替代path variable 为 *
             Anonymous controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Anonymous.class);
-            Optional.ofNullable(controller).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns())
-                    .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
+            Optional.ofNullable(controller).ifPresent(anonymous ->
+                    patternsOf(info).forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
         });
     }
 
+    /**
+     * 取一个映射的路径模式集合,兼容 PathPatternParser 与 AntPathMatcher 两种策略。
+     * 票 120:PathPatternParser 下 getPatternsCondition() 为 null,要用 PathPatternsRequestCondition。
+     */
+    private static Set<String> patternsOf(RequestMappingInfo info)
+    {
+        PathPatternsRequestCondition pathPatterns = info.getPathPatternsCondition();
+        if (pathPatterns != null)
+        {
+            Set<String> result = new LinkedHashSet<>();
+            pathPatterns.getPatterns().forEach(pattern -> result.add(pattern.getPatternString()));
+            return result;
+        }
+        PatternsRequestCondition antPatterns = info.getPatternsCondition();
+        if (antPatterns != null && antPatterns.getPatterns() != null)
+        {
+            return new LinkedHashSet<>(antPatterns.getPatterns());
+        }
+        return new LinkedHashSet<>();
+    }
+
     @Override
     public void setApplicationContext(ApplicationContext context) throws BeansException
     {
@@ -70,4 +99,4 @@ public class PermitAllUrlProperties implements InitializingBean, ApplicationCont
     {
         this.urls = urls;
     }
-}
+}

+ 3 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/collectionRecords/CockpitCollectionRecordsService.java

@@ -31,7 +31,9 @@ public class CockpitCollectionRecordsService {
             throw new CockpitInvalidRequestException("设备编码不能为空");
         }
         deviceCode = deviceCode.trim();
-        if (deviceCode.length() > 128 || deviceCode.matches(".*[\\x00-\\x20/\\\\%].*")) {
+        // 票 120:设备编码本身可能含字面斜杠(如视频监控「41010500002000000004/34020000001310000002」),
+        // 因此校验里**不再拒绝 '/'**;仍拒绝控制字符/空白与反斜杠、百分号,防止畸形或二次编码绕过。
+        if (deviceCode.length() > 128 || deviceCode.matches(".*[\\x00-\\x20\\\\%].*")) {
             throw new CockpitInvalidRequestException("设备编码不合法");
         }
         EquipmentBase equipment = equipmentMapper.selectOne(new QueryWrapper<EquipmentBase>()